<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
     <el-row>
       <el-col :span="8">
         <el-form-item label="端口号" prop="portNo">
           <el-input
             v-model="queryParams.portNo"
             placeholder="请输入报警设备端口号"
             clearable
             @keyup.enter.native="handleQuery"
           />
         </el-form-item>
       </el-col>
       <el-col :span="8">
         <el-form-item label="协议类型" prop="protocol">
           <el-input
             v-model="queryParams.protocol"
             placeholder="请输入协议类型"
             clearable
             @keyup.enter.native="handleQuery"
           />
         </el-form-item>
       </el-col>
       <el-col :span="8">
         <el-form-item label="通道名称" prop="channelName">
           <el-input
             v-model="queryParams.channelName"
             placeholder="请输入通道名称"
             clearable
             @keyup.enter.native="handleQuery"
           />
         </el-form-item>
       </el-col>
       <el-col :span="8">
        <el-form-item label="状态表" prop="statusResult">
          <el-input
            v-model="queryParams.statusResult"
            placeholder="请输入状态表状态"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
       </el-col>
       <el-col :span="8">
         <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-col>
     </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manage:dialIndicator:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manage:dialIndicator:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manage:dialIndicator:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manage:dialIndicator:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dialIndicatorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="协议类型" align="center" prop="protocol" />
      <el-table-column label="通道名称" align="center" prop="channelName" />
      <el-table-column label="事件类型" align="center" prop="eventType" />
      <el-table-column label="设备编号" align="center" prop="deviceUuid" />
      <el-table-column label="报警图片" align="center" prop="photo" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:dialIndicator:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manage:dialIndicator:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改计报警记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="报警设备IPv4地址" prop="ipAddress">
          <el-input v-model="form.ipAddress" placeholder="请输入报警设备IPv4地址" />
        </el-form-item>
        <el-form-item label="报警设备端口号" prop="portNo">
          <el-input v-model="form.portNo" placeholder="请输入报警设备端口号" />
        </el-form-item>
        <el-form-item label="协议类型" prop="protocol">
          <el-input v-model="form.protocol" placeholder="请输入协议类型" />
        </el-form-item>
        <el-form-item label="触发报警的设备通道号" prop="channelId">
          <el-input v-model="form.channelId" placeholder="请输入触发报警的设备通道号" />
        </el-form-item>
        <el-form-item label="通道名称" prop="channelName">
          <el-input v-model="form.channelName" placeholder="请输入通道名称" />
        </el-form-item>
        <el-form-item label="设备ID" prop="deviceId">
          <el-input v-model="form.deviceId" placeholder="请输入设备ID" />
        </el-form-item>
        <el-form-item label="设备编号" prop="deviceUuid">
          <el-input v-model="form.deviceUuid" placeholder="请输入设备编号" />
        </el-form-item>
        <el-form-item label="场景ID" prop="sceneId">
          <el-input v-model="form.sceneId" placeholder="请输入场景ID" />
        </el-form-item>
        <el-form-item label="规则ID" prop="ruleId">
          <el-input v-model="form.ruleId" placeholder="请输入规则ID" />
        </el-form-item>
        <el-form-item label="标定集ID" prop="tagsetId">
          <el-input v-model="form.tagsetId" placeholder="请输入标定集ID" />
        </el-form-item>
        <el-form-item label="报警图片" prop="photo">
          <el-input v-model="form.photo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="当前读数值" prop="readingResult">
          <el-input v-model="form.readingResult" placeholder="请输入当前读数值" />
        </el-form-item>
        <el-form-item label="状态表状态 " prop="statusResult">
          <el-input v-model="form.statusResult" placeholder="请输入状态表状态" />
        </el-form-item>
        <el-form-item label="指示灯当前读数值" prop="pilotLampstate">
          <el-input v-model="form.pilotLampstate" placeholder="请输入指示灯当前读数值" />
        </el-form-item>
        <el-form-item label="8朝向旋钮当前读数值 " prop="eightPositionSelectorKnobTate">
          <el-input v-model="form.eightPositionSelectorKnobTate" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="空开当前读数值" prop="airSwitchCircuitBreakerState">
          <el-input v-model="form.airSwitchCircuitBreakerState" placeholder="请输入空开当前读数值 0#空开向下, 1#空开向上" />
        </el-form-item>
        <el-form-item label="压板当前读数值 " prop="relayProtectionControllerState">
          <el-input v-model="form.relayProtectionControllerState" placeholder="请输入压板当前读数值 0#压板开, 1#压板合" />
        </el-form-item>
        <el-form-item label="硅胶筒当前读数值" prop="silicaGelBreatherState">
          <el-input v-model="form.silicaGelBreatherState" placeholder="请输入硅胶筒当前读数值 0#硅胶筒未变色, 1#硅胶筒变色" />
        </el-form-item>
        <el-form-item label="字符当前读数值" prop="charactersState">
          <el-input v-model="form.charactersState" placeholder="请输入字符当前读数值 0#字符分, 1#字符合, 2#字符0, 3#字符1, 4#字符OFF, 5#字符ON, 6#字符未储能, 7#字符已储能" />
        </el-form-item>
        <el-form-item label="断路器当前读数值" prop="circuitBreakerState">
          <el-input v-model="form.circuitBreakerState" placeholder="请输入断路器当前读数值 0#断路器分, 1#断路器合, 2#断路器0, 3#断路器1, 4#断路器OFF, 5#断路器ON, 6#断路器未储能, 7#断路器已储能" />
        </el-form-item>
        <el-form-item label="刀闸当前读数值" prop="knifeSwitchState">
          <el-input v-model="form.knifeSwitchState" placeholder="请输入刀闸当前读数值 0#刀闸开" />
        </el-form-item>
        <el-form-item label="开集类型当前读数值" prop="openSetTypeState">
          <el-input v-model="form.openSetTypeState" placeholder="请输入开集类型当前读数值 0#开集类型开, 1#开集类别关" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDialIndicator, getDialIndicator, delDialIndicator, addDialIndicator, updateDialIndicator } from "@/api/manage/dialIndicator"

