<!--安全检查发布记录-->
<template>
  <div class="app-container releasePage">
    <div class="releasePageMin" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="检查名称" prop="releaseDescribe">
          <el-input
            v-model="queryParams.releaseDescribe"
            placeholder="请输入检查名称"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="发布时间" label-width="70px">
          <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="releaseList" @selection-change="handleSelectionChange">
        <!--<el-table-column type="selection" width="55" align="center" />-->
        <!--<el-table-column label="创建人id" align="center" prop="id" />-->
        <el-table-column label="检查名称" align="left" prop="releaseDescribe" />
        <el-table-column label="实验室数量" align="left" prop="laboratorNum" />
        <el-table-column label="隐患数量" align="left" prop="laboratorYhsl" />
        <el-table-column label="已整改" align="left" prop="laboratorYzg" />
        <el-table-column label="发布时间" align="left" prop="strTime" />
        <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="goPageInfo(2,scope.row)"
               v-hasPermi="['laboratory:checkRecord:list']"
            >查看</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>
    <list-page v-if="pageType == 2" :checkId="checkId"></list-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="检查表主键id" prop="checkId">
          <el-input v-model="form.checkId" placeholder="请输入检查表主键id" />
        </el-form-item>
        <el-form-item label="描述" prop="releaseDescribe">
          <el-input v-model="form.releaseDescribe" placeholder="请输入描述" />
        </el-form-item>
        <el-form-item label="创建人id" prop="createByid">
          <el-input v-model="form.createByid" placeholder="请输入创建人id" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </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 { listRelease, getRelease, delRelease, addRelease, updateRelease } from "@/api/laboratory/release";
import listPage from "./listPage.vue"

export default {
  name: "Release",
  components: {
    listPage
  },
  data() {
    return {
      tableButtonType:this.hasPermiDom(['laboratory:checkRecord:list']),
      pageType:1,
      checkId:"",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检查发布关系表格数据
      releaseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        checkId: null,
        releaseDescribe: null,
        createByid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      dateRange:[]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //页面状态切换
    goPageInfo(type,row){
      if(type == 2){
        this.pageType = 2;
        this.checkId = row.checkId;
      }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
      }
      listRelease(this.queryParams).then( response => {
        this.releaseList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        checkId: null,
        releaseDescribe: null,
        createByid: null,
        createBy: null,
        createTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.beginTime = "";
      this.queryParams.endTime = "";
      // this.resetForm("queryForm");
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize:20,
        releaseDescribe:"",
      });
      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
      getRelease(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) {
            updateRelease(this.form).then( response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRelease(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 delRelease(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('laboratory/release/export', {
        ...this.queryParams
      }, `laboratory_release.xlsx`)
    }
  }
};
</script>
<style scoped lang="scss">
  .releasePage{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    .releasePageMin{
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden !important;
      padding: 20px 20px 20px;
    }
  }
</style>
