<template>
  <el-dialog title="选择巡检设备" :visible.sync="visible" width="55%" style="height:100%" @close="handleClose" :close-on-click-modal="false" append-to-body>
    <el-row class="card-page">
      <el-form label-width="0px" :model="form" ref="ruleForm">
        <el-col :span="24">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="设备类型" prop="type">
              <el-select v-model="queryParams.type" placeholder="请选择">
                <el-option v-for="item in dict.type.device_type" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="设备名称" prop="patroldeviceName">
              <el-input v-model="queryParams.patroldeviceName" placeholder="请输入设备名称" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="设备编码" prop="patroldeviceCode">
              <el-input v-model="queryParams.patroldeviceCode" placeholder="请输入设备编码" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="生产厂家" prop="manufacturer">
              <el-input v-model="queryParams.manufacturer" placeholder="请输入生产厂家" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>

          <el-table v-loading="loading" :data="eqpbookList" @row-click="handleCurrentChange" :multiple="false" highlight-current-row>
            <el-table-column label="设备名称" width="100" align="center" prop="patroldeviceName" fixed />
            <el-table-column label="设备编码" width="100" align="center" prop="patroldeviceCode" fixed />
            <el-table-column label="视频NVR编码" width="100" align="center" prop="videoNvrCode" fixed />
            <el-table-column label="生产厂家" width="100" align="center" prop="manufacturer" fixed />
            <el-table-column label="主系统编号" width="100" align="center" prop="mainSystemCode" fixed />
            <el-table-column label="变电站名称" width="150" align="center" prop="stationName" />
            <el-table-column label="变电站编码" width="100" align="center" prop="stationCode" />
            <el-table-column label="区域名称" width="150" align="center" prop="areaName" />
            <el-table-column label="设备类型" width="100" align="center" prop="type">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.device_type" :value="scope.row.type" />
              </template>
            </el-table-column>

            <el-table-column label="设备型号" width="100" align="center" prop="deviceModel" />
            <el-table-column label="使用单位" width="100" align="center" prop="useUnit" />
            <el-table-column label="设备来源" width="100" align="center" prop="deviceSource" />
            <el-table-column label="生产日期" width="100" align="center" prop="productionDate" />
            <el-table-column label="出厂编号" width="100" align="center" prop="productionCode" />
            <el-table-column label="是否轮转" width="100" align="center" prop="istransport">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.is_transport" :value="scope.row.istransport" />
              </template>
            </el-table-column>
            <el-table-column label="使用类型" width="100" align="center" prop="useMode">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.use_mode" :value="scope.row.useMode" />
              </template>
            </el-table-column>
            <el-table-column label="视频类型" width="100" align="center" prop="videoMode">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.video_mode" :value="scope.row.videoMode" />
              </template>
            </el-table-column>

            <el-table-column label="所属机器人" width="100" align="center" prop="robotsCode" />
            <el-table-column label="ip地址" width="200" align="center" prop="ipAddr" />
            <el-table-column label="端口" width="100" align="center" prop="port" />
            <el-table-column label="用户" width="100" align="center" prop="user" />
            <el-table-column label="密码" width="100" align="center" prop="password" />

          </el-table>

          <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

        </el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer card-page">
      <el-button @click="eventOk" :disabled="loading" type="primary">确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  listEqpbook
} from "@/api/basedata/eqpbook/eqpbook";
import linq from 'linq'
export default {
  dicts: ["device_type", "video_mode", "use_mode", "is_transport"],
  props: {
    show: {
      type: Boolean,
      default: false,
    }
  },
  watch: {
    show (newVal) {
      this.visible = newVal
      if (newVal === true) {
        this.getList();
      }
    }
  },
  data () {
    return {
      currentRow: null,
      total: 0,
      loading: false,
      // 基础数据-设备台账主表格数据
      eqpbookList: [],
      form: {
        algList: []
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stationName: null,
        stationCode: null,
        areaName: null,
        patroldeviceName: null,
        patroldeviceCode: null,
        deviceModel: null,
        manufacturer: null,
        useUnit: null,
        deviceSource: null,
        productionDate: null,
        productionCode: null,
        istransport: null,
        useMode: null,
        videoMode: null,
        place: null,
        positionX: null,
        positionY: null,
        positionZ: null,
        type: null,
        patroldeviceInfo: null,
        robotsCode: null,
        ipAddr: null,
        port: null,
        user: null,
        password: null,
        video_mode: null,
        use_mode: null,
        is_transport: null,
      },
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      visible: false,
      algList: [],/* 算法类型 */
      alertTitle: "设置智能识别类型", /* 弹窗标题 */
      rules: {
        algId: [{ required: true, message: "必选", trigger: "blur" }],
        algSubtypeId: [{ required: true, message: "必选", trigger: "blur" }],
        upperValue: [{ required: true, message: "必选", trigger: "blur" }],
        lowerValue: [{ required: true, message: "必选", trigger: "blur" }],
      }
    }
  },
  created () {


  },
  computed: {
  },
  methods: {
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleCurrentChange (row) {
      this.currentRow = row;
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.eqpbookId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查询基础数据-设备台账主列表 */
    getList () {
      this.loading = true;
      listEqpbook(this.queryParams).then((response) => {
        this.eqpbookList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //弹窗关闭事件
    handleClose () {
      // 重置表单
      this.resetForm('queryForm');
      this.visible = false;
      this.$emit('update:show', false)
    },
    //选择好智能识别类型后的事件
    eventOk () {
      const me = this;
      if (this.currentRow === null) {
        this.$message({
          type: 'warning',
          message: '请选中一行数据。'
        })
        return;
      }
      me.visible = false;
      this.$emit('confirm', this.currentRow)
    }
  }
}
</script>
