<template>
  <div>
    <div class="filter-container">
      <div class="filter-control">
        <span>机构名称:</span>
        <el-input v-model="listQuery.authParty" placeholder="机构名称" @keyup.enter.native="handleFilter" />
      </div>
      <div class="filter-control">
        <span>手机号:</span>
        <el-input
          v-model="listQuery.mobile"
          placeholder="手机号"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="handleFilter"
        />
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList(listQuery)">查询</el-button>
      </div>
    </div>
    <!-- 表格区域 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%"
      border
      fit
      highlight-current-row
      header-row-class-name="tableHeader"
      cell-class-name="table-cell"
    >
      <el-table-column label="序号" :index="indexMethod" type="index" width="80" align="center" />
      <el-table-column prop="authParty" label="机构名称" align="center" />
      <el-table-column label="手机号" width="120px" align="center" prop="mobile" />
      <el-table-column label="审核状态" width="120px" align="center">
        <template slot-scope="{ row }">
          <audit-status :status="row.shopAuditStatus" :reason="row.invalidReason" />
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" width="200px">
        <template slot-scope="{ row }">
          <span v-if="row.shopAuditStatus !== 2">{{ row.shopAuditBy }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.shopAuditStatus !== 2">{{ row.shopAuditTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.shopAuditStatus !== 2">{{ row.createTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="240px" align="center">
        <template slot-scope="{ row }">
          <permission-button
            v-if="row.shopAuditStatus === 1"
            type="primary"
            size="mini"
            style="margin-right: 5px"
            @click="onClick(row, 'review')"
          >查看</permission-button>
          <permission-button
            v-else
            type="primary"
            size="mini"
            style="margin-right: 5px"
            @click="onClick(row, 'audit')"
          >审核</permission-button>
          <el-badge :hidden="row.shopWaitAuditNum === 0" :value="row.shopWaitAuditNum" :max="99">
            <permission-button
              type="primary"
              size="mini"
              @click="navigationTo(`/supplier-audit/club/device/list?authId=${row.authId}`)"
            >设备认证</permission-button>
          </el-badge>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域END -->
    <!-- 页码 -->
    <pagination
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="fecthAuthList"
    />
  </div>
</template>

<script>
import { fecthAuthList } from '@/api/auth'
import { mapGetters } from 'vuex'
export default {
  props: {
    shopAuditStatus: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      listLoading: false,
      // 查询参数
      listQuery: {
        listType: 3,
        authParty: '', // 授权机构
        mobile: '',
        authUserId: '', // 供应商用户id
        pageNum: 1, // 页码
        pageSize: 10, // 分页
        shopAuditStatus: 0
      },
      total: 0,
      // 机构信息审核列表
      list: []
    }
  },
  computed: {
    ...mapGetters(['authUserId'])
  },
  created() {
    this.listQuery.authUserId = this.authUserId
    this.listQuery.shopAuditStatus = this.shopAuditStatus
    this.getList()
  },
  methods: {
    // 获取授权列表
    getList() {
      this.listQuery.pageNum = 1
      this.list = []
      this.fecthAuthList()
    },

    async fecthAuthList() {
      try {
        this.listLoading = true
        const res = await fecthAuthList(this.listQuery)
        this.list = res.data.list
        this.total = res.data.total
      } catch (error) {
        console.log(error)
      } finally {
        this.listLoading = false
      }
    },

    onClick(row, type) {
      this.$router.push(`/supplier-audit/club/club-detail?authId=${row.authId}&type=${type}`)
    },

    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>
