<template>
    <div class="charge-record">
        <el-card shadow="never" class="!border-none">
            <el-alert title="温馨提示： 用户充值记录" type="success" :closable="false" show-icon />

            <el-form :model="formData" label-width="90px" inline class="mt-[16px]">
                <el-form-item label="充值单号">
                    <el-input class="w-[280px]" v-model="formData.sn" placeholder="请输入充值单号" />
                </el-form-item>
                <el-form-item label="用户信息">
                    <el-input class="w-[280px]" v-model="formData.keyword" placeholder="请输入用户信息" />
                </el-form-item>
                <el-form-item label="支付方式">
                    <el-select v-model="formData.payWay" class="w-[280px]" placeholder="请选择">
                        <el-option label="全部" value />
                        <el-option label="微信支付" :value="1" />
                        <el-option label="支付宝支付" :value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="支付状态">
                    <el-select v-model="formData.payStatus" class="w-[280px]" placeholder="请选择">
                        <el-option label="全部" value />
                        <el-option label="未支付" :value="0" />
                        <el-option label="已支付" :value="1" />
                    </el-select>
                </el-form-item>
                <el-form-item label="下单时间">
                    <daterange-picker v-model:startTime="formData.startTime" v-model:endTime="formData.endTime">
                    </daterange-picker>
                </el-form-item>
                <el-form-item>
                    <div class="ml-[20px]">
                        <el-button type="primary" @click="resetPage">查询</el-button>
                        <el-button @click="resetParams">重置</el-button>
                        <!-- <el-button @click="resetParams">导出</el-button> -->
                    </div>
                </el-form-item>
            </el-form>
        </el-card>

        <el-card shadow="never" class="!border-none mt-4">
            <div class="m-t-20">
                <el-table ref="tableData" :data="pager.lists" style="width: 100%" v-loading="pager.loading">
                    <el-table-column prop="id" label="ID" />
                    <el-table-column prop="nickname" label="用户信息" min-width="180">
                        <template #default="{ row }">
                            <div class="flex items-center">
                                <el-image style="width: 60px; height: 60px" :src="row?.avatar"></el-image>
                                <div class="ml-2">{{ `${row.nickname}` }}</div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="orderSn" label="充值单号" min-width="180" />
                    <el-table-column prop="orderAmount" label="充值金额" />
                    <el-table-column prop="payWay" label="支付方式" />
                    <el-table-column prop="payStatus" label="支付状态">
                        <template #default="{ row }">
                            <div v-if="!row.payStatus" style="color: red">未支付</div>
                            <div v-if="row.payStatus">已支付</div>
                        </template>
                    </el-table-column>
                    <el-table-column property="createTime" label="提交时间" min-width="180" />
                    <el-table-column property="payTime" label="支付时间" min-width="180" />
                </el-table>
            </div>

            <div class="flex justify-end mr-2">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { apiRechargeRecord } from '@/api/finance/recharge'
import { ref } from 'vue'
import Pagination from '@/components/pagination/index.vue'
import { usePaging } from '@/hooks/usePaging'
// import DataPicker from "@/components/data-picker/index.vue";

interface FormDataObj {
    sn: number | any // 充值订单编号
    keyword?: string // 用户信息
    payWay: number | string // 支付方式
    payStatus?: number | string // 支付状态：0-待支付 1-已支付
    startTime: string // 开始下单时间
    endTime: string // 结束下单时间
}

// 表单数据
const formData = ref<FormDataObj>({
    sn: '',
    keyword: '',
    payWay: '',
    payStatus: '',
    startTime: '',
    endTime: ''
})
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiRechargeRecord,
    params: formData.value
})

getLists()
</script>

<style lang="scss">
.ls-input {
    width: 170px;
}

.el-alert--success.is-light {
    background-color: #edefff;
    color: #4a5dff;
}
</style>
