<template>
  <!-- 工程管理页面 -->
  <div class="app-container">
    <!-- 表格 -->
    <TableModel
      :formLabel="formLabel"
      :columnsList="columnsList"
      :request-api="queryDeviceListApi"
      ref="tableRef"
      @transIdList="getIdList"
    >
      <template slot="btn" slot-scope="{ queryParams }">
        <el-button type="primary" @click="handleAddData()" icon="el-icon-plus" size="mini"
        >新增设备</el-button
        >
        <el-button
          @click="handleExportData(
                    exportList,
                    'base/tbDevice/export',
                    '设备清单',
                    queryParams
                  )"
          icon="el-icon-upload2"
          size="mini"
        >导出数据</el-button
        >
      </template>
      <template slot="handle" slot-scope="{ data }">
        <el-button
          type="primary"
          size="mini"
          @click="handleEditData(data)"
        >编辑</el-button
        >
        <el-button
          type="danger"
          size="mini"
          @click="handleDeleteData(data.id, deleteDeviceApi)"
        >删除</el-button
        >
      </template>
<!--      <template slot="isMatch" slot-scope="{ data }">
        {{ data.proId == null ? '不匹配' : '匹配' }}
      </template>-->
      <template slot="configName" slot-scope="{ data }">
        <span
          style="color:blue;"
        >{{ data.configName }}</span>
      </template>
      <template slot="configName" slot-scope="{ data }">
        <span
          style="color:blue;"
        >{{ data.configName || '-' }}</span>
      </template>

      <template slot="devStatusName" slot-scope="{ data }">
        <span
          v-if="data.devStatusName === '在线'"
          style="color: #11AB21;"
        >{{ data.devStatusName }}</span>
        <span
          v-if="data.devStatusName === '离线'"
          style="color: darkgrey;"
        >{{ data.devStatusName }}</span>
        <span
          v-if="data.devStatusName === '未知状态'"
          style="color: bisque;"
          >{{ data.devStatusName }}</span>
      </template>
    </TableModel>

    <!-- 新增以及修改时的弹框 -->
    <DialogModel
      :dialogConfig="dialogConfig"
      @closeDialogOuter="closeDialogOuter"
    >
      <template slot="outerContent">
        <!-- 新增以及修改数据的表单组件 -->
        <FormDevice
          :editParams="editParams"
          @closeDialog="closeDialog"
        />
      </template>
    </DialogModel>

  </div>
</template>

<script>
import { formLabel, columnsList, dialogConfig, queryDeviceTypes } from './config'
import { commonMixin } from '../mixins/common'
import {
  queryDeviceListApi,
  deleteDeviceApi
} from '@/api/base/device'
import FormDevice from './components/form-device.vue'
export default {
  name: 'Device',
  methods: {
    queryDeviceListApi,
    deleteDeviceApi,
    getIdList(idList) {
      this.exportList = []
      idList.forEach(item => {
        this.exportList.push(item.id)
      })
    },
    // handleAddData() {
    //   this.editParams = {
    //     submitType: 'add',
    //     deviceId: this.deviceAddData.id
    //   }
    //   this.dialogConfig.outerTitle = '新增设备'
    //   this.dialogConfig.outerVisible = true
    // },
    // handleEditData(data) {
    //   data.submitType = 'edit'
    //   this.editParams = data
    //   this.dialogConfig.outerTitle = '修改设备'
    //   this.dialogConfig.outerVisible = true
    // },
  },

    // closeDialog(type) {
    //       this.dialogConfig.outerVisible = false
    //       if(type) {
    //         this.$refs.tableRef.getTableList()
    //       }
    //     },
    //   closeDialogOuter() {
    //     this.dialogConfig.outerVisible = false
    //   },
  mixins: [commonMixin],
  components: {
    FormDevice
  },
  created() {
    queryDeviceTypes()
  },
  data() {
    return {
      // 搜索区表单配置项
      formLabel,
      // 表格导出id列表
      exportList: [],
      // 列表区配置项
      columnsList,
      // 弹框区配置项
      dialogConfig,
      // 新建时弹框标题
      addDialogTitle: '新增设备',
      // 修改时弹框标题
      editDialogTitle: '修改设备',
      editParams: undefined,
    }
  },
}
</script>
