<template>
    <ele-page flex-table>
        <book-push-erp-log-search @search="reload" />
        <common-table ref="pageRef" :pageConfig="pageConfig" :columns="columns">
            <template #toolbar>
                <el-button
                    type="primary"
                    @click="handleExport"
                    v-permission="'recycle:bookPushErpLog:export'"
                    >批量导出</el-button
                >
            </template>
            <template #cover="{ row }">
                <el-image
                    style="width: 80px; height: 100px"
                    fit="cover"
                    :src="row.cover"
                    :preview-src-list="[row.cover]"
                    :initial-index="0"
                    preview-teleported
                />
            </template>
            <template #baseInfo="{ row }">
                <book-base-info :row="row" @refresh="reload" />
            </template>
        </common-table>
    </ele-page>
</template>

<script setup>
    import { ref, reactive } from 'vue';
    import CommonTable from '@/components/CommonPage/CommonTable.vue';
    import BookPushErpLogSearch from './components/book-push-erp-log-search.vue';
    import BookBaseInfo from './components/book-base-info.vue';

    const columns = ref([
        {
            type: 'selection',
            columnKey: 'selection',
            width: 50,
            align: 'center',
            fixed: 'left'
        },
        {
            label: '商品图',
            prop: 'cover',
            slot: 'cover',
            align: 'center'
        },
        {
            label: '商品名称',
            prop: 'baseInfo',
            slot: 'baseInfo',
            align: 'left',
            minWidth: 320
        },
        {
            label: '商品编码',
            prop: 'bookCode',
            align: 'center'
        },

        {
            label: '更新时间',
            prop: 'createTime',
            align: 'center',
            width: 180
        }
    ]);

    const pageRef = ref(null);
    const pageConfig = reactive({
        pageUrl: '/book/stock/getBookPushErpLogList',
        exportUrl: '/book/stock/exportBookPushErpLogList',
        fileName: '图书推送ERP日志',
        cacheKey: 'book-push-erp-log'
    });

    function reload(where) {
        pageRef.value?.reload(where);
    }

    function handleExport() {
        pageRef.value?.exportData('图书推送ERP日志', 'GET');
    }
</script>
