<!-- 随手拍 -->
<template>
  <div class="app-container snapshot">
    <div class="page-container snapshotPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <div class="table-school-college-toggle-box">
            <p :class="tableButtonCheckType==null?'p-check':''" @click="tableCheck(null)">全部</p>
            <p :class="tableButtonCheckType==0?'p-check':''" @click="tableCheck(0)">待整改</p>
            <p :class="tableButtonCheckType==1?'p-check':''" @click="tableCheck(1)">已整改</p>
            <p :class="tableButtonCheckType==2?'p-check':''" @click="tableCheck(2)">暂无法整改</p>
          </div>
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="学院单位" style="width: 160px">
              <el-option
                v-for="dict in deptOptions"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="实验室/房间号"
              style="width: 160px"
            />
          </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>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-hasPermiRouter="['security:photo:add']"
          >上报</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <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="120" show-overflow-tooltip/>
          <el-table-column label="上报时间" 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"  show-overflow-tooltip/>
          <el-table-column label="整改人" prop="rectifyUserName" width="100" show-overflow-tooltip/>
          <el-table-column label="处理时间" prop="rectifyTime" width="130" 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="整改状态" prop="rectifyStatus" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.rectifyStatus == 0?'待整改':(scope.row.rectifyStatus == 1?'已完成':(scope.row.rectifyStatus == 2?'暂无法整改':''))}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="130" 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(2,scope.row)"
                >详情</p>
                <p class="table-button-p"
                   v-if="scope.row.rectifyStatus == 0"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['security:photo:del']"
                >删除</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 {
    securityCheckPhotoMyList,
    securityCheckPhotoDelete,
  } from '@/api/safetyCheck/index'
  import {
    getDeptDropList,
  } from '@/api/commonality/permission'
  import snapshotInfo from "@/views/safetyCheck/components/snapshotInfo.vue";
  export default {
    name: 'index',
    components: {
      snapshotInfo
    },
    data () {
      return {
        //页面状态
        pageType:1,
        //整改状态选项卡
        tableButtonCheckType:null,
        //页面遮罩
        loading:false,
        //下拉列表数据
        deptOptions:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
          deptId :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getDeptDropList();
      this.getList();
    },
    methods: {
      //整改状态选项卡切换
      tableCheck(type){
        if (this.tableButtonCheckType !== type){
          this.$set(this,'tableButtonCheckType',type);
          this.resetQuery();
        }
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
          deptId :null,
        });
        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.tableButtonCheckType
        securityCheckPhotoMyList(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:false,
            rectify:false,
          });
          this.$set(this,'pageType',2);
        }else if(type == 2){
          //详情
          this.$set(this,'propsData',{
            showType:true,
            rectify:false,
            photoId:row.photoId
          });
          this.$set(this,'pageType',2);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityCheckPhotoDelete({photoId:row.photoId}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      /** 查询二级单位列表 */
      getDeptDropList() {
        getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptOptions', response.data)
        })
      },
    },
  }
</script>
<style scoped lang="scss">
  .snapshot{
    .snapshotPage{
      .table-school-college-toggle-box{
        overflow: hidden;
        display: inline-block;
        margin-right:10px;
        p{
          display: inline-block;
          text-align: center;
          width:100px;
          line-height:40px;
          height:40px;
          color:#333;
          background-color: #fff;
          border:1px solid #E0E0E0;
          font-size:14px;
          cursor: pointer;
        }
        p:nth-child(1){
          border-top-left-radius: 4px;
          border-bottom-left-radius: 4px;
          /*border-right:none;*/
        }
        p:nth-child(4){
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
          /*border-left:none;*/
        }
        .p-check{
          border:1px solid #0183FA;
          background-color: #0183FA;
          color:#fff;
        }
      }
    }
  }
</style>
