<!--检查记录-->
<template>
  <div class="app-container checkRecord">
    <div class="checkRecordPage" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" style="margin-top:20px;" :inline="true" v-show="showSearch">
        <el-form-item label="关键字" prop="searchValue" label-width="70px">
          <el-input
            style="width:230px;"
            v-model="queryParams.searchValue"
            placeholder="请输入实验室/负责人/检查单号"
            clearable
            size="small"
            maxLength="20"
          />
        </el-form-item>
        <el-form-item label="整改类型" prop="zgType" label-width="80px">
          <el-select v-model="queryParams.zgType" placeholder="请选择整改类型" clearable size="small">
            <el-option label="一般整改" value="0" />
            <el-option label="重大整改" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="检查时间" label-width="80px">
          <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>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
      </el-form>
      <div class="checkRecordPage-top-box" v-hasPermi="['laboratory:checkRecord:list']">
        <p class="el-icon-question img-p" @mouseenter="showText" @mouseout="hideText"></p>
        <p class="checkRecordPage-title">草稿箱检查数：{{listCount}}</p>
        <p class="checkRecordPage-button" @click="goPageInfo(3)">立即处理>></p>
        <p class="checkRecordPage-null"></p>
        <div class="position-box" v-if="textType">
          <p>温馨提示</p>
          <p>PC端和手机端录入检查时选择保存到草稿箱的数据</p>
        </div>
      </div>
      <el-table v-loading="loading" border :data="checkRecordList" ref="selection" @selection-change="handleSelectionChange">
        <!--<el-table-column type="selection" width="55" align="center"/>-->
        <el-table-column label="检查单号" align="left" prop="checkNum" width="180"/>
        <el-table-column label="状态" align="center" prop="zgStatus" width="120">
          <template slot-scope="scope">
            <p style="margin:0;" v-if="scope.row.isZgStatus == 1">暂时无法整改</p>
            <p style="margin:0;" v-if="scope.row.isZgStatus == 0">{{scope.row.zgStatus==0?'待整改':(scope.row.zgStatus==1?'整改待复核':(scope.row.zgStatus==2?'复核未通过':(scope.row.zgStatus==4?'整改完成':(scope.row.zgStatus==5?'逾期':''))))}}</p>
          </template>
        </el-table-column>
        <el-table-column label="整改类型" align="left" prop="zgType" width="120">
          <template slot-scope="scope">{{scope.row.zgType==0?'一般整改':(scope.row.zgType==1?'重大整改':'')}}</template>
        </el-table-column>
        <el-table-column label="实验室名称" align="left" prop="laboratoryName"  :show-overflow-tooltip="true"/>
        <el-table-column label="实验楼" align="left" prop="buildingName" width="160"/>
        <el-table-column label="房间号" align="left" prop="fjNumber" width="100"/>
        <el-table-column label="隐患/已改/未改" align="left" prop="fjNumber" width="120">
          <template slot-scope="scope">
            <span style="color:#FFAE00;">{{scope.row.countYh}}</span>
            <span>/</span>
            <span style="color:#14BA3B;">{{scope.row.countYzg}}</span>
            <span>/</span>
            <span style="color:#FF5E5E;font-size: 18px;font-weight: bold;">{{scope.row.countWzg}}</span>
          </template>
        </el-table-column>
        <el-table-column label="检查单位" align="left" prop="jcDwName" width="160" :show-overflow-tooltip="true"/>
        <el-table-column label="检查时间" align="left" prop="createTime" width="200"/>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120" v-if="tableButtonType">
          <template slot-scope="scope">
            <div class="button-box" style="display: flex;margin-left:20px;">
            <p class="table-min-button"
               v-hasPermi="['laboratory:checkRecordDetails:query']"
               @click="goPageInfo(2,scope.row)"
            >查看</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <check-record-info-page v-if="pageType == 2" :infoId="infoId"></check-record-info-page>
    <unsubmitted-page-list v-if="pageType == 3"></unsubmitted-page-list>
    <check-list v-if="pageType == 4"></check-list>
  </div>
</template>

