front/src/views/h5/admin-center/ops/fulfill-pack.vue
zzh b7d7ea1113
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m10s
feat: 工作台操作/运营体验改版,代发进度去掉待绑定
线路双指标对比、运营柱线趋势、操作区左右待办队列;创建代发必绑口径对齐前后端 Tab。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 11:23:22 +08:00

310 lines
9.6 KiB
Vue

<template>
<div class="h5-ops">
<H5OpsPageHeader :title="t('h5Admin.ops.fulfillPack')" @change="onWarehouseChange" />
<div class="h5-ops__scan-row">
<H5ScanInput
ref="scanRef"
v-model="scanNumber"
:placeholder="t('operation.fulfillPack.scan.placeholder')"
:sheet-title="t('h5Admin.ops.cameraSheetTitle')"
:sheet-hint="t('h5Admin.ops.cameraSheetHint')"
:close-label="t('h5Admin.ops.cameraClose')"
:torch-on-label="t('h5Admin.ops.torchOn')"
:torch-off-label="t('h5Admin.ops.torchOff')"
@enter="runLookup()"
@detect="onDetect"
@error="onScanError"
/>
<button type="button" class="h5-ops__primary" :disabled="lookingUp" @click="runLookup()">
{{ t('h5Admin.ops.lookup') }}
</button>
</div>
<p v-if="feedbackMessage" class="h5-ops__feedback" :class="`is-${feedbackType}`">
{{ feedbackMessage }}
</p>
<section v-if="lookup" class="h5-ops__panel">
<p class="h5-ops__waybill">{{ lookup.serviceNo || lookup.clientNo || lookup.orderId }}</p>
<p class="h5-ops__meta">
{{ lookup.salesProductName || '-' }} ·
{{ lookup.destinationCountryName || lookup.destinationCountry || '-' }} ·
{{ bindStatusLabel }}
</p>
<div v-for="(item, idx) in bindItems" :key="`${item.skuCode}-${idx}`" class="h5-ops__card">
<strong>{{ item.skuName || item.skuCode || item.productName || '-' }}</strong>
<span>
{{ item.skuCode || '-' }}
<template v-if="item.binCode"> · {{ item.binCode }}</template>
<template v-if="item.bindQty != null"> · x{{ item.bindQty }}</template>
</span>
<em v-if="item.trackingNo">{{ item.trackingNo }}</em>
</div>
<button
v-if="canConfirm"
type="button"
class="h5-ops__primary"
style="width: 100%; margin-top: 8px"
:disabled="confirmLoading"
@click="confirmOutbound"
>
{{ t('operation.fulfillPack.actions.confirmOutbound') }}
</button>
</section>
<section class="h5-ops__recent">
<div class="h5-ops__queue-head">
<h2>{{ t('h5Admin.ops.fulfillQueue') }}</h2>
<button type="button" @click="loadQueue">{{ t('h5Admin.ops.refresh') }}</button>
</div>
<a-spin :loading="listLoading" style="width: 100%">
<p v-if="!listLoading && !queue.length" class="h5-ops__empty">
{{ t('h5Admin.ops.emptyRecent') }}
</p>
<article
v-for="row in queue"
:key="row.id"
class="h5-ops__card"
:class="{ 'is-active': selectedOrderId === row.id }"
@click="selectQueueRow(row)"
>
<strong>{{ row.waybillNo || '-' }}</strong>
<span>
{{ row.primaryBinCode || '-' }} · {{ row.primarySkuCodes || '-' }} ·
x{{ row.stockBindQtyTotal || 0 }}
</span>
<em>{{ progressLabel(row.fulfillProgress) }}</em>
</article>
</a-spin>
</section>
</div>
</template>
<script lang="ts" setup>
import { computed, nextTick, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { Modal } from '@arco-design/web-vue';
import H5ScanInput from '@/components/h5/H5ScanInput.vue';
import H5OpsPageHeader from './H5OpsPageHeader.vue';
import {
printLabelLookup,
type PrintLabelBindItem,
type PrintLabelLookupResult,
} from '@/api/operation';
import { postOrderList, postOrderStockBindConfirmDeduct } from '@/api/order';
import { useCurrentWarehouseStore } from '@/store';
import { normalizeFulfillBindLookup } from '@/composables/useFulfillBindLookup';
import { useOperationScanFeedback } from '@/composables/useOperationScanFeedback';
import { hasPermission } from '@/utils/rbac-permission';
defineOptions({ name: 'H5AdminOpsFulfillPack' });
const { t } = useI18n();
const scanRef = ref<InstanceType<typeof H5ScanInput> | null>(null);
const currentWarehouseStore = useCurrentWarehouseStore();
const {
feedbackType,
feedbackMessage,
clearFeedback,
showError,
showSuccess,
showWarning,
} = useOperationScanFeedback('h5FulfillPack');
type QueueRow = {
id: number;
waybillNo: string;
primaryBinCode: string;
primarySkuCodes: string;
stockBindQtyTotal: number;
fulfillProgress: string;
domesticTrackingNos: string;
};
const scanNumber = ref('');
const lookingUp = ref(false);
const confirmLoading = ref(false);
const listLoading = ref(false);
const lookup = ref<PrintLabelLookupResult | null>(null);
const queue = ref<QueueRow[]>([]);
const selectedOrderId = ref<number | null>(null);
const bindItems = computed(() => (lookup.value?.bindItems || []) as PrintLabelBindItem[]);
const bindStatusLabel = computed(() => {
const code = lookup.value?.bindStatus || 'none';
const key = `order.myOrders.stockBind.status.${code}`;
const text = t(key);
return text === key ? code : text;
});
const canConfirm = computed(
() =>
hasPermission('Operation.FulfillPack.ConfirmOutbound') &&
Boolean(lookup.value?.matched && lookup.value?.bindStatus === 'bound'),
);
function refocus() {
nextTick(() => scanRef.value?.focus());
}
function onWarehouseChange() {
clearFeedback();
scanNumber.value = '';
lookup.value = null;
selectedOrderId.value = null;
void loadQueue();
refocus();
}
function progressLabel(code: string) {
const key = `order.fulfillOrders.progress.${code || 'arrivedPendingPick'}`;
const text = t(key);
return text === key ? code : text;
}
function pick(raw: any, ...keys: string[]) {
for (const k of keys) {
const v = raw?.[k];
if (v !== undefined && v !== null && v !== '') return v;
}
return undefined;
}
function onScanError(message: string) {
showError(message);
}
async function loadQueue() {
listLoading.value = true;
try {
const { items } = await postOrderList({
page: 1,
pageSize: 50,
status: 'all',
fulfillmentType: 'warehouse',
stockBindStatus: 'bound',
warehouseId: currentWarehouseStore.warehouseId,
sortField: 'primaryBinCode',
sortOrder: 'asc',
});
queue.value = (items || []).map((raw: any) => ({
id: Number(pick(raw, 'id', 'Id') || 0),
waybillNo: String(pick(raw, 'serviceNo', 'ServiceNo') || ''),
primaryBinCode: String(pick(raw, 'primaryBinCode', 'PrimaryBinCode') || ''),
primarySkuCodes: String(pick(raw, 'primarySkuCodes', 'PrimarySkuCodes') || ''),
stockBindQtyTotal: Number(pick(raw, 'stockBindQtyTotal', 'StockBindQtyTotal') || 0),
fulfillProgress: String(pick(raw, 'fulfillProgress', 'FulfillProgress') || ''),
domesticTrackingNos: String(pick(raw, 'domesticTrackingNos', 'DomesticTrackingNos') || ''),
}));
} catch (e: any) {
queue.value = [];
showError(e?.message || t('operation.fulfillPack.message.loadFailed'));
} finally {
listLoading.value = false;
}
}
async function runLookup(silent = false) {
const number = scanNumber.value.trim();
if (!number) {
if (!silent) showWarning(t('operation.fulfillPack.message.numberRequired'));
refocus();
return;
}
lookingUp.value = true;
try {
const raw = await printLabelLookup({ number, numberType: 'auto' });
const data = normalizeFulfillBindLookup(raw);
if (data.candidates?.length && !data.matched) {
lookup.value = null;
showWarning(t('operation.printLabel.preview.multiMatch'));
refocus();
return;
}
if (!data.matched || !data.orderId) {
lookup.value = null;
showWarning(t('operation.fulfillPack.message.lookupFailed'));
refocus();
return;
}
lookup.value = data;
selectedOrderId.value = Number(data.orderId);
if (!silent) showSuccess(t('operation.fulfillPack.message.lookupSuccess'));
refocus();
} catch (e: any) {
lookup.value = null;
showError(e?.message || t('operation.fulfillPack.message.lookupFailed'));
refocus();
} finally {
lookingUp.value = false;
}
}
async function onDetect(code: string) {
scanNumber.value = code;
await runLookup();
}
async function selectQueueRow(row: QueueRow) {
selectedOrderId.value = row.id;
const domestic = String(row.domesticTrackingNos || '')
.split(',')
.map((s) => s.trim())
.filter(Boolean)[0];
scanNumber.value = domestic || row.waybillNo;
await runLookup(true);
}
function confirmOutbound() {
const orderId = Number(lookup.value?.orderId);
if (!orderId) {
showWarning(t('operation.fulfillPack.message.lookupFirst'));
return;
}
if (lookup.value?.bindStatus !== 'bound') {
showWarning(t('operation.fulfillPack.message.notBound'));
return;
}
const queueRow = queue.value.find((r) => r.id === orderId);
if (queueRow && queueRow.fulfillProgress !== 'arrivedPendingPick') {
showWarning(t('operation.fulfillPack.message.domesticInTransit'));
return;
}
Modal.confirm({
title: t('operation.fulfillPack.confirm.title'),
content: t('operation.fulfillPack.confirm.content', {
waybill: lookup.value?.serviceNo || orderId,
qty: lookup.value?.bindQtyTotal || 0,
}),
onOk: async () => {
confirmLoading.value = true;
try {
await postOrderStockBindConfirmDeduct(orderId);
showSuccess(t('operation.fulfillPack.message.confirmSuccess'));
lookup.value = null;
scanNumber.value = '';
selectedOrderId.value = null;
await loadQueue();
refocus();
} catch (e: any) {
showError(e?.message || t('operation.fulfillPack.message.confirmFailed'));
} finally {
confirmLoading.value = false;
}
},
});
}
onMounted(() => {
clearFeedback();
void loadQueue();
refocus();
});
</script>
<style lang="less" scoped>
@import './ops-shared.less';
</style>