<!--准入凭证审核/未通过-->
<template>
  <div class="failed">
    <el-table v-loading="loading" border :data="approvalList" @selection-change="handleSelectionChange">

      <el-table-column label="申请人" align="left" prop="userName" />
      <el-table-column label="申请人身份" align="left" prop="userType">
        <template slot-scope="scope">
          {{scope.row.userType == '11' ? '教职工':(scope.row.userType == '22' ? '学生':'')}}
        </template>
      </el-table-column>
      <el-table-column label="申请实验室" align="left" prop="subjectName" />
      <el-table-column label="申请时间" align="left" prop="creatTime" >
        <template slot-scope="scope">
          {{scope.row.creatTime}} {{scope.row.hi}}
        </template>
      </el-table-column>
      <el-table-column label="有效期" align="left" prop="validBeginTime">
        <template slot-scope="scope">
          {{scope.row.validBeginTime}}至{{scope.row.validEndTime}}
        </template>
      </el-table-column>
      <el-table-column label="驳回原因" align="left" prop="rejectCause" show-overflow-tooltip></el-table-column>
      <!--<el-table-column label="准入凭证名称" align="left" prop="configureName" />-->
      <!--<el-table-column label="凭证申请时间" align="left" prop="createTime" />-->
      <!--<el-table-column label="凭证未通过时间" align="left" prop="failedDate" />-->
      <!--<el-table-column label="凭证未通过原因" align="left" prop="failedReason" />-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      layout="total, prev, pager, next, sizes, jumper"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改审批记录对话框 -->
    <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="joinUserId">
          <el-input v-model="form.joinUserId" placeholder="请输入关联用户表id" />
        </el-form-item>
        <el-form-item label="审批内容">
          <editor v-model="form.recordContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="部门名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入部门名称" />
        </el-form-item>
        <el-form-item label="创建人" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入创建人" />
        </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 @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import { listApproval, getApproval, delApproval, addApproval, updateApproval,applyApproval,applyList } from "@/api/laboratory/approval";

  export default {
    name: "failed",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 审批记录表格数据
        approvalList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          joinUserId: null,
          recordContent: null,
          deptId: null,
          deptName: null,
          userId: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
    },
    mounted(){
      this.getList();
    },
    methods: {
      /** 查询审批记录列表 */
      getList() {
        this.loading = true;
        this.queryParams.auditStatus = 1
        applyList(this.queryParams).then(response => {
          this.approvalList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          joinUserId: null,
          recordContent: null,
          deptId: null,
          deptName: null,
          userId: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        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
        getApproval(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) {
              updateApproval(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addApproval(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除审批记录?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delApproval(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('laboratory/approval/export', {
          ...this.queryParams
        }, `laboratory_approval.xlsx`)
      }
    }
  };
</script>
<style scoped lang="scss">
  .failed {
    flex:1;
    display: flex!important;
    flex-direction: column;
  }
</style>
