<template>
    <order-page
        ref="pageRef"
        :pageConfig="pageConfig"
        permissionKey="auditNotSubmit"
    >
        <template #toolbar>
            <el-button
                type="success"
                plain
                v-permission="'recycleOrder:auditNotSubmit:batchAuditComplete'"
                @click="handleBatchAuditComplete"
            >
                批量审核完成
            </el-button>
            <el-button
                type="primary"
                plain
                :icon="DownloadOutlined"
                v-permission="'recycleOrder:auditNotSubmit:export'"
                @click="exportData"
            >
                导出订单明细
            </el-button>
        </template>
        <BatchComplete ref="batchCompleteRef" @refresh="refresh" />
    </order-page>
</template>

<script setup>
    import { ref, reactive } from 'vue';
    import { DownloadOutlined } from '@/components/icons';
    import { ElMessage } from 'element-plus';
    import OrderPage from '@/views/recycleOrder/components/order-page-all.vue';
    import BatchComplete from '@/views/recycleOrder/components/batch-complete.vue';

    defineOptions({ name: 'RecycleOrderAuditNotSubmit' });

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

    const pageConfig = reactive({
        pageUrl: '/order/orderInfo/auditing/pageList',
        exportUrl: '/order/orderInfo/auditing/export',
        fileName: '审核未提交',
        cacheKey: 'auditNotSubmitTable'
    });

    //批量审核完成
    function handleBatchAuditComplete() {
        let orderIds = pageRef.value?.selections?.map((item) => item.orderId);
        if (!orderIds.length) {
            ElMessage.error('请至少选择一条数据');
            return;
        }
        batchCompleteRef.value?.handleOpen(orderIds);
    }

    //刷新
    function refresh() {
        pageRef.value?.reload();
    }

    //导出数据
    function exportData() {
        pageRef.value?.exportData('审核未提交');
    }
</script>
