<!-- 整改报告 -->
<template>
  <div class="app-container rectificationReport">
    <div class="page-container rectificationReportPage" 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="checkCategory==1?'p-check':''" @click="schoolCollegeToggle(1)">校级检查</p>
            <p :class="checkCategory==2?'p-check':''" @click="schoolCollegeToggle(2)">学院自查</p>
          </div>
          <el-form-item label="" prop="isApprove">
            <el-select v-model="queryParams.isApprove" placeholder="状态" style="width:120px;">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="deptId" v-if="checkCategory==1">
            <el-select v-model="queryParams.deptId" placeholder="学院单位" style="width:140px;">
              <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="typeId" v-if="checkCategory==2">
            <el-select v-model="queryParams.typeId" placeholder="安全分类" style="width:120px;">
              <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" v-if="checkCategory==2">
            <el-select v-model="queryParams.levelId" placeholder="安全分级" style="width:120px;">
              <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" v-if="checkCategory==2">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="实验室/房间号"
              style="width:120px;"
            />
          </el-form-item>
          <el-form-item label="" prop="adminName" v-if="checkCategory==2">
            <el-input
              maxLength="30"
              v-model="queryParams.adminName"
              placeholder="实验室负责人"
              style="width:120px;"
            />
          </el-form-item>
          <el-form-item label="" prop="planTitle">
            <el-input
              maxLength="30"
              v-model="queryParams.planTitle"
              placeholder="计划标题"
              style="width:120px;"
            />
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 250px"
              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;display: inline-block;margin-right:10px;"
             @click="allDownload">批量下载</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList" ref="multipleTable" @selection-change="handleSelectionChange"  :row-key="getRowKeys">
          <el-table-column type="selection" width="50" align="center" :reserve-selection="true"/>
          <el-table-column label="编号" prop="reportNum" width="120"  show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-p" style="margin:0!important;"
                   @click="tableButton(1,scope.row)"
                >{{scope.row.reportNum}}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="学院单位" prop="deptName" width="180" show-overflow-tooltip v-if="checkCategory==1">
            <template slot-scope="scope">
              <span>{{scope.row.deptName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="实验室" prop="subName" width="240" show-overflow-tooltip v-if="checkCategory==2">
            <template slot-scope="scope">
              <span>{{scope.row.subName}}{{scope.row.roomNum?' ('+scope.row.roomNum+')':''}}</span>
            </template>
          </el-table-column>
          <el-table-column label="实验室负责人" prop="adminName" width="120" show-overflow-tooltip v-if="checkCategory==2">
            <template slot-scope="scope">
              <span>{{scope.row.adminName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="计划标题" prop="planTitle"  show-overflow-tooltip/>
          <el-table-column label="检查名称" prop="checkName" width="150" show-overflow-tooltip/>
          <el-table-column label="完成时间" prop="createTime" width="200" 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="isApprove" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.isApprove?'已提交':'未提交'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="260" 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.isApprove&&scope.row.showSubmit"
                   @click="tableButton(2,scope.row)"

                >提交</p>
                <p class="table-button-p"
                   @click="downloadButton(scope.row)"

                >下载</p>
                <p class="table-button-p"
                   @click="tableButton(3,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>
    <list-page :propsData="propsData" v-if="pageType === 2"></list-page>
    <el-dialog class="rectificationNotice-dialog" title='整改报告' width="836px" append-to-body
               :visible.sync="propsReportDomType" v-if="propsReportDomType" @close="dialogOff()"
               :close-on-click-modal="false" :close-on-press-escape="false">
      <div class="scrollbar-box" style="height:600px;">
        <rectificationReportDom :propsReportDomData="propsReportDomData"></rectificationReportDom>
      </div>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogSubmit">下载</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    getDeptDropList,
    laboratoryClassLevelGetList,
    laboratoryClassTypeGetList,
  } from '@/api/commonality/permission'
  import {
    securityRectifyReportList,
    securityRectifyReportUpdate
  } from "@/api/safetyCheck/index";
  import listPage from "./listPage.vue";
  import rectificationReportDom from '@/views/safetyCheck/components/rectificationReportDom.vue'
  export default {
    name: 'index',
    components: {
      listPage,
      rectificationReportDom
    },
    data () {
      return {
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //状态下拉列表
        optionList:[{value:0,label:'未提交'},{value:1,label:'已提交'}],
        //学院列表
        deptOption:[],
        //分级
        levelOption:[],
        //分类
        classOption:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          isApprove:null,
          planTitle:"",
          deptId :null,
          typeId :null,
          levelId :null,
          searchValue:'',
          adminName:'',
        },
        //时间数据
        dateRange:[],
        //校院级状态
        checkCategory:1,
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        selectedNum:0,
        ids:[],
        //组件传参
        propsData:{},
        propsReportDomData:{},
        propsReportDomType:false,
      }
    },
    created () {
      this.getDeptDropList();
      this.laboratoryClassLevelGetList();
      this.laboratoryClassTypeGetList();
    },
    mounted () {
      this.getList();
    },
    methods: {
      //检查/自查切换
      schoolCollegeToggle(type){
        if(this.checkCategory !== type){
          this.$set(this,'checkCategory',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,
          isApprove:null,
          planTitle:"",
          deptId :null,
          typeId :null,
          levelId :null,
          searchValue:'',
          adminName:'',
        });
        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.checkCategory = this.checkCategory;
        securityRectifyReportList(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,'propsReportDomData',{
            reportId:row.reportId,
            checkCategory:this.checkCategory,
            reportNum:row.reportNum,
          })
          this.$set(this,'propsReportDomType',true)
        }else if(type == 2){
          //提交
          this.$confirm('是否确认提交?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            securityRectifyReportUpdate({reportId:row.reportId,isApprove:1}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 3){
          //整改情况
          this.$set(this,'propsData',{
            reportId:row.reportId
          });
          this.$set(this,'pageType',2);
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      dialogSubmit(){
        this.downloadButton(this.propsReportDomData);
      },
      dialogOff(){
        this.$set(this,'propsReportDomType',false)
      },
      /*===记录勾选数据===
        需要再el-table 添加  :row-key="getRowKeys"
        需要在selection 添加 :reserve-selection="true"
      */
      getRowKeys(row) {
        return row.reportId
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.selectedNum = selection.length;
        this.ids = selection.map(item => item.reportId)
      },
      // 批量下载
      allDownload(){
        let self = this;
        if(!this.ids[0]){
          this.msgError('请先勾选数据')
          return
        }
        this.$confirm('是否批量下载?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          //生成时间
          let date = new Date();
          let year = date.getFullYear();
          let month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始，需要加1，并确保两位数
          let day = date.getDate().toString().padStart(2, '0'); // 确保两位数
          let hours = date.getHours().toString().padStart(2, '0'); // 确保两位数
          let minutes = date.getMinutes().toString().padStart(2, '0'); // 确保两位数
          let seconds = date.getSeconds().toString().padStart(2, '0'); // 确保两位数
          let time = year+month+day+hours+minutes+seconds
          let text = self.ids+'';
          self.downloadGet('/security/rectifyReport/genReport/zip?idListStr='+text+'&fileUrl='+localStorage.getItem('fileBrowseEnvironment'), '整改报告_'+time+'.zip')
          self.$refs['multipleTable'].clearSelection();
        }).then(() => {
        }).catch(() => {});
      },
      // 单个下载按钮
      downloadButton(row){
        this.downloadGet('/security/rectifyReport/getRectifyReport?reportId='+row.reportId+'&fileUrl='+localStorage.getItem('fileBrowseEnvironment'), '整改报告('+row.reportNum+').docx')
      },
      getDeptDropList(){
        getDeptDropList({level: 2, deptType: 1 }).then(response => {
          this.$set(this,'deptOption',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">
  .rectificationReport{
    .rectificationReportPage{
      .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;
          }
        }
      }
      .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(2){
          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>
