<!--准入凭证审核/已通过-->
<template>
  <div class="passed">
    <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.subjectName"
          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 label="专业" prop="major" label-width="90px">
        <el-select v-model="queryParams.userMajorId" filterable  placeholder="请选择">
          <el-option
            v-for="item in majorList"
            :key="item.id"
            :label="item.majorName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <p class="inquire-button-one" @click="handleQuery">查询</p>
        <p class="reset-button-one" @click="resetQuery">重置</p>
        <p style="margin-left: 10px" class="inquire-button-one" @click="handleExport"
           v-hasPermi="['laboratory:apply:export']">导出</p>
      </el-form-item>
    </el-form>
    <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="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <div class="button-box" style="display: flex;margin-left:20px;">
            <p class="table-min-button"
               v-hasPermi="['laboratory:apply:query']"
               @click="goInfoPage(scope.row)">查看</p>
          </div>
        </template>
      </el-table-column>
      <!--<el-table-column label="准入凭证名称" align="left" prop="configureName" />-->
      <!--<el-table-column label="凭证通过时间" align="left" prop="passedDate" />-->
      <!--<el-table-column label="凭证到期时间" align="left" prop="expirationDate" >-->
        <!--<template slot-scope="scope">-->
  <!--          <p v-for="(item,index) in recordContents" :key="index" v-if="scope.row.recordOther ==item.type">-->
              <!--{{scope.row.expirationDate}}-->
              <!--<el-tag :type="scope.row.recordOther==4?'danger':scope.row.recordOther==3?'warning':'green'">-->
                <!--{{item.value}}-->
              <!--</el-tag>-->
            <!--</p >-->
<!--        </template>-->
      <!--</el-table-column>-->
    </el-table>

    <pagination :page-sizes="[20, 30, 40, 50]"
      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,
  majorListPower
} from "@/api/laboratory/approval";
  import { listMajorAll } from '@/api/system/major'

  export default {
    name: "passed",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 审批记录表格数据
        approvalList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        dateRange:[],
        majorList:[],//专业

        recordContents: [
          {
            type: 0,
            value: "未通过",
          },
          {
            type: 1,
            value: "已办理",
          },
          {
            type: 2,
            value: "待审核",
          },
          {
            type: 3,
            value: "即将过期",
          },
          {
            type: 4,
            value: "已过期",
          },
        ],
        // 查询参数
        queryParams: {
          subjectName:'',//实验室
          userMajorId:'',//专业
          beginTime:'',
          endTime:'',
          pageNum: 1,
          pageSize:20,
          joinUserId: null,
          recordContent: null,
          deptId: null,
          deptName: null,
          userId: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
    },
    mounted(){
      this.getList();
      this.getMajorList();
    },
    methods: {
      goInfoPage(row){
        this.$parent.pageClick(1,row);
      },
      /**查询专业*/
      getMajorList() {
        let _this=this;
        this.majorList=[];
        majorListPower().then(response => {
          for(let i=0;i<response.rows.length;i++){
            if(response.rows[i].majorName!=null && response.rows[i].majorName!='' ){
              _this.majorList.push(response.rows[i])
            }
          }

        });
      },
      /** 查询审批记录列表 */
      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
        }
        this.queryParams.auditStatus = 2
        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.queryParams.subjectName='';
        this.queryParams.beginTime='';
        this.queryParams.endTime='';
        this.queryParams.userMajorId='';
        this.dateRange=[];
        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() {
        let date = new Date();
        let monthStr = (date .getMonth()+1);
        let dateStr = date.getDate();
        let hoursStr = date.getHours();
        if(monthStr<10){
          monthStr = '0'+monthStr
        }
        if(dateStr<10){
          dateStr = '0'+dateStr
        }
        if(hoursStr<10){
          hoursStr = '0'+hoursStr
        }
        let newDateStr = date .getFullYear()+''+monthStr+''+dateStr+''+hoursStr;
        this.download('laboratory/apply/export', {
          ...this.queryParams
        }, '准入资格'+newDateStr+'.xlsx')
      }
    }
  };
</script>
<style scoped lang="scss">
  .passed {
    flex:1;
    display: flex!important;
    flex-direction: column;
  }
</style>
