<!--供应商管理-->
<template>
  <div class="page-container supplier">
    <div class="page-top-title-box">
      <p class="page-top-title-name-p">{{pageData.subName+' - 已授权列表'}}</p>
      <p class="page-top-title-out-p" @click="backPage">返回</p>
    </div>
    <div class="page-form-title-box">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="" prop="searchValue">
          <el-input
            maxlength="20"
            v-model="queryParams.searchValue"
            placeholder="姓名/工号/学号"
            clearable
            size="small"/>
        </el-form-item>
        <el-form-item label="" prop="userType" >
          <el-select v-model="queryParams.userType" clearable placeholder="类别">
            <el-option
              v-for="item in optionsListTwo"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="state" >
          <el-select v-model="queryParams.state" clearable placeholder="状态">
            <el-option
              v-for="item in optionsList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <p class="page-inquire-common-style-button" @click="handleQuery" style="margin-right:10px;">查询</p>
        <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        <p class="page-submit-common-style-button"
           style="float: right;"
           @click="allButton"
        >批量重试</p>
      </el-form>
    </div>
    <div class="page-content-box">
      <el-table class="table-box" border :data="tableData" ref="table-box" :row-key="getRowKeys2" @selection-change="handleSelectionChange2">
        <el-table-column type="selection" width="55" :reserve-selection="true" align="center"></el-table-column>
        <el-table-column label="所属单位" align="left" prop="deptName" show-overflow-tooltip/>
        <el-table-column label="姓名" align="left" prop="nickName"></el-table-column>
        <el-table-column label="类别" align="left" prop="userType">
          <template slot-scope="scope">
            <span>{{scope.row.userType == 0?'系统':(scope.row.userType == 1?'教职工':(scope.row.userType == 2?'学生':(scope.row.userType == 3?'大屏':'')))}}</span>
          </template>
        </el-table-column>
        <el-table-column label="授权状态" align="left" prop="isretry">
          <template slot-scope="scope">
            <span v-if="scope.row.state">成功</span>
            <span v-if="!scope.row.state">失败</span>
          </template>
        </el-table-column>
        <el-table-column label="授权时间" align="left" prop="createTime" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{parseTime(scope.row.createTime,'{y}-{m}-{d} {h}:{i}')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="授权人" align="left" prop="createName"></el-table-column>
        <el-table-column label="失效时间" align="left" prop="invalidTime" width="200">
          <template slot-scope="scope">
            <span>{{parseTime(scope.row.invalidTime,'{y}-{m}-{d} {h}:{i}')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="handleClick(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"
                  style="margin:0;"
                  :page.sync="queryParams.page"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
  import { laboratoryHaikangUserUserList,laboratoryHaikangUserRetryAccredit } from '@/api/integratedManagement/index'
  import {
    AddImpowerHaikang,
    delUserHaikang,
    editImpowerHaikang,
    getHaikangQueryTypes,
    getHaikangUserList, retryImpowerHaikang
  } from '@/apiDemo/laboratory/subject'

  export default {
    name: 'Approval',
    props: {
      pageData: {}
    },
    data() {
      return {
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 20,
          searchValue: '',
          userType: '',
          hardId: '',
          startTime: '',
          endTime: ''
        },
        total: 0,
        tableData: [],
        dateRange: [],
        unifyDeploy: false,
        optionsList:[{ label: '授权验证成功', value: true }, { label: '授权验证失败', value: false }],
        optionsListTwo:[{ label: '学生', value: '2' }, { label: '教师', value: '1' }],
        impowerList:[],
      }

    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.queryParams.pageSize = 20;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'queryParams',{});
        this.$refs['table-box'].clearSelection();
        this.$set(this,'impowerList',[]);
        this.handleQuery();
      },
      //返回
      backPage() {
        this.$parent.handleClick('', '', 'back')
        this.$parent.getList()
      },
      getList() {
        laboratoryHaikangUserUserList(this.queryParams).then(response => {
          this.$set(this,'tableData',response.data.records);
          this.$set(this,'total',response.data.total);
        })
      },
      handleClick(row){
        let obj = {
          hardId: row.hardId,
          detailList: [
            {id: row.id}
          ]
        };
        laboratoryHaikangUserRetryAccredit(obj).then(response => {
          this.msgSuccess(response.message)
          this.getList();
        })
      },
      allButton(){
        let self = this;
        if(!this.impowerList[0]){
          this.msgError('请勾选数据')
          return
        }
        let obj = {
          hardId: this.pageData.hardId,
          detailList:[]
        };
        for(let i=0;i<self.impowerList.length;i++){
          obj.detailList.push({id:self.impowerList[i]})
        }
        laboratoryHaikangUserRetryAccredit(obj).then(response => {
          this.$refs['table-box'].clearSelection();
          this.$set(this,'impowerList',[]);
          this.msgSuccess(response.message)
          this.getList();
        })
      },
      getRowKeys2(row) {
        return row.id;   //指定row-key的一个标识
      },
      //已授权列表
      handleSelectionChange2(val){
        this.$set(this,'impowerList',val.map(item => item.id));

      },
    },
    mounted() {
      this.queryParams.hardId = this.pageData.hardId
      this.getList()
    }
  }
</script>

<style lang="scss">
  .supplier {
  }
</style>
