<!-- 随手拍隐患 -->
<template>
  <div class="app-container snapshotHazard">
    <div class="page-container snapshotHazardPage" v-if="pageType === 1">
      <div class="top-table-button-box">
        <div :class="rectifyStatus === null ? 'tableCheck':''" @click="tableCheck(null)">
          <p>全部</p>
          <p></p>
        </div>
        <div :class="rectifyStatus === 0 ? 'tableCheck':''" @click="tableCheck(0)">
          <p>待整改</p>
          <p></p>
        </div>
        <div :class="rectifyStatus === 1 ? 'tableCheck':''" @click="tableCheck(1)">
          <p>已整改</p>
          <p></p>
        </div>
        <div :class="rectifyStatus === 2 ? 'tableCheck':''" @click="tableCheck(2)">
          <p>暂无法整改</p>
          <p></p>
        </div>
      </div>
      <div class="page-form-title-box" style="border:none;">
        <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: 150px">
              <el-option
                v-for="dict in deptOption"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="buildId">
            <el-select v-model="queryParams.buildId" placeholder="楼栋" style="width: 150px">
              <el-option
                v-for="dict in buildOption"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="typeId">
            <el-select v-model="queryParams.typeId" placeholder="安全分类" style="width: 150px">
              <el-option
                v-for="dict in classOption"
                :key="dict.typeId"
                :label="dict.typeName"
                :value="dict.typeId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="levelId">
            <el-select v-model="queryParams.levelId" placeholder="安全分级" style="width: 150px">
              <el-option
                v-for="dict in levelOption"
                :key="dict.levelId"
                :label="dict.levelName"
                :value="dict.levelId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="实验室/房间号"
              style="width: 150px"
            />
          </el-form-item>
          <el-form-item label="" prop="rectifyUserName">
            <el-input
              maxLength="30"
              v-model="queryParams.rectifyUserName"
              placeholder="整改人"
              style="width: 150px"
            />
          </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>
          <!--与我相关-->
          <div class="form-button-max-big-box-me">
            <div class="form-button-big-box-me">
              <div :class="queryParams.myRelated==1?'checkDiv-me':''" @click="topRightClickType">
                <p class="text-p-me">与我相关</p>
                <p class="el-icon-check icon-p-me" v-if="queryParams.myRelated==1"></p>
              </div>
            </div>
          </div>
          <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" style="padding-top:0;">
        <el-table class="table-box" ref="tableBox" v-loading="loading" border :data="dataList" @sort-change="sortChange">
          <el-table-column label="序号" type="index" width="60"/>
          <el-table-column label="实验室" prop="subName" width="220" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.subName}}{{scope.row.subRoom?'('+scope.row.subRoom+')':''}}</span>
            </template>
          </el-table-column>
          <el-table-column label="学院单位" prop="deptName" width="150" show-overflow-tooltip/>
          <el-table-column label="实验室负责人" prop="adminName" width="130" show-overflow-tooltip/>
          <el-table-column label="上报人" prop="createName" width="100" show-overflow-tooltip/>
          <el-table-column label="上报时间" sortable="custom" prop="createTime" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="隐患描述" prop="hazardDescribe" width="350" show-overflow-tooltip/>
          <el-table-column label="整改状态" prop="rectifyStatus" width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.rectifyStatus == 1?'已完成':(scope.row.rectifyStatus == 2?'暂无法整改':'待整改')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="整改人" prop="rectifyUserName" width="100" show-overflow-tooltip/>
          <el-table-column label="处理时间" sortable="custom" prop="rectifyTime" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.rectifyTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" show-overflow-tooltip >
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(1,scope.row)"

                >详情</p>
                <p class="table-button-p"
                   v-if="scope.row.canRectify && scope.row.rectifyStatus == 0"
                   @click="tableButton(2,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.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <snapshotInfo :propsData="propsData" v-if="pageType === 2"></snapshotInfo>
  </div>
