<template>
  <div class="app-container warningNotice">
    <div class="warningNotice-page" v-if="pageType == 1">
      <div class="title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true" label-width="80px">
          <el-form-item label="预警类型" prop="deptId" label-width="100px">
            <el-select v-model="queryParams.warningType" clearable placeholder="全部" style="width:150px;">
              <el-option
                v-for="item in selectListA"
                :key="item.key"
                :label="item.value"
                :value="item.key">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="预警方式" prop="deptId">
            <el-select v-model="queryParams.warningWay" clearable placeholder="全部" style="width:150px;">
              <el-option
                v-for="item in selectListB"
                :key="item.key"
                :label="item.value"
                :value="item.key">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="预警时间" prop="dateRange" style="margin-left:10px;" label-width="70px">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <p class="inquire-button-one" @click="handleQuery" style="margin-right:10px;">查询</p>
            <p class="reset-button-one" @click="resetQuery">重置</p>
          </el-form-item>
          <el-form-item style="float: right;">
            <el-col :span="1.5">
              <p class="inquire-button-one"
                 style="width:100px;"
                 @click="goPage(3)"
              >危险源预警</p>
            </el-col>
          </el-form-item>
          <el-form-item style="float: right;">
            <el-col :span="1.5">
              <p class="inquire-button-one"
                 style="width:100px;"
                 @click="goPage(2)"
              >算法预警</p>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <div class="content-box">
        <el-table  border :data="tableList" ref="multipleTable">
          <el-table-column label="预警时间" align="center" prop="warningTime" show-overflow-tooltip/>
          <el-table-column label="预警类型" align="center" prop="warningType" show-overflow-tooltip width="300">
            <template slot-scope="scope">
              <div class="table-button-box">
                <span v-if="scope.row.warningType==1">算法识别</span>
                <span v-if="scope.row.warningType==2">化学品</span>
                <span v-if="scope.row.warningType==3">气瓶</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="预警内容" align="center" prop="warningContent" show-overflow-tooltip width="300"/>
          <el-table-column label="预警方式" align="center" prop="warningWay" show-overflow-tooltip width="300"/>
          <el-table-column label="实验室" sortable="custom" align="center" prop="subName" show-overflow-tooltip width="300"/>
          <el-table-column label="操作" align="center" prop="deptName" width="150">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" @click="clickPage(4,scope.row)">详情</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <algorithmForewarning v-if="pageType == 2"></algorithmForewarning>
    <sourceOfDangerForewarning v-if="pageType == 3"></sourceOfDangerForewarning>
    <infoPage :pageData="pageData" v-if="pageType == 4"></infoPage>
  </div>
</template>

<script>
  import {warningNoticeLogList} from "@/api/laboratory/warningNotice";
  import algorithmForewarning from './algorithmForewarning.vue'
  import sourceOfDangerForewarning from './sourceOfDangerForewarning.vue'
  import infoPage from './infoPage.vue'
  export default {
    name: 'index',
    components: {
      algorithmForewarning,
      sourceOfDangerForewarning,
      infoPage
    },
    data(){
      return{
        pageType:1,
        selectListA:[{key:'0',value:"全部"},{key:"1",value:"算法识别"},{key:"2",value:"化学品"},{key:"3",value:"气瓶"}],
        selectListB:[{key:"",value:"全部"},{key:"1",value:"系统通知"},{key:"2",value:"短信通知"},{key:"3",value:"声光报警"},{key:"4",value:"语音播报"},{key:"5",value:"电话通知"}],
        queryParams:{
          pageNum: 1,
          pageSize:20,
          warningType:'0',//预警类型
          warningWay:'',//预警方式
          warningStartTime:'',
          warningEndTime:'',
        },
        dateRange:[],
        tableList:[],
        total:0,
        pageData:{},
      }
    },
    created(){

    },
    mounted(){
        this.getList()
    },
    methods:{
      goPage(type){
        if(type != this.pageType){
          this.$set(this,'pageType',type);
        }
        if(type==1){
          this.getList()
        }
      },
      //详情
      clickPage(type,row){
        this.pageData.id=row.id
        this.$set(this,'pageType',type);

      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.warningStartTime = this.dateRange[0];
        }else{
          obj.warningStartTime = "";
        }
        if(this.dateRange[1]){
          obj.warningEndTime = this.dateRange[1];
        }else{
          obj.warningEndTime = "";
        }
        warningNoticeLogList(obj).then(response => {
          this.total = response.data.total;
          //处理预警方式
          for(let i=0;i<response.data.records.length;i++){
            if(response.data.records[i].warningWay!='' && response.data.records[i].warningWay!=null){
              response.data.records[i].warningWay=response.data.records[i].warningWay.replace(/1/, "系统通知")
              response.data.records[i].warningWay=response.data.records[i].warningWay.replace(/2/, "短信通知")
              response.data.records[i].warningWay=response.data.records[i].warningWay.replace(/3/, "声光报警")
              response.data.records[i].warningWay=response.data.records[i].warningWay.replace(/4/, "语音播报")
              response.data.records[i].warningWay=response.data.records[i].warningWay.replace(/5/, "电话通知")
              if (response.data.records[i].warningWay.endsWith(',')) {
                response.data.records[i].warningWay=response.data.records[i].warningWay.replace(/,/, " ")
              }
              response.data.records[i].warningWay= response.data.records[i].warningWay.replace(/,/g, "+");

            }else{
              response.data.records[i].warningWay='-'
            }
          }
          this.tableList = response.data.records;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'pageNum',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          pageNum:1,
          pageSize:20,
          warningType:'',//预警类型
          warningWay:'',//预警方式
          warningStartTime:'',
          warningEndTime:'',
        });
        this.handleQuery();
      },
    }
  }
</script>

<style scoped lang="scss">
  .warningNotice{
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    .warningNotice-page{
      flex: 1;
      display: flex !important;
      flex-direction: column;
      overflow: hidden;
      .title-box{
        margin-top:20px;
        border-bottom:1px solid #dedede;
      }
      .content-box{
        padding:20px;
        flex: 1;
        display: flex !important;
        flex-direction: column;
        overflow: hidden;
      }
    }
  }
</style>
