<!--分级管控执行-->
<template>
  <div class="app-container gradeManageRecord">
    <div class="page-container gradeManageRecord-page" v-if="pageType == 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm" :inline="true" v-show="showSearch" label-width="70px">
          <el-form-item label="" prop="searchValue" label-width="60px">
            <el-input
              style="width:150px;"
              v-model="queryParams.searchValue"
              placeholder="规则名称"
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="deptId" label-width="46px">
            <el-select v-model="queryParams.deptId" placeholder="请选择学院" clearable style="width:150px;">
              <el-option
                v-for="dict in deptIdOptionList"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="typeId">
            <el-select v-model="queryParams.typeId" placeholder="请选择安全分类" clearable style="width:150px;">
              <el-option
                v-for="dict in typeOptionList"
                :key="dict.typeId"
                :label="dict.typeName"
                :value="dict.typeId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="levelId">
            <el-select v-model="queryParams.levelId" placeholder="请选择安全分级" clearable style="width:150px;">
              <el-option
                v-for="dict in levelOptionList"
                :key="dict.levelId"
                :label="dict.levelName"
                :value="dict.levelId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="cycle">
            <el-select v-model="queryParams.cycle" placeholder="请选择执行周期" clearable style="width:150px;">
              <el-option
                v-for="dict in cycleList"
                :key="dict"
                :label="dict"
                :value="dict"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="status" label-width="40px">
            <el-select v-model="queryParams.status" placeholder="请选择执行状态" clearable style="width:150px;">
              <el-option label="未执行" value="0" />
              <el-option label="已执行" value="2" />
            </el-select>
          </el-form-item>
          <!--<el-form-item label="执行时间" prop="carryTime">-->
          <!--<el-date-picker-->
          <!--:clearable="false"-->
          <!--v-model="createTimeDate"-->
          <!--size="small"-->
          <!--style="width: 240px"-->
          <!--value-format="yyyy-MM-dd"-->
          <!--type="daterange"-->
          <!--range-separator="-"-->
          <!--start-placeholder="开始日期"-->
          <!--end-placeholder="结束日期"-->
          <!--&gt;</el-date-picker>-->
          <!--</el-form-item>-->
          <el-form-item>
            <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
            <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          </el-form-item>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="gradeManageRecordList">
          <el-table-column label="实验室" align="center" prop="subName" width="199" show-overflow-tooltip/>
          <el-table-column label="规则名称" align="center" prop="ruleName" show-overflow-tooltip/>
          <el-table-column label="类型" align="center" prop="moldName" width="149"/>
          <el-table-column label="安全分类" align="center" prop="typeName" width="130"/>
          <el-table-column label="安全分级" align="center" prop="levelName" width="130"/>
          <el-table-column label="学院" align="center" prop="deptName" width="130" show-overflow-tooltip/>
          <el-table-column label="执行周期" align="center" prop="cycle" width="149"/>
          <el-table-column label="状态" align="center" prop="status"width="149">
            <template slot-scope="scope">
              <span :class="scope.row.status==2?'tableTypeColorA':''">{{scope.row.status==0?'未执行':(scope.row.status==2?'已执行':'')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="执行时间" align="center" prop="carryTime" width="150">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.carryTime,"{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="pageTypeClick(2,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>
    <info-page v-if="pageType == 2" :recordId="recordId"></info-page>
  </div>
</template>

<script>
import {
  laboratoryGradeManageRecordList
} from "@/api/hierarchicalControl/index";
import {
  systemDeptGetLoginUserByDeptList,
  laboratoryClassLevelGetList,
  laboratoryClassTypeGetList,
} from '@/api/commonality/permission'
import infoPage from "./infoPage.vue"
export default {
  name: "GradeManageRecord",
  components: {
    infoPage
  },
  data() {
    return {
      //页面状态
      pageType:1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 管控执行记录表格数据
      gradeManageRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        page: 1,
        pageSize:20,
        searchValue: null,
        deptId: null,
        typeId:null,
        levelId:null,
        status: null,
      },
      createTimeDate:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      recordId:"",
      //学院列表
      deptIdOptionList:[],
      levelOptionList:[],
      typeOptionList:[],
      cycleList:['一天','一周','一月','季度','半年','一年'],
    };
  },
  created() {
    this.getList();
  },
  mounted(){
    this.systemDeptGetLoginUserByDeptList();
    this.laboratoryClassLevelGetList();
    this.laboratoryClassTypeGetList();
  },
  methods: {
    //查询安全分级
    laboratoryClassLevelGetList(){
      laboratoryClassLevelGetList({}).then(response=>{
        if(response.code==200){
          this.$set(this,'levelOptionList',response.data);
        }
      })
    },
    //查询安全分类
    laboratoryClassTypeGetList(){
      laboratoryClassTypeGetList({}).then(response=>{
        if(response.code==200){
          this.$set(this,'typeOptionList',response.data);
        }
      });
    },
    pageTypeClick(type,row){
      if(this.pageType != type){
        if(type == 1){
          this.pageType = 1;
        }else if(type == 2){
          this.recordId = row.id;
          this.pageType = 2;
        }
      }
    },
    /** 查询管控执行记录列表 */
    getList() {
      if(this.createTimeDate[0]){
        this.queryParams.statTime = this.createTimeDate[0];
        this.queryParams.endTime = this.createTimeDate[1];
      }else {
        this.queryParams.statTime = null
        this.queryParams.endTime = null
      }
      this.loading = true;
      laboratoryGradeManageRecordList(this.queryParams).then( response => {
        this.$set(this,'gradeManageRecordList',response.data.records);
        this.$set(this,'total',response.data.total);
        this.loading = false;
      });
    },
    //获取学院
    systemDeptGetLoginUserByDeptList(){
      systemDeptGetLoginUserByDeptList({}).then(response => {
        this.$set(this,'deptIdOptionList',response.data);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptId: null,
        deptName: null,
        userId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        ruleId: null,
        ruleName: null,
        subId: null,
        joinUserId: null,
        userPosition: null,
        status: 0,
        carryTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTimeDate = []
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        page: 1,
        pageSize:20,
        searchValue: "",
        deptId: "",
        typeId:null,
        levelId:null,
        status: "",
        endTime:"",
        statTime:"",
      });
      this.handleQuery();
    },
  }
};
</script>

<style lang="scss" scoped>
  .gradeManageRecord{
    .gradeManageRecord-page{
      .tableTypeColorA{
        color:#2AA408;
      }
    }
  }
</style>
