<template>
  <el-dialog width="70%" title="设备详情" :visible.sync="dialogFormVisible" top="10vh" append-to-body>
    <el-descriptions class="margin-top" title="" :column="2" border>
      <el-descriptions-item v-if="deviceForm.deviceName " label="设备名称">
        {{ deviceForm.deviceName }}
      </el-descriptions-item>
      <el-descriptions-item label="设备编号">
        {{ deviceForm.devcode }}
      </el-descriptions-item>
      <el-descriptions-item label="设备类型">
        {{ deviceForm.deviceTypeName }}
      </el-descriptions-item>
      <el-descriptions-item label="设备型号">
        {{ deviceForm.modelName }}
      </el-descriptions-item>
      <el-descriptions-item label="安装日期">
        {{ deviceForm.installDate }}
      </el-descriptions-item>
      <el-descriptions-item label="在线状态">
        <span :style="{color:deviceForm.onlineState=='0'?'#909399':'#67C23A'}">{{ deviceForm.onlineStateName }}
        </span>
      </el-descriptions-item>
      <el-descriptions-item label="电量">
        <span :style="{color:deviceForm.cell<'20'?'#f62c45':'#67C23A'}">{{ deviceForm.cell }}
        </span>
      </el-descriptions-item>
      <el-descriptions-item label="安装高度">
        {{ deviceForm.installHeight?deviceForm.installHeight+' m':'--' }}
      </el-descriptions-item>
      <el-descriptions-item label="点位编号">
        {{ deviceForm.wellCode }}
      </el-descriptions-item>
      <el-descriptions-item label="权属单位">
        {{ deviceForm.deptName }}
      </el-descriptions-item>
      <!--      <el-descriptions-item label="布防状态">-->
      <!--        {{ deviceForm.bfztName }}-->
      <!--      </el-descriptions-item>-->
      <el-descriptions-item label="关联集中器编号">
        {{ deviceForm.concenCode }}
      </el-descriptions-item>
      <el-descriptions-item label="位置" :span="2">
        {{ deviceForm.position }}
      </el-descriptions-item>
    </el-descriptions>
    <component :is="cmpName" v-if="showData" ref="dataDetail" :devcode="deviceForm.devcode" />
  </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 listWellcoverData from './components/listWellcoverData'
import listHydrantData from './components/listHydrantData'
import listWellLocaData from './components/listWellLocaData'
import ListH2SData from './components/listH2SData'
import SingleGasDetectorData from '@/views/deviceManage/components/listGasDetectorData'

export default {
  name: 'EditDevice',
  components: {
    SingleGasDetectorData,
    ListH2SData,
    listDigData,
    listGasData,
    listHarmfulData,
    listLiquidData,
    listLiquidGasData,
    listNoiseData,
    listTempData,
    listTubeData,
    listWellcoverData,
    listWellLocaData,
    listHydrantData
  },
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      dialogStatus: '', // 对话框类型：create,update,detail
      showData: true, // 是否显示近期数据
      cmpName: '', // 组件名称
      deviceForm: {
        id: '',
        deviceName: '',
        devcode: '',
        deviceType: '',
        wellCode: '',
        modelId: '',
        installDate: '',
        concenCode: '',
        installHeight: ''
      }, // 表单
      compDict: {
        '1': 'list-wellcover-data',
        '2': 'list-liquid-data',
        '3': 'list-harmful-data',
        '4': 'list-gas-data',
        '5': 'list-temp-data',
        '6': 'list-dig-data',
        '7': 'list-well-loca-data',
        '8': 'list-noise-data',
        '9': 'list-temp-press-data',
        '10': 'list-liquid-gas-data',
        '11': 'list-hydrant-data',
        '12': 'list-tube-data',
        '14': 'list-h2-s-data'
        // '101': 'single-gas-detector-data'
      } // 组件对照表
    }
  },
  methods: {
    // 初始化对话框
    initDialog: function(dialogStatus, row = null) {
      this.dialogFormVisible = true
      this.deviceForm = {
        id: row.id,
        deviceName: row.deviceName,
        devcode: row.devcode,
        deviceType: row.deviceType,
        deviceTypeName: row.deviceTypeName,
        wellCode: row.wellCode,
        modelName: row.modelName,
        installDate: row.installDate,
        concenCode: row.concenCode,
        onlineStateName: row.onlineStateName,
        deptName: row.deptName,
        bfztName: row.bfztName,
        position: row.position
      }
      // 展示相对应的设备列表组件
      this.cmpName = this.compDict[row.deviceType]
      setTimeout(() => {
        this.$refs.dataDetail.init()
      }, 100)
    }
  }
}
</script>

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