<template>
  <el-dialog
    v-model="dialogFormVisible"
    :title="title"
    width="500px"
    @close="close"
  >
    <el-form ref="form" :model="form" label-width="100px" label-position="left">
      <el-form-item label="属性种类">
        <el-select
          v-model="type"
          placeholder="请选择属性种类"
          @change="getType"
        >
          <el-option
            v-for="item in typeData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="show" label="功能码">
        <el-select v-model="form.functionCode" placeholder="请选择功能码">
          <el-option
            v-for="item in codeData"
            :key="item.dataCode"
            :label="item.dataValue"
            :value="item.dataCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="show" label="数据格式">
        <el-select v-model="form.dataFormat" placeholder="请选择数据格式">
          <el-option
            v-for="item in formatData"
            :key="item.dataCode"
            :label="item.dataValue"
            :value="item.dataCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <vab-query-form>
        <el-button type="primary" @click="save">保存</el-button>
      </vab-query-form>
    </el-form>
  </el-dialog>
</template>

<script>
import {
  selectDataFormat,
  selectFunctionCode,
  getDictData,
} from '@/api/sensor';
export default {
  name: 'Parameter',
  data() {
    return {
      type: 0,
      show: false,
      dialogFormVisible: false,
      title: '',
      codeData: [],
      formatData: [],
      typeData: [
        {
          value: 0,
          label: '请选择属性种类',
        },
        {
          value: 1,
          label: 'Modbus RTU',
        },
        {
          value: 2,
          label: '请选择属性种类',
        },
      ],
      form: {
        functionCode: '',
        dataFormat: '',
      },
    };
  },
  created() {},
  methods: {
    getType(value) {
      if (value == 1) {
        this.show = true;
      } else {
        this.show = false;
      }
    },
    showEdit() {
      this.title = '参数配置';
      this.dialogFormVisible = true;
      this.getDictData();
    },
    async getDictData() {
      const { data } = await getDictData();
      this.codeData = data.functionCode;
      this.formatData = data.formatData;
    },
    save() {
      this.$emit('getParameter', this.form);
      this.dialogFormVisible = false;
    },
  },
};
</script>
