<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="filter-container">
      <div class="filter-control">
        <span>供应商名称:</span>
        <el-input v-model="listQuery.shopName" placeholder="供应商名称" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <span>供应商类型:</span>
        <el-select v-model="listQuery.shopType" placeholder="供应商类型" clearable @change="getList">
          <el-option label="所有类型" value="" />
          <el-option label="代理商" :value="2" />
          <el-option label="品牌方" :value="1" />
        </el-select>
      </div>
      <div class="filter-control">
        <span>手机号:</span>
        <el-input v-model="listQuery.mobile" placeholder="手机号" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <span>审核状态:</span>
        <el-select v-model="listQuery.lowerAuditStatus" placeholder="审核状态" clearable @change="getList">
          <el-option label="全部" value="" />
          <el-option label="已完成审核" :value="1" />
          <el-option label="未完成审核" :value="0" />
        </el-select>
      </div>
      <div class="filter-control">
        <span>联系人:</span>
        <el-input v-model="listQuery.linkMan" placeholder="联系人" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList">查询</el-button>
      </div>
    </div>
    <!-- 搜索区域END -->
    <!-- 表格区域 -->
    <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 :index="indexMethod" label="序号" type="index" width="80" align="center" />
      <el-table-column prop="name" label="供应商名称" align="center" />
      <el-table-column label="供应商类型" width="150px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.shopType === 1">品牌方</span>
          <span v-if="row.shopType === 2">代理商</span>
        </template>
      </el-table-column>
      <el-table-column prop="mobile" label="手机号" width="200px" align="center" />
      <el-table-column prop="linkMan" label="联系人" width="200px" align="center" />
      <el-table-column label="审核状态" width="220px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.lowerAuditStatus === 0" class="status warning">未完成审核</span>
          <span v-if="row.lowerAuditStatus === 1" class="status success">已完成审核</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160px" align="center">
        <template slot-scope="{ row }">
          <el-badge :hidden="row.lowerAuditStatus === 1" :value="row.productTypeWaitNum" :max="99">
            <el-button
              type="primary"
              size="mini"
              @click="navigationTo(`/audit/device/device-list?authUserId=${row.authUserId}`)"
            >设备分类审核</el-button>
          </el-badge>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域END -->
    <!-- 页码 -->
    <pagination
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList(listQuery)"
    />
  </div>
</template>

<script>
import { fetchSupplierList } from '@/api/supplier'
export default {
  name: 'AuditDevice',
  data() {
    return {
      listQuery: {
        listType: 6,
        infoId: '', // 品牌id
        linkMan: '', // 联系人
        mobile: '', // 手机号
        pageNum: 0, // 页码
        pageSize: 10, // 分页大小
        shopName: '', // 供应商名称
        shopType: '', // 供应商类型
        lowerAuditStatus: ''
      },
      listLoading: false,
      list: [],
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 过滤列表
    handleFilter() {},
    // 获取供应商列表
    getList() {
      this.listLoading = true
      fetchSupplierList(this.listQuery)
        .then((res) => {
          if (res.code !== 0) return
          this.list = res.data.list
          this.total = res.data.total
        })
        .finally(() => {
          this.listLoading = false
        })
    },
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>

<style lang="scss" scoped>
.el-table .cell {
  overflow: visible;
}
</style>
