<template>
    <div class="default-main ba-table-box">
        <MallPageIntro page-key="dailyPush" />
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <TableHeader
            :buttons="['refresh', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: t('mall.dailyPush.quick Search Fields') })"
        >
            <template #refreshAppend>
                <el-tooltip v-if="baTable.auth('export')" :content="t('mall.dailyPush.export_excel')" placement="top">
                    <el-button v-blur class="table-header-operate btns-ml-12" type="success" @click="exportVisible = true">
                        <Icon name="fa fa-file-excel-o" />
                        <span class="table-header-operate-text">{{ t('mall.dailyPush.export_excel') }}</span>
                    </el-button>
                </el-tooltip>
            </template>
        </TableHeader>

        <Table ref="tableRef"></Table>
        <ExportDialog v-model="exportVisible" />
    </div>
</template>

<script setup lang="ts">
import { onMounted, provide, ref, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n'
import { baTableApi } from '/@/api/common'
import MallPageIntro from '/@/components/mall/MallPageIntro.vue'
import TableHeader from '/@/components/table/header/index.vue'
import Table from '/@/components/table/index.vue'
import baTableClass from '/@/utils/baTable'
import ExportDialog from './exportDialog.vue'

defineOptions({
    name: 'mall/dailyPush',
})

const { t } = useI18n()
const tableRef = useTemplateRef('tableRef')
const exportVisible = ref(false)

const baTable = new baTableClass(
    new baTableApi('/admin/mall.DailyPush/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('mall.dailyPush.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
            {
                label: t('mall.dailyPush.user_id'),
                prop: 'user_id',
                align: 'center',
                operatorPlaceholder: t('Fuzzy query'),
                sortable: false,
                operator: 'LIKE',
            },
            {
                label: t('mall.dailyPush.date'),
                prop: 'date',
                align: 'center',
                render: 'date',
                operator: 'RANGE',
                comSearchRender: 'date',
                sortable: 'custom',
                width: 120,
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('mall.dailyPush.username'),
                prop: 'username',
                align: 'center',
                minWidth: 95,
                operatorPlaceholder: t('Fuzzy query'),
                showOverflowTooltip: true,
                sortable: false,
                operator: 'LIKE',
            },
            {
                label: t('mall.dailyPush.yesterday_win_loss_net'),
                prop: 'yesterday_win_loss_net',
                align: 'center',
                minWidth: 90,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('mall.dailyPush.converted_points'),
                prop: 'converted_points',
                align: 'center',
                minWidth: 80,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('mall.dailyPush.yesterday_total_deposit'),
                prop: 'yesterday_total_deposit',
                align: 'center',
                minWidth: 90,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('mall.dailyPush.lifetime_total_deposit'),
                prop: 'lifetime_total_deposit',
                align: 'center',
                minWidth: 90,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('mall.dailyPush.lifetime_total_withdraw'),
                prop: 'lifetime_total_withdraw',
                align: 'center',
                minWidth: 90,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('mall.dailyPush.lifetime_win_loss_net'),
                prop: 'lifetime_win_loss_net',
                align: 'center',
                minWidth: 90,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('mall.dailyPush.create_time'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                sortable: 'custom',
                width: 160,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: {},
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getData()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

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