<template>
  <div class="members-page">
    <h2 class="page-title">会员管理</h2>
    <el-card>
      <el-form :inline="true" class="search-form">
        <el-form-item>
          <el-input v-model="keyword" placeholder="会员姓名/手机号" clearable style="width: 200px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="fetchList">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="list" border size="small" :header-cell-style="{ background:'#f8fafc', color:'#64748b', fontWeight:600 }" v-loading="loading">
        <el-table-column prop="khmc" label="会员姓名" width="120" />
        <el-table-column prop="sjh" label="手机号" width="140" />
        <el-table-column prop="gsmdName" label="归属门店" width="140" />
        <el-table-column label="操作" width="120" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="viewDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-size="pageSize"
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        @size-change="val => { pageSize = val; handlePageChange(1) }"
        @current-change="handlePageChange"
        style="margin-top: 16px; text-align: right;"
      />
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Members',
  data() {
    return {
      keyword: '',
      list: [],
      loading: false,
      page: 1,
      pageSize: 10,
      total: 0
    }
  },
  created() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      this.loading = true
      // TODO: 对接会员列表接口
      setTimeout(() => {
        this.list = []
        this.total = 0
        this.loading = false
      }, 300)
    },
    resetSearch() {
      this.keyword = ''
      this.page = 1
      this.fetchList()
    },
    handlePageChange(p) {
      this.page = p
      this.fetchList()
    },
    viewDetail(row) {
      this.$message.info('详情功能待对接')
    }
  }
}
</script>

<style lang="scss" scoped>
.page-title {
  margin: 0 0 20px;
  font-size: 20px;
  color: #303133;
}

.search-form {
  margin-bottom: 16px;
}
</style>
