优化订单导出功能

This commit is contained in:
pikachu1995@126.com 2024-06-26 11:51:22 +08:00
parent 3bfa99f578
commit 92559ca9e7
4 changed files with 96 additions and 73 deletions

View File

@ -78,6 +78,11 @@ export const getOrderList = (params) => {
return getRequest(`/order/order`, params) return getRequest(`/order/order`, params)
} }
// 导出订单列表
export const exportOrder = (params) => {
return getRequest(`/order/order/queryExportOrder`, params,'blob')
}
// 订单付款 // 订单付款
export const orderPay = (sn) => { export const orderPay = (sn) => {
return postRequest(`/order/order/${sn}/pay`) return postRequest(`/order/order/${sn}/pay`)

View File

@ -79,15 +79,7 @@
> >
</Form> </Form>
<div> <div>
<download-excel <Button @click="exportOrder" type="info" class="export">导出订单</Button>
class="export-excel-wrapper"
:data="data"
:fields="fields"
:fetch="exportOrder"
name="商品订单.xls"
>
<Button type="info" class="export"> 导出订单 </Button>
</download-excel>
</div> </div>
<div class="order-tab"> <div class="order-tab">
@ -391,20 +383,35 @@ export default {
}, },
// //
async exportOrder() { async exportOrder() {
const params = JSON.parse(JSON.stringify(this.searchForm)); if(this.searchForm.startDate==""||this.searchForm.endDate==""){
params.pageNumber = 1; this.$Message.error("必须选择时间范围,搜索后进行导出!");
params.pageSize = 10000; }else{
const result = await API_Order.getOrderList(params); API_Order.exportOrder(this.searchForm)
if (result.success) { .then((res) => {
if (result.result.records.length === 0) { const blob = new Blob([res], {
this.$Message.warning("暂无待发货订单"); type: "application/vnd.ms-excel;charset=utf-8",
return []; });
//<a> Firefox Chrome download
//IE10blobdownload
if ("download" in document.createElement("a")) {
//adownload
const link = document.createElement("a"); //a
link.download = "订单列表.xlsx"; //a
link.style.display = "none";
link.href = URL.createObjectURL(blob);
document.body.appendChild(link);
link.click(); //
URL.revokeObjectURL(link.href); //url
document.body.removeChild(link); //
} else { } else {
return result.result.records; navigator.msSaveBlob(blob, fileName);
} }
} else { })
this.$Message.warning("导出订单失败,请重试"); .catch((err) => {
console.log(err);
});
} }
}, },
// //
orderStatusClick(item) { orderStatusClick(item) {

View File

@ -32,6 +32,11 @@ export const getOrderList = params => {
return getRequest(`/order/order`, params); return getRequest(`/order/order`, params);
}; };
// 导出订单列表
export const exportOrder = (params) => {
return getRequest(`/order/order/queryExportOrder`, params,'blob')
};
// 获取普通订单详细信息 // 获取普通订单详细信息
export const getOrderDetail = sn => { export const getOrderDetail = sn => {
return getRequest(`/order/order/${sn}`); return getRequest(`/order/order/${sn}`);

View File

@ -73,18 +73,20 @@
<Button @click="handleReset" class="search-btn">重置</Button> <Button @click="handleReset" class="search-btn">重置</Button>
</Form> </Form>
<div class="export"> <div class="export">
<Button type="primary" class="mr_10" @click="expressOrderDeliver"> <Button type="primary" class="mr_10" @click="expressOrderDeliver">批量发货</Button>
批量发货 <Button @click="exportOrder" type="info" class="export">导出订单</Button>
<Poptip @keydown.enter.native="orderVerification" placement="bottom-start" width="400">
<Button class="export">
核验订单
</Button> </Button>
<download-excel <div class="api" slot="content">
style="display: inline-block" <h2>核验码</h2>
:data="data" <div style="margin:10px 0;">
:fields="excelColumns" <Input v-model="orderCode" style="width:300px; margin-right:10px;" />
:fetch="exportOrder" <Button style="primary" @click="orderVerification">核验</Button>
name="待发货订单.xls" </div>
> </div>
<Button>导出待发货订单</Button> </Poptip>
</download-excel>
</div> </div>
<Table <Table
:loading="loading" :loading="loading"
@ -115,6 +117,7 @@
import * as API_Order from "@/api/order"; import * as API_Order from "@/api/order";
import JsonExcel from "vue-json-excel"; import JsonExcel from "vue-json-excel";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import {verificationCode} from "@/api/order";
export default { export default {
name: "orderList", name: "orderList",
components: { components: {
@ -306,6 +309,19 @@ export default {
}; };
}, },
methods: { methods: {
/**
* 核验订单
*/
async orderVerification() {
let result = await verificationCode(this.orderCode);
if (result.success) {
this.$router.push({
name: "order-detail",
query: { sn: result.result.sn || this.orderCode },
});
}
},
/** /**
* 批量发货 * 批量发货
*/ */
@ -364,47 +380,37 @@ export default {
} }
}); });
}, },
// //
async exportOrder() { async exportOrder() {
let userInfo = JSON.parse(Cookies.get("userInfoSeller")); if(this.searchForm.startDate==""||this.searchForm.endDate==""){
const params = { this.$Message.error("必须选择时间范围,搜索后进行导出!");
// }else{
pageNumber: 1, // API_Order.exportOrder(this.searchForm)
pageSize: 10000, // .then((res) => {
sort: "startDate", // const blob = new Blob([res], {
order: "desc", // type: "application/vnd.ms-excel;charset=utf-8",
startDate: "", // });
endDate: "", // //<a> Firefox Chrome download
orderSn: "", //IE10blobdownload
buyerName: "", if ("download" in document.createElement("a")) {
tag: "WAIT_SHIP", //adownload
orderType: "NORMAL", const link = document.createElement("a"); //a
storeId: userInfo.id, link.download = "订单列表.xlsx"; //a
}; link.style.display = "none";
const res = await API_Order.queryExportOrder(params); link.href = URL.createObjectURL(blob);
if (res.success) { document.body.appendChild(link);
if (res.result.length === 0) { link.click(); //
this.$Message.warning("暂无待发货订单"); URL.revokeObjectURL(link.href); //url
return []; document.body.removeChild(link); //
}
for (let i = 0; i < res.result.length; i++) {
res.result[i].index = i + 1;
res.result[i].consigneeAddress =
res.result[i].consigneeAddressPath.replace(/,/g, "") +
res.result[i].consigneeDetail;
res.result[i].goodsPrice = this.$options.filters.unitPrice(
res.result[i].goodsPrice,
"¥"
);
res.result[i].flowPrice = this.$options.filters.unitPrice(
res.result[i].flowPrice,
"¥"
);
}
return res.result;
} else { } else {
this.$Message.warning("导出订单失败,请重试"); navigator.msSaveBlob(blob, fileName);
} }
})
.catch((err) => {
console.log(err);
});
}
}, },
// //
detail(v) { detail(v) {