<!--整改审核-->
<template>
  <div class="app-container verifyCheck">
    <div class="verifyCheckPage" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="关键字" prop="searchValue">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="实验室名称/负责人/单号"
            clearable
            style="width:200px;"
          />
        </el-form-item>
        <el-form-item label="整改类型" prop="zgType">
          <el-select v-model="queryParams.zgType" placeholder="请选择整改类型" clearable style="width:150px;">
            <el-option label="一般整改" value="0" />
            <el-option label="重大整改" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态" prop="spStatus">
          <el-select v-model="queryParams.spStatus" placeholder="请选择整改类型" clearable style="width:150px;">
            <el-option label="待复核" value="1" />
            <el-option label="已通过" value="4" />
            <el-option label="未通过" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="检查时间">
          <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 label="整改时间">
          <el-date-picker
            :clearable="false"
            v-model="dateRangeTwo"
            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="序号" type="index" align="center" width="50"/>
        <!--<el-table-column label="项目序号" align="left" prop="jcxNum" width="180"/>-->
        <el-table-column label="隐患描述" align="left" prop="yhMs" width="290" :show-overflow-tooltip="true"/>
        <el-table-column label="整改类型" align="left" prop="zgType" width="150">
          <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="fzrName" width="150" />
        <el-table-column label="检查时间" align="left" prop="checkTime" width="180" />
        <el-table-column label="整改提交时间" align="left" prop="zgTime" width="180" />
        <el-table-column label="审核状态" align="left" prop="spStatus" width="120" >
          <template slot-scope="scope">
            <span :class="scope.row.spStatus == 1?'spStatus-1':(scope.row.spStatus == 2?'spStatus-2':(scope.row.spStatus == 4?'spStatus-3':''))">{{scope.row.spStatus == 1?'待复核':(scope.row.spStatus == 2?'未通过':(scope.row.spStatus == 4?'已通过':''))}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120" v-if="tableButtonType">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="goPageInfo(2,scope.row)"
                 v-hasPermi="['laboratory:checkRecordDetails:query']"
              >{{scope.row.zgStatus == 1?'审核':'查看'}}</p>
              <p class="table-button-null"></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>
    <verify-check-info v-if="pageType == 2" :infoId="infoId"></verify-check-info>
  </div>
</template>

<script>
import { listDzgCheckRecord, getCheckRecord, delCheckRecord, addCheckRecord, updateCheckRecord } from "@/api/laboratory/checkRecord";
import verifyCheckInfo from "./verifyCheckInfo.vue"
export default {
  name: "CheckRecord",
  components: {
    verifyCheckInfo
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:checkRecordDetails:query']),
      //页面状态
      pageType:1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安全检查表格数据
      checkRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:"",
        zgType: '',
        spStatus: '',
      },
      //查询时间
      dateRange:[],
      //整改时间
      dateRangeTwo:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        laboratoryId: [
          { required: true, message: "实验室id不能为空", trigger: "blur" },
          { required: true, message: "实验室id不能为空", validator: this.spaceJudgment, trigger: "blur" }
        ],
      },
      //审核组件数据
      infoId:"",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //页面状态切换
    goPageInfo(type,row){
      if(type == 2){
        this.pageType = 2;
        this.infoId = row.id;
      }else if(type == 1){
        this.pageType = 1;
        this.getList();
      }
    },
    /** 查询安全检查列表 */
    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
      }
      if(this.dateRangeTwo&&this.dateRangeTwo.length>0){
        this.queryParams.zgBeginTime=this.dateRangeTwo[0]
        this.queryParams.zgEndTime=this.dateRangeTwo[1]
      }else{
        this.queryParams.zgBeginTime=null;
        this.queryParams.zgEndTime=null
      }
      listDzgCheckRecord(this.queryParams).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,
        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: '',
        spStatus: '',
      });
      this.dateRange = [];
      this.queryParams.searchValue = "";
      this.queryParams.beginTime = "";
      this.queryParams.endTime = "";
      this.dateRangeTwo = [];
      this.queryParams.zgBeginTime = "";
      this.queryParams.zgEndTime = "";

      this.handleQuery();
    },
    // 多选框选中数据
    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">
  .verifyCheck{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    .verifyCheckPage{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:20px!important;
      .spStatus-1{
        color:#FF9600;
      }
      .spStatus-2{
        color:#FF0000;
      }
      .spStatus-3{
        color:#21CC1D;
      }
    }
  }
</style>
