<template>
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" append-to-body :close-on-click-modal="false">
    <el-form ref="dataForm" :rules="rules" :model="deviceForm" label-well-code="right" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="12" >
          <el-form-item label="产品名称" prop="productName">
            <el-input v-model.trim="deviceForm.productName" :disabled="isEditMode" type="text" placeholder="必填"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品型号" prop="productModel">
            <el-input v-model.trim="deviceForm.productModel" :disabled="isEditMode" type="text" placeholder="必填"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12" >
          <el-form-item label="设计归档" prop="kpi">
            <el-input v-model.trim="deviceForm.designArchive" :disabled="isEditMode" type="textarea" placeholder="必填" rows = "4"/>
          </el-form-item>
        </el-col>
        <el-col :span="12" >
          <el-form-item label="批产归档" prop="kpi">
            <el-input v-model.trim="deviceForm.batchFiling" :disabled="isEditMode" type="textarea" placeholder="必填" rows = "4"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12" >
          <el-form-item label="性能指标" prop="kpi">
            <el-input v-model.trim="deviceForm.kpi" :disabled="isEditMode" type="textarea" placeholder="必填" rows = "4"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { getDeviceTypeKpi } from '@/api/devicetype'
export default {
  name: 'CheckDeviceParameter',
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      dialogStatus: '', // 对话框类型：create,update
      deviceForm: {
        productName: '',
        productModel: '',
        designArchive: '',
        batchFiling: '',
        kpi: ''
      }, // 表单
      textMap: {
        update: '编辑',
        create: '新增',
        detail: '设备参数'
      }, // 表头显示标题
      rules: {
      }, // 前端校验规则
      isEditMode: false
    }
  },
  watch: {
  },
  mounted() {
  },
  methods: {
    // 初始化对话框
    initDialog: function(dialogStatus, dialogFormVisible, row = null) {
      this.dialogStatus = dialogStatus
      this.dialogFormVisible = dialogFormVisible
      if (dialogStatus === 'detail') { // 如果是修改，将row中数据填写到输入框中
        this.deviceForm = {
          productName: row.productName,
          productModel: row.productModel,
          designArchive: row.designArchive,
          batchFiling: row.batchFiling,
          kpi: ''
        }
        this.fetchDeviceTypeKpi(row.id)
        this.isEditMode = true
      }
    },
    // 重置表单
    resetForm() {
      this.deviceForm = {
        productName: '',
        productModel: '',
        designArchive: '',
        batchFiling: '',
        kpi: ''
      }
    },
    fetchDeviceTypeKpi(id) {
      getDeviceTypeKpi(id).then(response => {
        this.deviceForm.kpi = response.data.kpi
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-select{
    width: 100%;
  }
  .el-date-editor{
    width: 100%;
  }
</style>
