2029 lines
69 KiB
Vue
2029 lines
69 KiB
Vue
<template>
|
||
<div class="storage-receiving-container order-recheck-page" :style="{ height: containerHeight }">
|
||
<div class="recheck-panel-wrapper">
|
||
<RecheckOrderPanel
|
||
ref="recheckPanelRef"
|
||
:orders="panelOrders"
|
||
:total-count="panelTotalCount"
|
||
:remaining-count="panelRemainingCount"
|
||
:loading="scanLoading"
|
||
:active-waybill="panelActiveWaybill"
|
||
:scan-mode="panelScanMode"
|
||
:all-scanned="allItemsScanned"
|
||
:task-id="panelTaskId"
|
||
:refresh-task-loading="refreshTaskLoading"
|
||
waybill-field="waybill_no"
|
||
recheck-status-field="recheck_status"
|
||
@search="handlePanelSearch"
|
||
@select="handlePanelSelect"
|
||
@scan-barcode="handleScanBarcode"
|
||
@confirm="handleConfirm"
|
||
@refresh-task="handleRefreshTask"
|
||
/>
|
||
</div>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<el-button
|
||
v-if="!hasSelectedIntercept"
|
||
size="small"
|
||
type="success"
|
||
:disabled="!canConfirm"
|
||
:loading="confirmLoading"
|
||
@click="handleConfirm"
|
||
>
|
||
确认复核
|
||
</el-button>
|
||
<el-button
|
||
v-if="hasSelectedIntercept"
|
||
size="small"
|
||
type="danger"
|
||
@click="handleConfirmIntercept"
|
||
>
|
||
确认拦截
|
||
</el-button>
|
||
<el-button size="small" @click="resetAll">清空</el-button>
|
||
<el-button size="small" type="primary" plain @click="batchRecheckDialogVisible = true">
|
||
批量快捷复核
|
||
</el-button>
|
||
<el-button size="small" type="primary" plain @click="singleListDialogVisible = true">
|
||
散单复核列表
|
||
</el-button>
|
||
<el-button
|
||
v-if="!hasSelectedIntercept"
|
||
size="small"
|
||
type="warning"
|
||
:disabled="!activeOrderId"
|
||
:loading="reprintLoading"
|
||
@click="handleReprint"
|
||
>
|
||
面单补打
|
||
</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="info"
|
||
:disabled="!activeOrderId"
|
||
@click="openWeighingDialog"
|
||
>
|
||
称重
|
||
</el-button>
|
||
<el-select
|
||
v-model="recheckPrintStationId"
|
||
placeholder="选择打印台"
|
||
size="small"
|
||
style="width: 130px"
|
||
:loading="stationLoading"
|
||
clearable
|
||
@change="handleRecheckStationChange"
|
||
>
|
||
<el-option
|
||
v-for="item in stationOptions"
|
||
:key="item.stationId"
|
||
:label="item.name"
|
||
:value="item.stationId"
|
||
/>
|
||
</el-select>
|
||
<el-select
|
||
v-model="recheckWorkflowMode"
|
||
placeholder="复核流程"
|
||
size="small"
|
||
style="width: 130px"
|
||
clearable
|
||
@change="handleWorkflowModeChange"
|
||
>
|
||
<el-option label="先打印后复核" value="print_first" />
|
||
<el-option label="先复核后打印" value="recheck_first" />
|
||
</el-select>
|
||
<el-select
|
||
v-model="recheckWeighingMode"
|
||
placeholder="数据一致后称重"
|
||
size="small"
|
||
style="width: 150px"
|
||
clearable
|
||
@change="handleWeighingModeChange"
|
||
>
|
||
<el-option label="不称重" value="off" />
|
||
<el-option label="称重" value="on" />
|
||
</el-select>
|
||
</div>
|
||
<div v-if="scanPayload" class="toolbar-right">
|
||
<el-tag v-if="scanPayloadPickerName" size="small" type="primary">拣货人:{{ scanPayloadPickerName }}</el-tag>
|
||
<el-tag v-if="scanPayloadStoreRemark" size="small" type="primary">货主:{{ scanPayloadStoreRemark }}</el-tag>
|
||
<el-tag v-if="scanPayloadWaveNo && scanPayloadWaveNo !== '—'" size="small" type="info">波次:{{ scanPayloadWaveNo }}</el-tag>
|
||
<el-tag v-if="scanPayloadWaveIndex" size="small" type="warning">篮号:{{ scanPayloadWaveIndex }}</el-tag>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div v-if="showDetailPane" class="detail-pane">
|
||
<div class="detail-header">
|
||
<div class="detail-header-title">商品明细</div>
|
||
<div class="detail-header-summary" v-if="itemsRows.length">
|
||
已扫 <strong class="text-scanned">{{ scannedCount }}</strong> / {{ itemsTotalCount }} 件
|
||
</div>
|
||
</div>
|
||
<div class="detail-container">
|
||
<div class="recheck-detail-pane">
|
||
<el-table v-if="itemsRows.length" :data="itemsRows" border size="small" height="100%" :summary-method="itemsSummary" show-summary :row-class-name="itemsRowClassName" @row-contextmenu="handleItemsRowContextMenu">
|
||
<el-table-column prop="scanned_qty" label="已扫" width="70" align="center" class-name="col-scanned" />
|
||
<el-table-column prop="plan_qty" label="总数" width="70" align="center" class-name="col-plan" />
|
||
<el-table-column prop="name" label="商品名称" min-width="160" show-overflow-tooltip />
|
||
<el-table-column label="图片" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<template v-if="row.images && row.images.length">
|
||
<el-image
|
||
style="width: 36px; height: 36px; border-radius: 3px; cursor: pointer; display: block; margin: 0 auto"
|
||
:src="row.images[0]"
|
||
:preview-src-list="row.images"
|
||
preview-teleported
|
||
fit="cover"
|
||
/>
|
||
</template>
|
||
<span v-else style="color:#c0c4cc;font-size:12px">—</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="条码" min-width="140" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<template v-if="row.barcodes && row.barcodes.length">
|
||
<span v-for="(bc, bi) in row.barcodes" :key="bi">
|
||
{{ bc }}<template v-if="bi < row.barcodes.length - 1">、</template>
|
||
</span>
|
||
</template>
|
||
<span v-else>{{ row.barcode || '—' }}</span>
|
||
<el-tag v-if="row.has_shared_barcode" size="small" type="warning" effect="light" style="margin-left:4px">共享</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="spec" label="规格" min-width="100" show-overflow-tooltip />
|
||
<el-table-column prop="packing_requirements" label="打包要求" min-width="120" show-overflow-tooltip />
|
||
</el-table>
|
||
<div v-else class="detail-empty-tip">暂无商品明细</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div v-else class="no-selection">
|
||
<div class="empty-tip">
|
||
<p>在左侧列表选择订单后,在此查看商品明细</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<el-dialog
|
||
v-model="weighingDialogVisible"
|
||
:title="weighingBeforeConfirm ? '称重(复核前)' : '称重'"
|
||
width="360px"
|
||
align-center
|
||
@opened="focusWeighingInput"
|
||
@closed="resetWeighingForm"
|
||
>
|
||
<el-form ref="weighingFormRef" :model="weighingForm" :rules="weighingRules" label-width="80px" @submit.prevent>
|
||
<el-form-item label="重量" prop="weight">
|
||
<el-input-number
|
||
ref="weighingInputRef"
|
||
v-model="weighingForm.weight"
|
||
:min="0.001"
|
||
:max="9999"
|
||
:precision="3"
|
||
:step="0.001"
|
||
style="width: 100%"
|
||
placeholder="请输入重量(kg)"
|
||
@keyup.enter.prevent="submitWeighing"
|
||
/>
|
||
</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>
|
||
|
||
<BatchQuickRecheckDialog
|
||
v-model="batchRecheckDialogVisible"
|
||
:suggested-ids="batchRecheckSuggestedIds"
|
||
@success="handleBatchQuickRecheckSuccess"
|
||
/>
|
||
|
||
<RecheckOrderSingleListForm
|
||
v-model="singleListDialogVisible"
|
||
@load-recheck="handleSingleListLoadRecheck"
|
||
@batch-recheck-success="handleSingleListBatchRecheckSuccess"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, h, nextTick, 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 BatchQuickRecheckDialog from './component/BatchQuickRecheckDialog.vue'
|
||
import RecheckOrderSingleListForm from './form/RecheckOrderSingleListForm.vue'
|
||
import * as stationApi from '@/api/print/print'
|
||
import { getOrderPrintData } from '@/api/order.print/orderprint'
|
||
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
||
import { unwrapWavePlatformPrintPayload } from '@/views/order/waveOrder/config/wave-config'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { recheckAvailableFields } from './recheck-config'
|
||
import {
|
||
scanOrder,
|
||
scanTask,
|
||
confirmRecheck,
|
||
confirmIntercept,
|
||
unwrapScanOrderResponse,
|
||
normalizeScanOrderPanelRow,
|
||
normalizeScanOrderGroupWaveRow,
|
||
isOrderRecheckFinished,
|
||
type ConfirmRecheckResultShape,
|
||
type RecheckScanOrderParams,
|
||
type ScanOrderResultShape
|
||
} from '@/api/order.recheckorder/recheckOrder'
|
||
import { orderUpdateExpressWeighingWeight } from '@/api/order.index/orderindex'
|
||
import { isOrderIndexApiSuccess } from '@/views/order/orderManagement/utils/order-index-helpers'
|
||
|
||
const SCAN_PARAM_KEYS: (keyof RecheckScanOrderParams)[] = [
|
||
'keyword',
|
||
'value',
|
||
'waybill_no',
|
||
'waybillCode',
|
||
'waybill_code',
|
||
'wave_no',
|
||
'waveNo',
|
||
'cart_code',
|
||
'cartCode'
|
||
]
|
||
|
||
const scanBox = ref<InstanceType<typeof ScanBox> | null>(null)
|
||
const recheckPanelRef = ref<InstanceType<typeof RecheckOrderPanel> | null>(null)
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(recheckAvailableFields)))
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const userStore = useUserStore()
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
const splitStackRef = ref<HTMLElement | null>(null)
|
||
|
||
const detailVisible = ref(true)
|
||
const activeTab = ref('order')
|
||
const tableSize = ref('small')
|
||
|
||
// ─── 打印台选择 ─────────────────────────────────────────────────────────────
|
||
const RECHECK_PRINT_STATION_KEY = 'order_recheck_print_station_id'
|
||
|
||
type StationOption = {
|
||
stationId: string
|
||
computer_id_legacy: string
|
||
name: string
|
||
default_printer_name: string
|
||
}
|
||
|
||
const stationOptions = ref<StationOption[]>([])
|
||
const stationLoading = ref(false)
|
||
const recheckPrintStationId = ref('')
|
||
|
||
function getSavedRecheckStationId(): string {
|
||
try {
|
||
return String(localStorage.getItem(RECHECK_PRINT_STATION_KEY) || '').trim()
|
||
} catch {
|
||
return ''
|
||
}
|
||
}
|
||
|
||
function saveRecheckStationId(stationId: string) {
|
||
try {
|
||
localStorage.setItem(RECHECK_PRINT_STATION_KEY, stationId)
|
||
} catch {
|
||
// ignore
|
||
}
|
||
}
|
||
|
||
function clearSavedRecheckStationId() {
|
||
try {
|
||
localStorage.removeItem(RECHECK_PRINT_STATION_KEY)
|
||
} catch {
|
||
// ignore
|
||
}
|
||
}
|
||
|
||
function extractPrintStationRows(res: any): any[] {
|
||
const root = res?.data
|
||
if (Array.isArray(root)) return root
|
||
if (!root || typeof root !== 'object') return []
|
||
if (Array.isArray(root.list)) return root.list
|
||
if (Array.isArray(root.records)) return root.records
|
||
if (Array.isArray(root.items)) return root.items
|
||
const inner = root.data
|
||
if (Array.isArray(inner)) return inner
|
||
if (inner && typeof inner === 'object') {
|
||
if (Array.isArray(inner.list)) return inner.list
|
||
if (Array.isArray(inner.records)) return inner.records
|
||
}
|
||
return []
|
||
}
|
||
|
||
function mapStationRow(item: Record<string, any>): StationOption {
|
||
const rawSid = item.id ?? item.print_station_id ?? item.station_id
|
||
let stationId = rawSid != null && String(rawSid).trim() !== '' ? String(rawSid).trim() : ''
|
||
const rawComputer = item.computer_id ?? item.computerId
|
||
const computer_id_legacy =
|
||
rawComputer != null && String(rawComputer).trim() !== '' ? String(rawComputer).trim() : ''
|
||
if (!stationId && computer_id_legacy) {
|
||
stationId = computer_id_legacy
|
||
}
|
||
const nameRaw =
|
||
item.name ??
|
||
item.station_name ??
|
||
item.print_station_name ??
|
||
item.printName ??
|
||
item.stationName ??
|
||
item.label ??
|
||
''
|
||
const name = nameRaw != null && String(nameRaw).trim() !== '' ? String(nameRaw).trim() : stationId
|
||
const defPrinter =
|
||
item.default_printer_name ??
|
||
item.defaultPrinterName ??
|
||
item.printer_name ??
|
||
item.default_printer ??
|
||
''
|
||
const default_printer_name = String(defPrinter ?? '').trim()
|
||
return { stationId, computer_id_legacy, name, default_printer_name }
|
||
}
|
||
|
||
async function loadRecheckStationOptions() {
|
||
stationLoading.value = true
|
||
try {
|
||
const stations: any = await stationApi.getList({ page: 1, pageSize: 100, where: {} })
|
||
const root = stations?.data
|
||
const ok = stations && (stations.code === 1 || stations.code === 200 || stations.flag === 'success')
|
||
if (!ok) {
|
||
stationOptions.value = []
|
||
recheckPrintStationId.value = ''
|
||
return
|
||
}
|
||
const rawList = extractPrintStationRows(stations)
|
||
stationOptions.value = rawList.filter((x: any) => x && typeof x === 'object').map((item: any) => mapStationRow(item))
|
||
|
||
// 初始化:优先本地存储,其次列表中有该值,否则置空
|
||
const saved = getSavedRecheckStationId()
|
||
const hasSaved = !!saved && stationOptions.value.some((item) => item.stationId === saved)
|
||
if (hasSaved) {
|
||
recheckPrintStationId.value = saved
|
||
} else {
|
||
recheckPrintStationId.value = ''
|
||
clearSavedRecheckStationId()
|
||
}
|
||
} catch {
|
||
stationOptions.value = []
|
||
recheckPrintStationId.value = ''
|
||
} finally {
|
||
stationLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleRecheckStationChange(val: string | number | undefined) {
|
||
const stationId = String(val ?? '').trim()
|
||
if (!stationId) {
|
||
clearSavedRecheckStationId()
|
||
return
|
||
}
|
||
saveRecheckStationId(stationId)
|
||
}
|
||
|
||
// ─── 复核流程配置 ───────────────────────────────────────────────────────────
|
||
const RECHECK_WORKFLOW_KEY = 'order_recheck_workflow_mode'
|
||
const recheckWorkflowMode = ref(loadWorkflowMode())
|
||
|
||
function loadWorkflowMode(): string {
|
||
try {
|
||
return localStorage.getItem(RECHECK_WORKFLOW_KEY) || ''
|
||
} catch {
|
||
return ''
|
||
}
|
||
}
|
||
|
||
function handleWorkflowModeChange(val: string | undefined) {
|
||
const mode = String(val ?? '').trim()
|
||
try {
|
||
if (mode) {
|
||
localStorage.setItem(RECHECK_WORKFLOW_KEY, mode)
|
||
} else {
|
||
localStorage.removeItem(RECHECK_WORKFLOW_KEY)
|
||
}
|
||
} catch {
|
||
// ignore
|
||
}
|
||
}
|
||
|
||
// ─── 数据一致后称重配置 ─────────────────────────────────────────────────────
|
||
const RECHECK_WEIGHING_KEY = 'order_recheck_weighing_mode'
|
||
const recheckWeighingMode = ref(loadWeighingMode())
|
||
|
||
function loadWeighingMode(): string {
|
||
try {
|
||
return localStorage.getItem(RECHECK_WEIGHING_KEY) || 'off'
|
||
} catch {
|
||
return 'off'
|
||
}
|
||
}
|
||
|
||
function handleWeighingModeChange(val: string | undefined) {
|
||
const mode = String(val ?? 'off').trim()
|
||
try {
|
||
if (mode === 'on') {
|
||
localStorage.setItem(RECHECK_WEIGHING_KEY, mode)
|
||
} else {
|
||
localStorage.removeItem(RECHECK_WEIGHING_KEY)
|
||
}
|
||
} catch {
|
||
// ignore
|
||
}
|
||
}
|
||
|
||
// ─── RecheckOrderPanel 状态 ─────────────────────────────────────────────────
|
||
const panelOrders = ref<any[]>([])
|
||
const panelTotalCount = ref(0)
|
||
const panelRemainingCount = ref(0)
|
||
const panelActiveWaybill = ref('')
|
||
/** 面板扫描模式:search=查询, recheck=复核扫描 */
|
||
const panelScanMode = ref<'search' | 'recheck'>('search')
|
||
const panelTaskId = ref<number | string | undefined>(undefined)
|
||
const refreshTaskLoading = ref(false)
|
||
const batchRecheckDialogVisible = ref(false)
|
||
const singleListDialogVisible = ref(false)
|
||
const lastScanParams = ref<RecheckScanOrderParams | null>(null)
|
||
|
||
function handleSingleListLoadRecheck(payload: { keyword: string }) {
|
||
void executeScan({ keyword: payload.keyword })
|
||
}
|
||
|
||
function handleSingleListBatchRecheckSuccess() {
|
||
if (lastScanParams.value) {
|
||
void executeScan(lastScanParams.value)
|
||
}
|
||
}
|
||
|
||
function handlePanelSearch(keyword: string) {
|
||
void executeScan({ keyword })
|
||
}
|
||
|
||
/** 判断订单是否已打印面单(兼容 print_status、is_printed、unprinted_count 字段) */
|
||
function isOrderAlreadyPrinted(order: any): boolean {
|
||
if (!order) return false
|
||
// 团购单:unprinted_count === 0 表示全部已打印
|
||
const unprinted = order.unprinted_count
|
||
if (unprinted !== undefined && unprinted !== null) {
|
||
return Number(unprinted) === 0
|
||
}
|
||
// 优先检查 print_status
|
||
if (String(order.print_status ?? '').trim() === 'fin') return true
|
||
// 其次检查 is_printed 布尔/数字字段
|
||
const printed = order.is_printed
|
||
if (printed === true || printed === 1 || printed === 'true' || printed === '1') return true
|
||
return false
|
||
}
|
||
|
||
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 信息(兼容 wave_id)
|
||
const orderId = Number(order?.id ?? order?.order_id ?? order?.wave_id)
|
||
if (Number.isFinite(orderId) && orderId > 0) {
|
||
selectedOrderId.value = orderId
|
||
}
|
||
// 清除旧订单的扫描状态
|
||
const prevOrder = selectedOrderRow.value as any
|
||
if (prevOrder?.stock) {
|
||
for (const s of prevOrder.stock) {
|
||
delete s._scanned_qty
|
||
}
|
||
}
|
||
selectedOrderRow.value = order as Record<string, unknown>
|
||
// 保留原始 scanPayload 中的波次级字段(拣货人、货主、篮号等),只更新订单级字段
|
||
const matchType = isWave ? 'wave' : 'waybill'
|
||
scanPayload.value = {
|
||
...scanPayload.value,
|
||
match_type: matchType,
|
||
order: order as Record<string, unknown>,
|
||
waybill_no: waybill,
|
||
order_id: orderId
|
||
}
|
||
if (isIntercept) {
|
||
scanHint.value = '该订单已拦截,仅查看详情。'
|
||
} else if (isReviewed) {
|
||
scanHint.value = isWave ? '该波次已复核,仅查看详情。' : '该订单已复核,仅查看详情。'
|
||
} else {
|
||
scanHint.value = isWave ? '已选择波次,扫描商品条码进行复核。' : '已选择订单,扫描商品条码进行复核。'
|
||
}
|
||
scanHintType.value = 'info'
|
||
activeTab.value = 'order'
|
||
|
||
// 先打印后复核模式(默认):散单/团购波次未打印时自动拉取打印数据并发送
|
||
const isPrintFirst = !recheckWorkflowMode.value || recheckWorkflowMode.value === 'print_first'
|
||
if (isPrintFirst && !isReviewed && !isIntercept && Number.isFinite(orderId) && orderId > 0) {
|
||
const alreadyPrinted = isOrderAlreadyPrinted(order as any)
|
||
if (!alreadyPrinted) {
|
||
const waveIds = isWave ? ((order as any)?.order_ids as Array<number | string> | undefined) : undefined
|
||
await autoPrintForOrder(orderId, waveIds)
|
||
}
|
||
}
|
||
}
|
||
|
||
/** 播放提示音:type=success(短促高音), warning(低沉长音) */
|
||
function playBeep(type: 'success' | 'warning' | 'complete') {
|
||
try {
|
||
const ctx = new (window.AudioContext || (window as any).webkitAudioContext)()
|
||
const osc = ctx.createOscillator()
|
||
const gain = ctx.createGain()
|
||
osc.connect(gain)
|
||
gain.connect(ctx.destination)
|
||
if (type === 'complete') {
|
||
// 数据一致提示:双音
|
||
osc.frequency.value = 800
|
||
gain.gain.value = 0.3
|
||
osc.start()
|
||
osc.stop(ctx.currentTime + 0.08)
|
||
// 第二个音
|
||
const osc2 = ctx.createOscillator()
|
||
const gain2 = ctx.createGain()
|
||
osc2.connect(gain2)
|
||
gain2.connect(ctx.destination)
|
||
osc2.frequency.value = 1200
|
||
gain2.gain.value = 0.3
|
||
osc2.start(ctx.currentTime + 0.1)
|
||
osc2.stop(ctx.currentTime + 0.25)
|
||
} else if (type === 'success') {
|
||
osc.frequency.value = 1200
|
||
gain.gain.value = 0.3
|
||
osc.start()
|
||
osc.stop(ctx.currentTime + 0.1)
|
||
} else {
|
||
osc.frequency.value = 300
|
||
gain.gain.value = 0.4
|
||
osc.start()
|
||
osc.stop(ctx.currentTime + 0.3)
|
||
}
|
||
} catch {
|
||
// 浏览器不支持 AudioContext 时静默忽略
|
||
}
|
||
}
|
||
|
||
/** 在 itemsRows 中按 barcodes 数组精确匹配条码 */
|
||
function findItemIndexByBarcode(items: any[], code: string): number {
|
||
return items.findIndex((item: any) => {
|
||
const barcodes = item.barcodes || (item.barcode ? [item.barcode] : [])
|
||
return barcodes.some((bc: string) => bc === code)
|
||
})
|
||
}
|
||
|
||
/** 在 stock 中按 barcodes 数组精确匹配 */
|
||
function findStockIndexByBarcode(stock: any[], code: string): number {
|
||
return stock.findIndex((s: any) => {
|
||
const barcodes = s.barcodes || (s.barcode ? [s.barcode] : [])
|
||
return barcodes.some((bc: string) => String(bc).trim() === code)
|
||
})
|
||
}
|
||
|
||
/** 执行条码扫描计数 */
|
||
function doScanCount(stockIndex: number, addQty: number) {
|
||
const selectedOrder = selectedOrderRow.value as any
|
||
if (!selectedOrder?.stock) return
|
||
if (!selectedOrder.stock[stockIndex]._scanned_qty) {
|
||
selectedOrder.stock[stockIndex]._scanned_qty = 0
|
||
}
|
||
selectedOrder.stock[stockIndex]._scanned_qty += addQty
|
||
selectedOrderRow.value = { ...selectedOrder }
|
||
}
|
||
|
||
/** 复核扫描:匹配条码并增加已扫数量 */
|
||
function handleScanBarcode(barcode: string, qty: number) {
|
||
const code = barcode.trim()
|
||
if (!code) return
|
||
const addQty = Math.max(1, Math.floor(qty))
|
||
|
||
const items = itemsRows.value
|
||
const index = findItemIndexByBarcode(items, code)
|
||
if (index === -1) {
|
||
playBeep('warning')
|
||
ElMessage.warning(`未匹配到条码「${code}」`)
|
||
return
|
||
}
|
||
|
||
const item = items[index] as any
|
||
const planQty = Number(item.plan_qty)
|
||
const scannedQty = Number(item.scanned_qty)
|
||
|
||
if (scannedQty >= planQty) {
|
||
playBeep('warning')
|
||
ElMessage.warning(`商品「${item.name}」已扫完(${scannedQty}/${planQty}),超出 ${addQty} 件`)
|
||
return
|
||
}
|
||
|
||
const actualAdd = Math.min(addQty, planQty - scannedQty)
|
||
const exceeded = addQty > actualAdd
|
||
|
||
const selectedOrder = selectedOrderRow.value as any
|
||
const stockIndex = findStockIndexByBarcode(selectedOrder?.stock || [], code)
|
||
|
||
// 共享条码:需要二次确认
|
||
if (item.has_shared_barcode && stockIndex !== -1) {
|
||
const stockItem = selectedOrder.stock[stockIndex]
|
||
ElMessageBox.confirm(
|
||
h('div', { style: 'line-height:1.8' }, [
|
||
h('p', { style: 'font-weight:600;margin-bottom:8px' }, `扫描条码「${code}」在仓库内与其他商品共享,请确认是否为本商品:`),
|
||
h('div', { style: 'display:flex;gap:12px;align-items:center;margin-bottom:8px' },
|
||
item.images?.length
|
||
? [h('img', { src: item.images[0], style: 'width:60px;height:60px;border-radius:4px;object-fit:cover' })]
|
||
: []
|
||
),
|
||
h('p', {}, `商品:${item.name}`),
|
||
h('p', {}, `规格:${item.spec || '—'}`),
|
||
h('p', {}, `计划数量:${planQty},已扫:${scannedQty}`)
|
||
]),
|
||
'条码核对确认',
|
||
{
|
||
confirmButtonText: '确认计入',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
closeOnClickModal: false,
|
||
closeOnPressEscape: false
|
||
}
|
||
).then(() => {
|
||
doScanCount(stockIndex, actualAdd)
|
||
finishScanFeedback(exceeded, addQty, actualAdd, scannedQty, planQty, item.name)
|
||
}).catch(() => {
|
||
// 用户取消,不计入
|
||
})
|
||
return
|
||
}
|
||
|
||
// 普通条码:直接计数
|
||
if (stockIndex !== -1) {
|
||
doScanCount(stockIndex, actualAdd)
|
||
}
|
||
finishScanFeedback(exceeded, addQty, actualAdd, scannedQty, planQty, item.name)
|
||
}
|
||
|
||
function finishScanFeedback(exceeded: boolean, addQty: number, actualAdd: number, scannedQty: number, planQty: number, name: string) {
|
||
if (exceeded) {
|
||
playBeep('warning')
|
||
ElMessage.warning(`商品「${name}」超出 ${addQty - actualAdd} 件(已扫 ${scannedQty + actualAdd}/${planQty})`)
|
||
}
|
||
const allScanned = itemsRows.value.every((it: any) => Number(it.scanned_qty) >= Number(it.plan_qty))
|
||
if (allScanned) {
|
||
playBeep('complete')
|
||
ElMessage.success('全部商品已扫描完成,可点击「确认复核」')
|
||
} else if (!exceeded) {
|
||
playBeep('success')
|
||
ElMessage.success(`已扫描 ${scannedCount.value}/${itemsTotalCount.value} 件`)
|
||
}
|
||
}
|
||
|
||
const scanLoading = ref(false)
|
||
const confirmLoading = ref(false)
|
||
const scanPayload = ref<ScanOrderResultShape | null>(null)
|
||
const scanHint = ref('')
|
||
const scanHintType = ref<'info' | 'success' | 'warning'>('info')
|
||
const selectedOrderId = ref<number | null>(null)
|
||
const selectedOrderRow = ref<Record<string, unknown> | null>(null)
|
||
|
||
const showDetailPane = computed(() => scanPayload.value != null && activeOrderId.value != null)
|
||
|
||
function resolvePanelOrderId(order: any): number | null {
|
||
if (order?._is_wave) return null
|
||
const raw = order?.order_id ?? order?.id
|
||
const n = Number(raw)
|
||
return Number.isFinite(n) && n > 0 ? n : null
|
||
}
|
||
|
||
const batchRecheckSuggestedIds = computed(() => {
|
||
const ids: number[] = []
|
||
const seen = new Set<number>()
|
||
for (const o of panelOrders.value) {
|
||
const id = resolvePanelOrderId(o)
|
||
if (id == null) continue
|
||
const status = String(o.recheck_status ?? o.is_reviewed ?? '').trim()
|
||
if (status === 'fin' || status === 'true') continue
|
||
if (!seen.has(id)) {
|
||
seen.add(id)
|
||
ids.push(id)
|
||
}
|
||
}
|
||
return ids
|
||
})
|
||
|
||
const waybillSummaryRows = computed(() => (scanPayload.value ? [{}] : []))
|
||
|
||
function clearScanResult() {
|
||
scanPayload.value = null
|
||
scanHint.value = ''
|
||
scanHintType.value = 'info'
|
||
selectedOrderId.value = null
|
||
selectedOrderRow.value = null
|
||
activeTab.value = 'order'
|
||
}
|
||
|
||
function resetAll() {
|
||
clearScanResult()
|
||
panelOrders.value = []
|
||
panelTotalCount.value = 0
|
||
panelRemainingCount.value = 0
|
||
panelActiveWaybill.value = ''
|
||
panelScanMode.value = 'search'
|
||
lastPrintWaveGroups.value = null
|
||
lastPrintOrderId.value = null
|
||
panelTaskId.value = undefined
|
||
recheckPanelRef.value?.resetLocalState?.()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
clearScanResult()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
clearScanResult()
|
||
}
|
||
|
||
function pickScanFieldValue(raw: unknown): string {
|
||
if (raw == null) return ''
|
||
if (typeof raw === 'object' && !Array.isArray(raw) && 'value' in (raw as object)) {
|
||
const v = (raw as Record<string, unknown>).value
|
||
return v != null && String(v).trim() !== '' ? String(v).trim() : ''
|
||
}
|
||
return String(raw).trim()
|
||
}
|
||
|
||
/** 从 ScanBox 条件对象解析 scanOrder 入参(与 API pickScanOrderBody 字段优先级一致) */
|
||
function buildScanParamsFromCondition(condition: unknown): RecheckScanOrderParams | null {
|
||
if (!condition || typeof condition !== 'object') return null
|
||
const c = condition as Record<string, unknown>
|
||
const flat: Record<string, string> = {}
|
||
|
||
const merge = (src: Record<string, unknown>) => {
|
||
for (const [k, v] of Object.entries(src)) {
|
||
if (k === 'type' || k === 'preset') continue
|
||
const val = pickScanFieldValue(v)
|
||
if (val) flat[k] = val
|
||
}
|
||
}
|
||
|
||
if (c.conditions && typeof c.conditions === 'object') {
|
||
merge(c.conditions as Record<string, unknown>)
|
||
} else {
|
||
merge(c)
|
||
}
|
||
|
||
for (const key of SCAN_PARAM_KEYS) {
|
||
const v = flat[key]
|
||
if (v) return { [key]: v }
|
||
}
|
||
return null
|
||
}
|
||
|
||
async function handleScanSubmit(condition?: unknown) {
|
||
const params =
|
||
buildScanParamsFromCondition(condition) ??
|
||
buildScanParamsFromCondition(scanBox.value?.getConditions?.())
|
||
if (!params) {
|
||
ElMessage.warning('请在左侧筛选栏输入运单号、车号或扫描关键词')
|
||
return
|
||
}
|
||
await executeScan(params)
|
||
}
|
||
|
||
function unwrapResponse(res: unknown): ScanOrderResultShape {
|
||
return unwrapScanOrderResponse(res)
|
||
}
|
||
|
||
function asRecord(v: unknown): Record<string, unknown> | null {
|
||
if (v && typeof v === 'object' && !Array.isArray(v)) return v as Record<string, unknown>
|
||
return null
|
||
}
|
||
|
||
function asArray(v: unknown): unknown[] {
|
||
return Array.isArray(v) ? v : []
|
||
}
|
||
|
||
const isCartMatch = computed(() => scanPayload.value?.match_type === 'cart')
|
||
|
||
const cartMatchView = computed(() => asRecord(scanPayload.value?.cart_match_view))
|
||
|
||
const cartViewKind = computed(() => {
|
||
const vt = cartMatchView.value?.view_type
|
||
if (vt === 'groups' || vt === 'orders' || vt === 'pick_groups' || vt === 'box_groups') return vt
|
||
const code = Number(cartMatchView.value?.mode_code)
|
||
if (code === 2) return 'orders'
|
||
if (code === 3) return 'pick_groups'
|
||
if (code === 4) return 'box_groups'
|
||
if (code === 1 || code === 5) return 'groups'
|
||
return ''
|
||
})
|
||
|
||
const cartViewTypeLabel = computed(() => {
|
||
const map: Record<string, string> = {
|
||
groups: '波次分组',
|
||
orders: '订单列表',
|
||
pick_groups: '拣货状态分组',
|
||
box_groups: '箱号分组'
|
||
}
|
||
return cartViewKind.value ? (map[cartViewKind.value] ?? cartViewKind.value) : ''
|
||
})
|
||
|
||
const cartModeName = computed(() => {
|
||
const v = cartMatchView.value?.mode_name
|
||
return v != null && String(v) !== '' ? String(v) : ''
|
||
})
|
||
|
||
const cartGroups = computed(() =>
|
||
asArray(cartMatchView.value?.groups).map(asRecord).filter(Boolean) as Record<string, unknown>[]
|
||
)
|
||
|
||
const cartPickGroups = computed(() =>
|
||
asArray(cartMatchView.value?.pick_groups).map(asRecord).filter(Boolean) as Record<string, unknown>[]
|
||
)
|
||
|
||
const cartBoxGroups = computed(() =>
|
||
asArray(cartMatchView.value?.box_groups).map(asRecord).filter(Boolean) as Record<string, unknown>[]
|
||
)
|
||
|
||
function groupOrders(grp: Record<string, unknown>): Record<string, unknown>[] {
|
||
return asArray(grp.orders).map(asRecord).filter(Boolean) as Record<string, unknown>[]
|
||
}
|
||
|
||
function flattenOrdersFromGroups(groups: Record<string, unknown>[]): Record<string, unknown>[] {
|
||
const out: Record<string, unknown>[] = []
|
||
for (const g of groups) out.push(...groupOrders(g))
|
||
return out
|
||
}
|
||
|
||
const cartSelectableOrders = computed(() => {
|
||
const view = cartMatchView.value
|
||
if (!view) return []
|
||
const kind = cartViewKind.value
|
||
if (kind === 'orders') {
|
||
return asArray(view.orders).map(asRecord).filter(Boolean) as Record<string, unknown>[]
|
||
}
|
||
if (kind === 'groups') return flattenOrdersFromGroups(cartGroups.value)
|
||
if (kind === 'pick_groups') return flattenOrdersFromGroups(cartPickGroups.value)
|
||
if (kind === 'box_groups') return flattenOrdersFromGroups(cartBoxGroups.value)
|
||
return []
|
||
})
|
||
|
||
const cartTaskRows = computed(() => {
|
||
const task = asRecord(cartMatchView.value?.task)
|
||
if (!task) return []
|
||
const pick = (keys: string[], label: string) => {
|
||
for (const k of keys) {
|
||
const v = task[k]
|
||
if (v !== undefined && v !== null && String(v) !== '') return { label, value: String(v) }
|
||
}
|
||
return null
|
||
}
|
||
return [
|
||
pick(['cart_code', 'current_cart_code_snapshot', 'cartCode'], '车号'),
|
||
pick(['wave_no', 'waveNo', 'batch_no'], '波次/批次'),
|
||
pick(['task_id', 'id', 'pick_task_id'], '拣货任务ID'),
|
||
pick(['pick_status', 'status'], '拣货状态')
|
||
].filter(Boolean) as { label: string; value: string }[]
|
||
})
|
||
|
||
function orderRowId(row: Record<string, unknown>): number | undefined {
|
||
const raw = row.id ?? row.order_id ?? row.orderId
|
||
if (raw == null || raw === '') return undefined
|
||
const n = Number(raw)
|
||
return Number.isFinite(n) ? n : undefined
|
||
}
|
||
|
||
function orderRowSn(row: Record<string, unknown>): string {
|
||
const v = row.order_sn ?? row.orderSn ?? row.order_no ?? row.tid
|
||
return v != null && String(v) !== '' ? String(v) : '—'
|
||
}
|
||
|
||
function orderRowWaybill(row: Record<string, unknown>): string {
|
||
const v = row.waybill_no ?? row.waybillNo ?? row.express_no
|
||
return v != null && String(v) !== '' ? String(v) : '—'
|
||
}
|
||
|
||
function groupTitle(grp: Record<string, unknown>, index: number): string {
|
||
const wave = grp.wave_no ?? grp.waveNo ?? grp.wave_id ?? grp.group_name
|
||
return wave != null ? `波次 ${wave}` : `分组 ${index + 1}`
|
||
}
|
||
|
||
function pickGroupTitle(grp: Record<string, unknown>): string {
|
||
const s = grp.pick_status ?? grp.status ?? grp.label ?? grp.name
|
||
return s != null ? `拣货状态 ${s}` : '拣货分组'
|
||
}
|
||
|
||
function boxGroupTitle(grp: Record<string, unknown>): string {
|
||
const b = grp.box_no ?? grp.boxNo ?? grp.box_code
|
||
return b != null ? `箱号 ${b}` : '箱分组'
|
||
}
|
||
|
||
function onCartOrderSelect(row: Record<string, unknown> | null | undefined) {
|
||
if (!row) return
|
||
const id = orderRowId(row)
|
||
if (id == null) {
|
||
ElMessage.warning('该订单行缺少有效订单 ID')
|
||
return
|
||
}
|
||
selectedOrderId.value = id
|
||
selectedOrderRow.value = row
|
||
scanHint.value = `已选择订单 ID ${id},核对后点击「确认复核」。`
|
||
scanHintType.value = 'info'
|
||
}
|
||
|
||
function resolveTopOrderId(p: ScanOrderResultShape | null): number | undefined {
|
||
if (!p) return undefined
|
||
const top = p.order_id
|
||
if (top != null && String(top).trim() !== '') {
|
||
const n = Number(top)
|
||
if (Number.isFinite(n)) return n
|
||
}
|
||
const order = asRecord(p.order)
|
||
if (order) {
|
||
const oid = order.id ?? order.order_id
|
||
if (oid != null && oid !== '') {
|
||
const n = Number(oid)
|
||
if (Number.isFinite(n)) return n
|
||
}
|
||
}
|
||
return undefined
|
||
}
|
||
|
||
/** 从 scanOrder 响应提取 RecheckOrderPanel 所需数据 */
|
||
function updatePanelFromPayload(payload: ScanOrderResultShape) {
|
||
const tid = payload.task_id
|
||
panelTaskId.value = tid != null ? tid : undefined
|
||
|
||
const rawList = asArray(payload.list)
|
||
const listType = String(payload.list_type ?? '').trim()
|
||
|
||
if (rawList.length && listType === 'group') {
|
||
const waves = rawList.map((w) => normalizeScanOrderGroupWaveRow(w))
|
||
panelOrders.value = waves
|
||
panelTotalCount.value =
|
||
payload.total_orders ?? waves.reduce((sum, w) => sum + (Number(w.order_count) || 0), 0)
|
||
panelRemainingCount.value =
|
||
payload.unreviewed_count ??
|
||
waves.filter((w) => !isOrderRecheckFinished(w)).length
|
||
panelActiveWaybill.value = ''
|
||
return
|
||
}
|
||
|
||
if (rawList.length) {
|
||
const orders = rawList.map((o) => normalizeScanOrderPanelRow(o))
|
||
panelOrders.value = orders
|
||
panelTotalCount.value = payload.total_orders ?? orders.length
|
||
panelRemainingCount.value =
|
||
payload.unreviewed_count ?? orders.filter((o) => !isOrderRecheckFinished(o)).length
|
||
panelActiveWaybill.value = ''
|
||
return
|
||
}
|
||
|
||
if (payload.match_type === 'cart') {
|
||
const orders = cartSelectableOrders.value.map((o) => normalizeScanOrderPanelRow(o))
|
||
panelOrders.value = orders
|
||
panelTotalCount.value = orders.length
|
||
panelRemainingCount.value = orders.filter((o) => !isOrderRecheckFinished(o)).length
|
||
if (panelRemainingCount.value === 1) {
|
||
const unreviewed = orders.find((o) => !isOrderRecheckFinished(o))
|
||
if (unreviewed) {
|
||
panelActiveWaybill.value = String(unreviewed.waybill_no ?? '').trim()
|
||
}
|
||
}
|
||
return
|
||
}
|
||
|
||
if (payload.match_type === 'waybill') {
|
||
const order = normalizeScanOrderPanelRow(asRecord(payload.order) || {})
|
||
const waybill = String(payload.waybill_no || order.waybill_no || '').trim()
|
||
panelOrders.value = [
|
||
{
|
||
...order,
|
||
waybill_no: waybill,
|
||
waybillCode: waybill,
|
||
waybill_code: waybill
|
||
}
|
||
]
|
||
panelTotalCount.value = 1
|
||
panelRemainingCount.value = isOrderRecheckFinished(order) ? 0 : 1
|
||
panelActiveWaybill.value = waybill
|
||
return
|
||
}
|
||
|
||
panelOrders.value = []
|
||
panelTotalCount.value = 0
|
||
panelRemainingCount.value = 0
|
||
panelActiveWaybill.value = ''
|
||
}
|
||
|
||
const activeOrderId = computed(() => selectedOrderId.value ?? resolveTopOrderId(scanPayload.value))
|
||
|
||
const displayOrder = computed(() => {
|
||
if (selectedOrderRow.value) return selectedOrderRow.value
|
||
return asRecord(scanPayload.value?.order)
|
||
})
|
||
|
||
const matchTypeLabel = computed(() => {
|
||
const t = scanPayload.value?.match_type
|
||
if (t === 'waybill') return '运单命中'
|
||
if (t === 'wave') return '波次命中'
|
||
if (t === 'cart') return '车号命中'
|
||
if (t === 'task') return '任务命中'
|
||
if (t != null && String(t) !== '') return String(t)
|
||
return ''
|
||
})
|
||
|
||
const matchTypeTagType = computed(() => {
|
||
const t = scanPayload.value?.match_type
|
||
if (t === 'cart') return 'warning'
|
||
if (t === 'waybill') return 'success'
|
||
if (t === 'wave') return 'primary'
|
||
return 'info'
|
||
})
|
||
|
||
const displayWaybill = computed(() => {
|
||
const row = selectedOrderRow.value
|
||
if (row) return orderRowWaybill(row)
|
||
const w = scanPayload.value?.waybill_no
|
||
return w != null && String(w) !== '' ? String(w) : '—'
|
||
})
|
||
|
||
/** 散单/波次命中时的列表与波次信息 */
|
||
const scanPayloadList = computed(() => asArray((scanPayload.value as any)?.list))
|
||
const scanPayloadWaveNo = computed(() => String((scanPayload.value as any)?.wave_no ?? '').trim() || '—')
|
||
const scanPayloadTotalOrders = computed(() => (scanPayload.value as any)?.total_orders ?? scanPayloadList.value.length)
|
||
const scanPayloadUnreviewedCount = computed(() => (scanPayload.value as any)?.unreviewed_count ?? 0)
|
||
const scanPayloadPickerName = computed(() => String((scanPayload.value as any)?.picker_name ?? '').trim() || '—')
|
||
const scanPayloadStoreRemark = computed(() => {
|
||
const order = selectedOrderRow.value as any
|
||
const val = (scanPayload.value as any)?.store_remark ?? order?.store_remark
|
||
return val != null && String(val).trim() !== '' ? String(val).trim() : ''
|
||
})
|
||
const scanPayloadWaveIndex = computed(() => {
|
||
const order = selectedOrderRow.value as any
|
||
const val = (scanPayload.value as any)?.wave_index ?? order?.wave_index
|
||
return val != null && String(val).trim() !== '' ? String(val).trim() : ''
|
||
})
|
||
|
||
/** 所有商品是否已扫完 */
|
||
const allItemsScanned = computed(() => {
|
||
if (!itemsRows.value.length) return false
|
||
return itemsRows.value.every((item: any) => {
|
||
const scanned = Number(item.scanned_qty)
|
||
const plan = Number(item.plan_qty)
|
||
return Number.isFinite(scanned) && Number.isFinite(plan) && scanned >= plan
|
||
})
|
||
})
|
||
|
||
/** 团购波次且所有商品一致(同款同码) */
|
||
const isAllSameProductInWave = computed(() => {
|
||
const order = selectedOrderRow.value as any
|
||
if (!order?._is_wave) return false
|
||
const stock = order?.stock || order?.stocks
|
||
if (!Array.isArray(stock) || stock.length <= 1) return false
|
||
const firstCode = String(stock[0]?.item_code || stock[0]?.barcode || '').trim()
|
||
if (!firstCode) return false
|
||
return stock.every((s: any) => String(s.item_code || s.barcode || '').trim() === firstCode)
|
||
})
|
||
|
||
/** 选中订单是否设置了拦截 */
|
||
const hasSelectedIntercept = computed(() => {
|
||
const order = selectedOrderRow.value as any
|
||
if (!order) return false
|
||
return String(order?.intercept_status ?? 'none').trim() !== 'none'
|
||
})
|
||
|
||
async function handleConfirmIntercept() {
|
||
const id = activeOrderId.value
|
||
if (id == null) return
|
||
try {
|
||
await ElMessageBox.confirm(`确认对订单 ID ${id} 执行拦截操作?`, '确认拦截', {
|
||
type: 'warning'
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
try {
|
||
const res = await confirmIntercept({ order_id: id })
|
||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||
if (ok) {
|
||
ElMessage.success('拦截操作已提交')
|
||
// 更新列表中该订单的拦截状态
|
||
panelOrders.value = panelOrders.value.map((o: any) => {
|
||
if (Number(o?.order_id) === id) {
|
||
return { ...o, intercept_status: 'intercepted_at_warehouse' }
|
||
}
|
||
return o
|
||
})
|
||
// 同步更新 selectedOrderRow
|
||
const curRow = selectedOrderRow.value as any
|
||
if (curRow && Number(curRow?.order_id) === id) {
|
||
selectedOrderRow.value = { ...curRow, intercept_status: 'intercepted_at_warehouse' }
|
||
}
|
||
} else {
|
||
ElMessage.error(res?.message || '拦截操作失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('拦截操作失败')
|
||
}
|
||
}
|
||
|
||
const canConfirm = computed(() => activeOrderId.value != null && !scanLoading.value && allItemsScanned.value && !hasSelectedIntercept.value)
|
||
|
||
// ─── 自动打印(散单复核流程)──────────────────────────────────────────────────
|
||
const autoPrintingRef = ref(false)
|
||
const reprintLoading = ref(false)
|
||
const lastPrintWaveGroups = ref<unknown[] | null>(null)
|
||
const lastPrintOrderId = ref<number | null>(null)
|
||
|
||
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('未选择打印台,无法自动打印')
|
||
return
|
||
}
|
||
autoPrintingRef.value = true
|
||
try {
|
||
// 团购波次:使用波次内的实际订单 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 || '获取打印数据失败')
|
||
}
|
||
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
|
||
}
|
||
// 缓存 waveGroups,供面单补打使用
|
||
lastPrintWaveGroups.value = waveGroups
|
||
lastPrintOrderId.value = orderId
|
||
const warehouseId = Number(userStore.user?.warehouse_id ?? userStore.user?.store_id ?? 0)
|
||
const requestCode = `recheck-print-${warehouseId}-${orderId}-${Date.now()}`
|
||
const printRes: any = await stationApi.sendPrint({
|
||
type: 'express',
|
||
printStationId: stationId,
|
||
requestCode,
|
||
data: { waveGroups }
|
||
})
|
||
const ok = printRes && (printRes.code === 1 || printRes.code === 200 || printRes.flag === 'success')
|
||
if (ok) {
|
||
ElMessage.success(printRes?.message || '打印任务已发送至打印台')
|
||
} else {
|
||
ElMessage.error(printRes?.message || '发送打印任务失败')
|
||
}
|
||
} catch (error: any) {
|
||
ElMessage.error(error?.message || '自动打印失败')
|
||
} finally {
|
||
autoPrintingRef.value = false
|
||
}
|
||
}
|
||
|
||
async function handleReprint() {
|
||
const currentId = activeOrderId.value
|
||
if (currentId == null || currentId <= 0) {
|
||
ElMessage.warning('未选中订单')
|
||
return
|
||
}
|
||
const stationId = recheckPrintStationId.value
|
||
if (!stationId) {
|
||
ElMessage.warning('未选择打印台,无法补打')
|
||
return
|
||
}
|
||
if (reprintLoading.value) return
|
||
reprintLoading.value = true
|
||
try {
|
||
// 始终按当前选中订单拉取打印数据,不使用缓存
|
||
const selectedRow = selectedOrderRow.value as any
|
||
const waveIds = selectedRow?._is_wave ? (selectedRow?.order_ids as Array<number | string> | undefined) : undefined
|
||
const queryIds = (waveIds && waveIds.length) ? waveIds : [currentId]
|
||
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 = unwrapWavePlatformPrintPayload(res)
|
||
let waveGroups: unknown[] | null | undefined = payload.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
|
||
}
|
||
const warehouseId = Number(userStore.user?.warehouse_id ?? userStore.user?.store_id ?? 0)
|
||
const requestCode = `recheck-reprint-${warehouseId}-${currentId}-${Date.now()}`
|
||
const printRes: any = await stationApi.sendPrint({
|
||
type: 'express',
|
||
printStationId: stationId,
|
||
requestCode,
|
||
data: { waveGroups }
|
||
})
|
||
const ok = printRes && (printRes.code === 1 || printRes.code === 200 || printRes.flag === 'success')
|
||
if (ok) {
|
||
ElMessage.success(printRes?.message || '面单补打已发送至打印台')
|
||
} else {
|
||
ElMessage.error(printRes?.message || '面单补打发送失败')
|
||
}
|
||
} catch (error: any) {
|
||
ElMessage.error(error?.message || '面单补打失败')
|
||
} finally {
|
||
reprintLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleRefreshTask(taskId: number) {
|
||
if (refreshTaskLoading.value) return
|
||
refreshTaskLoading.value = true
|
||
try {
|
||
const res = await scanTask({ task_id: taskId })
|
||
const payload = unwrapResponse(res) as ScanOrderResultShape
|
||
// 用 scanTask 返回的数据更新面板
|
||
updatePanelFromPayload(payload)
|
||
// 如果只返回一个未复核订单,自动选中
|
||
const rawList = asArray((payload as any).list)
|
||
if (rawList.length === 1) {
|
||
const unreviewed = rawList.find((o: any) => {
|
||
const status = String(o.recheck_status ?? o.is_reviewed ?? '').trim()
|
||
return status !== 'fin' && status !== 'true'
|
||
})
|
||
if (unreviewed) {
|
||
handlePanelSelect(unreviewed)
|
||
}
|
||
}
|
||
// 更新 scanPayload(保留原始的 order 信息)
|
||
if (payload.order_id != null || payload.order != null) {
|
||
scanPayload.value = {
|
||
...scanPayload.value,
|
||
...(payload as any),
|
||
} as any
|
||
}
|
||
ElMessage.success(res?.message || '任务数据已刷新')
|
||
} catch (error: any) {
|
||
ElMessage.error(error?.message || '刷新任务数据失败')
|
||
} finally {
|
||
refreshTaskLoading.value = false
|
||
}
|
||
}
|
||
|
||
const orderHeadRows = computed(() => {
|
||
const o = displayOrder.value
|
||
if (!o) return []
|
||
const pick = (keys: string[], label: string) => {
|
||
for (const k of keys) {
|
||
const v = o[k]
|
||
if (v !== undefined && v !== null && String(v) !== '') return { label, value: String(v) }
|
||
}
|
||
return null
|
||
}
|
||
return [
|
||
pick(['order_sn', 'orderSn', 'order_no', 'tid', 'delivery_order_code'], '订单号'),
|
||
pick(['buyer_nick', 'buyerNick', 'receiver_name', 'name'], '买家/收件人'),
|
||
pick(['receiver_mobile', 'mobile', 'phone'], '手机'),
|
||
pick(['warehouse_name', 'store_name', 'shop_nick'], '仓库/店铺'),
|
||
pick(['sys_platform_name', 'source_platform_name'], '平台'),
|
||
pick(['logistics_name', 'sys_logistics_name'], '物流')
|
||
].filter(Boolean) as { label: string; value: string }[]
|
||
})
|
||
|
||
function normalizeItemRow(raw: unknown): { scanned_qty: number; plan_qty: string; name: string; barcode: string; spec: string; packing_requirements: string } {
|
||
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
||
return { scanned_qty: 0, plan_qty: '—', name: '—', barcode: '—', spec: '', packing_requirements: '' }
|
||
}
|
||
const r = raw as Record<string, unknown>
|
||
return {
|
||
scanned_qty: 0,
|
||
plan_qty: String(r.qty ?? r.quantity ?? r.num ?? r.plan_qty ?? '—'),
|
||
name: String(r.name ?? r.title ?? r.product_name ?? r.goods_name ?? '—').trim(),
|
||
barcode: String(r.barcode ?? r.sku ?? r.item_code ?? '—').trim(),
|
||
spec: String(r.sku_property ?? r.spec ?? '').trim(),
|
||
packing_requirements: String(r.packing_requirements ?? '').trim()
|
||
}
|
||
}
|
||
|
||
const itemsRows = computed(() => {
|
||
const selectedOrder = selectedOrderRow.value as Record<string, unknown> | null
|
||
let stockRaw = selectedOrder?.stock
|
||
if (!Array.isArray(stockRaw) || !stockRaw.length) {
|
||
stockRaw = selectedOrder?.stocks
|
||
}
|
||
if (Array.isArray(stockRaw) && stockRaw.length) {
|
||
return stockRaw.map((item: any) => ({
|
||
scanned_qty: Number(item._scanned_qty ?? 0),
|
||
plan_qty: String(item.plan_qty ?? '—'),
|
||
name: String(item.item_name || '—').trim(),
|
||
barcode: String((item.barcodes?.[0] || item.barcode || item.item_code || '—')).trim(),
|
||
barcodes: Array.isArray(item.barcodes) ? item.barcodes.map((b: any) => String(b).trim()).filter(Boolean) : [],
|
||
has_shared_barcode: !!item.has_shared_barcode,
|
||
spec: String(item.sku_property || '').trim(),
|
||
packing_requirements: String(item.packing_requirements || '').trim(),
|
||
images: Array.isArray(item.images) ? item.images.filter(Boolean) : []
|
||
}))
|
||
}
|
||
|
||
const detailItems = selectedOrder?.items
|
||
const payloadItems = scanPayload.value?.items
|
||
const items = Array.isArray(detailItems) ? detailItems : Array.isArray(payloadItems) ? payloadItems : null
|
||
if (Array.isArray(items)) {
|
||
return items.map(normalizeItemRow)
|
||
}
|
||
return []
|
||
})
|
||
|
||
const scannedCount = computed(() => {
|
||
return itemsRows.value.reduce((sum, item) => {
|
||
const qty = Number(item.scanned_qty)
|
||
return sum + (Number.isFinite(qty) ? qty : 0)
|
||
}, 0)
|
||
})
|
||
|
||
const itemsTotalCount = computed(() => {
|
||
return itemsRows.value.reduce((sum, item) => {
|
||
const qty = Number(item.plan_qty)
|
||
return sum + (Number.isFinite(qty) ? qty : 0)
|
||
}, 0)
|
||
})
|
||
|
||
/** 底部统计行 */
|
||
function itemsSummary(param: { columns: any[]; data: any[] }) {
|
||
const sums: string[] = []
|
||
param.columns.forEach((column: any, index: number) => {
|
||
if (index === 0) {
|
||
sums[index] = '合计'
|
||
return
|
||
}
|
||
const prop = column.property
|
||
if (prop === 'scanned_qty') {
|
||
sums[index] = String(scannedCount.value)
|
||
} else if (prop === 'plan_qty') {
|
||
sums[index] = String(itemsTotalCount.value)
|
||
} else {
|
||
sums[index] = ''
|
||
}
|
||
})
|
||
return sums
|
||
}
|
||
|
||
/** 商品行右键菜单:无条码复核 */
|
||
function handleItemsRowContextMenu(row: any, _column: any, event: MouseEvent) {
|
||
event.preventDefault()
|
||
const item = row as any
|
||
const planQty = Number(item.plan_qty)
|
||
const scannedQty = Number(item.scanned_qty)
|
||
if (scannedQty >= planQty) {
|
||
ElMessage.info('该商品已扫完')
|
||
return
|
||
}
|
||
ElMessageBox.confirm(
|
||
`将商品「${item.name}」标记为已复核(${scannedQty}/${planQty} → ${planQty}/${planQty})?`,
|
||
'无条码复核',
|
||
{
|
||
confirmButtonText: '确认',
|
||
cancelButtonText: '取消',
|
||
type: 'info'
|
||
}
|
||
).then(() => {
|
||
const selectedOrder = selectedOrderRow.value as any
|
||
if (selectedOrder?.stock) {
|
||
const rowBarcode = String(item.barcode || '').trim()
|
||
const idx = findStockIndexByBarcode(selectedOrder.stock, rowBarcode)
|
||
if (idx !== -1) {
|
||
selectedOrder.stock[idx]._scanned_qty = planQty
|
||
selectedOrderRow.value = { ...selectedOrder }
|
||
}
|
||
}
|
||
ElMessage.success(`商品「${item.name}」已标记为复核完成`)
|
||
}).catch(() => {
|
||
// 取消
|
||
})
|
||
}
|
||
|
||
/** 商品行样式:已扫完的行绿色底白色字 */
|
||
function itemsRowClassName({ row }: { row: any }) {
|
||
const scanned = Number(row.scanned_qty)
|
||
const plan = Number(row.plan_qty)
|
||
if (Number.isFinite(scanned) && Number.isFinite(plan) && scanned >= plan && plan > 0) {
|
||
return 'row-scanned-complete'
|
||
}
|
||
return ''
|
||
}
|
||
|
||
const expressRows = computed(() => {
|
||
const selectedOrder = selectedOrderRow.value as Record<string, unknown> | null
|
||
const ex = selectedOrder?.expresses ?? scanPayload.value?.expresses
|
||
if (!Array.isArray(ex)) return []
|
||
return ex.filter((x) => x && typeof x === 'object' && !Array.isArray(x)) as Record<string, unknown>[]
|
||
})
|
||
|
||
const expressColumns = computed(() => {
|
||
const rows = expressRows.value
|
||
if (!rows.length) return []
|
||
const keys = new Set<string>()
|
||
for (const row of rows) Object.keys(row).forEach((k) => keys.add(k))
|
||
return Array.from(keys).slice(0, 12)
|
||
})
|
||
|
||
function normalizeLogRow(raw: unknown): { time: string; operator: string; action: string; message: string } {
|
||
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
||
return { time: '—', operator: '—', action: '—', message: '—' }
|
||
}
|
||
const r = raw as Record<string, unknown>
|
||
return {
|
||
time: String(r.created_at ?? r.create_time ?? r.time ?? '—'),
|
||
operator: String(r.operator_name ?? r.operator ?? r.user_name ?? '—'),
|
||
action: String(r.operation_type ?? r.action ?? r.type ?? '—'),
|
||
message: String(r.message ?? r.content ?? r.remark ?? '—')
|
||
}
|
||
}
|
||
|
||
const logRows = computed(() => {
|
||
const selectedOrder = selectedOrderRow.value as Record<string, unknown> | null
|
||
const logs = selectedOrder?.logs ?? scanPayload.value?.logs
|
||
if (!Array.isArray(logs)) return []
|
||
return logs.map(normalizeLogRow)
|
||
})
|
||
|
||
watch(cartSelectableOrders, (list) => {
|
||
if (!isCartMatch.value || list.length !== 1) return
|
||
const row = list[0]
|
||
if (!row) return
|
||
const id = orderRowId(row)
|
||
if (id != null) {
|
||
selectedOrderId.value = id
|
||
selectedOrderRow.value = row
|
||
}
|
||
})
|
||
|
||
async function handleBatchQuickRecheckSuccess() {
|
||
const taskId = Number(panelTaskId.value)
|
||
if (Number.isFinite(taskId) && taskId > 0) {
|
||
await handleRefreshTask(taskId)
|
||
return
|
||
}
|
||
if (lastScanParams.value) {
|
||
await executeScan(lastScanParams.value)
|
||
}
|
||
}
|
||
|
||
async function executeScan(params: RecheckScanOrderParams) {
|
||
lastScanParams.value = { ...params }
|
||
scanHint.value = ''
|
||
scanHintType.value = 'info'
|
||
selectedOrderId.value = null
|
||
selectedOrderRow.value = null
|
||
activeTab.value = 'order'
|
||
scanLoading.value = true
|
||
try {
|
||
const res = await scanOrder(params)
|
||
const payload = unwrapResponse(res)
|
||
scanPayload.value = payload
|
||
|
||
// ── 更新 RecheckOrderPanel 数据 ──
|
||
updatePanelFromPayload(payload)
|
||
|
||
const rawList = asArray((payload as any).list)
|
||
const topId = resolveTopOrderId(payload)
|
||
|
||
if (rawList.length) {
|
||
// 使用 panelOrders(已规范化)自动选中,避免原始数据字段名差异
|
||
const panelList = panelOrders.value
|
||
const topWaybill = String((payload as any).waybill_no || '').trim()
|
||
const matchedRow = topWaybill
|
||
? panelList.find((r: any) => String(r.waybill_no ?? '').trim() === topWaybill)
|
||
: null
|
||
if (matchedRow) {
|
||
handlePanelSelect(matchedRow)
|
||
} else if (panelList.length === 1) {
|
||
handlePanelSelect(panelList[0])
|
||
} else {
|
||
scanHint.value = `共 ${rawList.length} 个订单,请从左侧列表中选择要复核的订单。`
|
||
scanHintType.value = 'info'
|
||
ElMessage.success(`已加载 ${rawList.length} 个订单`)
|
||
}
|
||
} else if (payload.match_type === 'cart') {
|
||
const list = cartSelectableOrders.value
|
||
if (list.length > 1) {
|
||
scanHint.value = '车号命中:请从列表中选择要复核的订单。'
|
||
scanHintType.value = 'warning'
|
||
ElMessage.success('已加载车号关联订单')
|
||
} else if (topId != null || list.length === 1) {
|
||
if (topId != null && selectedOrderId.value == null) selectedOrderId.value = topId
|
||
scanHint.value = '车号命中,已定位订单,核对后请点击「确认复核」。'
|
||
} else if (topId != null || list.length === 1) {
|
||
if (topId != null && selectedOrderId.value == null) selectedOrderId.value = topId
|
||
scanHint.value = '车号命中,已定位订单,核对后请点击「确认复核」。'
|
||
scanHintType.value = 'info'
|
||
ElMessage.success('已查询到订单')
|
||
} else {
|
||
scanHint.value = '车号命中但未解析到可复核的订单 ID。'
|
||
scanHintType.value = 'warning'
|
||
ElMessage.warning('未解析到订单 ID')
|
||
}
|
||
} else if (topId == null) {
|
||
scanHint.value = '运单已命中但未返回订单 ID,无法确认复核。'
|
||
scanHintType.value = 'warning'
|
||
ElMessage.warning('未解析到订单 ID')
|
||
} else {
|
||
selectedOrderId.value = topId
|
||
scanHint.value = '运单命中,核对订单信息后点击「确认复核」。'
|
||
scanHintType.value = 'info'
|
||
ElMessage.success('已查询到订单')
|
||
}
|
||
} catch {
|
||
scanPayload.value = null
|
||
} finally {
|
||
scanLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleConfirm() {
|
||
const id = activeOrderId.value
|
||
if (id == null) {
|
||
ElMessage.warning(
|
||
isCartMatch.value ? '请先在车号视图中选择要复核的订单' : '请先扫描查询并确保返回有效订单 ID'
|
||
)
|
||
return
|
||
}
|
||
|
||
// 数据一致后称重模式:数据一致后先弹出称重弹窗,称重完成时并发确认复核
|
||
if (recheckWeighingMode.value === 'on' && allItemsScanned.value) {
|
||
weighingBeforeConfirm.value = true
|
||
weighingForm.weight = null
|
||
weighingDialogVisible.value = true
|
||
return
|
||
}
|
||
|
||
// 团购波次且所有商品一致:先弹出称重弹窗,称重完成后再确认复核
|
||
if (isAllSameProductInWave.value) {
|
||
weighingBeforeConfirm.value = true
|
||
weighingForm.weight = null
|
||
weighingDialogVisible.value = true
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(`确认对订单 ID ${id} 提交复核记录?`, '确认复核', {
|
||
type: 'warning'
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
await doConfirm()
|
||
}
|
||
|
||
/** 复核完成后更新面板并跳转下一个未复核订单 */
|
||
async function finishConfirmAndAdvance() {
|
||
const id = activeOrderId.value
|
||
if (id == null) return
|
||
|
||
// 先复核后打印模式:复核成功后先拉取打印数据并发送
|
||
if (recheckWorkflowMode.value === 'recheck_first') {
|
||
const selectedRow = selectedOrderRow.value as any
|
||
const waveIds = selectedRow?._is_wave ? (selectedRow?.order_ids as Array<number | string> | undefined) : undefined
|
||
await autoPrintForOrder(id, waveIds)
|
||
}
|
||
|
||
// 更新面板:将该订单标记为已复核
|
||
const confirmedWaybill = panelActiveWaybill.value
|
||
panelOrders.value = panelOrders.value.map((o: any) => {
|
||
if (String(o.waybill_no ?? '').trim() === confirmedWaybill) {
|
||
return { ...o, recheck_status: 'fin' }
|
||
}
|
||
return o
|
||
})
|
||
panelRemainingCount.value = panelOrders.value.filter((o: any) => {
|
||
const status = String(o.recheck_status ?? '').trim()
|
||
return status !== 'fin'
|
||
}).length
|
||
|
||
// 自动选中下一个未复核订单:先找当前之后的下一个,找不到再从头找第一个
|
||
const confirmedIndex = panelOrders.value.findIndex((o: any) =>
|
||
String(o.waybill_no ?? '').trim() === confirmedWaybill
|
||
)
|
||
let nextUnreviewed: any = null
|
||
if (confirmedIndex >= 0) {
|
||
for (let i = confirmedIndex + 1; i < panelOrders.value.length; i++) {
|
||
const status = String(panelOrders.value[i].recheck_status ?? '').trim()
|
||
if (status !== 'fin') {
|
||
nextUnreviewed = panelOrders.value[i]
|
||
break
|
||
}
|
||
}
|
||
}
|
||
// 当前之后没有未复核的,再从头找第一个未复核的(兜底)
|
||
if (!nextUnreviewed) {
|
||
nextUnreviewed = panelOrders.value.find((o: any) => {
|
||
const status = String(o.recheck_status ?? '').trim()
|
||
return status !== 'fin'
|
||
})
|
||
}
|
||
if (nextUnreviewed) {
|
||
handlePanelSelect(nextUnreviewed)
|
||
} else {
|
||
// 清除当前订单的扫描状态
|
||
const curOrder = selectedOrderRow.value as any
|
||
if (curOrder?.stock) {
|
||
for (const s of curOrder.stock) delete s._scanned_qty
|
||
}
|
||
scanHint.value = '全部订单已复核完成!'
|
||
scanHintType.value = 'success'
|
||
panelActiveWaybill.value = ''
|
||
panelScanMode.value = 'search'
|
||
}
|
||
}
|
||
|
||
/** 执行复核确认(不含用户二次确认弹窗) */
|
||
async function doConfirm() {
|
||
const id = activeOrderId.value
|
||
if (id == null) return
|
||
confirmLoading.value = true
|
||
try {
|
||
// 团购波次:使用 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,
|
||
payload.recheck_status,
|
||
payload.recheck_time
|
||
].filter((x) => x != null && String(x) !== '')
|
||
ElMessage.success(parts.length ? `复核成功:${parts.join(' / ')}` : '复核已记录')
|
||
|
||
await finishConfirmAndAdvance()
|
||
} finally {
|
||
confirmLoading.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(loadRecheckStationOptions)
|
||
|
||
// ─── 称重 ──────────────────────────────────────────────────────────────────
|
||
const weighingDialogVisible = ref(false)
|
||
const weighingSubmitting = ref(false)
|
||
const weighingBeforeConfirm = ref(false)
|
||
const weighingFormRef = ref<FormInstance>()
|
||
const weighingInputRef = ref<any>(null)
|
||
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' }
|
||
]
|
||
}
|
||
|
||
// 数据一致后自动弹出称重窗口
|
||
watch(allItemsScanned, (val) => {
|
||
if (!val) return
|
||
if (recheckWeighingMode.value !== 'on') return
|
||
if (weighingDialogVisible.value) return
|
||
if (hasSelectedIntercept.value) return
|
||
const id = activeOrderId.value
|
||
if (id == null || id <= 0) return
|
||
weighingBeforeConfirm.value = true
|
||
weighingForm.weight = null
|
||
weighingDialogVisible.value = true
|
||
})
|
||
|
||
function resetWeighingForm() {
|
||
weighingForm.weight = null
|
||
weighingFormRef.value?.clearValidate()
|
||
weighingBeforeConfirm.value = false
|
||
}
|
||
|
||
function focusWeighingInput() {
|
||
nextTick(() => {
|
||
weighingInputRef.value?.focus?.()
|
||
})
|
||
}
|
||
|
||
function openWeighingDialog() {
|
||
weighingBeforeConfirm.value = false
|
||
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
|
||
|
||
// 数据一致后称重模式:并发提交确认复核 + 保存重量
|
||
if (weighingBeforeConfirm.value && recheckWeighingMode.value === 'on') {
|
||
const selectedRow = selectedOrderRow.value as any
|
||
const confirmParams: any = { order_id: id }
|
||
if (selectedRow?._is_wave && selectedRow?.wave_id) {
|
||
confirmParams.wave_id = selectedRow.wave_id
|
||
delete confirmParams.order_id
|
||
}
|
||
const weight = Number(weighingForm.weight)
|
||
|
||
const [confirmResult, weighResult] = await Promise.allSettled([
|
||
confirmRecheck(confirmParams),
|
||
orderUpdateExpressWeighingWeight({ order_id: id, weighing_weight: weight })
|
||
])
|
||
|
||
const confirmOk = confirmResult.status === 'fulfilled' && (() => {
|
||
const r: any = confirmResult.value
|
||
return r && (r.code === 1 || r.code === 200 || r.flag === 'success')
|
||
})()
|
||
const weighOk = weighResult.status === 'fulfilled' && isOrderIndexApiSuccess(weighResult.value)
|
||
|
||
if (confirmOk && weighOk) {
|
||
const payload = unwrapResponse(confirmResult.value) as ConfirmRecheckResultShape
|
||
const parts = [
|
||
payload.review_no ?? payload.reviewNo,
|
||
payload.recheck_status,
|
||
payload.recheck_time
|
||
].filter((x) => x != null && String(x) !== '')
|
||
ElMessage.success(parts.length ? `复核成功:${parts.join(' / ')},称重 ${weight} kg` : `复核已记录,称重 ${weight} kg`)
|
||
weighingDialogVisible.value = false
|
||
weighingBeforeConfirm.value = false
|
||
await finishConfirmAndAdvance()
|
||
} else {
|
||
const msgs: string[] = []
|
||
if (!confirmOk) {
|
||
const errMsg = confirmResult.status === 'fulfilled'
|
||
? ((confirmResult.value as any)?.message || '确认复核失败')
|
||
: '确认复核请求失败'
|
||
msgs.push(errMsg)
|
||
}
|
||
if (!weighOk) {
|
||
const errMsg = weighResult.status === 'fulfilled'
|
||
? ((weighResult.value as any)?.message || '称重保存失败')
|
||
: '称重保存请求失败'
|
||
msgs.push(errMsg)
|
||
}
|
||
ElMessage.error(msgs.join(';'))
|
||
}
|
||
weighingSubmitting.value = false
|
||
return
|
||
}
|
||
|
||
// 原有逻辑:仅称重 或 团购同款预称重
|
||
try {
|
||
const res: any = await orderUpdateExpressWeighingWeight({
|
||
order_id: id,
|
||
weighing_weight: Number(weighingForm.weight)
|
||
})
|
||
const ok = isOrderIndexApiSuccess(res)
|
||
if (ok) {
|
||
ElMessage.success(res?.message || '称重保存成功')
|
||
weighingDialogVisible.value = false
|
||
// 团购同款预称重模式:称重完成后继续复核确认
|
||
if (weighingBeforeConfirm.value) {
|
||
weighingBeforeConfirm.value = false
|
||
const id = activeOrderId.value
|
||
if (id == null || id <= 0) return
|
||
try {
|
||
await ElMessageBox.confirm(`称重已完成,确认对订单 ID ${id} 提交复核记录?`, '确认复核', {
|
||
type: 'warning'
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
await doConfirm()
|
||
}
|
||
} else {
|
||
ElMessage.error(res?.message || '称重保存失败')
|
||
}
|
||
} catch (error: any) {
|
||
ElMessage.error(error?.message || '称重保存失败')
|
||
} finally {
|
||
weighingSubmitting.value = false
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.storage-receiving-container {
|
||
display: flex;
|
||
width: 100%;
|
||
background-color: #f0f2f5;
|
||
|
||
.recheck-panel-wrapper {
|
||
flex: 0 0 330px;
|
||
width: 330px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 10px;
|
||
overflow: hidden;
|
||
min-width: 0;
|
||
|
||
.toolbar {
|
||
padding: 5px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
background-color: #fff;
|
||
flex-shrink: 0;
|
||
|
||
.toolbar-left {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.toolbar-right {
|
||
display: flex;
|
||
flex-direction: row;
|
||
gap: 8px;
|
||
height: 30px;
|
||
align-items: center;
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
|
||
.split-stack {
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.pane-resizer {
|
||
flex: 0 0 6px;
|
||
min-height: 6px;
|
||
background: #e4e7ed;
|
||
cursor: row-resize;
|
||
flex-shrink: 0;
|
||
position: relative;
|
||
z-index: 2;
|
||
|
||
&:hover {
|
||
background: #dcdfe6;
|
||
}
|
||
}
|
||
|
||
.detail-pane {
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-top: 1px solid #ebeef5;
|
||
overflow: hidden;
|
||
background-color: #fff;
|
||
flex: 1;
|
||
min-height: 0;
|
||
|
||
.detail-header {
|
||
flex-shrink: 0;
|
||
padding: 6px 10px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
background-color: #fafafa;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
|
||
.detail-header-title {
|
||
font-weight: 600;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.detail-header-summary {
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
|
||
.text-scanned {
|
||
color: #409eff;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.detail-tab {
|
||
margin-bottom: -1px;
|
||
|
||
:deep(.el-tabs__header) {
|
||
margin: 0;
|
||
}
|
||
|
||
:deep(.el-tabs__item) {
|
||
height: 28px;
|
||
line-height: 28px;
|
||
font-size: 12px;
|
||
padding: 0 10px;
|
||
}
|
||
|
||
:deep(.el-tabs__nav-wrap::after) {
|
||
height: 1px;
|
||
}
|
||
}
|
||
}
|
||
|
||
.detail-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
padding: 6px 10px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
box-sizing: border-box;
|
||
|
||
.recheck-detail-pane {
|
||
flex: 1;
|
||
min-height: 0;
|
||
min-width: 0;
|
||
width: 100%;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
}
|
||
}
|
||
|
||
.no-selection {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #909399;
|
||
background-color: #fff;
|
||
padding: 10px;
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
max-width: 360px;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.recheck-empty,
|
||
.detail-empty-tip {
|
||
color: var(--el-text-color-secondary);
|
||
padding: 24px;
|
||
text-align: center;
|
||
line-height: 1.6;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.detail-empty-tip {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
// 已扫完商品行:绿底白字
|
||
:deep(.el-table .row-scanned-complete td) {
|
||
background-color: #67c23a !important;
|
||
color: #fff !important;
|
||
}
|
||
|
||
:deep(.el-table .row-scanned-complete td .cell) {
|
||
color: #fff !important;
|
||
}
|
||
|
||
// 已扫/总数列高亮
|
||
:deep(.el-table .col-scanned .cell),
|
||
:deep(.el-table .col-plan .cell) {
|
||
font-weight: 600;
|
||
}
|
||
|
||
:deep(.el-table .row-scanned-complete td.col-scanned .cell),
|
||
:deep(.el-table .row-scanned-complete td.col-plan .cell) {
|
||
color: #fff !important;
|
||
font-weight: 700;
|
||
}
|
||
</style>
|