diff --git a/src/pages/packaging/index.vue b/src/pages/packaging/index.vue
index ae32c4e..557b6d6 100644
--- a/src/pages/packaging/index.vue
+++ b/src/pages/packaging/index.vue
@@ -40,8 +40,8 @@
- 波次
- {{ currentWaveNo || '暂无波次' }}
+ {{ isSandan === 1 ? '运单' : '波次' }}
+ {{ isSandan === 1 ? (currentWaybillCode || '暂无运单') : (currentWaveNo || '暂无波次') }}
共{{ waveTotalOrders || 0 }}单
@@ -61,19 +61,48 @@
- 商品明细
+
+ 商品明细
+ {{ isGroupOrder ? '团单' : '散单' }}
+ 已扫 {{ scannedKindCount }}/{{ totalKindCount }} 种
+
+
暂无商品明细
-
- 商品名称
- 条码
- 数量
-
-
- {{ item.name }}
- {{ item.barcode }}
- {{ item.qty }}
+
+ {{ index + 1 }}
+
+
+
+ -
+ {{ item.imageCount }}
+
+
+
+ {{ item.name }}
+ 【{{ item.barcode }}】
+
+ x{{ item.qty }}
@@ -188,7 +217,7 @@
×
确认移除操作员「{{ removeTargetName }}」?
-
+
+
+
+
+ {{ imagePreviewIndex + 1 }} / {{ imagePreviewList.length }}
+
+ {{ Math.round(previewScale * 100) }}%
+
+
+
+
+
+ ‹
+
+ ›
+
+
+
+
+
+
+
+ 无条码复核
+ ×
+
+ 将「{{ (noBarcodeReviewTarget && noBarcodeReviewTarget.name) || '' }}」标记为已扫?
+
+
+
+
+
+
+
+
@@ -208,6 +304,8 @@ import {
bindWorkbenchMember,
removeWorkbenchMember,
queryPackOrder,
+ packOrder,
+ finishPack,
} from '@/api/index'
// 扫码枪识别参数(广播扫描:扫码枪为键盘 HID 设备,按键事件全局广播)
@@ -273,6 +371,34 @@ export default {
operatorSearchTimer: null,
removeConfirmVisible: false,
orderQuerying: false,
+ // ---- 打包订单类型 / 无条码复核 ----
+ isSandan: null,
+ noBarcodeReviewVisible: false,
+ noBarcodeReviewTarget: null,
+ cancelVerifyPopupOpen: false,
+ // ---- 打包流程(预检/上报/完成)----
+ currentOrderCode: '',
+ currentWaybillCode: '',
+ currentDeliveryOrderCode: '',
+ currentOrderRaw: null,
+ precheckPassed: false,
+ packStarted: false,
+ packReporting: false,
+ packFinishing: false,
+ // ---- 商品图片预览 ----
+ imagePreviewVisible: false,
+ imagePreviewList: [],
+ imagePreviewIndex: 0,
+ previewScale: 1,
+ previewOffsetX: 0,
+ previewOffsetY: 0,
+ previewTouchMode: '',
+ previewTouchStartX: 0,
+ previewTouchStartY: 0,
+ previewTouchOriginX: 0,
+ previewTouchOriginY: 0,
+ previewPinchStartDistance: 0,
+ previewPinchStartScale: 1,
}
},
computed: {
@@ -316,6 +442,36 @@ export default {
removeTargetName() {
return this.workbenchMember?.user_name || '该操作员'
},
+ previewImageUrl() {
+ return this.imagePreviewList[this.imagePreviewIndex] || ''
+ },
+ previewImageStyle() {
+ return {
+ transform: `translate(${this.previewOffsetX}px, ${this.previewOffsetY}px) scale(${this.previewScale})`,
+ }
+ },
+ isGroupOrder() {
+ return this.isSandan === 0
+ },
+ scannedKindCount() {
+ return this.detailList.filter((item) => this.isItemScanned(item)).length
+ },
+ totalKindCount() {
+ return this.detailList.length
+ },
+ groupVerifiedCount() {
+ return this.scannedKindCount
+ },
+ },
+ watch: {
+ groupVerifiedCount(val) {
+ if (!this.isGroupOrder || !this.precheckPassed || this.packStarted || this.packReporting) {
+ return
+ }
+ if (this.totalKindCount > 0 && val >= this.totalKindCount) {
+ this.handleSubmitGroupPack()
+ }
+ },
},
onLoad() {
// 简单守卫:无 token 时回到登录页
@@ -354,6 +510,26 @@ export default {
this.queryAndBindOperator(kw)
return
}
+ // 已绑定:团单已进入核实态时,按核实进度决定扫码含义
+ if (this.isGroupOrder && this.precheckPassed && this.detailList.length > 0) {
+ if (this.groupVerifiedCount === 0) {
+ // 尚未开始核实:先按商品条码匹配,匹配不到则视为新运单号切换订单
+ const matched = this.detailList.some(
+ (item) =>
+ (Array.isArray(item.barcodes) && item.barcodes.includes(kw)) ||
+ item.barcode === kw
+ )
+ if (matched) {
+ this.matchProductBarcode(kw)
+ } else {
+ this.queryPackOrderByCode(kw)
+ }
+ } else {
+ // 已开始核实:扫码内容按商品条码核实
+ this.matchProductBarcode(kw)
+ }
+ return
+ }
// 已绑定:扫码运单号查询订单
this.queryPackOrderByCode(kw)
},
@@ -404,13 +580,38 @@ export default {
const batch = raw?.batch && typeof raw.batch === 'object' ? raw.batch : {}
const items = Array.isArray(raw?.items) ? raw.items : []
+ // 订单类型:isSandan=1 散单、0 团单(团单需扫码商品条码核验)
+ const rawSandan = this.pickInfoField(raw, {}, ['isSandan', 'is_sandan'])
+ this.isSandan = rawSandan === '' ? null : Number(rawSandan)
+
+ // 记录当前订单上下文(用于预检/上报)
+ this.currentOrderRaw = raw
+ this.currentOrderCode = code || ''
+ this.packStarted = false
+ this.precheckPassed = false
+
+ // 运单号(散单展示用:waybill_code 优先,兜底 barcode)
+ this.currentWaybillCode =
+ this.pickInfoField(raw, {}, ['waybill_code', 'waybillCode']) ||
+ this.pickInfoField(raw, {}, ['barcode']) ||
+ ''
+
+ // 发货单号(上报用:order.delivery_order_code)
+ this.currentDeliveryOrderCode = this.pickInfoField(order, {}, [
+ 'delivery_order_code',
+ 'deliveryOrderCode',
+ ])
+
// 波次号:团购优先 batch.wave_no,散单用 order.wave_no
this.currentWaveNo =
this.pickInfoField(batch, {}, ['wave_no', 'waveNo']) ||
this.pickInfoField(order, {}, ['wave_no', 'waveNo'])
- // 波次总订单数(团购 batch.total_orders)
+ // 波次总订单数(团购 batch.total_orders);散单固定 1 单
this.waveTotalOrders = this.pickInfoField(batch, {}, ['total_orders', 'totalOrders'])
+ if (!this.isGroupOrder && !this.waveTotalOrders) {
+ this.waveTotalOrders = 1
+ }
// 货主备注
this.storeRemark = this.pickInfoField(raw, {}, ['store_remark', 'storeRemark'])
@@ -438,12 +639,366 @@ export default {
? rawBarcodes[0].barcode || rawBarcodes[0].code || ''
: String(rawBarcodes[0])
: ''
+ const images = this.extractImages(it)
+ const barcodeList = rawBarcodes
+ .map((bc) =>
+ typeof bc === 'object' && bc !== null ? bc.barcode || bc.code || '' : String(bc)
+ )
+ .filter((bc) => bc)
return {
name: it?.item_name || it?.item_code || '',
barcode: firstBarcode || it?.item_code || '',
+ barcodes: barcodeList.length > 0 ? barcodeList : firstBarcode ? [firstBarcode] : [],
qty: it?.plan_qty ?? '',
+ scannedQty: 0,
+ image: images[0] || '',
+ imageCount: images.length,
+ images,
}
})
+
+ // ---- 预检与分流 ----
+ const precheck = this.packPrecheck()
+ if (!precheck.ok) {
+ this.speak(precheck.reason)
+ uni.showToast({ title: precheck.reason, icon: 'none' })
+ return
+ }
+ this.precheckPassed = true
+ if (this.isGroupOrder) {
+ // 团单:无商品明细 = 无需核实,直接提交开始打包
+ if (this.detailList.length === 0) {
+ this.handleSubmitGroupPack()
+ }
+ return
+ }
+ // 散单:预检通过立即自动上报开始打包
+ this.startPack()
+ },
+ matchProductBarcode(barcode) {
+ const target = this.detailList.find(
+ (item) =>
+ (Array.isArray(item.barcodes) && item.barcodes.includes(barcode)) ||
+ item.barcode === barcode
+ )
+ if (target) {
+ if (this.isItemScanned(target)) {
+ this.keyword = ''
+ this.speak('数据一致')
+ uni.showToast({ title: `${target.name || ''} 已核实`, icon: 'none' })
+ return
+ }
+ // 按商品种类:扫 1 次即标记为已核实,无需扫满数量
+ target.scannedQty = Number(target.qty) || 0
+ this.addScanRecord(barcode)
+ this.keyword = ''
+ this.speak('数据一致')
+ uni.showToast({ title: `${target.name || ''} 已核实`, icon: 'none' })
+ } else {
+ this.speak('无记录')
+ uni.showToast({ title: '条码与待核实商品不匹配', icon: 'none' })
+ }
+ },
+ isItemScanned(item) {
+ const qty = Number(item?.qty) || 0
+ const scanned = Number(item?.scannedQty) || 0
+ return qty > 0 && scanned >= qty
+ },
+ handleLongPressProduct(item) {
+ if (!item || !this.isGroupOrder) {
+ return
+ }
+ if (this.isItemScanned(item)) {
+ uni.showToast({ title: '该商品已全部扫码', icon: 'none' })
+ return
+ }
+ this.noBarcodeReviewTarget = item
+ this.noBarcodeReviewVisible = true
+ },
+ closeNoBarcodeReview() {
+ this.noBarcodeReviewVisible = false
+ this.noBarcodeReviewTarget = null
+ },
+ confirmNoBarcodeReview() {
+ const target = this.noBarcodeReviewTarget
+ if (!target) {
+ this.closeNoBarcodeReview()
+ return
+ }
+ const total = Number(target.qty) || 0
+ if (total <= 0) {
+ uni.showToast({ title: '该商品无数量,无法标记', icon: 'none' })
+ return
+ }
+ if ((Number(target.scannedQty) || 0) >= total) {
+ uni.showToast({ title: '该商品已全部扫码', icon: 'none' })
+ this.closeNoBarcodeReview()
+ return
+ }
+ target.scannedQty = total
+ uni.showToast({ title: `已将「${target.name || ''}」标记为已扫`, icon: 'none' })
+ this.closeNoBarcodeReview()
+ },
+ handleCancelGroupVerify() {
+ this.cancelVerifyPopupOpen = true
+ },
+ handleCloseCancelVerifyPopup() {
+ this.cancelVerifyPopupOpen = false
+ },
+ confirmCancelVerify() {
+ // 清空核实与订单,回到可查询态
+ this.clearPackState()
+ this.cancelVerifyPopupOpen = false
+ this.speak('已取消核实')
+ uni.showToast({ title: '已取消核实', icon: 'none' })
+ },
+ /**
+ * 打包预检(本地判断,基于 queryOrder 返回字段)
+ * - 散单:拦截(intercept_flag=1) / 未复核(recheck_status≠fin) / 已打包(pack_flag=1)
+ * - 团单:未复核 / 已打包(pack_status≠none),不判拦截
+ */
+ packPrecheck() {
+ const order =
+ this.currentOrderRaw?.order && typeof this.currentOrderRaw.order === 'object'
+ ? this.currentOrderRaw.order
+ : {}
+ const batch =
+ this.currentOrderRaw?.batch && typeof this.currentOrderRaw.batch === 'object'
+ ? this.currentOrderRaw.batch
+ : {}
+ if (this.isGroupOrder) {
+ const recheckStatus = order?.recheck_status ?? order?.recheckStatus ?? ''
+ if (recheckStatus && String(recheckStatus) !== 'fin') {
+ return { ok: false, reason: '订单未复核,禁止打包' }
+ }
+ const packStatus =
+ order?.pack_status ?? order?.packStatus ?? batch?.pack_status ?? batch?.packStatus ?? ''
+ if (packStatus && String(packStatus) !== 'none') {
+ return { ok: false, reason: '订单已打包,禁止重复打包' }
+ }
+ return { ok: true }
+ }
+ if (Number(order?.intercept_flag) === 1) {
+ return { ok: false, reason: '订单已拦截,禁止打包' }
+ }
+ const recheckStatus = order?.recheck_status ?? order?.recheckStatus ?? ''
+ if (recheckStatus && String(recheckStatus) !== 'fin') {
+ return { ok: false, reason: '订单未复核,禁止打包' }
+ }
+ if (Number(order?.pack_flag) === 1) {
+ return { ok: false, reason: '订单已打包,禁止重复打包' }
+ }
+ return { ok: true }
+ },
+ /**
+ * 上报开始打包(复用 workbench.packOrder,status=1)
+ */
+ reportPackOrder(status = 1) {
+ const token = this.getWorkbenchToken()
+ if (!token) {
+ return Promise.reject(new Error('工作台登录已失效'))
+ }
+ const payload = {
+ token: String(token),
+ delivery_order_code:
+ this.currentDeliveryOrderCode || this.currentOrderCode || this.currentWaveNo || '',
+ status,
+ pack_time: Date.now(),
+ wave_no: this.isGroupOrder && this.currentWaveNo ? this.currentWaveNo : undefined,
+ items_count: this.totalKindCount || undefined,
+ items_total: this.productCount || undefined,
+ }
+ return packOrder(payload).then((body) => {
+ const res = body?.data || body?.result || body
+ const flag = body?.flag || res?.flag || ''
+ if (flag === 'failure') {
+ throw new Error(body?.message || body?.msg || '打包上报失败')
+ }
+ return body
+ })
+ },
+ startPack() {
+ if (this.packReporting || this.packStarted) {
+ return
+ }
+ this.packReporting = true
+ this.reportPackOrder(1)
+ .then(() => {
+ this.packStarted = true
+ this.speak('开始打包')
+ })
+ .catch((err) => {
+ uni.showToast({ title: err?.message || '打包上报失败', icon: 'none' })
+ })
+ .finally(() => {
+ this.packReporting = false
+ })
+ },
+ handleSubmitGroupPack() {
+ this.startPack()
+ },
+ ensurePackFinishedBeforeLeave() {
+ const token = this.getWorkbenchToken()
+ if (!token) {
+ return
+ }
+ if (!this.packStarted) {
+ return
+ }
+ if (this.packFinishing) {
+ return
+ }
+ this.packFinishing = true
+ finishPack(String(token))
+ .then(() => {
+ this.packStarted = false
+ this.speak('打包完成')
+ })
+ .catch(() => {
+ // 失败不阻断
+ })
+ .finally(() => {
+ this.packFinishing = false
+ })
+ },
+ clearPackState() {
+ this.detailList = []
+ this.currentWaveNo = ''
+ this.waveTotalOrders = ''
+ this.storeRemark = ''
+ this.packageMaterialName = ''
+ this.productCount = 0
+ this.isSandan = null
+ this.currentOrderCode = ''
+ this.currentWaybillCode = ''
+ this.currentDeliveryOrderCode = ''
+ this.currentOrderRaw = null
+ this.precheckPassed = false
+ this.packStarted = false
+ },
+ speak(text) {
+ try {
+ if (typeof window !== 'undefined' && window.speechSynthesis) {
+ window.speechSynthesis.cancel()
+ const utterance = new SpeechSynthesisUtterance(String(text))
+ utterance.lang = 'zh-CN'
+ window.speechSynthesis.speak(utterance)
+ }
+ } catch (e) {
+ // 语音不可用时静默忽略
+ }
+ },
+ previewItemImage(item) {
+ const urls =
+ Array.isArray(item?.images) && item.images.length > 0
+ ? item.images
+ : item?.image
+ ? [item.image]
+ : []
+ if (!urls.length) {
+ return
+ }
+ this.imagePreviewList = urls
+ this.imagePreviewIndex = 0
+ this.previewScale = 1
+ this.previewOffsetX = 0
+ this.previewOffsetY = 0
+ this.previewTouchMode = ''
+ this.imagePreviewVisible = true
+ },
+ closeImagePreview() {
+ this.imagePreviewVisible = false
+ this.previewTouchMode = ''
+ this.previewScale = 1
+ this.previewOffsetX = 0
+ this.previewOffsetY = 0
+ },
+ previewZoomIn() {
+ this.previewScale = Math.min(Number((this.previewScale + 0.2).toFixed(2)), 6)
+ },
+ previewZoomOut() {
+ this.previewScale = Math.max(Number((this.previewScale - 0.2).toFixed(2)), 0.2)
+ },
+ previewResetZoom() {
+ this.previewScale = 1
+ this.previewOffsetX = 0
+ this.previewOffsetY = 0
+ },
+ previewPrev() {
+ if (this.imagePreviewList.length <= 1) {
+ return
+ }
+ this.imagePreviewIndex =
+ (this.imagePreviewIndex - 1 + this.imagePreviewList.length) % this.imagePreviewList.length
+ this.previewResetZoom()
+ },
+ previewNext() {
+ if (this.imagePreviewList.length <= 1) {
+ return
+ }
+ this.imagePreviewIndex = (this.imagePreviewIndex + 1) % this.imagePreviewList.length
+ this.previewResetZoom()
+ },
+ previewTouchStart(event) {
+ const touches = this.getPreviewTouches(event)
+ if (touches.length >= 2) {
+ // 双指捏合缩放
+ this.previewTouchMode = 'pinch'
+ this.previewPinchStartDistance = this.getTouchDistance(touches)
+ this.previewPinchStartScale = this.previewScale
+ } else if (touches.length === 1) {
+ // 单指拖拽平移
+ this.previewTouchMode = 'drag'
+ this.previewTouchStartX = this.getTouchX(touches[0])
+ this.previewTouchStartY = this.getTouchY(touches[0])
+ this.previewTouchOriginX = this.previewOffsetX
+ this.previewTouchOriginY = this.previewOffsetY
+ }
+ },
+ previewTouchMove(event) {
+ const touches = this.getPreviewTouches(event)
+ if (this.previewTouchMode === 'pinch' && touches.length >= 2) {
+ const distance = this.getTouchDistance(touches)
+ if (this.previewPinchStartDistance > 0) {
+ const next = this.previewPinchStartScale * (distance / this.previewPinchStartDistance)
+ this.previewScale = Math.min(Math.max(Number(next.toFixed(2)), 0.2), 6)
+ }
+ } else if (this.previewTouchMode === 'drag' && touches.length >= 1) {
+ const x = this.getTouchX(touches[0])
+ const y = this.getTouchY(touches[0])
+ this.previewOffsetX = this.previewTouchOriginX + (x - this.previewTouchStartX)
+ this.previewOffsetY = this.previewTouchOriginY + (y - this.previewTouchStartY)
+ }
+ },
+ previewTouchEnd() {
+ this.previewTouchMode = ''
+ },
+ getPreviewTouches(event) {
+ const touches = event?.touches
+ if (touches && typeof touches.length === 'number' && touches.length > 0) {
+ return touches
+ }
+ const changed = event?.changedTouches
+ if (changed && typeof changed.length === 'number' && changed.length > 0) {
+ return changed
+ }
+ return []
+ },
+ getTouchX(touch) {
+ return touch?.clientX ?? touch?.pageX ?? touch?.x ?? 0
+ },
+ getTouchY(touch) {
+ return touch?.clientY ?? touch?.pageY ?? touch?.y ?? 0
+ },
+ getTouchDistance(touches) {
+ const a = touches[0]
+ const b = touches[1]
+ if (!a || !b) {
+ return 0
+ }
+ const dx = this.getTouchX(a) - this.getTouchX(b)
+ const dy = this.getTouchY(a) - this.getTouchY(b)
+ return Math.sqrt(dx * dx + dy * dy)
},
handleSearchFocus() {
this.searchFocused = true
@@ -1110,6 +1665,7 @@ export default {
}
const removed = Number(raw?.removed ?? body?.removed ?? 0)
if (removed > 0) {
+ this.ensurePackFinishedBeforeLeave()
this.workbenchMember = null
uni.removeStorageSync(MEMBER_STORAGE_KEY)
this.removeConfirmVisible = false
@@ -1140,6 +1696,38 @@ export default {
}
return ''
},
+ /**
+ * 提取商品图片 URL 列表
+ * 兼容 images 数组(元素为字符串或 { url/image_url/path/src } 对象)与单字段 image/image_url/imageUrl
+ */
+ extractImages(item) {
+ const raw =
+ item?.images !== undefined && item?.images !== null
+ ? item.images
+ : item?.image ?? item?.image_url ?? item?.imageUrl
+ let list = []
+ if (Array.isArray(raw)) {
+ list = raw
+ } else if (raw !== undefined && raw !== null && raw !== '') {
+ list = [raw]
+ }
+ const urls = []
+ for (const el of list) {
+ if (typeof el === 'string') {
+ const v = el.trim()
+ if (v) {
+ urls.push(v)
+ }
+ } else if (el && typeof el === 'object') {
+ const v =
+ el.url || el.image_url || el.imageUrl || el.path || el.src || el.value || ''
+ if (v) {
+ urls.push(String(v))
+ }
+ }
+ }
+ return urls
+ },
loadWorkbenchInfo() {
if (this.infoLoading) {
return
@@ -1214,6 +1802,7 @@ export default {
}, 400)
},
finishLogout() {
+ this.ensurePackFinishedBeforeLeave()
this.exitToLogin('已退出登录')
},
handleLogout() {
@@ -1254,7 +1843,7 @@ export default {