<template>
  <div>
    <div class="filter-container">
      <div class="filter-control">
        <span>供应商名称:</span>
        <el-input
          v-model="listQuery.shopName"
          size="mini"
          placeholder="供应商名称"
          clearable
          @keyup.enter.native="fetchSupplierList"
        />
      </div>
      <div class="filter-control">
        <span>供应商类型:</span>
        <el-select
          v-model="listQuery.shopType"
          placeholder="供应商类型"
          size="mini"
          clearable
          @change="fetchSupplierList"
        >
          <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"
          clearable
          size="mini"
          placeholder="手机号"
          @keyup.enter.native="fetchSupplierList"
        />
      </div>
      <div class="filter-control">
        <el-button type="primary" size="mini" @click="filterSupplierList">查询</el-button>
      </div>
    </div>
    <el-table
      v-infinite-scroll="onLoad"
      :data="supplierList"
      border
      class="infinite-list hide-table-check-all"
      style="overflow: auto"
      :infinite-scroll-delay="300"
      :infinite-scroll-immediate="false"
      header-row-class-name="tableHeader"
      highlight-current-row
      @row-click="handleSelectSupplier"
    >
      >
      <el-table-column label="选择" width="55" align="center">
        <template slot-scope="{ row }">
          <el-radio v-model="selectedAuthUserId" :label="row.authUserId"><span v-show="false">1</span></el-radio>
        </template>
      </el-table-column>
      <el-table-column label="序号" type="index" width="80" align="center" />
      <el-table-column property="name" label="供应商名称" />
      <el-table-column label="供应商类型" align="center" width="120">
        <template slot-scope="{ row }">
          <span v-if="row.shopType === 1">品牌方</span>
          <span v-else>代理商</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="登录账号" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.loginAccount">{{ row.loginAccount }}</span>
          <span v-else>未绑定</span>
        </template>
      </el-table-column> -->
      <el-table-column prop="mobile" label="手机号" align="center" width="160" />
      <el-table-column prop="linkMan" label="联系人" align="center" />
    </el-table>
  </div>
</template>
<script>
import { fetchSupplierList } from '@/api/supplier'
export default {
  name: 'SupplierList',
  data() {
    return {
      listQuery: {
        shopName: '',
        shopType: '',
        mobile: '',
        pageNum: 1,
        pageSize: 10
      },
      supplierList: [],
      selectedAuthUserId: ''
    }
  },
  created() {
    this.filterSupplierList()
  },
  methods: {
    // 确认选中的供应商
    handleSubmitSupplier() {
      this.dialogTableVisible = false
      this.currentSupplierList = [this.selectedSupplierInfo]
    },
    // 选择供应商
    handleSelectSupplier(e) {
      this.selectedAuthUserId = e.authUserId
      this.selectedSupplierInfo = e
      this.$emit('selected', e)
    },
    // 选择供应商对话框关闭事件
    handleDialogClosed() {
      this.listQuery.pageNum = 1
      this.listQuery.shopName = ''
      this.listQuery.shopType = ''
      this.listQuery.mobile = ''
      this.listQuery.linkMan = ''
    },
    // 筛选供应商
    filterSupplierList() {
      this.pageNum = 1
      this.supplierList = []
      this.fetchSupplierList()
    },
    // 获取供应商列表
    fetchSupplierList() {
      fetchSupplierList(this.listQuery)
        .then((res) => {
          console.log(res)
          this.supplierList = [...this.supplierList, ...res.data.list]
          this.hasNextPage = res.data.hasNextPage
          this.total = res.data.total
        })
        .catch((error) => {
          console.log(error)
        })
    },
    onLoad() {
      if (!this.hasNextPage) return
      this.listQuery.pageNum++
      this.fetchSupplierList()
    }
  }
}
</script>
<style lang="scss" scoped></style>
