<!--准入凭证审核/已通过-->
<template>
  <div class="passed page-container">
    <div class="passed-page page-container">
      <div class="page-form-title-box">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
          <el-form-item label="" prop="releaseDescribe">
            <el-input
              v-model="queryParams.searchValue"
              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.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-inquire-common-style-button" style="margin-left: 10px"
             @click="handleExport">导出</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="申请人" align="left" prop="userName"/>
          <el-table-column label="申请人身份" align="left" prop="userType">
            <template slot-scope="scope">
              {{scope.row.userType == '1' ? '教职工':(scope.row.userType == '2' ? '学生':'')}}
            </template>
          </el-table-column>
          <el-table-column label="申请实验室" align="left" prop="subName"/>
          <el-table-column label="申请时间" align="left" prop="creatTime">
            <template slot-scope="scope">
              <span>{{parseTime(scope.row.creatTime,'{y}-{m}-{d} {h}:{i}')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="有效期" align="left" prop="validBeginTime">
            <template slot-scope="scope">
              <span>{{parseTime(scope.row.validBeginTime,'{y}-{m}-{d} {h}:{i}')}} 至 {{parseTime(scope.row.validEndTime,'{y}-{m}-{d} {h}:{i}')}}</span>
            </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="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   v-hasPermiRouter="['laboratory:audit:detail']"
                   @click="goInfoPage(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"
                    layout="total, prev, pager, next, sizes, jumper"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
  import {
    listApproval,
    getApproval,
    delApproval,
    addApproval,
    updateApproval,
    applyApproval,
    applyList,
    majorListPower,
    listMajorAll
  } from '@/api/secureAccess/index'
  //                    V3
  import { systemUserMajorSelect } from '@/api/commonality/permission'
  import { laboratoryApplyList } from '@/api/secureAccess/index'

  export default {
    name: 'passed',
    data() {
      return {
        tableButtonType:this.hasPermiDom(['laboratory:audit:detail']),
        pageType:1,
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 审批记录表格数据
        dataList: [],
        // 查询参数
        dateRange: [],
        majorList: [],//专业
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 20,
          searchValue: null,
          userMajorId: null,
        },
      }
    },
    created() {
    },
    mounted() {
      this.getList()
      this.systemUserMajorSelect()
    },
    methods: {
      goInfoPage(row) {
        this.$parent.pageClick(true,1,row);
      },
      /**查询专业*/
      systemUserMajorSelect() {
        systemUserMajorSelect({ type: 1 }).then(response => {
          this.$set(this, 'majorList', response.data)
        })
      },
      /** 查询审批记录列表 */
      getList() {
        this.loading = true
        let obj = JSON.parse(JSON.stringify(this.queryParams));
        if (this.dateRange && this.dateRange.length > 0) {
          obj.startTime = this.dateRange[0] + 'T00:00:00'
          obj.endTime = this.dateRange[1] + 'T23:59:59'
        }
        else {
          obj.startTime = null
          obj.endTime = null
        }
        obj.auditStatus = 2
        laboratoryApplyList(obj).then(response => {
          this.$set(this, 'dataList', response.data.records)
          this.$set(this, 'total', response.data.total)
          this.loading = false
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this, 'queryParams', {
          page: 1,
          searchValue: '',
          userMajorId: ''
        })
        this.dateRange = []
        this.handleQuery()
      },
      /** 导出按钮操作 */
      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 {
    .passed-page{
      .page-form-title-box {
        border: none;
      }
      .page-content-box {
        padding-top: 0;
      }
    }
  }
</style>