<script>
import { listCheckRecord, listCountCheckRecord, getCheckRecord, delCheckRecord, addCheckRecord, updateCheckRecord,listJcjl } from "@/api/laboratory/checkRecord";
import checkRecordInfoPage from "./checkRecordInfoPage.vue"
import unsubmittedPageList from "./unsubmittedPageList.vue"
import checkList from "./checkList.vue"
export default {
  name: "CheckRecord",
  components: {
    checkRecordInfoPage,
    unsubmittedPageList,
    checkList
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:checkRecordDetails:query']),
      //传参参数
      infoId:"",
      //页面状态
      pageType:1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安全检查表格数据
      checkRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue: null,
        laboratoryName: null,
        fzrName: null,
        zgType: null,
      },
      //查询时间
      dateRange:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        laboratoryId: [
          { required: true, message: "实验室id不能为空", trigger: "blur" }
        ],
      },
      // 未提交数量
      listCount:"",
      //检查单位名称
      jcDwName:"",
      //展示开关
      textType:false,
    };
  },
  created() {
  },
  mounted(){
    this.getList();
    this.getListCount();
  },
  methods: {
    //悬浮展示
    showText(){
      console.log("1")
      this.textType = true;
    },
    hideText(){
      console.log("2")
      this.textType = false;
    },
    //页面状态切换
    goPageInfo(type,row){
      if(type == 2){
        this.pageType = 2;
        this.infoId = row.id;
      }else if(type == 3){
        this.pageType = 3;
      }else if(type == 1){
        this.pageType = 1;
        this.getList();
        this.getListCount();
      }else if(type == 4){
        this.pageType = 4;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      if(!this.ids[0]){
        this.msgError("请选择要生成的数据")
        return
      }
      this.download('/laboratory/checkOption/genNotify/'+this.ids, {
      }, `整改告知书.docx`)
    },
    /** 查询安全检查列表 */
    getList() {
      this.loading = true;
      if(this.dateRange&&this.dateRange.length>0){
        this.queryParams.beginTime=this.dateRange[0]
        this.queryParams.endTime=this.dateRange[1]
      }else{
        this.queryParams.beginTime=null;
        this.queryParams.endTime=null
      }
      this.queryParams.isCg = 0;
      // listCheckRecord(this.queryParams).then( response => {
      listJcjl(this.queryParams).then( response => {
        this.checkRecordList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
    getListCount() {
      listCountCheckRecord().then( response => {
        this.listCount = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        laboratoryName: null,
        laboratoryId: null,
        buildingName: null,
        buildingId: null,
        jcDw: null,
        jcRyxm: null,
        fjNumber: null,
        fzrId: null,
        fzrName: null,
        fzrLxfs: null,
        zmClMs: null,
        zmClImg: null,
        zgMs: null,
        zgCs: null,
        zgJg: null,
        zgYyfx: null,
        zgStatus: 0,
        zgType: null,
        isCg: null,
        zgjzTime: null,
        zgbhTime: null,
        zgqrTime: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize:20,
        searchValue:"",
        zgType: '',
      });
      this.dateRange = [];
      this.queryParams.searchValue = "";
      this.queryParams.beginTime = "";
      this.queryParams.endTime = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      let self = this;
      let list = selection.map(item => item.id);
      for(let i=0;i<self.checkRecordList.length;i++){
        if(list[0] == self.checkRecordList[i].id){
          if(self.checkRecordList[i].zgType == 1){
            this.$refs.selection.toggleRowSelection(self.checkRecordList[i],false);
            this.msgError("批量生成整改告知书只可勾选一般整改");
            return
          }
        }
      }
      if(selection[0]){
        if(!this.ids[0]){
          this.ids = selection.map(item => item.id);
          this.single = selection.length != 1;
          this.multiple = !selection.length;
          for(let i=0;i<self.checkRecordList.length;i++){
            if(list[0] == self.checkRecordList[i].id){
              self.jcDwName = self.checkRecordList[i].jcDwName;
            }
          }
        }else{
          let newId = list[list.length-1];
          let newName = "";
          let obj = {};
          for(let i=0;i<self.checkRecordList.length;i++){
            if(newId == self.checkRecordList[i].id){
              newName = self.checkRecordList[i].jcDwName;
              obj = self.checkRecordList[i];
            }
          }
          if(newName != this.jcDwName){
            this.$refs.selection.toggleRowSelection(obj,false);
            this.msgError("批量生成整改告知书只可勾选相同检查单位");
          }else{
            this.ids = selection.map(item => item.id);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
          }
        }
      }else{
        this.ids = selection.map(item => item.id);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
        self.jcDwName = "";
      }
    },
    // 多选框选中数据
    handleSelectionChangeTwo(selection) {
      console.log("123",selection);
      this.idsTwo = selection.map(item => item.id)
      this.singleTwo = selection.length!==1
      this.multipleTwo = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加安全检查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCheckRecord(id).then( response => {
        this.form =  response.data;
        this.open = true;
        this.title = "修改安全检查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCheckRecord(this.form).then( response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCheckRecord(this.form).then( response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除安全检查编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCheckRecord(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
  }
};
</script>


<style scoped lang="scss">
  .checkRecord{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    .checkRecordPage{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden !important;
      padding:0 20px 20px;
      .checkRecordPage-top-box{
        display: flex;
        background: #CCE6FE;
        border-radius:6px;
        margin:0 0 20px 0;
        position: relative;
        .img-p{
          font-size:18px;
          margin:0 10px;
          line-height:40px;
          color:#FFC000;
          margin-left:20px;
        }
        .checkRecordPage-title{
          color:#333;
          margin:0;
          line-height:40px;
          font-size:14px;
        }
        .checkRecordPage-button{
          margin:0;
          line-height:40px;
          font-size:14px;
          color:#0183FA;
          margin-left:40px;
          cursor: pointer;
        }
        .checkRecordPage-null{
          flex:1;
        }
        .position-box{
          padding:10px 20px;
          background: rgba(0,0,0,0.8);
          position: absolute;
          top:10px;
          left:48px;
          z-index:999;
          border-radius:4px;
          p{
            margin:0;
            font-size:12px;
            line-height:20px;
            color:#fff;
            font-weight:500;
          }
        }
      }
    }
  }
</style>
