<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-control">
        <span>培训医师姓名:</span>
        <el-input v-model="listQuery.doctorName" placeholder="培训医师姓名" @keyup.enter.native="handleFilter" />
      </div>
      <div class="filter-control">
        <span>从业资格证编号:</span>
        <el-input v-model="listQuery.certificateNo" placeholder="从业资格证编号" @keyup.enter.native="handleFilter" />
      </div>
      <div class="filter-control">
        <span>审核状态:</span>
        <el-select v-model="listQuery.auditStatus" placeholder="审核状态" clearable @change="getList">
          <el-option label="全部" value="" />
          <el-option label="待审核" :value="2" />
          <el-option label="审核通过" :value="1" />
          <el-option label="审核未通过" :value="0" />
        </el-select>
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList">查询</el-button>
      </div>
    </div>
    <!-- 表格区域 -->
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      header-row-class-name="tableHeader"
    >
      <el-table-column label="序号" :index="indexMethod" type="index" align="center" width="80" />
      <el-table-column label="医生姓名" align="center" prop="doctorName" />
      <el-table-column label="从业资格证编号" align="center" prop="certificateNo" />

      <el-table-column label="审核状态" width="120px" align="center">
        <template slot-scope="{ row }">
          <el-tag v-if="row.auditStatus === 2" size="small" type="warning">待审核</el-tag>
          <el-tag v-if="row.auditStatus === 1" size="small" type="success">审核通过</el-tag>
          <!-- 未通过原因展示 -->
          <template v-if="row.auditStatus === 0">
            <!-- <span class="status danger">审核未通过&nbsp;</span> -->
            <el-popover placement="top-start" title="审核说明" width="400" trigger="hover" :content="row.invalidReason">
              <el-tag slot="reference" size="small" type="danger" class="reason">
                <span>审核未通过</span>
                <span class="el-icon-question status danger " />
              </el-tag>
            </el-popover>
            <!-- 未通过原因展示END -->
          </template>
        </template>
      </el-table-column>

      <el-table-column label="审核时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.auditStatus !== 2">{{ row.auditTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>

      <el-table-column label="审核人" align="center" width="280px">
        <template slot-scope="{ row }">
          <span v-if="row.auditStatus !== 2">{{ row.auditBy }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>

      <!-- <el-table-column v-if="false" label="创建人" width="180px" align="center" prop="createBy" /> -->
      <el-table-column label="操作" align="center" width="160px" class-name="small-padding fixed-width">
        <template slot-scope="{ row }">
          <el-button
            v-if="row.auditStatus !== 1"
            type="primary"
            size="mini"
            @click="$_navigationTo(`doctor-detail?id=${row.doctorId}`)"
          >
            审核
          </el-button>
          <span v-else class="status success el-icon-check">&nbsp;已审核</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { mapGetters } from 'vuex'
import { fetchDoctorList } from '@/api/doctor'

export default {
  components: { Pagination },
  data() {
    return {
      listLoading: false,
      tableKey: 0,
      total: 0,
      listQuery: {
        authUserId: '',
        listType: 2,
        auditStatus: '',
        certificateNo: '',
        doctorName: '',
        doctorType: 2,
        status: '',
        pageNum: 1,
        pageSize: 10
      },
      list: []
    }
  },
  computed: {
    ...mapGetters(['authUserId', 'proxyInfo'])
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.listQuery.authUserId = this.$route.query.authUserId

      console.log(this.listQuery.authUserId)
      fetchDoctorList(this.listQuery).then(res => {
        console.log(res)
        this.list = res.data.list
        this.total = res.data.total
      })
    },
    // 表格索引
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
