<!--问题整改列表-->
<template>
  <div class="app-container reformCheck">
    <div class="reformCheckPage" v-if="pageType == 1">
      <div class="top-big-box">
        <div>
          <p :class="spStatus==0?'color_one':'color_99'" @click="tableClick(0)">待整改({{num0}})</p>
          <p :class="{'back_one':spStatus==0}"></p>
        </div>
        <div>
          <p :class="spStatus==1?'color_one':'color_99'" @click="tableClick(1)">待复核({{num1}})</p>
          <p :class="{'back_one':spStatus==1}"></p>
        </div>
        <div>
          <p :class="spStatus==2?'color_one':'color_99'" @click="tableClick(2)">复核未通过({{num2}})</p>
          <p :class="{'back_one':spStatus==2}"></p>
        </div>
        <div>
          <p :class="spStatus==3?'color_one':'color_99'" @click="tableClick(3)">暂时无法整改({{num3}})</p>
          <p :class="{'back_one':spStatus==3}"></p>
        </div>
        <div>
          <p :class="spStatus==4?'color_one':'color_99'" @click="tableClick(4)">整改完成({{num4}})</p>
          <p :class="{'back_one':spStatus==4}"></p>
        </div>
      </div>
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <el-form-item label="实验室名称" prop="laboratoryName" label-width="90px">
          <el-input
            v-model="queryParams.laboratoryName"
            placeholder="请输入实验室名称"
            clearable
            size="small"
          />
        </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>
      <el-table v-loading="loading" border :data="checkRecordList" border>
        <el-table-column label="项目序号" align="left" prop="jcxSstkNum" width="100" show-overflow-tooltip/>
        <el-table-column label="隐患描述" align="left" prop="yhMs" show-overflow-tooltip/>
        <el-table-column label="整改类型" align="left" prop="zgType" width="110" show-overflow-tooltip>
          <template slot-scope="scope">{{scope.row.zgType==0?'一般整改':(scope.row.zgType==1?'重大整改':'')}}</template>
        </el-table-column>
        <el-table-column label="实验室名称" align="left" prop="laboratoryName" width="180" show-overflow-tooltip/>
        <el-table-column label="房间号" align="left" prop="fjNumber" width="90"/>
        <el-table-column label="实验楼" align="left" prop="buildingName" width="150" show-overflow-tooltip/>
        <el-table-column label="检查单位" align="left" prop="jcDwName" width="150" show-overflow-tooltip/>
        <el-table-column label="检查时间" align="left" prop="checkTime" width="200"/>
        <el-table-column label="整改截止时间" align="left" prop="zgjzTime" width="150" v-if="queryParams.spStatus == 0"/>
        <el-table-column label="整改完成时间" align="left" prop="zgTime" width="150" v-if="queryParams.spStatus == 1"/>
        <el-table-column label="整改驳回时间" align="left" prop="spTime" width="150" v-if="queryParams.spStatus == 2"/>
        <el-table-column label="复核时间" align="left" prop="spTime" width="150" v-if="queryParams.spStatus == 4"/>
        <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"
               @click="goPageType(2,scope.row)"
               v-hasPermi="['laboratory:checkRecordDetails:query']"
            >查看</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        style="margin-bottom:20px;"
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"/>
    </div>
    <check-record-info v-if="pageType == 2" :infoId="infoId"></check-record-info>
    <!-- 添加或修改安全检查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="实验室名称" prop="laboratoryName" :show-overflow-tooltip="true">
          <el-input v-model="form.laboratoryName" placeholder="请输入实验室名称" />
        </el-form-item>
        <el-form-item label="实验室id" prop="laboratoryId">
          <el-input v-model="form.laboratoryId" placeholder="请输入实验室id" />
        </el-form-item>
        <el-form-item label="实验楼名称" prop="buildingName">
          <el-input v-model="form.buildingName" placeholder="请输入实验楼名称" />
        </el-form-item>
        <el-form-item label="实验楼id" prop="buildingId">
          <el-input v-model="form.buildingId" placeholder="请输入实验楼id" />
        </el-form-item>
        <el-form-item label="检查单位" prop="jcDw" :show-overflow-tooltip="true">
          <el-input v-model="form.jcDw" placeholder="请输入检查单位" />
        </el-form-item>
        <el-form-item label="检查人" prop="jcRyxm">
          <el-input v-model="form.jcRyxm" placeholder="请输入检查人" />
        </el-form-item>
        <el-form-item label="房间号" prop="fjNumber">
          <el-input v-model="form.fjNumber" placeholder="请输入房间号" />
        </el-form-item>
        <el-form-item label="负责人id" prop="fzrId">
          <el-input v-model="form.fzrId" placeholder="请输入负责人id" />
        </el-form-item>
        <el-form-item label="负责人姓名" prop="fzrName">
          <el-input v-model="form.fzrName" placeholder="请输入负责人姓名" />
        </el-form-item>
        <el-form-item label="负责人联系方式" prop="fzrLxfs">
          <el-input v-model="form.fzrLxfs" placeholder="请输入负责人联系方式" />
        </el-form-item>
        <el-form-item label="证明材料描述" prop="zmClMs">
          <el-input v-model="form.zmClMs" placeholder="请输入证明材料描述" />
        </el-form-item>
        <el-form-item label="证明材料图片" prop="zmClImg">
          <el-input v-model="form.zmClImg" placeholder="请输入证明材料图片" />
        </el-form-item>
        <el-form-item label="整改描述" prop="zgMs">
          <el-input v-model="form.zgMs" placeholder="请输入整改描述" />
        </el-form-item>
        <el-form-item label="整改措施" prop="zgCs">
          <el-input v-model="form.zgCs" placeholder="请输入整改措施" />
        </el-form-item>
        <el-form-item label="整改结果" prop="zgJg">
          <el-input v-model="form.zgJg" placeholder="请输入整改结果" />
        </el-form-item>
        <el-form-item label="原因分析" prop="zgYyfx">
          <el-input v-model="form.zgYyfx" placeholder="请输入原因分析" />
        </el-form-item>
        <el-form-item label=" 0待整改 1整改待确认 2复核未通过 3整改中 4完成">
          <el-radio-group v-model="form.spStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="0一般整改 1重大整改" prop="zgType">
          <el-select v-model="form.zgType" placeholder="请选择0一般整改 1重大整改">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="0否 1是" prop="isCg">
          <el-input v-model="form.isCg" placeholder="请输入0否 1是" />
        </el-form-item>
        <el-form-item label="整改截止时间" prop="zgjzTime">
          <el-date-picker clearable size="small"
            v-model="form.zgjzTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择整改截止时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="整改驳回时间" prop="zgbhTime">
          <el-date-picker clearable size="small"
            v-model="form.zgbhTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择整改驳回时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="整改确认时间" prop="zgqrTime">
          <el-date-picker clearable size="small"
            v-model="form.zgqrTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择整改确认时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { checkRecordList, selectStatusList,listWtzg } from "@/api/laboratory/checkRecord";
