<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="上报时间：">
         <el-date-picker
          style="margin-top:5px;;width:340px"
          v-model="dateRange"
          size="small"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="处理状态">
        <el-select v-model.trim="queryParams.status"  size="small" style="width:120px">
          <el-option value="0" label="未处理"></el-option>
          <el-option value="1" label="已处理"></el-option>
        </el-select>
      </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-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:admin:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="20">
      <el-col :span="2.4">
        <el-col class="event">
            事件总数<span class="color1 colorc">{{collectList.total}}</span>
        </el-col>
      </el-col>
      <el-col :span="2.4">
        <el-col class="event">
            已处理数<span class="color2 colorc">{{collectList.checkCount}}</span>
        </el-col>
      </el-col>
      <el-col :span="2.4" >
        <el-col class="event">
            未处理数<span class="color3 colorc">{{collectList.noCheckCount}}</span>
        </el-col>
      </el-col>
      <el-col :span="2.4">
        <el-col class="event">
            处置率
            <span class="color4 colorc " v-if="collectList.checkRadio">{{Number((collectList.checkRadio)*100).toFixed(1)}}%</span>
        </el-col>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="adminList" style="margin-top:20px;" height="calc(100vh - 34vh)">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="单位名称" align="center" prop="companyName" show-overflow-tooltip />
      <el-table-column label="设备名称" align="center" prop="deviceName" show-overflow-tooltip />
      <el-table-column label="报告内容" align="center" prop="alarmContent" show-overflow-tooltip />
      <el-table-column label="隐患类型" align="center" prop="property" show-overflow-tooltip />
      <el-table-column label="上报时间" align="center" prop="createTime" show-overflow-tooltip />
      <!-- <el-table-column label="是否误报" align="center" prop="isAlarm" >
        <template slot-scope="scope">
          <span :class="scope.row.isAlarm == true ? 'color3' : 'color4'">{{scope.row.isAlarm == true ? "是" : "否"}}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="处理状态" align="center" prop="alarmStatus" show-overflow-tooltip >
        <template slot-scope="scope">
          <span :class="scope.row.alarmStatus == 0 ? 'color3' : 'color4'">{{scope.row.alarmStatus == 0 ? "未处理" : "已处理"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理内容" align="center" prop="checkContent" show-overflow-tooltip />
      <el-table-column label="处理人" align="center" prop="updateBy" show-overflow-tooltip />
      <el-table-column label="处理时间" align="center" prop="updateTime" show-overflow-tooltip />
      <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="['system:admin:edit']"
          >处置</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :before-close="cancel" :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="auto" >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="单位名称" prop="companyName">
              <el-input v-model="form.companyName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="设备名称" prop="deviceName">
              <el-input v-model="form.deviceName" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" >
            <el-form-item label="报告内容" prop="alarmContent">
              <el-input v-model="form.alarmContent" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="误报" prop="isAlarm">
              <el-radio v-model="form.isAlarm" :label="false">否</el-radio>
              <el-radio v-model="form.isAlarm" :label="true">是</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" >
            <el-form-item label="批量处理" >
              <el-radio v-model="piliang" :label="false">否</el-radio>
              <el-radio v-model="piliang" :label="true">是</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理内容" prop="checkContent">
              <el-input  type="textarea" rows="5" maxlength="50" show-word-limit  v-model.trim="form.checkContent" placeholder="请填写处理内容" @input="onInput()"/>
            </el-form-item>
          </el-col>
        </el-row>
      </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>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
    <!-- 导出-->
    <a href="" download="" id="xz" style="position: absolute;z-index: -1;opacity: 0;"></a>
  </div>
</template>
<script>
import { addTbAlarm, delTbAlarm, updateTbAlarm, getTbAlarm, exportTbAlarm, updateTbAlarmP,collectTbAlarm } from "@/api/business/OM/eventCenter";
import { BASEPATH } from "@/assets/js/common.js";
export default {
  name: "TbAlarm",
  data() {
    return {
      piliang:false,
      exportLoading:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      adminList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        name: undefined,
        type:1
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

      },
      // 日期范围
      dateRange: [],
      //综合数据
      collectList:[

      ]
    };
  },
  created() {
    this.getList();//初始化table
    this.getCollect();//初始化table
  },
  methods: {
    //强制el-input刷新
    onInput(){
        this.$forceUpdate();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        name:undefined,
        current:1,
        size:10,
        type:1
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      let data = this.addDateRange(this.queryParams,this.dateRange)
      if(JSON.stringify(data.params) == "{}"){
        delete data.params
      }else{
        data.endTime = data.params.endTime
        data.startTime = data.params.beginTime
      }
      getTbAlarm(data).then(response => {
        this.adminList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 综合列表列表 */
    getCollect(){
      collectTbAlarm({type:1}).then(response => {
        this.collectList = response.data
      });
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      if(row.isAlarm === true){
        row.isAlarm = true
      }else{
        row.isAlarm = false
      }
      this.title = "处置";
      this.form = JSON.parse(JSON.stringify(row))
      this.open = true;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增";
    },
    /** 提交按钮 */
    submitForm(row) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true
          let data = this.form
          if (this.form.id != undefined) {
            this.form.alarmStatus = 1
            if(this.piliang === true){
              updateTbAlarmP(data).then(response => {
                this.loading = false,
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).catch(()=>{
                this.loading = false,
                this.open = false;
              })
            }else{
              updateTbAlarm(data).then(response => {
                this.loading = false,
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).catch(()=>{
                this.loading = false,
                this.open = false;
              })
            }

          }
        }
      });
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.id || this.ids;
    //   this.$confirm('是否确认删除', "警告", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }).then(function() {
    //       return delTbAlarm(ids);
    //     }).then(() => {
    //       this.getList();
    //       this.msgSuccess("删除成功");
    //     }).catch(() => {});
    // },


    /** 导出按钮操作 */
    handleExport() {
      let queryParams = {...this.queryParams};
      delete queryParams.current
      delete queryParams.size
      this.exportLoading = true;
      exportTbAlarm(queryParams).then(response =>{
        this.exportLoading = false;
        document.getElementById("xz").href = BASEPATH() + response.data
        document.getElementById("xz").download = response.data
        document.getElementById("xz").click()
      })
    },
  }
};
</script>

