From b215f34aa86728e314526afa9e028f56ab756964 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 14 Jan 2026 12:29:35 +0800 Subject: [PATCH] 1 --- src/views/system/jdorder/orderList.vue | 210 ++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 3 deletions(-) diff --git a/src/views/system/jdorder/orderList.vue b/src/views/system/jdorder/orderList.vue index 71290a6..1d1471e 100644 --- a/src/views/system/jdorder/orderList.vue +++ b/src/views/system/jdorder/orderList.vue @@ -97,6 +97,8 @@ 一键发货到腾峰 批量标记后返到账 反向同步第三方单号 + 批量复制录单格式 + 批量复制后返录表 @@ -108,9 +110,12 @@ border stripe :default-sort="{prop: 'createTime', order: 'descending'}" - @sort-change="handleSortChange" + @sort-change="handleSortChange" + @selection-change="handleSelectionChange" style="width: 100%;" class="order-table"> + + @@ -642,7 +647,9 @@ export default { // 复制录单格式loading状态 copyExcelTextLoading: false, // 已复制录单格式的订单ID集合(页面级缓存,刷新后消失) - copiedExcelTextOrderIds: new Set() + copiedExcelTextOrderIds: new Set(), + // 选中的行数据 + selectedRows: [] } }, computed: { @@ -666,7 +673,9 @@ export default { { key: 'touser', label: '接收人配置', type: 'warning', icon: 'el-icon-user', handler: () => { this.showTouserConfig = true } }, { key: 'sync', label: '一键发货到腾峰', type: 'primary', icon: 'el-icon-refresh-right', handler: () => this.handleBatchSyncLogistics(), loading: this.batchSyncLoading }, { key: 'mark', label: '批量标记后返到账', type: 'success', icon: 'el-icon-check', handler: () => this.handleBatchMarkRebateReceived(), loading: this.batchMarkLoading }, - { key: 'reverse', label: '反向同步第三方单号', type: 'warning', icon: 'el-icon-sort', handler: () => this.handleReverseSyncThirdPartyOrderNo(), loading: this.reverseSyncLoading } + { key: 'reverse', label: '反向同步第三方单号', type: 'warning', icon: 'el-icon-sort', handler: () => this.handleReverseSyncThirdPartyOrderNo(), loading: this.reverseSyncLoading }, + { key: 'batchCopyExcel', label: '批量复制录单格式', type: 'primary', icon: 'el-icon-document-copy', handler: () => this.handleBatchCopyExcelText(), disabled: this.selectedRows.length === 0 }, + { key: 'batchCopyRebate', label: '批量复制后返录表', type: 'success', icon: 'el-icon-document-copy', handler: () => this.handleBatchCopyRebateText(), disabled: this.selectedRows.length === 0 } ] } }, @@ -1770,6 +1779,201 @@ export default { } finally { this.reverseSyncLoading = false } + }, + + /** 处理表格选择变化 */ + handleSelectionChange(selection) { + this.selectedRows = selection + }, + + /** 批量复制录单格式 */ + handleBatchCopyExcelText() { + if (!this.selectedRows || this.selectedRows.length === 0) { + this.$message.warning('请先选择要复制的订单') + return + } + + try { + const lines = [] + + // 遍历选中的每一行,生成录单格式文本 + this.selectedRows.forEach(row => { + // 日期(格式:yyyy/MM/dd) + let dateStr = '' + if (row.orderTime) { + const date = new Date(row.orderTime) + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + dateStr = `${year}/${month}/${day}` + } + + // 多多单号(第三方单号,如果没有则使用内部单号) + const duoduoOrderNo = (row.thirdPartyOrderNo && row.thirdPartyOrderNo.trim()) + ? row.thirdPartyOrderNo : (row.remark || '') + + // 型号 + const modelNumber = row.modelNumber || '' + + // 数量(固定为1) + const quantity = '1' + + // 地址 + const address = row.address || '' + + // 姓名(从地址中提取,地址格式通常是"姓名 电话 详细地址") + let buyer = '' + if (address) { + // 提取地址中的第一个词作为姓名 + const addressParts = address.trim().split(/\s+/) + if (addressParts.length > 0) { + buyer = addressParts[0] + } + } + + // 售价(固定为0) + const sellingPriceStr = '0' + + // 成本(售价 - 利润,售价是0) + const costStr = '' // 售价是0,成本也设为空 + + // 利润(后返金额) + const profitStr = '' + + // 京东单号 + const orderId = row.orderId || '' + + // 物流链接 + const logisticsLink = row.logisticsLink || '' + + // 下单付款 + const paymentAmountStr = row.paymentAmount + ? row.paymentAmount.toFixed(2) : '' + + // 后返 + const rebateAmountStr = row.rebateAmount + ? row.rebateAmount.toFixed(2) : '' + const shopName = '' + + // 按顺序拼接:日期、多多单号、型号、数量、姓名、地址、售价、成本、利润、京东单号、物流、下单付款、后返 + const text = [ + dateStr, + duoduoOrderNo, + shopName, + modelNumber, + quantity, + buyer, + address, + sellingPriceStr, + costStr, + profitStr, + orderId, + logisticsLink, + paymentAmountStr, + rebateAmountStr + ].join('\t') + + lines.push(text) + }) + + // 将所有行用换行符连接 + const finalText = lines.join('\n') + + this.copyToClipboard(finalText) + + // 记录已复制的订单ID + this.selectedRows.forEach(row => { + if (row.id) { + this.copiedExcelTextOrderIds.add(row.id) + } + }) + + this.$message.success(`已复制 ${this.selectedRows.length} 条订单的录单格式到剪贴板,可以直接粘贴到Excel`) + } catch (e) { + this.$message.error('批量复制失败:' + (e.message || '未知错误')) + console.error('批量复制录单格式失败', e) + } + }, + + /** 批量复制后返录表 */ + handleBatchCopyRebateText() { + if (!this.selectedRows || this.selectedRows.length === 0) { + this.$message.warning('请先选择要复制的订单') + return + } + + try { + const lines = [] + + // 遍历选中的每一行,生成后返录表格式文本 + this.selectedRows.forEach(row => { + // 前5列:空(发过运营、需要重发运营、已经重发、需要二次重发运营、二次重发) + const emptyCols = ['', '', '', '', ''] + + // 单号:orderId + const orderId = row.orderId || '' + + // 型号:modelNumber + const modelNumber = row.modelNumber || '' + + // 返现金额(团长):空 + const leaderRebateAmount = '' + + // 晒单金额(主图没标):空 + const reviewRebateAmount = '' + + // 总共返现:rebateAmount(整数格式) + const totalRebateAmount = row.rebateAmount + ? Math.round(row.rebateAmount).toString() : '' + + // 确认收货日期:finishTime,格式yyyy/MM/dd + let finishDateStr = '' + if (row.finishTime) { + const finishDate = new Date(row.finishTime) + const year = finishDate.getFullYear() + const month = String(finishDate.getMonth() + 1).padStart(2, '0') + const day = String(finishDate.getDate()).padStart(2, '0') + finishDateStr = `${year}/${month}/${day}` + } + + // 认领人:buyer + const buyer = row.buyer || '' + + // 下单日期:orderTime,格式yyyyMMdd + let orderDateStr = '' + if (row.orderTime) { + const orderDate = new Date(row.orderTime) + const year = orderDate.getFullYear() + const month = String(orderDate.getMonth() + 1).padStart(2, '0') + const day = String(orderDate.getDate()).padStart(2, '0') + orderDateStr = `${year}${month}${day}` + } + + // 按顺序拼接:发过运营、需要重发运营、已经重发、需要二次重发运营、二次重发、单号、型号、返现金额(团长)、晒单金额(主图没标)、总共返现、确认收货日期、认领人、下单日期 + const text = [ + ...emptyCols, + orderId, + modelNumber, + leaderRebateAmount, + reviewRebateAmount, + totalRebateAmount, + finishDateStr, + buyer, + orderDateStr + ].join('\t') + + lines.push(text) + }) + + // 将所有行用换行符连接 + const finalText = lines.join('\n') + + this.copyToClipboard(finalText) + this.$message.success(`已复制 ${this.selectedRows.length} 条订单的后返录表格式到剪贴板,可以直接粘贴到Excel`) + } catch (e) { + this.$message.error('批量复制失败:' + (e.message || '未知错误')) + console.error('批量复制后返录表格式失败', e) + } } }