import checkRecordInfo from "./CheckRecordInfo.vue"
export default {
  name: "CheckRecord",
  components: {
    checkRecordInfo
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:checkRecordDetails:query']),
      //传参数据
      infoId:"",
      //各状态数量
      num0:"",
      num1:"",
      num2:"",
      num3:"",
      num4:"",
      //页面状态
      pageType:1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安全检查表格数据
      checkRecordList: [{}],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        //整改状态
        spStatus:0,
        pageNum: 1,
        pageSize: 10,
        laboratoryName: null,
        zgType: null,
        isZgStatus:"",
      },
      spStatus:0,
      //查询时间
      dateRange:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        laboratoryId: [
          { required: true, message: "实验室id不能为空", trigger: "blur" },
          { required: true, message: "实验室id不能为空", validator: this.spaceJudgment, trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getNum();
    this.getList();
  },
  methods: {
    goPageType(type,row){
      if(type == 2){
        this.infoId = row.id;
        this.pageType = 2;
      }else if(type == 1){
        this.pageType = 1;
        this.getNum();
        this.getList();
      }
    },
    //整改状态切换
    tableClick(type){
      console.log('type',type);
      if(this.spStatus != type){
        if(type == 3){
          this.queryParams.isZgStatus = 1;
          this.queryParams.spStatus = "4";
        }else if(type == 4){
          this.queryParams.isZgStatus = 0;
          this.queryParams.spStatus = type;
        }else{
          this.queryParams.isZgStatus = "";
          this.queryParams.spStatus = type;
        }
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        this.spStatus = type;
        // this.resetQuery();
        this.getNum();
        this.getList();
      }
    },
    getNum(){
      this.queryParams.isCg = 0;
      selectStatusList(this.queryParams).then( response => {
        let self = this;
        for(let i=0;i<response.data.length;i++){
          if(response.data[i].lx == '0'){
            self.num0 = response.data[i].sl
          }else if(response.data[i].lx == '1'){
            self.num1 = response.data[i].sl
          }else if(response.data[i].lx == '2'){
            self.num2 = response.data[i].sl
          }else if(response.data[i].lx == '3'){
            self.num3 = response.data[i].sl
          }else if(response.data[i].lx == '4'){
            self.num4 = response.data[i].sl
          }
        }
        // this.checkRecordList =  response.rows;
      });
    },
    /** 查询安全检查列表 */
    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;
      let obj = JSON.parse(JSON.stringify(this.queryParams))
      if(obj.spStatus == 3){
        obj.spStatus = 1;
      }
      // checkRecordList(this.queryParams).then( response => {
      listWtzg(obj).then( response => {
        this.checkRecordList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    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,
        spStatus: 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.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.queryParams.laboratoryName = '';
      this.queryParams.zgType = '';
      this.dateRange = [];
      this.queryParams.beginTime = "";
      this.queryParams.endTime = "";
      this.handleQuery();
      this.getNum();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !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(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('laboratory/checkRecord/export', {
        ...this.queryParams
      }, `laboratory_checkRecord.xlsx`)
    }
  }
};
</script>
<style scoped lang="scss">
  .reformCheck{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    .reformCheckPage{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:20px!important;
      .top-big-box{
        display: flex;
        border-bottom:2px solid #E0E0E0;
        margin-top:-9px;
        margin-bottom:20px;
        div{
          cursor:pointer;
          padding:0 30px;
          p:nth-child(1){
            line-height:58px;
            font-size:18px;
            text-align: center;
            margin:0;
          }
          p:nth-child(2){
            height:4px;
            margin:0 auto;
            border-radius:1px;
          }
        }
      }
    }
  }
</style>
