<template>
  <div>
    <el-form :model="searchForm" inline @submit.prevent>
      <el-form-item>
        <el-input v-model="searchForm.phone" placeholder="学员手机号" clearable />
      </el-form-item>
      <el-form-item>
        <el-select v-model="searchForm.memberId" placeholder="选择会员类型" clearable filterable>
          <el-option
            v-for="item in vipOptions"
            :key="item.memberId"
            :label="item.memberName"
            :value="item.memberId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="searchList">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableList" height="calc(100vh - 260px)">
      <el-table-column type="index" width="55" align="center" />
      <el-table-column label="手机号" align="left" prop="phone" min-width="140" />
      <el-table-column label="会员名" align="left" prop="memberName" min-width="140" />
      <el-table-column label="来源" align="left" prop="source" min-width="100" />
      <el-table-column label="截止日期" align="left" prop="endDate" min-width="120" />
      <el-table-column label="操作人" align="left" prop="operUser" min-width="100" />
      <el-table-column label="操作时间" align="left" prop="operTime" min-width="120" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="searchForm.pageNo"
      v-model:limit="searchForm.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="VipUser">
import { getVipTypeList, searchVipRecord } from '@/api/gds/appletUser'
const searchForm = ref({
  memberId: undefined,
  phone: undefined,
  pageNo: 1,
  pageSize: 50
})

const loading = ref(false)
const tableList = ref([])
const total = ref(0)

const vipOptions = ref([])

onMounted(() => {
  changeCarType()
})

function changeCarType() {
  getVipTypeList({ pageNo: 1, pageSize: -1 }).then((response) => {
    vipOptions.value = response.list
  })
  searchList()
}

function searchList() {
  searchForm.value.pageNo = 1
  getList()
}

function getList() {
  loading.value = true
  searchVipRecord(searchForm.value).then((response) => {
    tableList.value = response.list
    total.value = response.total
    loading.value = false
  })
}
</script>

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