<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.type"  size="small" style="width:120px">
          <el-option value="1" label="消防隐患"></el-option>
          <el-option value="2" label="消防告警"></el-option>
          <el-option value="3" 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="eventName" show-overflow-tooltip />
      <el-table-column label="事件类型" align="center" prop="eventType" show-overflow-tooltip >
        <template slot-scope="scope">
          <span :class="scope.row.eventType == 1 ? 'color1' : scope.row.eventType == 2 ? 'color2' : 'color3'">{{scope.row.eventType  == 1 ? '消防隐患' : scope.row.eventType  == 2 ? '消防告警' : '设备设施'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="报告内容" align="center" prop="eventContent" show-overflow-tooltip />
      <el-table-column label="上报时间" align="center" prop="reportingTime" show-overflow-tooltip />
      <el-table-column label="处理状态" align="center" prop="clzt" >
        <template slot-scope="scope">
          <span :class="scope.row.clzt == 0 ? 'color3' : 'color4'">{{scope.row.clzt == 0 ? "未处理" : "已处理"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="处置内容" align="center" prop="clContent" show-overflow-tooltip />
      <el-table-column label="处理人" align="center" prop="clPeople" show-overflow-tooltip />
      <el-table-column label="处理时间" align="center" prop="clTiem" 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>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:admin:remove']"
          >删除</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"  @input="onInput()" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="报告内容" prop="eventContent">
              <el-input v-model="form.eventContent"  @input="onInput()" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="处理内容" prop="clContent">
              <el-input  type="textarea" rows="5" maxlength="50" show-word-limit  v-model.trim="form.clContent" 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 { addEventManage, delEventManage, updateEventManage, getEventManage, exportEventManage, collectEventManage } from "@/api/business/OM/eventCenter";
import { BASEPATH } from "@/assets/js/common.js";
// import { listChannel } from "@/api/system/product";
export default {
  name: "EventManage",
  data() {
    return {
      exportLoading:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      adminList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        name: undefined,
      },
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {

      },
      //综合数据
      collectList:[

      ],
      //单位列表 =>表单
      companyList:[

      ],
    };
  },
  created() {
    this.getList();//初始化table
    this.getCollect();//初始化table
    // this.company();//初始化单位选项
    // this.facilityType();//初始化类别选项
  },
  methods: {
    //强制el-input刷新
    onInput(){
        this.$forceUpdate();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        name:undefined,
        current:1,
        size:10,
      }
      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
      }
      getEventManage(data).then(response => {
        this.adminList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 综合列表列表 */
    getCollect(){
      collectEventManage().then(response => {
        this.collectList = response.data
        if(!this.collectList.checkRadio){
          this.collectList.checkRadio = 0
        }
      });
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      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
          this.form.clzt = 1
          // this.form.addr1 = this.form.data2.value
          // this.form.addr2 = this.form.data3.value
          // this.form.addr3 = this.form.data4.value
          // this.form.data2 = this.form.data2.label
          // this.form.data3 = this.form.data3.label
          // this.form.data4 = this.form.data4.label
          if (this.form.id != undefined) {
            updateEventManage(this.form).then(response => {
              this.loading = false,
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).catch(()=>{
              this.loading = false
            })
          } else {
            addEventManage(this.form).then(response => {
              this.loading = false,
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).catch(()=>{
              this.loading = 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;
      exportEventManage(queryParams).then(response =>{
        this.exportLoading = false;
        document.getElementById("xz").href = BASEPATH() + response.data
        document.getElementById("xz").download = response.data
        document.getElementById("xz").click()
      })
    },

    /** 公司下拉列表 */
    company(){
      listChannel(this.queryParams).then(response => {
        if(response.data.records.length>0){
          this.companyList = response.data.records.map(val =>{
            return {
              id:val.ownerId,
              name:val.ownerName,
              address:val.ownerAddress,
            }
          })
        }
      });
    },
  }
};
</script>

<style>
.event{
  border:1px solid #ccc;
  padding:1.5vh 0;
  font-size:0.9vw;
}
.colorc{
  font-size:1.2vw;
  margin-left:4px;
}
.color1{
  color:#6F99FA!important;
}
.color2{
  color:#DE8C54!important
}
.color3{
  color:#FF5801!important
}
.color4{
  color:#37FF01!important
}
</style>