</template>
<script>
  import {
    getDeptDropList,
    systemBuildingGetOptList,
    laboratoryClassLevelGetList,
    laboratoryClassTypeGetList,
  } from '@/api/commonality/permission'
  import {
    securityCheckPhotoList
  } from "@/api/safetyCheck/index";
  import snapshotInfo from "@/views/safetyCheck/components/snapshotInfo.vue";
  export default {
    name: 'index',
    components: {
      snapshotInfo
    },
    data () {
      return {
        //页面状态
        pageType:1,
        //选项卡状态
        rectifyStatus:null,
        //页面遮罩
        loading:false,
        //学院
        deptOption:[],
        //楼栋
        buildOption:[],
        //分级
        levelOption:[],
        //分类
        classOption:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          myRelated:1,
          deptId:null,
          buildId:null,
          typeId :null,
          levelId :null,
          searchValue:'',
          rectifyUserName:'',
          upTimeOrder:'',
          rectifyTimeOrder:'',
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getList();
      this.getDeptDropList();
      this.systemBuildingGetOptList();
      this.laboratoryClassLevelGetList();
      this.laboratoryClassTypeGetList();
    },
    methods: {
      //选项卡切换
      tableCheck(type){
        if (this.rectifyStatus !== type){
          this.$set(this,'rectifyStatus',type);
          this.resetQuery();
        }
      },
      //与我相关按钮
      topRightClickType(){
        this.$set(this.queryParams,'myRelated',this.queryParams.myRelated==1?0:1);
        this.handleQuery();
      },
      //时间排序方法
      sortChange(val){
        console.log('val',val)
        if(val.prop == 'createTime'){
          this.$set(this.queryParams,'upTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'rectifyTimeOrder','');
          this.handleQuery();
        }else if(val.prop == 'rectifyTime'){
          this.$set(this.queryParams,'rectifyTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.$set(this.queryParams,'upTimeOrder','');
          this.handleQuery();
        }
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          myRelated:1,
          deptId:null,
          buildId:null,
          typeId :null,
          levelId :null,
          searchValue:'',
          rectifyUserName:'',
          upTimeOrder:'',
          rectifyTimeOrder:'',
        });
        this.$refs.tableBox.clearSort();
        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 = "";
        }
        obj.rectifyStatus = this.rectifyStatus;
        securityCheckPhotoList(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){
        let self = this;
        if(type == 1){
          //详情
          this.$set(this,'propsData',{
            showType:true,
            rectify:false,
            photoId:row.photoId
          });
          this.$set(this,'pageType',2);
        }else if(type == 2){
          //编辑
          this.$set(this,'propsData',{
            showType:false,
            rectify:true,
            photoId:row.photoId
          });
          this.$set(this,'pageType',2);
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      /*********************************** 学院/楼栋/分类/分级 ***********************************/
      //学院下拉列表
      getDeptDropList(){
        getDeptDropList({level: 2, deptType: 1 }).then(response => {
          this.$set(this,'deptOption',response.data);
        });
      },
      //楼栋下拉列表
      systemBuildingGetOptList(){
        systemBuildingGetOptList({}).then(response => {
          this.$set(this,'buildOption',response.data);
        });
      },
      //分级下拉列表
      laboratoryClassLevelGetList(){
        laboratoryClassLevelGetList({}).then(response => {
          this.$set(this,'levelOption',response.data);
        });
      },
      //分类下拉列表
      laboratoryClassTypeGetList(){
        laboratoryClassTypeGetList({}).then(response => {
          this.$set(this,'classOption',response.data);
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .snapshotHazard{
    .snapshotHazardPage{
      .top-table-button-box{
        display: flex;
        padding:0 40px;
        border-bottom: 1px solid #dedede;
        div{
          cursor: pointer;
          padding:20px 0 20px 0;
          margin-right:30px;
          p:nth-child(1){
            font-size:16px;
            color:#333;
            padding:0 15px;
            line-height:36px;
            height:36px;
          }
          p:nth-child(2){
            height:4px;
            border-radius:4px;
          }
        }
        .tableCheck{
          p:nth-child(1){
            color:#0045AF;
          }
          p:nth-child(2){
            background-color: #0045AF;
          }
        }
      }
      .form-button-max-big-box-me{
        display: inline-block;
        overflow: hidden;
        margin-right:10px;
        .form-button-big-box-me{
          display: flex;
          div{
            position: relative;
            height:40px;
            width:100px;
            line-height: 40px;
            text-align: center;
            color:#999;
            font-size:14px;
            border:1px solid #999;
            border-radius:4px;
            font-weight:500;
            cursor: pointer;
            .icon-p-me{
              width:15px;
              height:15px;
              line-height:15px;
              text-align: center;
              position: absolute;
              right:0;
              bottom:0;
              color:#fff;
              background: #0183fa;
              border-top-left-radius:4px;
            }
          }
          .checkDiv-me{
            color:#0183FA!important;
            border:1px solid #0183FA!important;
          }
        }
      }
    }
  }
</style>
