<!-- 报表-会员报表 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" :loading="loading">
                <template #before>
                    <app-date-range v-model:cycleType="cycleType" v-model:dateValue="dateValue" />
                </template>
            </app-filter>
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="columns" :loading="loading">
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onRefresh" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { useDataFilter } from '@/hooks/datatable'
import { useMemberReportList } from '@/business/report'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'
import AppDateRange from '../components/daterange/index.vue'

const { loading, dataList, columns, total, pageIndex, pageSize, cycleType, dateValue, getMemberReportList } = useMemberReportList()
const { filterOptons } = useDataFilter<Ermcp.MemberReportReq>()

const onSearch = (clear = false) => {
    if (clear) {
        dateValue.value = []
    }
    pageIndex.value = 1
    getMemberReportList()
}

const onRefresh = () => {
    getMemberReportList().catch((err) => ElMessage.error(err))
}

filterOptons.buttonList = [
    { lable: '重置', onClick: () => onSearch(true) },
    { lable: '查询', className: 'el-button--primary', onClick: () => onSearch() }
]

onRefresh()
</script>