export default {
  name: "DialIndicator",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 计报警记录表格数据
      dialIndicatorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ipAddress: null,
        portNo: null,
        protocol: null,
        channelId: null,
        channelName: null,
        eventType: null,
        deviceId: null,
        deviceUuid: null,
        sceneId: null,
        ruleId: null,
        tagsetId: null,
        photo: null,
        readingType: null,
        readingResult: null,
        statusResult: null,
        pilotLampstate: null,
        eightPositionSelectorKnobTate: null,
        airSwitchCircuitBreakerState: null,
        relayProtectionControllerState: null,
        silicaGelBreatherState: null,
        charactersState: null,
        circuitBreakerState: null,
        knifeSwitchState: null,
        openSetTypeState: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询计报警记录列表 */
    getList() {
      this.loading = true
      listDialIndicator(this.queryParams).then(response => {
        this.dialIndicatorList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        logId: null,
        ipAddress: null,
        portNo: null,
        protocol: null,
        channelId: null,
        channelName: null,
        eventType: null,
        deviceId: null,
        deviceUuid: null,
        sceneId: null,
        ruleId: null,
        tagsetId: null,
        photo: null,
        readingType: null,
        readingResult: null,
        statusResult: null,
        pilotLampstate: null,
        eightPositionSelectorKnobTate: null,
        airSwitchCircuitBreakerState: null,
        relayProtectionControllerState: null,
        silicaGelBreatherState: null,
        charactersState: null,
        circuitBreakerState: null,
        knifeSwitchState: null,
        openSetTypeState: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.logId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加计报警记录"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const logId = row.logId || this.ids
      getDialIndicator(logId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改计报警记录"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.logId != null) {
            updateDialIndicator(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addDialIndicator(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const logIds = row.logId || this.ids
      this.$modal.confirm('是否确认删除计报警记录编号为"' + logIds + '"的数据项？').then(function() {
        return delDialIndicator(logIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manage/dialIndicator/export', {
        ...this.queryParams
      }, `dialIndicator_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
