<template>
  <div>
    <el-form :model="searchForm" inline @submit.prevent>
      <el-form-item>
        <el-input v-model="searchForm.phone" placeholder="学员手机号" />
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="searchForm.distributionId"
          placeholder="选择分销人"
          clearable
          filterable
        >
          <el-option
            v-for="item in distributionOptions"
            :key="item.distributionId"
            :label="item.name"
            :value="item.distributionId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="searchForm.createDate"
          type="daterange"
          range-separator="-"
          value-format="YYYY-MM-DD"
          format="YYYY-MM-DD"
          start-placeholder="充值日期"
          end-placeholder="充值日期"
        />
      </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" width="140" />
      <el-table-column label="会员名" align="left" prop="memberName" min-width="140" />
      <el-table-column label="支付金额" align="left" prop="money" min-width="100" />
      <el-table-column label="车型" prop="carName" align="left" width="100" />
      <el-table-column label="科目" align="left" prop="subjects" width="100" />
      <el-table-column label="充值日期" align="left" prop="payTime" min-width="120" />
      <el-table-column label="截止日期" align="left" prop="endDate" min-width="120" />
      <el-table-column label="分销人" align="left" prop="distributionName" min-width="100" />
    </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="Recharge">
import { getRechargeRecords } from '@/api/xjapplet/vip'
import { getResellSimpleList } from '@/api/xjapplet/resell'

const searchForm = ref({
  distributionId: undefined,
  phone: undefined,
  createDate: [],
  pageNo: 1,
  pageSize: 50
})

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

const distributionOptions = ref([])

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

function changeCarType() {
  getResellSimpleList().then((response) => {
    distributionOptions.value = response
  })
  searchList()
}

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

function getList() {
  loading.value = true
  if (searchForm.value.createDate && searchForm.value.createDate.length > 0) {
    searchForm.value.payTimeBegin = searchForm.value.createDate[0] + ' 00:00:00'
    searchForm.value.payTimeEnd = searchForm.value.createDate[1] + ' 23:59:59'
  } else {
    searchForm.value.payTimeBegin = undefined
    searchForm.value.payTimeEnd = undefined
  }
  getRechargeRecords(searchForm.value).then((response) => {
    tableList.value = response.list
    total.value = response.total
    loading.value = false
  })
}
</script>

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