<!--分级管控执行-->
<template>
  <div class="app-container gradeManageRecord">
    <div class="gradeManageRecord-page" v-if="pageType == 1">
      <el-form :model="queryParams" 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 deptList"
              :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 typeList"
              :key="dict.id"
              :label="dict.typeName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="安全分级" prop="level">
          <el-select v-model="queryParams.level" placeholder="请选择安全分级" clearable style="width:150px;">
            <el-option
              v-for="dict in levelList"
              :key="dict.id"
              :label="dict.classifiedName"
              :value="dict.id"
            ></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="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="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"/>
        <el-table-column label="执行周期" align="center" prop="cycle" width="149"/>
        <!--<el-table-column label="执行人身份" align="center" prop="userPosition" />-->
        <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="130">
          <template slot-scope="scope">{{scope.row.carryTime?scope.row.carryTime:'-'}}</template>
        </el-table-column>
        <el-table-column label="操作" align="center" 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;">
              <!--v-if="scope.row.status==2"-->
              <p class="table-min-button"
                 @click="pageTypeClick(2,scope.row)"
                 v-hasPermi="['laboratory:gradeManageRecord:query']"
              >详情</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>
    <info-page v-if="pageType == 2" :recordId="recordId"></info-page>
    <!-- 添加或修改管控执行记录对话框 -->
    <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="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="规则ID" prop="ruleId">
          <el-input v-model="form.ruleId" placeholder="请输入规则ID" />
        </el-form-item>
        <el-form-item label="规则名称" prop="ruleName">
          <el-input v-model="form.ruleName" placeholder="请输入规则名称" />
        </el-form-item>
        <el-form-item label="实验室ID" prop="subId">
          <el-input v-model="form.subId" placeholder="请输入实验室ID" />
        </el-form-item>
        <el-form-item label="执行用户ID" prop="joinUserId">
          <el-input v-model="form.joinUserId" placeholder="请输入执行用户ID" />
        </el-form-item>
        <el-form-item label="执行人身份" prop="userPosition">
          <el-input v-model="form.userPosition" placeholder="请输入执行人身份" />
        </el-form-item>
        <el-form-item label="执行状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="执行时间" prop="carryTime">
          <el-date-picker clearable size="small"
            v-model="form.carryTime"
            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 { listDepartments } from "@/api/system/dept";
import { listGradeManageRecord, getGradeManageRecord, delGradeManageRecord, addGradeManageRecord, updateGradeManageRecord } from "@/api/laboratory/gradeManageRecord";
import { listClassifiedAll } from "@/api/laboratory/classified";
import { listClasstypeAll } from "@/api/laboratory/classtype";
import { queryOption } from "@/api/laboratory/labMold";
import infoPage from "./infoPage.vue"
import { gradeManageWorkInfo } from "@/api/laboratory/gradeManageWork";
export default {
  name: "GradeManageRecord",
  components: {
    infoPage
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:gradeManageRecord:query']),
      //页面状态
      pageType:1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 管控执行记录表格数据
      gradeManageRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: null,
        deptId: null,
        status: null,
      },
      createTimeDate:[],
      //学院列表
      deptList:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      recordId:"",
      labMoldList:[],
      levelList:[],
      typeList:[],
      cycleList:['一天','一周','一月','季度','半年','一年'],
    };
  },
  created() {
    this.getList();
  },
  mounted(){
    this.listDepartments();
    this.getListClassifiedAll();
    this.getListClasstypeAll();
    this.queryOption();
  },
  methods: {
    queryOption(){
      queryOption({}).then(response=>{
        if(response.code==200){
          this.labMoldList=response.data
        }
      })
    },
    //查询安全分级
    getListClassifiedAll(){
      listClassifiedAll().then(response=>{
        if(response.code==200){
          console.log(response)
          this.levelList=response.data
        }
      })
    },
    //查询安全分类
    getListClasstypeAll(){
      listClasstypeAll().then(response=>{
        if(response.code==200){
          this.typeList=response.data;
        }
      });
    },
    pageTypeClick(type,row){
      if(this.pageType != type){
        if(type == 1){
          this.pageType = 1;
        }else if(type == 2){
          gradeManageWorkInfo(row.id).then( response => {
            console.log('response',response)
            if (response.code == 504){
              this.msgError(response.msg);
            }else if (response.code == 200){
              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;
      listGradeManageRecord(this.queryParams).then( response => {
        this.gradeManageRecordList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
    //获取学院
    listDepartments(){
      listDepartments().then(response => {
        this.deptList = 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.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTimeDate = []
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize: 10,
        searchValue: "",
        deptId: "",
        status: "",
        endTime:"",
        statTime:"",
      });
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加管控执行记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGradeManageRecord(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) {
            updateGradeManageRecord(this.form).then( response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGradeManageRecord(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 delGradeManageRecord(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('laboratory/gradeManageRecord/export', {
        ...this.queryParams
      }, `laboratory_gradeManageRecord.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
  .gradeManageRecord{
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    .gradeManageRecord-page{
      flex:1;
      display: flex!important;
      flex-direction: column;
      padding:20px 20px!important;
      overflow: hidden;
    }
    .tableTypeColorA{
      color:#2AA408;
    }
  }
</style>
