<!-- 报表-交易报表 -->
<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="getTradeReportList" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { useDataFilter } from '@/hooks/datatable'
import { Category, getCurrencyTypeList } from '@/constants/diamond'
import { useTradeReportList } 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, getTradeReportList } = useTradeReportList()
const { filterOptons, getQueryParams } = useDataFilter<Ermcp.WRPositionReportReq>()

const onSearch = (clear = false) => {
    getQueryParams((qs) => {
        pageIndex.value = 1
        getTradeReportList(qs)
    }, clear)
}

const onRefresh = () => {
    getQueryParams((qs) => {
        getTradeReportList(qs).catch((err) => ElMessage.error(err))
    })
}

filterOptons.selectList = [
    {
        label: '商品分类',
        key: 'zscategory',
        options: [
            { label: '单颗裸钻', value: Category.Diamond },
            { label: '单颗彩钻', value: Category.Fancy },
            { label: '钻石首饰', value: Category.Jewelry }
        ],
    },
    {
        label: '商品币种',
        key: 'zscurrencytype',
        options: getCurrencyTypeList(),
    },
]

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

onRefresh()
</script>