<template>
  <div style="padding: 0 20px">
    <div ref="lxHeader">
      <lx-header icon="md-apps" text="会员管理" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
        <div slot="content"></div>
        <slot>
          <div>
            <Input style="width: 200px; margin-right: 10px" placeholder="关键字搜索" />
            <Button type="primary">查询</Button>
            <Button type="primary" style="margin-left: 10px" >新增会员</Button>
          </div>
        </slot>
      </lx-header>
    </div>

    <xy-table :list="list" :table-item="table"></xy-table>

    <div style="display: flex;justify-content: flex-end;">
      <Page :total="total" show-elevator @on-change="pageChange"/>
    </div>
  </div>
</template>

<script>
import {index} from '@/api/member'
import {parseTime} from "@/utils"
export default {
  data() {
    return {
      select:{
        pageSize:10,
        pageIndex:1
      },

      total:0,
      list:[],
      table:[
        {
          prop:'name',
          label:'姓名',
          width:180,
          sortable:false
        },
        {
          prop:'phone',
          label:'电话',
          width:200
        },
        {
          prop:'due_date',
          label:'预产期',
          width: 200
        },
        {
          prop:'area',
          label:'所属区域',
          width: 160,
        },
        {
          prop:'address',
          label:'住址',
          align:'left',
          width: 300
        },
        {
          prop:'hospital',
          label:'建卡医院',
          width: 200
        },
        {
          prop:'promotion',
          label:'推广人员',
          width:140,
          customFn:(row)=>{
            return (<Tag color={row.promotion == 1 ? 'success' : 'error'}>{row.promotion == 1 ? '是' : '否'}</Tag>)
          }
        },
        {
          prop:'created_at',
          label:'注册日期',
          width:200,
          formatter:(cell,data,value)=>{
            return parseTime(new Date(value),'{y}-{m}-{d}')
          }
        }
      ]
    }
  },
  methods: {
    pageChange(e){
      this.select.pageIndex = e
      this.getMembers()
    },

    async getMembers(){
      const res = await index({
        page_size:this.select.pageSize,
        page:this.select.pageIndex
      })
      console.log(res)
      this.total = res.total
      this.list = res.data
    }
  },
  mounted() {
    this.getMembers()
  }

}
</script>

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