<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="序号" :index="indexMethod" 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="150px" 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="460px" align="center">
        <template slot-scope="{ row }">
          <el-badge :hidden="row.articleWaitNum === 0" :value="row.articleWaitNum" :max="99">
            <el-button
              type="primary"
              icon="el-icon-tickets"
              size="mini"
              @click="$_navigationTo(`material/article-list?authUserId=${row.authUserId}`)"
            >文章</el-button>
          </el-badge>
          <el-badge :hidden="row.imageWaitNum === 0" :value="row.imageWaitNum" :max="99">
            <el-button
              type="primary"
              icon="el-icon-picture-outline"
              size="mini"
              @click="$_navigationTo(`material/image-list?authUserId=${row.authUserId}`)"
            >图片</el-button>
          </el-badge>
          <el-badge :hidden="row.videoWaitNum === 0" :value="row.videoWaitNum" :max="99">
            <el-button
              type="primary"
              icon="el-icon-video-camera"
              size="mini"
              @click="$_navigationTo(`material/video-list?authUserId=${row.authUserId}`)"
            >视频</el-button>
          </el-badge>
          <el-badge :hidden="row.fileWaitNum === 0" :value="row.fileWaitNum" :max="99">
            <el-button
              type="primary"
              icon="el-icon-document-copy"
              size="mini"
              @click="$_navigationTo(`material/file-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 Pagination from '@/components/Pagination'
import { fetchSupplierList } from '@/api/supplier'
export default {
  components: { Pagination },
  data() {
    return {
      listLoading: false,
      total: 0,
      listQuery: {
        listType: 3,
        brandId: '', // 品牌id
        linkMan: '', // 联系人
        mobile: '', // 手机号
        pageNum: 1, // 页码
        pageSize: 10, // 分页大小
        shopName: '', // 供应商名称
        shopType: '', // 供应商类型
        lowerAuditStatus: ''
      },
      list: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取供应商待审核列表数据
    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>
.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;
}
.el-badge{
  margin: 0 6px;
}
</style>
