<template>
  <div class="app-container rectificationReport">
    <div class="page-container" v-if="pageType == 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true" label-width="80px">
          <!--与我相关-->
          <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">与我有关{{correlationNum}}</p>
                <p class="el-icon-check icon-p-me" v-if="queryParams.myRelated==1"></p>
              </div>
            </div>
          </div>
          <el-form-item label="" prop="searchValue" style="margin-left:10px;">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="计划任务/实验室/房间号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="deptId" label-width="50px">
            <el-select v-model="queryParams.deptId" clearable placeholder="学院" style="width: 150px">
              <el-option
                v-for="item in deptSelectList"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId">
              </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>
          <p class="page-inquire-common-style-button" @click="handleQuery" style="margin-right:10px;">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             style="width:100px;float: right;"
             @click="allDownload"
          >批量下载</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" border :data="tableList" ref="multipleTable" @selection-change="handleSelectionChange"  :row-key="getRowKeys">
          <el-table-column type="selection" width="50" align="center" :reserve-selection="true"/>
          <el-table-column label="序号" align="center"  type="index" width="50" />
          <el-table-column label="计划任务" align="center" prop="title" show-overflow-tooltip/>
          <el-table-column label="学院" align="center" prop="collegeName" show-overflow-tooltip width="160"/>
          <el-table-column label="实验室" align="center" prop="subjectName" show-overflow-tooltip width="160"/>
          <el-table-column label="房间号" align="center" prop="roomNumber" show-overflow-tooltip width="80"/>
          <el-table-column label="楼栋" align="center" prop="buildName" show-overflow-tooltip width="100"/>
          <el-table-column label="隐患数" align="center" prop="hazardCount" show-overflow-tooltip width="80"/>
          <el-table-column label="计划周期" align="center" prop="cycleTime" show-overflow-tooltip width="200"/>
          <el-table-column label="检查者" align="center" prop="checkUser" show-overflow-tooltip width="80"/>
          <el-table-column label="检查时间" align="center" prop="checkTime" show-overflow-tooltip width="120"/>
          <el-table-column label="操作" align="center" prop="deptName" width="200">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" @click="goPage(2,scope.row)">检查详情</p>
                <p class="table-button-p" @click="lookDocumentButton(1,scope.row)">查看</p>
                <p class="table-button-p" @click="downloadButton(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>
    <listPage v-if="pageType == 2" :propsListPageData="propsListPageData"></listPage>
    <lookDocumentDataDialog v-if="lookDocumentType" :propsLookDocumentData="propsLookDocumentData"></lookDocumentDataDialog>
  </div>
</template>

<script>
  import {
    getDeptDropList
  } from '@/api/commonality/permission'
  import { checkRectifyList } from  '@/api/safetyCheck/indexTow'
  import listPage from './listPage.vue'
  import lookDocumentDataDialog from '@/components/lookDocumentDialog/lookDocumentDataDialog.vue'
  export default {
    name: 'index',
    components: {
      listPage,
      lookDocumentDataDialog
    },
    data(){
      return{
        //子组件数据
        lookDocumentType:false,
        propsLookDocumentData:{},
        propsListPageData:{},
        pageType:1,
        deptSelectList:[],
        queryParams:{
          page:1,
          pageSize:20,
          deptId:'',
          searchValue:'',
          myRelated:1,
        },
        dateRange:[],
        tableList:[],
        total:0,
        selectedNum:0,
        ids:[],
        correlationNum:'',
      }
    },
    created(){

    },
    mounted(){
      this.getDeptDropList();
      this.getList();
    },
    methods:{
      //获取相关数量
      getCorrelationNum(){
        checkRectifyList({
          page:1,
          pageSize:20,
          myRelated:1,
          deptId:this.queryParams.deptId,
          searchValue:this.queryParams.searchValue,
          beginDate:this.dateRange[0]?this.dateRange[0]:'',
          endDate:this.dateRange[1]?this.dateRange[1]:'',
        }).then(response => {
          this.$set(this,'correlationNum',response.data.total>999?' 999+':(response.data.total<1?'':' '+response.data.total));
        });
      },
      //与我相关按钮
      topRightClickType(){
        this.$set(this.queryParams,'myRelated',this.queryParams.myRelated==1?0:1);
        this.handleQuery();
      },
      // 批量下载
      allDownload(){
        let self = this;
        if(!this.ids[0]){
          this.msgError('请先勾选数据')
          return
        }
        this.$confirm('是否批量下载?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          let text = self.ids+'';
          self.downloadGet('/zd-security/checkRectify/genReport/zip?idListStr='+text+'&fileUrl='+localStorage.getItem('fileBrowseEnvironment'), '批量报告下载.zip')
        }).then(() => {
        }).catch(() => {});
      },
      // 单个下载按钮
      downloadButton(row){
        this.downloadGet('/zd-security/checkRectify/genReport?id='+row.id+'&fileUrl='+localStorage.getItem('fileBrowseEnvironment'), row.title+'(整改报告).docx')
      },
      //开关详情页面
      goPage(type,data){
        if(this.pageType != type){
          if(type == 2){
            this.$set(this.propsListPageData,'id',data.id);
          }
          this.$set(this,'pageType',type);
        }
      },
      //查看单个文档
      lookDocumentButton(type,row){
        if(type==1){
          this.$set(this,'propsLookDocumentData',{
            title:"整改报告",
            type:1,
            id:row.id,
            name:row.title
          });
          this.$set(this,'lookDocumentType',true);
        }else{
          this.$set(this,'lookDocumentType',false);
        }
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.beginDate = this.dateRange[0]
        }else{
          obj.beginDate = ""
        }
        if(this.dateRange[1]){
          obj.endDate = this.dateRange[1]
        }else{
          obj.endDate = ""
        }
        let self = this;
        setTimeout(function(){
          self.getCorrelationNum();
        },500);
        checkRectifyList(obj).then(response => {
          this.total = response.data.total;
          this.tableList = response.data.records;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId:'',
          searchValue:'',
          myRelated:1,
        });
        this.handleQuery();
      },
      /*===记录勾选数据===
        需要再el-table 添加  :row-key="getRowKeys"
        需要在selection 添加 :reserve-selection="true"
      */
      getRowKeys(row) {
        return row.id
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.selectedNum = selection.length;
        this.ids = selection.map(item => item.id)
      },
      //获取学院列表
      getDeptDropList(){
        //获取学院列表
        getDeptDropList({ deptName: '', level: 2, deptType: 1 }).then(response => {
          this.$set(this, 'deptSelectList', response.data)
        })
      },
    },
  }
</script>

<style scoped lang="scss">
  .rectificationReport{
    .page-container{
      .page-form-title-box{
        .form-button-max-big-box{
          display: inline-block;
          overflow: hidden;
          .form-button-big-box{
            display: flex;
            div{
              position: relative;
              height:40px;
              width:100px;
              line-height: 40px;
              text-align: center;
              color:#0045AF;
              font-size:14px;
              border:1px solid #0045AF;
              border-radius:4px;
              margin-left:10px;
              font-weight:500;
              cursor: pointer;
            }
            .checkDiv{
              color:#fff;
              background-color:#0045AF;
              border:1px solid #0045AF;
            }
          }
        }
        .form-button-max-big-box-me{
          display: inline-block;
          overflow: hidden;
          .form-button-big-box-me{
            display: flex;
            div{
              position: relative;
              height:40px;
              width:130px;
              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>
