From 5a6d95914ef31c344c06dedaaba74adba852c778 Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Tue, 2 Jun 2026 17:56:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=A3=E5=8D=95=E3=80=81?= =?UTF-8?q?=E5=9B=A2=E8=B4=AD=E6=8B=A3=E8=B4=A7=E9=A1=B5=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E3=80=81=E5=BA=95=E9=83=A8=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/work/order/groupon-picking-detail.vue | 446 +++++++++++++++++++- pages/work/order/scatter-picking-detail.vue | 192 +++++---- 2 files changed, 543 insertions(+), 95 deletions(-) diff --git a/pages/work/order/groupon-picking-detail.vue b/pages/work/order/groupon-picking-detail.vue index cb5f582..25a0abe 100644 --- a/pages/work/order/groupon-picking-detail.vue +++ b/pages/work/order/groupon-picking-detail.vue @@ -53,6 +53,46 @@ /> + + + + 打印设置 + + 打印台 + + {{ printStationName || '--' }} + + + + + {{ station.name }} + + + + + 打印 + + 打印 + + + + 打印消息 + {{ printMessage || '暂无打印消息' }} + + + @@ -67,6 +107,17 @@ pageSize: 20, currentPage: 1, paginationTotal: 0, + showPrintPopup: false, + showPrintStationDropdown: false, + printStationName: '--', + printStationId: '', + printStationList: [], + printMessage: '', + pendingPrintCount: 0, + printRequestCode: '', + printWaveGroups: [], + printWavePlatformPrintData: null, + printTargetList: [], orderList: [] }; }, @@ -142,11 +193,13 @@ const source = item && typeof item === 'object' ? item : {}; const waveNo = String(source.wave_no || '').trim(); const rowId = source.wave_id ?? source.waveId ?? source.id ?? waveNo; + const waveId = source.wave_id ?? source.waveId ?? source.id ?? ''; const pickerName = String(source.picker_name || source.pickerName || source.user_name || source.userName || '--').trim() || '--'; const pendingCount = Number(source.pending_count ?? source.pendingCount ?? source.unreviewed_count ?? source.unreviewedCount ?? 0); const assigneeId = String((source.picker_id ?? source.pickerId ?? source.user_id ?? source.userId) || '').trim(); return { id: String(rowId || ''), + waveId: typeof waveId === 'number' ? waveId : String(waveId || '').trim(), waveNo, pickerName, pendingCount: Number.isFinite(pendingCount) ? pendingCount : 0, @@ -177,6 +230,147 @@ } return 0; }, + resolveWarehouseId() { + const user = this.$store?.getters?.user || {}; + const userInfo = this.$store?.getters?.userInfo || {}; + const candidates = [ + user?.store_id, + user?.storeId, + userInfo?.store_id, + userInfo?.storeId, + uni.getStorageSync('store_id'), + uni.getStorageSync('storeId'), + user?.warehouse_id, + user?.warehouseId, + userInfo?.warehouse_id, + userInfo?.warehouseId, + uni.getStorageSync('warehouse_id'), + uni.getStorageSync('warehouseId') + ]; + for (let i = 0; i < candidates.length; i += 1) { + const value = Number(candidates[i]); + if (Number.isFinite(value) && value > 0) { + return value; + } + } + return 0; + }, + normalizeWaveIds(list) { + const sourceList = Array.isArray(list) ? list : []; + const normalized = sourceList + .map(item => item?.waveId ?? item?.id ?? '') + .map(value => (typeof value === 'number' ? value : String(value || '').trim())) + .filter(value => value !== '' && value !== '--'); + return Array.from(new Set(normalized)); + }, + buildWavePlatformPrintParams() { + const warehouseId = this.resolveWarehouseId(); + const waveIds = this.normalizeWaveIds(this.printTargetList); + return { + warehouse_id: warehouseId, + wave_ids: waveIds + }; + }, + extractWavePlatformPrintPayload(response) { + const candidates = [ + response?.data?.data, + response?.data, + response?.result, + response + ]; + for (let i = 0; i < candidates.length; i += 1) { + const current = candidates[i]; + if (current && typeof current === 'object') { + return current; + } + } + return {}; + }, + normalizeWaveGroups(payload) { + const groups = Array.isArray(payload?.waveGroups) ? payload.waveGroups : []; + return groups + .map(group => (group && typeof group === 'object' ? group : null)) + .filter(group => !!group); + }, + buildPrintRequestCode() { + const timePart = Date.now().toString(36); + const randomPart = Math.random().toString(36).slice(2, 10); + return `PRINT_${timePart}_${randomPart}`; + }, + async requestWavePlatformPrintData() { + const params = this.buildWavePlatformPrintParams(); + console.log('[GrouponPickingDetail] getWavePlatformPrintData params:', params); + try { + const response = await this.$http('order.print.getWavePlatformPrintData', params); + console.log('[GrouponPickingDetail] getWavePlatformPrintData success:', response); + const payload = this.extractWavePlatformPrintPayload(response); + const waveGroups = this.normalizeWaveGroups(payload); + if (!waveGroups.length) { + throw new Error('未获取到可打印的waveGroups'); + } + this.printWavePlatformPrintData = payload; + this.printWaveGroups = waveGroups; + this.printRequestCode = this.buildPrintRequestCode(); + return payload; + } catch (error) { + console.error('[GrouponPickingDetail] getWavePlatformPrintData error:', error); + throw error; + } + }, + buildPrintRecordWhere() { + return {}; + }, + buildPrintRecordParams() { + return { + page: 1, + pageSize: 20, + where: this.buildPrintRecordWhere() + }; + }, + extractPrintRecordList(response) { + const list = response?.data?.list || response?.data?.data?.list; + return Array.isArray(list) ? list : []; + }, + normalizePrintStations(list) { + return list + .map(item => { + const source = item && typeof item === 'object' ? item : {}; + const id = String(source.id ?? source.print_station_id ?? source.printStationId ?? '').trim(); + const name = String(source.name || source.station_name || source.print_station_name || '').trim(); + return { + id, + name + }; + }) + .filter(item => !!item.id && !!item.name); + }, + async loadPrintStations() { + const response = await this.$http('print.getList', this.buildPrintRecordParams()); + const list = this.extractPrintRecordList(response); + const stations = this.normalizePrintStations(list); + this.printStationList = stations; + this.printStationId = stations[0]?.id || ''; + this.printStationName = stations[0]?.name || '--'; + }, + togglePrintStationDropdown() { + if (!this.printStationList.length) { + uni.showToast({ + title: '暂无可用打印台', + icon: 'none' + }); + return; + } + this.showPrintStationDropdown = !this.showPrintStationDropdown; + }, + handlePrintStationSelect(station) { + this.printStationId = String(station?.id || ''); + this.printStationName = String(station?.name || '--'); + this.showPrintStationDropdown = false; + }, + handlePrintPopupClose() { + this.showPrintPopup = false; + this.showPrintStationDropdown = false; + }, async loadBatchWaveNoList(page = this.currentPage) { const targetPage = Math.max(1, Number(page || 1)); try { @@ -209,6 +403,7 @@ const isMine = index % 2 === 0; return { id: `${orderNo}-${index + 1}`, + waveId: `${index + 1}`, waveNo, pickerName: isMine ? '我' : `拣货员${(index % 3) + 1}`, pendingCount: (index % 5) + 1, @@ -216,17 +411,131 @@ }; }); }, - showRecordDetail(item) { - if (!item) return; - uni.showModal({ - title: '打印面单', - showCancel: false, - content: [ - `波次号:${item.waveNo || '--'}`, - `拣货员:${item.pickerName || '--'}`, - `未复核数量:${item.pendingCount || 0}` - ].join('\n') + async showRecordDetail(item) { + const target = item && typeof item === 'object' ? item : null; + console.log('[GrouponPickingDetail] print button clicked:', target); + if (!target) { + uni.showToast({ + title: '未找到可打印波次', + icon: 'none' + }); + return; + } + const targetWaveId = target.waveId ?? target.id ?? ''; + if (targetWaveId === '' || targetWaveId === null || targetWaveId === undefined) { + uni.showToast({ + title: '波次缺少wave_id,无法打印', + icon: 'none' + }); + return; + } + + this.printTargetList = [{ + ...target, + waveId: targetWaveId + }]; + this.printWaveGroups = []; + this.printWavePlatformPrintData = null; + try { + await this.requestWavePlatformPrintData(); + } catch (error) { + const message = String(error?.message || error?.msg || error?.errMsg || '打印数据获取失败'); + this.printMessage = message; + uni.showToast({ + title: message, + icon: 'none' + }); + return; + } + + try { + await this.loadPrintStations(); + } catch (error) { + this.printStationList = []; + this.printStationId = ''; + this.printStationName = '--'; + uni.showToast({ + title: '打印台加载失败', + icon: 'none' + }); + } + this.pendingPrintCount = Number(target.pendingCount || 0); + this.printMessage = `待打印未复核订单 ${this.pendingPrintCount} 条`; + this.showPrintStationDropdown = false; + this.showPrintPopup = true; + }, + buildPrintSendParams() { + if (!this.printRequestCode) { + this.printRequestCode = this.buildPrintRequestCode(); + } + return { + type: 'express', + printStationId: this.printStationId, + requestCode: this.printRequestCode, + data: { + waveGroups: Array.isArray(this.printWaveGroups) ? this.printWaveGroups : [] + } + }; + }, + async handleConfirmPrint() { + console.log('[GrouponPickingDetail] handleConfirmPrint clicked:', { + printStationId: this.printStationId, + printStationName: this.printStationName, + printStationListLength: Array.isArray(this.printStationList) ? this.printStationList.length : 0, + pendingPrintCount: this.pendingPrintCount, + waveGroupsLength: Array.isArray(this.printWaveGroups) ? this.printWaveGroups.length : 0 }); + if (!this.printStationList.length || !this.printStationId || !this.printStationName || this.printStationName === '--') { + console.warn('[GrouponPickingDetail] handleConfirmPrint blocked: invalid print station'); + this.printMessage = '请选择打印台'; + uni.showToast({ + title: '请选择打印台', + icon: 'none' + }); + return; + } + if (!Array.isArray(this.printWaveGroups) || !this.printWaveGroups.length) { + console.warn('[GrouponPickingDetail] handleConfirmPrint blocked: waveGroups empty'); + this.printMessage = '未获取到打印数据'; + uni.showToast({ + title: '未获取到打印数据', + icon: 'none' + }); + return; + } + + const params = this.buildPrintSendParams(); + const effectivePrintCount = Number(this.pendingPrintCount || 0) > 0 + ? Number(this.pendingPrintCount || 0) + : this.printWaveGroups.length; + console.log('[GrouponPickingDetail] print.send params:', params); + uni.showLoading({ + title: '发送打印中...' + }); + try { + const response = await this.$http('print.send', params); + console.log('[GrouponPickingDetail] print.send success:', response); + const success = response?.flag !== 'failure' && response?.code !== '500' && response?.code !== 500; + if (!success) { + throw new Error(response?.message || response?.msg || '打印失败'); + } + this.printMessage = `打印已发送,未复核订单 ${effectivePrintCount} 条`; + uni.showToast({ + title: `已发起打印${effectivePrintCount}条`, + icon: 'none' + }); + this.showPrintPopup = false; + } catch (error) { + console.error('[GrouponPickingDetail] print.send error:', error); + const message = String(error?.message || error?.msg || error?.errMsg || '打印失败'); + this.printMessage = message; + uni.showToast({ + title: message, + icon: 'none' + }); + } finally { + uni.hideLoading(); + } }, handlePageChange(page) { const targetPage = Math.max(1, Number(page || 1)); @@ -253,6 +562,11 @@ overflow: hidden; } + ::v-deep .u-popup, + ::v-deep .u-popup-mask { + z-index: 10090 !important; + } + ::v-deep .nav-title .right { width: auto; min-width: 136rpx; @@ -377,6 +691,118 @@ color: #909399; } + .print-popup { + padding: 24rpx 24rpx calc(20rpx + env(safe-area-inset-bottom)); + background: #ffffff; + border-top-left-radius: 20rpx; + border-top-right-radius: 20rpx; + } + + .print-popup-title { + font-size: 34rpx; + font-weight: 600; + color: #303133; + text-align: left; + margin-bottom: 20rpx; + } + + .print-row { + position: relative; + display: flex; + align-items: center; + justify-content: space-between; + padding: 16rpx 0; + border-bottom: 1rpx solid #f5f5f5; + gap: 16rpx; + } + + .print-row--station { + align-items: flex-start; + padding-top: 8rpx; + } + + .print-row--station .print-label { + padding-top: 10rpx; + } + + .print-label { + min-width: 120rpx; + font-size: 30rpx; + color: #606266; + line-height: 44rpx; + } + + .print-picker { + flex: 1; + min-width: 0; + display: flex; + align-items: center; + justify-content: space-between; + padding: 10rpx 16rpx; + border: 1rpx solid #dcdfe6; + border-radius: 10rpx; + background: #fafafa; + } + + .print-picker-value { + flex: 1; + font-size: 28rpx; + color: #303133; + padding-right: 16rpx; + word-break: break-all; + } + + .print-station-dropdown { + position: absolute; + right: 0; + top: calc(100% - 4rpx); + width: calc(100% - 144rpx); + max-height: 360rpx; + overflow-y: auto; + background: #ffffff; + border: 1rpx solid #ebeef5; + border-radius: 12rpx; + box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.08); + z-index: 12; + } + + .print-station-option { + padding: 16rpx 20rpx; + font-size: 28rpx; + line-height: 40rpx; + color: #303133; + } + + .print-station-option + .print-station-option { + border-top: 1rpx solid #f5f5f5; + } + + .print-station-option--active { + color: #2979ff; + background: rgba(41, 121, 255, 0.08); + } + + .print-row--action .u-btn { + min-width: 160rpx; + } + + .print-row--message { + align-items: flex-start; + justify-content: flex-start; + border-bottom: none; + padding-bottom: 0; + padding-top: 12rpx; + } + + .print-message { + flex: 1; + font-size: 28rpx; + line-height: 40rpx; + color: #606266; + text-align: left; + word-break: break-all; + } + .safe-area-bottom { height: calc(30rpx + env(safe-area-inset-bottom)); } diff --git a/pages/work/order/scatter-picking-detail.vue b/pages/work/order/scatter-picking-detail.vue index 932f42a..fdc1ff1 100644 --- a/pages/work/order/scatter-picking-detail.vue +++ b/pages/work/order/scatter-picking-detail.vue @@ -108,7 +108,7 @@ 打印 @@ -134,6 +134,7 @@ currentUserId: '', pageSize: 20, currentPage: 1, + paginationTotal: 0, showPrintPopup: false, showPrintStationDropdown: false, printStationName: '--', @@ -149,47 +150,8 @@ }; }, computed: { - filteredOrderList() { - let list = this.onlyMine - ? this.orderList.filter(item => item.isMine) - : this.orderList; - - const keyword = this.normalizeKeyword(this.keyword).toLowerCase(); - if (!keyword) { - return list; - } - - list = list.filter(item => { - const waybillCode = this.normalizeKeyword(item?.waybillCode).toLowerCase(); - const cartNo = this.normalizeKeyword(item?.cartNo).toLowerCase(); - return waybillCode.includes(keyword) || cartNo.includes(keyword); - }); - - return list; - }, - paginationTotal() { - return this.filteredOrderList.length; - }, displayOrderList() { - const page = Math.max(1, Number(this.currentPage || 1)); - const size = Math.max(1, Number(this.pageSize || 20)); - const start = (page - 1) * size; - return this.filteredOrderList.slice(start, start + size); - } - }, - watch: { - keyword() { - this.currentPage = 1; - }, - onlyMine() { - this.currentPage = 1; - }, - paginationTotal(newTotal) { - const total = Number(newTotal || 0); - const maxPage = Math.max(1, Math.ceil(total / this.pageSize)); - if (this.currentPage > maxPage) { - this.currentPage = maxPage; - } + return Array.isArray(this.orderList) ? this.orderList : []; } }, onLoad(options) { @@ -204,8 +166,7 @@ this.grabCount = hasGrabCountParam ? Math.max(0, parsedGrabCount) : 5; - this.orderList = this.buildMockOrderList(this.grabCount); - this.loadBatchWaveNoList(); + this.loadBatchWaveNoList(1); }, onShow() { this.safeDispatchBroadcast('setCallbacks', { @@ -220,18 +181,25 @@ this.safeDispatchBroadcast('stop'); }, methods: { - buildBatchListParams() { + buildBatchListParams(page = this.currentPage) { + const where = { + source: 0, + wave_type: 2 + }; + if (this.onlyMine && this.currentUserId) { + where.picker_id = this.currentUserId; + } return { pagination: { - page: 1, - pageSize: 20 + page: Math.max(1, Number(page || 1)), + pageSize: Math.max(1, Number(this.pageSize || 20)) }, - where: { - source: 0, - wave_type: 2 - } + where }; }, + extractPagination(payload, response) { + return payload?.pagination || payload?.page || response?.data?.pagination || response?.pagination || null; + }, extractBatchListPayload(response) { const candidates = [ response?.data?.data, @@ -268,35 +236,67 @@ if (!Array.isArray(list)) { return []; } - return list.map(item => { - const source = item && typeof item === 'object' ? item : {}; - return { - waveNo: String(source.wave_no || '').trim(), - waveId: source.wave_id ?? source.waveId ?? source.id ?? '' - }; - }).filter(item => !!item.waveNo); + return list + .map((item, index) => { + const source = item && typeof item === 'object' ? item : {}; + const waveNo = String(source.wave_no || source.waveNo || '').trim(); + const waveId = source.wave_id ?? source.waveId ?? source.id ?? ''; + const rowId = source.id ?? waveId ?? waveNo ?? `batch-${this.currentPage}-${index + 1}`; + const pickerName = String(source.picker_name || source.pickerName || source.user_name || source.userName || '--').trim() || '--'; + const cartNo = String(source.cart_code || source.cartCode || source.cart_no || source.cartNo || '--').trim() || '--'; + const unreviewedCount = Number(source.unreviewed_count ?? source.unreviewedCount ?? source.pending_count ?? source.pendingCount ?? 0); + const assigneeId = String((source.picker_id ?? source.pickerId ?? source.user_id ?? source.userId) || '').trim(); + return { + id: String(rowId || `batch-${this.currentPage}-${index + 1}`), + waveId: typeof waveId === 'number' ? waveId : String(waveId || '').trim(), + waveNo, + pickerName, + cartNo, + unreviewedCount: Number.isFinite(unreviewedCount) ? unreviewedCount : 0, + status: String(source.status || 'pending'), + waybillCode: String(source.waybill_no || source.waybillCode || source.waybill_code || ''), + isMine: !!this.currentUserId && !!assigneeId && assigneeId === this.currentUserId + }; + }) + .filter(item => !!item.waveNo); }, - applyWaveNoToMockList(batchWaveList) { - const count = batchWaveList.length ? batchWaveList.length : this.grabCount; - const mockList = this.buildMockOrderList(count); - if (batchWaveList.length) { - mockList.forEach((item, index) => { - const current = batchWaveList[index] || {}; - item.waveNo = current.waveNo || item.waveNo; - item.waveId = current.waveId || ''; - }); + resolvePaginationTotal(payload, response, pagination, list) { + const candidates = [ + pagination?.total, + payload?.total, + payload?.count, + payload?.totalCount, + response?.data?.total, + response?.total, + Array.isArray(list) ? list.length : 0 + ]; + for (let i = 0; i < candidates.length; i += 1) { + const value = Number(candidates[i]); + if (Number.isFinite(value) && value >= 0) { + return value; + } } - this.orderList = mockList; + return 0; }, - async loadBatchWaveNoList() { + async loadBatchWaveNoList(page = this.currentPage) { + const targetPage = Math.max(1, Number(page || 1)); try { - const response = await this.$http('order.wave.batchList', this.buildBatchListParams()); + const response = await this.$http('order.wave.batchList', this.buildBatchListParams(targetPage)); const payload = this.extractBatchListPayload(response); const list = this.extractBatchList(payload, response); + const pagination = this.extractPagination(payload, response); const batchWaveList = this.normalizeBatchWaveList(list); - this.applyWaveNoToMockList(batchWaveList); + this.orderList = batchWaveList; + this.paginationTotal = this.resolvePaginationTotal(payload, response, pagination, list); + this.currentPage = Number((pagination?.page ?? targetPage) || targetPage); + this.pageSize = Number((pagination?.pageSize ?? this.pageSize) || this.pageSize); } catch (error) { - this.orderList = this.buildMockOrderList(this.grabCount); + this.orderList = []; + this.paginationTotal = 0; + uni.showToast({ + title: '波次列表加载失败', + icon: 'none' + }); } }, resolveWarehouseId() { @@ -676,6 +676,8 @@ }, toggleOnlyMine() { this.onlyMine = !this.onlyMine; + this.currentPage = 1; + this.loadBatchWaveNoList(1); }, buildMockOrderList(count) { const listCount = Math.max(0, Number(count || 0)); @@ -724,7 +726,7 @@ }, async handlePrintAllUnreviewed(item) { const target = item && typeof item === 'object' ? item : null; - if (!target || Number(target.unreviewedCount || 0) <= 0) { + if (!target) { uni.showToast({ title: '暂无未复核订单可打印', icon: 'none' @@ -782,10 +784,6 @@ }); return; } - if (this.pendingPrintCount <= 0) { - this.printMessage = '暂无可打印订单'; - return; - } if (!Array.isArray(this.printWaveGroups) || !this.printWaveGroups.length) { this.printMessage = '未获取到打印数据'; uni.showToast({ @@ -796,6 +794,9 @@ } const params = this.buildPrintSendParams(); + const effectivePrintCount = Number(this.pendingPrintCount || 0) > 0 + ? Number(this.pendingPrintCount || 0) + : this.printWaveGroups.length; uni.showLoading({ title: '发送打印中...' }); @@ -805,9 +806,9 @@ if (!success) { throw new Error(response?.message || response?.msg || '打印失败'); } - this.printMessage = `打印已发送,未复核订单 ${this.pendingPrintCount} 条`; + this.printMessage = `打印已发送,未复核订单 ${effectivePrintCount} 条`; uni.showToast({ - title: `已发起打印${this.pendingPrintCount}条`, + title: `已发起打印${effectivePrintCount}条`, icon: 'none' }); this.showPrintPopup = false; @@ -823,7 +824,12 @@ } }, handlePageChange(page) { - this.currentPage = Math.max(1, Number(page || 1)); + const targetPage = Math.max(1, Number(page || 1)); + if (targetPage === this.currentPage) { + return; + } + this.currentPage = targetPage; + this.loadBatchWaveNoList(targetPage); } } }; @@ -1061,14 +1067,17 @@ } .print-popup { - padding: 24rpx; + padding: 24rpx 24rpx calc(20rpx + env(safe-area-inset-bottom)); + background: #ffffff; + border-top-left-radius: 20rpx; + border-top-right-radius: 20rpx; } .print-popup-title { - font-size: 32rpx; + font-size: 34rpx; font-weight: 600; color: #303133; - margin-bottom: 18rpx; + margin-bottom: 20rpx; } .print-row { @@ -1082,6 +1091,10 @@ position: relative; } + .print-row--station .print-label { + padding-top: 10rpx; + } + .print-row--action { align-items: center; } @@ -1091,6 +1104,7 @@ } .print-label { + min-width: 130rpx; width: 130rpx; font-size: 28rpx; line-height: 40rpx; @@ -1106,27 +1120,35 @@ .print-picker { flex: 1; + min-width: 0; display: flex; align-items: center; justify-content: space-between; + padding: 10rpx 16rpx; + border: 1rpx solid #dcdfe6; + border-radius: 10rpx; + background: #fafafa; } .print-picker-value { + flex: 1; font-size: 28rpx; line-height: 40rpx; color: #303133; + padding-right: 16rpx; + word-break: break-all; } .print-station-dropdown { position: absolute; - left: 130rpx; right: 0; - top: 74rpx; + top: calc(100% - 4rpx); + width: calc(100% - 154rpx); max-height: 300rpx; overflow-y: auto; background: #ffffff; border: 1rpx solid #ebeef5; - border-radius: 8rpx; + border-radius: 10rpx; z-index: 10091; }