<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-input v-model="listQuery.linkMan" placeholder="联系人" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <span>会员状态:</span>
        <el-select v-model="listQuery.vipStatus" 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">
        <el-button type="primary" @click="getList">查询</el-button>
        <el-button type="primary" @click="navigationTo('/member/handsel')">赠送会员</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"
      class="table-cell"
    >
      <el-table-column :index="indexMethod" label="序号" type="index" width="80" align="center" />
      <el-table-column prop="shopName" label="供应商名称" align="center" />
      <el-table-column label="供应商类型" align="center">
        <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" />
      <el-table-column prop="linkMan" label="联系人" align="center" />
      <el-table-column label="会员状态" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.vipStatus === '1'" class="status success">生效中</span>
          <span v-else class="status danger">已过期</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="280">
        <template slot-scope="{ row }">
          <el-button
            type="primary"
            size="mini"
            @click="navigationTo(`/member/record?id=${row.authUserId}`)"
          >购买记录</el-button>
          <el-button
            type="primary"
            size="mini"
            @click="navigationTo(`/member/service?id=${row.authUserId}`)"
          >配置订制化服务</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <pagination :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { fetchMemberList } from '@/api/member'
export default {
  name: 'MemberList',
  data() {
    return {
      listLoading: false,
      listQuery: {
        linkMan: '',
        mobile: '',
        vipStatus: '',
        shopName: '',
        shopType: '',
        pageNum: 1,
        pageSize: 10
      },
      list: [],
      total: 0,
      hasNextPage: false
    }
  },
  created() {
    this.getList()
  },
  activated() {
    this.getList()
  },
  methods: {
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    },
    getList() {
      fetchMemberList(this.listQuery)
        .then((res) => {
          console.log(res)
          this.list = res.data.list
          this.hasNextPage = res.data.hasNextPage
          this.total = res.data.total
        })
        .catch((error) => {
          console.log(error)
        })
    }
  }
}
</script>

<style scoped lang="scss"></style>
