<!-- 预警事件 -->
<template>
  <div class="app-container earlyWarningEvent">
    <div class="page-container earlyWarningEventPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="请选择学院" style="width: 200px">
              <el-option
                v-for="item in deptOptions"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="floorId">
            <el-cascader
              placeholder="请选择楼栋楼层"
              :props="{value: 'id', label: 'name',children:'buildFloorVoList',checkStrictly: true}"
              v-model="queryParams.buildIdAndfloorId"
              :options="buildFloorOptions">
            </el-cascader>
          </el-form-item>
          <el-form-item label="" prop="state">
            <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 label="" prop="queryParamsData1">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="实验室/房间号/预警事件/姓名"
              style="width: 220px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="报警时间" prop="createTime" width="180" fixed show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.warnTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="预警类型" prop="content" width="200" fixed show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.warnType==1?'化学品预警':(scope.row.warnType==2?'气瓶预警':'算法预警')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="预警事件" prop="warnContent" width="625" show-overflow-tooltip/>
          <el-table-column label="学院" prop="deptName" width="200" show-overflow-tooltip/>
          <el-table-column label="楼栋楼层" prop="content" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.buildName}}-{{scope.row.floorName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="实验室" prop="content" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.subName}}-{{scope.row.roomNum}}</span>
            </template>
          </el-table-column>
          <el-table-column label="安全员" prop="safeInfoStr" width="200" show-overflow-tooltip/>
          <el-table-column label="操作" width="100" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                   v-if="scope.row.noticeStatus==0 && scope.row.isHandlePeople"
                   v-hasPermiRouter="['warning:event:edit']"
                >处理</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-if="scope.row.noticeStatus==0 && scope.row.isHandlePeople==false"
                   v-hasPermiRouter="['warning:event:detail']"
                >详情</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-if="scope.row.noticeStatus!=0 "
                   v-hasPermiRouter="['warning:event:detail']"
                >详情</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.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <info-page :propsData="propsData" v-if="pageType === 2"></info-page>
  </div>
</template>
<script>
  import infoPage from "./infoPage.vue";
  import { getDeptDropList,systemBuildingGetTreeList,} from "@/api/commonality/permission";
  import {
    systemWarningNoticeDetail,
    systemWarningNoticeList,
    systemWarningNoticeWarningDetail, systemWarningNoticeWarningList
  } from '@/api/chemicalManage'
  export default {
    name: 'index',
    components: {
     infoPage
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['warning:event:edit','warning:event:detail']),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //学院
        deptOptions:[],
        //楼栋楼层
        buildFloorOptions:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
          deptId :null,
          buildId :null,
          buildIdAndfloorId :[],
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getDeptDropList();
      this.systemBuildingGetTreeList();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        if (this.queryParams.buildIdAndfloorId[0]){
          if (this.queryParams.buildIdAndfloorId.length ==1){
            this.$set(this.queryParams,'buildId',this.queryParams.buildIdAndfloorId[0]);
          }else if (this.queryParams.buildIdAndfloorId.length ==2){
            this.$set(this.queryParams,'buildId',this.queryParams.buildIdAndfloorId[0]);
            this.$set(this.queryParams,'floorId',this.queryParams.buildIdAndfloorId[1]);
          }
        }
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
          deptId :null,
          buildId :null,
          floorId :null,
          buildIdAndfloorId :[],
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        systemWarningNoticeWarningList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        if(type == 2 || type == 3){
          //详情
           systemWarningNoticeDetail({id:row.noticeId}).then(response => {
            this.$set(this,'propsData',JSON.parse(JSON.stringify(response.data)));
            this.$set(this,'pageType',2);
          });
        }else if(type == 'out'){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      //查询学院列表
      getDeptDropList(){
        getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
          this.$set(this, 'deptOptions', response.data)
        });
      },
      //查询楼栋楼层
      systemBuildingGetTreeList(){
        systemBuildingGetTreeList({}).then(response => {
          if (response.data[0]) {
            let list = this.forBuildFloor(response.data);
            let newList = [];
            for(let i=0;i<list.length;i++){
              if(list[i].buildFloorVoList){
                for(let o=0;o<list[i].buildFloorVoList.length;o++){
                  if(list[i].buildFloorVoList[o].buildFloorVoList){
                    newList.push(list[i].buildFloorVoList[o])
                  }
                }
              }
            }
            this.$set(this, 'buildFloorOptions', newList)
          }
        })
      },
      //处理楼栋楼层数据
      forBuildFloor(list){
        let self = this;
        for(let i=0;i<list.length;i++){
          if(list[i].buildFloorVoList){
            if(list[i].buildFloorVoList[0]){
              list[i].buildFloorVoList = self.forBuildFloor(list[i].buildFloorVoList);
            }else{
              delete list[i].buildFloorVoList;
            }
          }else{
            delete list[i].buildFloorVoList;
          }
        }
        return list
      },
    },
  }
</script>
<style scoped lang="scss">
  .earlyWarningEvent{
    .earlyWarningEventPage{

    }
  }
</style>
