新增:订单导出功能
This commit is contained in:
@@ -86,14 +86,11 @@
|
||||
/>
|
||||
<a-button @click="reset">重置</a-button>
|
||||
<a-button @click="setHasInvoice" :disabled="!selection?.length"
|
||||
>设置已开票</a-button
|
||||
>
|
||||
<!-- <a-button class="ele-btn-icon" :disabled="loading" @click="handleExport">-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <download-outlined />-->
|
||||
<!-- </template>-->
|
||||
<!-- <span>导出订单</span>-->
|
||||
<!-- </a-button>-->
|
||||
>设置已开票
|
||||
</a-button>
|
||||
<a-button class="ele-btn-icon" @click="handleExport">
|
||||
<span>导出订单</span>
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
@@ -126,6 +123,7 @@
|
||||
(e: 'add'): void;
|
||||
(e: 'remove'): void;
|
||||
(e: 'advanced'): void;
|
||||
(e: 'export'): void;
|
||||
}>();
|
||||
|
||||
// 表单数据
|
||||
@@ -175,8 +173,21 @@
|
||||
search();
|
||||
};
|
||||
|
||||
const handleExport = () => {
|
||||
const [d1, d2] = dateRange.value ?? [];
|
||||
xlsFileName.value = `${d1}至${d2}`;
|
||||
where.forAdmin = true;
|
||||
where.limit = 5000;
|
||||
where.page = 1;
|
||||
where.timeStart = d1 ? dayjs(d1).valueOf() / 1000 : undefined;
|
||||
where.timeEnd = d2 ? dayjs(d2).valueOf() / 1000 : undefined;
|
||||
emit('export', {
|
||||
...where
|
||||
});
|
||||
};
|
||||
|
||||
// 导出
|
||||
const handleExport = async () => {
|
||||
const handleExport2 = async () => {
|
||||
loading.value = true;
|
||||
const array: (string | number)[][] = [
|
||||
[
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
@add="openEdit"
|
||||
@remove="removeBatch"
|
||||
@batchMove="openMove"
|
||||
@export="handleExport"
|
||||
/>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
@@ -263,6 +264,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { createVNode, ref } from 'vue';
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
import { utils, writeFile } from 'xlsx';
|
||||
import {
|
||||
ExclamationCircleOutlined,
|
||||
CheckOutlined,
|
||||
@@ -270,6 +272,7 @@
|
||||
AlipayCircleOutlined
|
||||
} from '@ant-design/icons-vue';
|
||||
import { EleProTable, toDateString } from 'ele-admin-pro';
|
||||
import dayjs from "dayjs";
|
||||
import type {
|
||||
DatasourceFunction,
|
||||
ColumnItem
|
||||
@@ -306,6 +309,8 @@
|
||||
const showMove = ref(false);
|
||||
// 加载状态
|
||||
const loading = ref(true);
|
||||
// 订单列表
|
||||
const orderList = ref<ThinkOrder[]>([]);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({
|
||||
@@ -543,6 +548,72 @@
|
||||
}
|
||||
};
|
||||
|
||||
// 导出
|
||||
const handleExport = (where?: ThinkOrderParam) => {
|
||||
console.log('开始导出');
|
||||
loading.value = true;
|
||||
const array: (string | number)[][] = [
|
||||
[
|
||||
'订单号',
|
||||
'订单编号',
|
||||
'姓名',
|
||||
'电话号码',
|
||||
'预定信息',
|
||||
'消费金额',
|
||||
'实付金额',
|
||||
'付款时间',
|
||||
'下单时间'
|
||||
]
|
||||
];
|
||||
if (!where.timeStart) {
|
||||
message.error('请选择导出的开始日期、结束日期,每次最多导出5000条记录');
|
||||
return false;
|
||||
}
|
||||
pageThinkOrder(where)
|
||||
.then((data) => {
|
||||
data.list?.forEach((d: ThinkOrder) => {
|
||||
array.push([
|
||||
`${d.id}`,
|
||||
`${d.orderNum}`,
|
||||
`${d.name}`,
|
||||
`${d.phone}`,
|
||||
`${d.siteName} ${d.dateTime} ${d.totalPrice}`,
|
||||
`${d.totalPrice}`,
|
||||
`${d.payPrice}`,
|
||||
`${toDateString(d.payTime, 'YYYY年MM月dd日 HH:mm:ss')}`,
|
||||
`${toDateString(d.createTime, 'YYYY年MM月dd日 HH:mm:ss')}`
|
||||
]);
|
||||
});
|
||||
const sheetName = `订单数据导出`;
|
||||
const workbook = {
|
||||
SheetNames: [sheetName],
|
||||
Sheets: {}
|
||||
};
|
||||
const sheet = utils.aoa_to_sheet(array);
|
||||
workbook.Sheets[sheetName] = sheet;
|
||||
// 设置列宽
|
||||
sheet['!cols'] = [
|
||||
{ wch: 10 },
|
||||
{ wch: 10 },
|
||||
{ wch: 10 },
|
||||
{ wch: 10 },
|
||||
{ wch: 20 },
|
||||
{ wch: 40 },
|
||||
{ wch: 10 }
|
||||
];
|
||||
message.loading('正在导出...');
|
||||
setTimeout(() => {
|
||||
writeFile(workbook, `${sheetName}.xlsx`);
|
||||
loading.value = false;
|
||||
}, 2000);
|
||||
})
|
||||
.catch((msg) => {
|
||||
message.error(msg);
|
||||
loading.value = false;
|
||||
})
|
||||
.finally(() => {});
|
||||
};
|
||||
|
||||
/* 查询 */
|
||||
const query = () => {
|
||||
loading.value = true;
|
||||
|
||||
Reference in New Issue
Block a user