<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="filter-container">
      <span>供应商名称:</span>
      <el-input
        v-model="listQuery.shopName"
        placeholder="供应商名称"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="getList"
      />
      <span>供应商类型:</span>
      <el-select
        v-model="listQuery.shopType"
        placeholder="供应商类型"
        clearable
        style="width: 200px"
        class="filter-item"
        @change="getList"
      >
        <el-option label="所有类型" value="" />
        <el-option label="代理商" :value="2" />
        <el-option label="品牌方" :value="1" />
      </el-select>
      <span>手机号:</span>
      <el-input
        v-model="listQuery.mobile"
        placeholder="手机号"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="getList"
      />
      <span>审核状态:</span>
      <el-select
        v-model="listQuery.lowerAuditStatus"
        placeholder="供应商类型"
        clearable
        style="width: 200px"
        class="filter-item"
        @change="getList"
      >
        <el-option label="全部" value="" />
        <el-option label="已完成审核" :value="1" />
        <el-option label="未完成审核" :value="0" />
      </el-select>
      <span>联系人:</span>
      <el-input
        v-model="listQuery.linkMan"
        placeholder="联系人"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="getList"
      />
      <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
    </div>
    <!-- 搜索区域END -->
    <!-- 表格区域 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%"
      border
      fit
      highlight-current-row
      cell-class-name="table-cell"
    >
      <el-table-column 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 }">
          <el-tag v-if="row.lowerAuditStatus === 0" size="small" type="danger">未完成审核</el-tag>
          <el-tag v-if="row.lowerAuditStatus === 1" size="small" type="success">已完成审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="240px" align="center">
        <template slot-scope="{ row }">
          <el-badge :hidden="row.lowerAuditStatus === 1" :value="row.waitAuditNum" :max="99">
            <el-button
              type="primary"
              icon="el-icon-s-check"
              size="mini"
              @click="$_navigationTo(`auth-list?authUserId=${row.authUserId}`)"
            >品牌授权信息审核</el-button>
          </el-badge>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域END -->
    <!-- 页码 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList(listQuery)"
    />
  </div>
</template>

<script>
import { fetchSupplierList } from '@/api/supplier'
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data() {
    return {
      listQuery: {
        listType: 2,
        brandId: '', // 品牌id
        linkMan: '', // 联系人
        mobile: '', // 手机号
        pageNum: 0, // 页码
        pageSize: 20, // 分页大小
        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
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.filter-container {
  span {
    display: inline-block;
    margin-bottom: 10px;
    vertical-align: middle;
    font-size: 14px;
  }
  .el-button {
    display: inline-block;
    margin-bottom: 10px;
    vertical-align: middle;
  }
  .el-input,
  .el-select {
    margin-right: 10px;
    margin-left: 10px;
  }
}
.el-table .cell {
  overflow: visible;
}
</style>
