<template>
  <el-dialog width="70%" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" append-to-body>
    <el-form ref="dataForm" :model="deviceForm" label-well-code="right" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="设备编号" prop="devcode">
            <el-input v-model.trim="deviceForm.devcode" disabled type="text" placeholder="必填" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="安装日期" prop="installDate">
            <el-date-picker
              v-model.trim="deviceForm.installDate"
              disabled
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="设备类型" prop="deviceType">
            <el-select v-model="deviceForm.deviceType" disabled placeholder="请选择设备类型">
              <el-option
                v-for="item in deviceTypeList"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="设备型号" prop="modelId">
            <el-select v-model="deviceForm.modelId" disabled placeholder="请选择设备型号">
              <el-option
                v-for="item in deviceModelList"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="井编号" prop="wellCode">
            <el-input v-model.trim="deviceForm.wellCode" disabled type="text" placeholder="必填" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="安装高度(m)" prop="installHeight">
            <el-input v-model.trim="deviceForm.installHeight" disabled type="text" placeholder="必填" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <component :is="cmpName" ref="deviceTypeDialog" @watchChild="fetchDeviceList" />
  </el-dialog>
</template>

<script>
import listDigData from './components/listDigData'
import listGasData from './components/listGasData'
import listHarmfulData from './components/listHarmfulData'
import listLiquidData from './components/listLiquidData'
import listLiquidGasData from './components/listLiquidGasData'
import listNoiseData from './components/listNoiseData'
import listTempData from './components/listTempData'
import listTubeData from './components/listTubeData'
import listWellData from './components/listWellData'
import listWellLocaData from './components/listWellLocaData'

export default {
  name: 'EditDevice',
  components: {
    listDigData,
    listGasData,
    listHarmfulData,
    listLiquidData,
    listLiquidGasData,
    listNoiseData,
    listTempData,
    listTubeData,
    listWellData,
    listWellLocaData
  },
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      dialogStatus: '', // 对话框类型：create,update,detail
      cmpName: '', // 组件名称
      deviceForm: {
        id: '',
        deviceName: '',
        devcode: '',
        deviceType: '',
        wellCode: '',
        modelId: '',
        installDate: '',
        concenCode: '',
        installHeight: ''
      }, // 表单
      textMap: {
        update: '编辑',
        create: '新增',
        detail: '详情'
      }, // 表头显示标题
      deviceTypeList: null, // 设备类型列表
      deviceModelList: null // 设备型号列表
    }
  },
  methods: {
    // 初始化对话框
    initDialog: function(dialogStatus, dialogFormVisible, row = null) {
      this.dialogStatus = dialogStatus
      this.dialogFormVisible = dialogFormVisible
      this.resetForm()
      this.deviceForm = {
        id: row.id,
        deviceName: row.deviceName,
        devcode: row.devcode,
        deviceType: row.deviceType,
        modelId: row.modelId,
        wellCode: row.wellCode,
        concenCode: row.concenCode,
        installDate: row.installDate,
        installHeight: row.installHeight
      }
      // 展示相对应的设备列表组件
      if (row.deviceTypeName === '开挖监测仪') {
        this.cmpName = 'list-dig-data'
      } else if (row.deviceTypeName === '井盖状态监测仪') {
        this.cmpName = 'list-well-data'
      } else if (row.deviceTypeName === '液位监测仪') {
        this.cmpName = 'list-liquid-data'
      } else if (row.deviceTypeName === '燃气智能监测终端') {
        this.cmpName = 'list-gas-data'
      } else if (row.deviceTypeName === '噪声记录仪') {
        this.cmpName = 'list-noise-data'
      } else if (row.deviceTypeName === '有害气体监测仪') {
        this.cmpName = 'list-harmful-data'
      } else if (row.deviceTypeName === '温湿度监测仪') {
        this.cmpName = 'list-temp-data'
      } else if (row.deviceTypeName === '井盖定位监测仪') {
        this.cmpName = 'list-well-loca-data'
      } else if (row.deviceTypeName === '燃气智能终端（一体化）') {
        this.cmpName = 'list-liquid-gas-data'
      } else if (row.deviceTypeName === '管盯') {
        this.cmpName = 'list-tube-data'
      }
      setTimeout(() => {
        this.$refs.deviceTypeDialog.initData(row)
      }, 100)
    },
    fetchDeviceList() {},
    // 重置表单
    resetForm() {
      this.deviceForm = {
        id: '',
        deviceName: '',
        devcode: '',
        deviceType: '',
        wellCode: '',
        modelId: '',
        installDate: '',
        concenCode: '',
        installHeight: ''
      }
    }
  }
}
</script>

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