1
This commit is contained in:
parent
9eb6eded6e
commit
332ebac7b4
@ -96,11 +96,12 @@ export function scanTask(data: RecheckScanTaskParams): Promise<any> {
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 订单 ID;优先 order_id,兼容 id、orderId */
|
||||
/** 订单 ID;优先 order_id,兼容 id、orderId;团购模式支持 wave_id */
|
||||
export type ConfirmRecheckParams = {
|
||||
order_id?: string | number
|
||||
id?: string | number
|
||||
orderId?: string | number
|
||||
wave_id?: string | number
|
||||
}
|
||||
|
||||
function coerceOrderId(v: string | number): string | number {
|
||||
@ -111,7 +112,11 @@ function coerceOrderId(v: string | number): string | number {
|
||||
return s
|
||||
}
|
||||
|
||||
function pickConfirmRecheckBody(data: ConfirmRecheckParams): { order_id: string | number } {
|
||||
function pickConfirmRecheckBody(data: ConfirmRecheckParams): Record<string, string | number> {
|
||||
// 团购波次模式:优先使用 wave_id
|
||||
if (data.wave_id !== undefined && data.wave_id !== null && `${data.wave_id}`.trim() !== '') {
|
||||
return { wave_id: coerceOrderId(data.wave_id) }
|
||||
}
|
||||
const raw =
|
||||
data.order_id !== undefined && data.order_id !== null && `${data.order_id}`.trim() !== ''
|
||||
? data.order_id
|
||||
@ -121,7 +126,7 @@ function pickConfirmRecheckBody(data: ConfirmRecheckParams): { order_id: string
|
||||
? data.orderId
|
||||
: undefined
|
||||
if (raw === undefined) {
|
||||
throw new Error('订单 ID 不能为空(order_id / id / orderId)')
|
||||
throw new Error('订单 ID 不能为空(order_id / id / orderId / wave_id)')
|
||||
}
|
||||
return { order_id: coerceOrderId(raw) }
|
||||
}
|
||||
@ -161,3 +166,18 @@ export const orderRecheckOrder = {
|
||||
confirmRecheck,
|
||||
confirmIntercept
|
||||
}
|
||||
|
||||
/** order.updateExpressWeighingWeight:更新订单运单称重重量 */
|
||||
export function updateExpressWeighingWeight(data: { order_id: number; weighing_weight: number }) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'order.updateExpressWeighingWeight',
|
||||
v,
|
||||
timestamp: Date.now()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -54,6 +54,14 @@
|
||||
>
|
||||
面单补打
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="info"
|
||||
:disabled="!activeOrderId"
|
||||
@click="openWeighingDialog"
|
||||
>
|
||||
称重
|
||||
</el-button>
|
||||
<el-select
|
||||
v-model="recheckPrintStationId"
|
||||
placeholder="选择打印台"
|
||||
@ -143,12 +151,39 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
v-model="weighingDialogVisible"
|
||||
title="称重"
|
||||
width="360px"
|
||||
align-center
|
||||
@closed="resetWeighingForm"
|
||||
>
|
||||
<el-form ref="weighingFormRef" :model="weighingForm" :rules="weighingRules" label-width="80px">
|
||||
<el-form-item label="重量" prop="weight">
|
||||
<el-input-number
|
||||
v-model="weighingForm.weight"
|
||||
:min="0.001"
|
||||
:max="9999"
|
||||
:precision="3"
|
||||
:step="0.1"
|
||||
style="width: 100%"
|
||||
placeholder="请输入重量(kg)"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="weighingDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="weighingSubmitting" @click="submitWeighing">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import RecheckOrderPanel from './component/RecheckOrderPanel.vue'
|
||||
import * as stationApi from '@/api/print/print'
|
||||
@ -163,6 +198,7 @@ import {
|
||||
scanTask,
|
||||
confirmRecheck,
|
||||
confirmIntercept,
|
||||
updateExpressWeighingWeight,
|
||||
type ConfirmRecheckResultShape,
|
||||
type RecheckScanOrderParams,
|
||||
type ScanOrderResultShape
|
||||
@ -357,16 +393,18 @@ function handlePanelSearch(keyword: string) {
|
||||
void executeScan({ keyword })
|
||||
}
|
||||
|
||||
function handlePanelSelect(order: any) {
|
||||
async function handlePanelSelect(order: any) {
|
||||
const waybill = String(order?.waybill_no || '').trim()
|
||||
if (waybill) panelActiveWaybill.value = waybill
|
||||
// 已复核的订单切换回搜索模式
|
||||
const isReviewed = !!(order as any)?.is_reviewed || String((order as any)?.recheck_status ?? '').trim() === 'fin'
|
||||
const isIntercept = String((order as any)?.intercept_status ?? 'none').trim() !== 'none'
|
||||
// 判断是否为团购波次(有 _is_wave 标记)
|
||||
const isWave = !!(order as any)?._is_wave
|
||||
// 已复核或拦截订单:搜索模式,不可扫描复核
|
||||
panelScanMode.value = (isReviewed || isIntercept) ? 'search' : 'recheck'
|
||||
// 设置 order_id 和 order 信息
|
||||
const orderId = Number(order?.id ?? order?.order_id)
|
||||
// 设置 order_id 和 order 信息(兼容 wave_id)
|
||||
const orderId = Number(order?.id ?? order?.order_id ?? order?.wave_id)
|
||||
if (Number.isFinite(orderId) && orderId > 0) {
|
||||
selectedOrderId.value = orderId
|
||||
}
|
||||
@ -379,9 +417,10 @@ function handlePanelSelect(order: any) {
|
||||
}
|
||||
selectedOrderRow.value = order as Record<string, unknown>
|
||||
// 保留原始 scanPayload 中的波次级字段(拣货人、货主、篮号等),只更新订单级字段
|
||||
const matchType = isWave ? 'wave' : 'waybill'
|
||||
scanPayload.value = {
|
||||
...scanPayload.value,
|
||||
match_type: 'waybill',
|
||||
match_type: matchType,
|
||||
order: order as Record<string, unknown>,
|
||||
waybill_no: waybill,
|
||||
order_id: orderId
|
||||
@ -389,20 +428,23 @@ function handlePanelSelect(order: any) {
|
||||
if (isIntercept) {
|
||||
scanHint.value = '该订单已拦截,仅查看详情。'
|
||||
} else if (isReviewed) {
|
||||
scanHint.value = '该订单已复核,仅查看详情。'
|
||||
scanHint.value = isWave ? '该波次已复核,仅查看详情。' : '该订单已复核,仅查看详情。'
|
||||
} else {
|
||||
scanHint.value = '已选择订单,扫描商品条码进行复核。'
|
||||
scanHint.value = isWave ? '已选择波次,扫描商品条码进行复核。' : '已选择订单,扫描商品条码进行复核。'
|
||||
}
|
||||
scanHintType.value = 'info'
|
||||
activeTab.value = 'order'
|
||||
|
||||
// 先打印后复核模式:散单未打印时自动拉取打印数据并发送(已复核/拦截订单不打印)
|
||||
if (recheckWorkflowMode.value === 'print_first' && !isReviewed && !isIntercept) {
|
||||
// 先打印后复核模式(默认):散单/团购波次未打印时自动拉取打印数据并发送
|
||||
const isPrintFirst = !recheckWorkflowMode.value || recheckWorkflowMode.value === 'print_first'
|
||||
if (isPrintFirst && !isReviewed && !isIntercept && Number.isFinite(orderId) && orderId > 0) {
|
||||
const printStatus = String((order as any)?.print_status ?? '').trim()
|
||||
if (printStatus !== 'fin') {
|
||||
autoPrintForOrder(orderId)
|
||||
if (printStatus !== 'fin' && !skipAutoPrintOnce.value) {
|
||||
const waveIds = isWave ? ((order as any)?.order_ids as Array<number | string> | undefined) : undefined
|
||||
await autoPrintForOrder(orderId, waveIds)
|
||||
}
|
||||
}
|
||||
skipAutoPrintOnce.value = false
|
||||
}
|
||||
|
||||
/** 播放提示音:type=success(短促高音), warning(低沉长音) */
|
||||
@ -813,8 +855,41 @@ function updatePanelFromPayload(payload: ScanOrderResultShape) {
|
||||
const tid = (payload as any)?.task_id
|
||||
panelTaskId.value = tid != null && tid !== '' ? tid : undefined
|
||||
|
||||
// 散单/波次命中:响应顶层有 list、total_orders、unreviewed_count
|
||||
const rawList = asArray((payload as any).list)
|
||||
const listType = String((payload as any)?.list_type ?? '').trim()
|
||||
|
||||
// 团购模式:list_type === 'group',列表项为波次(含聚合 stocks)
|
||||
if (rawList.length && listType === 'group') {
|
||||
const waves = rawList.map((w: any) => ({
|
||||
...w,
|
||||
_is_wave: true,
|
||||
waybill_no: String(w.wave_no ?? '').trim(),
|
||||
id: w.wave_id,
|
||||
order_id: w.wave_id,
|
||||
stock: Array.isArray(w.stocks) ? w.stocks.map((s: any) => ({
|
||||
...s,
|
||||
item_name: s.item_name || s.name || '',
|
||||
barcode: s.barcodes?.[0] || s.item_code || '',
|
||||
barcodes: Array.isArray(s.barcodes) ? s.barcodes : (s.barcode ? [s.barcode] : []),
|
||||
plan_qty: s.plan_qty,
|
||||
images: Array.isArray(s.images) ? s.images : [],
|
||||
has_shared_barcode: !!s.has_shared_barcode
|
||||
})) : [],
|
||||
// 使用 wave 下的订单属性
|
||||
recheck_status: String(w.recheck_status ?? (w.processed_orders >= w.total_orders ? 'fin' : '')).trim(),
|
||||
is_reviewed: w.is_reviewed ?? (w.processed_orders >= w.total_orders && w.total_orders > 0)
|
||||
}))
|
||||
panelOrders.value = waves
|
||||
panelTotalCount.value = (payload as any).total_orders ?? waves.reduce((sum, w) => sum + (Number(w.order_count) || 0), 0)
|
||||
panelRemainingCount.value = (payload as any).unreviewed_count ?? waves.filter((w: any) => {
|
||||
const status = String(w.recheck_status ?? w.is_reviewed ?? '').trim()
|
||||
return status !== 'fin' && status !== 'true'
|
||||
}).length
|
||||
panelActiveWaybill.value = ''
|
||||
return
|
||||
}
|
||||
|
||||
// 散单/波次命中:响应顶层有 list、total_orders、unreviewed_count
|
||||
if (rawList.length) {
|
||||
const orders = rawList.map((o: any) => ({
|
||||
...o,
|
||||
@ -981,9 +1056,11 @@ const autoPrintingRef = ref(false)
|
||||
const reprintLoading = ref(false)
|
||||
const lastPrintWaveGroups = ref<unknown[] | null>(null)
|
||||
const lastPrintOrderId = ref<number | null>(null)
|
||||
const skipAutoPrintOnce = ref(false)
|
||||
|
||||
async function autoPrintForOrder(orderId: number) {
|
||||
async function autoPrintForOrder(orderId: number, waveOrderIds?: Array<number | string>) {
|
||||
if (autoPrintingRef.value) return
|
||||
if (!Number.isFinite(orderId) || orderId <= 0) return
|
||||
const stationId = recheckPrintStationId.value
|
||||
if (!stationId) {
|
||||
ElMessage.warning('未选择打印台,无法自动打印')
|
||||
@ -991,12 +1068,21 @@ async function autoPrintForOrder(orderId: number) {
|
||||
}
|
||||
autoPrintingRef.value = true
|
||||
try {
|
||||
const res: any = await getOrderPrintData({ order_ids: [orderId] })
|
||||
// 团购波次:使用波次内的实际订单 ID 列表拉取
|
||||
const queryIds = (waveOrderIds && waveOrderIds.length) ? waveOrderIds : [orderId]
|
||||
const res: any = await getOrderPrintData({ order_ids: queryIds })
|
||||
if (res?.code !== undefined && res?.code !== null && res?.code !== 1 && res?.code !== 200 && res?.code !== 0) {
|
||||
throw new Error(res?.message || '获取打印数据失败')
|
||||
}
|
||||
const payload: WavePlatformPrintDataPayload = unwrapWavePlatformPrintPayload(res)
|
||||
const waveGroups = payload.waveGroups
|
||||
let payload: WavePlatformPrintDataPayload = unwrapWavePlatformPrintPayload(res)
|
||||
let waveGroups = payload.waveGroups
|
||||
|
||||
// 兼容 wave/group 格式:直接用 list 作为 waveGroups 发送
|
||||
if (!Array.isArray(waveGroups) || !waveGroups.length) {
|
||||
const innerData = res?.data
|
||||
waveGroups = Array.isArray(innerData?.list) ? innerData.list : undefined
|
||||
}
|
||||
|
||||
if (!Array.isArray(waveGroups) || !waveGroups.length) {
|
||||
ElMessage.warning('未获取到可打印数据')
|
||||
return
|
||||
@ -1131,9 +1217,13 @@ function normalizeItemRow(raw: unknown): { scanned_qty: number; plan_qty: string
|
||||
}
|
||||
|
||||
const itemsRows = computed(() => {
|
||||
// 优先取选中行的 stock(散单复核),其次 scanPayload.items
|
||||
// 优先取选中行的 stock(散单/波次),其次 scanPayload.items
|
||||
const selectedOrder = selectedOrderRow.value
|
||||
const stockRaw = (selectedOrder as any)?.stock
|
||||
let stockRaw = (selectedOrder as any)?.stock
|
||||
// 兼容团购波次:原始数据用 stocks(复数)
|
||||
if (!Array.isArray(stockRaw) || !stockRaw.length) {
|
||||
stockRaw = (selectedOrder as any)?.stocks
|
||||
}
|
||||
if (Array.isArray(stockRaw) && stockRaw.length) {
|
||||
return stockRaw.map((item: any) => ({
|
||||
scanned_qty: Number(item._scanned_qty ?? 0),
|
||||
@ -1293,17 +1383,16 @@ async function executeScan(params: RecheckScanOrderParams) {
|
||||
const topId = resolveTopOrderId(payload)
|
||||
|
||||
if (rawList.length) {
|
||||
// 散单/波次命中:有完整订单列表
|
||||
// 使用 panelOrders(已规范化)自动选中,避免原始数据字段名差异
|
||||
const panelList = panelOrders.value
|
||||
const topWaybill = String((payload as any).waybill_no || '').trim()
|
||||
// 如果顶层有运单号,自动选中对应的订单
|
||||
const matchedRow = topWaybill
|
||||
? rawList.find((r: any) => String(r.waybill_no ?? '').trim() === topWaybill)
|
||||
? panelList.find((r: any) => String(r.waybill_no ?? '').trim() === topWaybill)
|
||||
: null
|
||||
if (matchedRow) {
|
||||
// 通过 handlePanelSelect 统一选中:更新左侧高亮 + 切换扫描模式 + 右侧显示
|
||||
handlePanelSelect(matchedRow)
|
||||
} else if (rawList.length === 1) {
|
||||
handlePanelSelect(rawList[0])
|
||||
} else if (panelList.length === 1) {
|
||||
handlePanelSelect(panelList[0])
|
||||
} else {
|
||||
scanHint.value = `共 ${rawList.length} 个订单,请从左侧列表中选择要复核的订单。`
|
||||
scanHintType.value = 'info'
|
||||
@ -1362,7 +1451,14 @@ async function handleConfirm() {
|
||||
}
|
||||
confirmLoading.value = true
|
||||
try {
|
||||
const res = await confirmRecheck({ order_id: id })
|
||||
// 团购波次:使用 wave_id;散单:使用 order_id
|
||||
const confirmParams: any = { order_id: id }
|
||||
const selectedRow = selectedOrderRow.value as any
|
||||
if (selectedRow?._is_wave && selectedRow?.wave_id) {
|
||||
confirmParams.wave_id = selectedRow.wave_id
|
||||
delete confirmParams.order_id
|
||||
}
|
||||
const res = await confirmRecheck(confirmParams)
|
||||
const payload = unwrapResponse(res) as ConfirmRecheckResultShape
|
||||
const parts = [
|
||||
payload.review_no ?? payload.reviewNo,
|
||||
@ -1371,9 +1467,10 @@ async function handleConfirm() {
|
||||
].filter((x) => x != null && String(x) !== '')
|
||||
ElMessage.success(parts.length ? `复核成功:${parts.join(' / ')}` : '复核已记录')
|
||||
|
||||
// 先复核后打印模式:复核成功后自动拉取打印数据并发送
|
||||
// 先复核后打印模式:复核成功后先拉取打印数据并缓存,再更新面板
|
||||
if (recheckWorkflowMode.value === 'recheck_first') {
|
||||
autoPrintForOrder(id)
|
||||
const waveIds = selectedRow?._is_wave ? (selectedRow?.order_ids as Array<number | string> | undefined) : undefined
|
||||
await autoPrintForOrder(id, waveIds)
|
||||
}
|
||||
|
||||
// 更新面板:将该订单标记为已复核
|
||||
@ -1388,12 +1485,13 @@ async function handleConfirm() {
|
||||
const status = String(o.recheck_status ?? '').trim()
|
||||
return status !== 'fin'
|
||||
}).length
|
||||
// 自动选中下一个未复核订单
|
||||
// 自动选中下一个未复核订单(跳过自动打印,保留当前波次的打印缓存)
|
||||
const nextUnreviewed = panelOrders.value.find((o: any) => {
|
||||
const status = String(o.recheck_status ?? '').trim()
|
||||
return status !== 'fin'
|
||||
})
|
||||
if (nextUnreviewed) {
|
||||
skipAutoPrintOnce.value = true
|
||||
handlePanelSelect(nextUnreviewed)
|
||||
} else {
|
||||
// 清除当前订单的扫描状态
|
||||
@ -1412,6 +1510,57 @@ async function handleConfirm() {
|
||||
}
|
||||
|
||||
onMounted(loadRecheckStationOptions)
|
||||
|
||||
// ─── 称重 ──────────────────────────────────────────────────────────────────
|
||||
const weighingDialogVisible = ref(false)
|
||||
const weighingSubmitting = ref(false)
|
||||
const weighingFormRef = ref<FormInstance>()
|
||||
const weighingForm = reactive({ weight: null as number | null })
|
||||
const weighingRules: FormRules = {
|
||||
weight: [
|
||||
{ required: true, message: '请输入重量', trigger: 'blur' },
|
||||
{ type: 'number', min: 0.001, message: '重量必须大于 0', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
function resetWeighingForm() {
|
||||
weighingForm.weight = null
|
||||
weighingFormRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
function openWeighingDialog() {
|
||||
weighingForm.weight = null
|
||||
weighingDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitWeighing() {
|
||||
if (!weighingFormRef.value || weighingSubmitting.value) return
|
||||
const valid = await weighingFormRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
const id = activeOrderId.value
|
||||
if (id == null || id <= 0) {
|
||||
ElMessage.warning('未获取到有效订单 ID')
|
||||
return
|
||||
}
|
||||
weighingSubmitting.value = true
|
||||
try {
|
||||
const res: any = await updateExpressWeighingWeight({
|
||||
order_id: id,
|
||||
weighing_weight: Number(weighingForm.weight)
|
||||
})
|
||||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||||
if (ok) {
|
||||
ElMessage.success(res?.message || '称重保存成功')
|
||||
weighingDialogVisible.value = false
|
||||
} else {
|
||||
ElMessage.error(res?.message || '称重保存失败')
|
||||
}
|
||||
} catch (error: any) {
|
||||
ElMessage.error(error?.message || '称重保存失败')
|
||||
} finally {
|
||||
weighingSubmitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user