<template>
    <ele-page flex-table>
        <page-search @search="reload" />
        <common-table
            ref="pageRef"
            :pageConfig="pageConfig"
            :columns="columns"
            :tools="false"
            :flex-table="false"
        >
            <template #toolbar="{ row }">
                <div>
                    <el-button
                        type="success"
                        plain
                        v-permission="'statistic:weight:export'"
                        @click="handleExportExcel(row)"
                    >
                        导出EXCEL
                    </el-button>
                </div>
            </template>
        </common-table>
    </ele-page>
</template>

<script setup>
    import { ref, reactive } from 'vue';
    import CommonTable from '@/components/CommonPage/CommonTable.vue';
    import pageSearch from './components/page-search.vue';

    defineOptions({ name: 'WeightStatistic' });

    /** 表格列配置 */
    const columns = ref([
        { label: 'ISBN', prop: 'isbn', align: 'center' },
        { label: '重量（kg）', prop: 'weight', align: 'center' },
        { label: '操作员', prop: 'createName', align: 'center' },
        { label: '操作时间', prop: 'createTime', align: 'center' }
    ]);

    /** 页面组件实例 */
    const pageRef = ref(null);

    const pageConfig = reactive({
        pageUrl: '/book/weightchange/getChangeLogPage',
        exportUrl: '/book/weightchange/export',
        fileName: '重量统计',
        cacheKey: 'weightStatisticTable'
    });

    //刷新表格
    function reload(where) {
        pageRef.value?.reload(where);
    }

    //导出excel
    function handleExportExcel() {
        pageRef.value?.exportData('重量统计');
    }
</script>
