All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m11s
地图支持全屏漫游、美国邮编港口与中国城市口岸图层;同步入出库扫码与培训手册等改动。 Co-authored-by: Cursor <cursoragent@cursor.com>
369 lines
11 KiB
Vue
369 lines
11 KiB
Vue
<template>
|
||
<div class="h5-ops">
|
||
<H5OpsPageHeader :title="t('h5Admin.ops.inbound')" @change="onWarehouseChange" />
|
||
|
||
<div class="h5-ops__scan-row">
|
||
<H5ScanInput
|
||
ref="scanRef"
|
||
v-model="form.waybillNumber"
|
||
:placeholder="t('operation.inbound.form.placeholder.scanOrInput')"
|
||
: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="onScanEnter"
|
||
@detect="onDetect"
|
||
@error="onScanError"
|
||
/>
|
||
<button
|
||
type="button"
|
||
class="h5-ops__primary"
|
||
:disabled="submitting || lookingUp"
|
||
@click="submit"
|
||
>
|
||
{{ t('operation.inbound.actions.inbound') }}
|
||
</button>
|
||
</div>
|
||
|
||
<div class="h5-ops__type-row">
|
||
<a-select
|
||
v-model="numberType"
|
||
class="h5-ops__type-select"
|
||
:placeholder="t('operation.printLabel.form.placeholder.numberType')"
|
||
>
|
||
<a-option v-for="item in numberTypeOptions" :key="item.value" :value="item.value">
|
||
{{ item.label }}
|
||
</a-option>
|
||
</a-select>
|
||
</div>
|
||
|
||
<p v-if="feedbackMessage" class="h5-ops__feedback" :class="`is-${feedbackType}`">
|
||
{{ feedbackMessage }}
|
||
</p>
|
||
|
||
<section v-if="candidates.length" class="h5-ops__panel">
|
||
<p class="h5-ops__meta">{{ t('operation.printLabel.preview.multiMatch') }}</p>
|
||
<button
|
||
v-for="c in candidates"
|
||
:key="c.orderId"
|
||
type="button"
|
||
class="h5-ops__candidate"
|
||
@click="selectCandidate(c)"
|
||
>
|
||
<strong>{{ c.serviceNo || c.clientNo || `#${c.orderId}` }}</strong>
|
||
<span>{{ c.clientNo || '-' }} · {{ c.trackNo || '-' }} · {{ c.orderStatusName || '-' }}</span>
|
||
</button>
|
||
</section>
|
||
|
||
<section v-else-if="form.orderId" class="h5-ops__panel">
|
||
<p class="h5-ops__waybill">{{ lookedUpServiceNo || form.waybillNumber || '-' }}</p>
|
||
<p class="h5-ops__meta">
|
||
{{ form.salesProductName || '-' }} · {{ form.destinationCountryName || '-' }}
|
||
</p>
|
||
<div class="h5-ops__metrics">
|
||
<div class="h5-ops__field">
|
||
<label>{{ t('operation.inbound.form.receivedWeight') }} (KG)</label>
|
||
<input v-model="form.weight" inputmode="decimal" />
|
||
</div>
|
||
<div class="h5-ops__field">
|
||
<label>{{ t('operation.inbound.form.dimensions') }}</label>
|
||
<div class="h5-ops__dims">
|
||
<input
|
||
v-model="form.length"
|
||
inputmode="decimal"
|
||
:placeholder="t('operation.inbound.form.placeholder.length')"
|
||
/>
|
||
<span>×</span>
|
||
<input
|
||
v-model="form.width"
|
||
inputmode="decimal"
|
||
:placeholder="t('operation.inbound.form.placeholder.width')"
|
||
/>
|
||
<span>×</span>
|
||
<input
|
||
v-model="form.height"
|
||
inputmode="decimal"
|
||
:placeholder="t('operation.inbound.form.placeholder.height')"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="h5-ops__recent">
|
||
<h2>{{ t('h5Admin.ops.recentRecords') }}</h2>
|
||
<a-spin :loading="listLoading" style="width: 100%">
|
||
<p v-if="!listLoading && !rows.length" class="h5-ops__empty">
|
||
{{ t('h5Admin.ops.emptyRecent') }}
|
||
</p>
|
||
<article v-for="row in rows" :key="row.key" class="h5-ops__card">
|
||
<strong>{{ row.waybillNumber }}</strong>
|
||
<span>{{ row.weight }} KG · {{ row.dimensions }}</span>
|
||
<em>{{ row.orderStatusName || row.operateTime }}</em>
|
||
</article>
|
||
</a-spin>
|
||
</section>
|
||
</div>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { nextTick, onMounted, reactive, ref, watch } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import H5ScanInput from '@/components/h5/H5ScanInput.vue';
|
||
import H5OpsPageHeader from './H5OpsPageHeader.vue';
|
||
import {
|
||
inboundCreate,
|
||
inboundOrderLookup,
|
||
inboundRecentList,
|
||
type OpsScanCandidate,
|
||
} from '@/api/operation';
|
||
import { useCurrentWarehouseStore } from '@/store';
|
||
import { useOperationScanFeedback } from '@/composables/useOperationScanFeedback';
|
||
import { useOpsScanNumberType } from '@/composables/useOpsScanNumberType';
|
||
import { applyScanExtract, ensureScanExtractBundle } from '@/utils/scanExtract';
|
||
|
||
defineOptions({ name: 'H5AdminOpsInbound' });
|
||
|
||
const { t } = useI18n();
|
||
const scanRef = ref<InstanceType<typeof H5ScanInput> | null>(null);
|
||
const currentWarehouseStore = useCurrentWarehouseStore();
|
||
const {
|
||
feedbackType,
|
||
feedbackMessage,
|
||
clearFeedback,
|
||
showError,
|
||
showRequestError,
|
||
showSuccess,
|
||
showWarning,
|
||
} = useOperationScanFeedback('h5Inbound');
|
||
const { numberType, numberTypeOptions } = useOpsScanNumberType('h5Inbound');
|
||
|
||
const form = reactive({
|
||
waybillNumber: '',
|
||
weight: '',
|
||
length: '',
|
||
width: '',
|
||
height: '',
|
||
salesProductName: '',
|
||
destinationCountryName: '',
|
||
orderId: undefined as number | undefined,
|
||
});
|
||
|
||
const lookedUpWaybillNo = ref('');
|
||
const lookedUpServiceNo = ref('');
|
||
const lookedUpNumberType = ref('auto');
|
||
const candidates = ref<OpsScanCandidate[]>([]);
|
||
const lookingUp = ref(false);
|
||
const submitting = ref(false);
|
||
const listLoading = ref(false);
|
||
const rows = ref<
|
||
Array<{
|
||
key: string;
|
||
waybillNumber: string;
|
||
weight: string;
|
||
dimensions: string;
|
||
orderStatusName: string;
|
||
operateTime: string;
|
||
}>
|
||
>([]);
|
||
|
||
function refocus() {
|
||
nextTick(() => scanRef.value?.focus());
|
||
}
|
||
|
||
function onWarehouseChange() {
|
||
clearFeedback();
|
||
form.waybillNumber = '';
|
||
clearLookup();
|
||
void loadRecent();
|
||
refocus();
|
||
}
|
||
|
||
function hasMetrics() {
|
||
return !!(form.weight && form.length && form.width && form.height);
|
||
}
|
||
|
||
function clearLookup() {
|
||
form.salesProductName = '';
|
||
form.destinationCountryName = '';
|
||
form.orderId = undefined;
|
||
form.weight = '';
|
||
form.length = '';
|
||
form.width = '';
|
||
form.height = '';
|
||
lookedUpWaybillNo.value = '';
|
||
lookedUpServiceNo.value = '';
|
||
lookedUpNumberType.value = numberType.value;
|
||
candidates.value = [];
|
||
}
|
||
|
||
async function ensureLookup() {
|
||
const no = form.waybillNumber.trim();
|
||
if (!no) {
|
||
clearLookup();
|
||
return false;
|
||
}
|
||
if (
|
||
form.orderId &&
|
||
lookedUpWaybillNo.value === no &&
|
||
lookedUpNumberType.value === numberType.value
|
||
) {
|
||
return true;
|
||
}
|
||
lookingUp.value = true;
|
||
try {
|
||
const info = await inboundOrderLookup(no, numberType.value);
|
||
if (info?.candidates?.length && info.matched === false) {
|
||
form.orderId = undefined;
|
||
form.salesProductName = '';
|
||
form.destinationCountryName = '';
|
||
lookedUpWaybillNo.value = no;
|
||
lookedUpServiceNo.value = '';
|
||
lookedUpNumberType.value = numberType.value;
|
||
candidates.value = info.candidates;
|
||
showWarning(t('operation.printLabel.preview.multiMatch'));
|
||
return false;
|
||
}
|
||
if (!info?.orderId) throw new Error(t('operation.common.message.orderNotFound'));
|
||
form.orderId = info.orderId;
|
||
form.salesProductName = info.salesProductName || info.productCode || '';
|
||
form.destinationCountryName =
|
||
info.destinationCountryName || info.destinationCountry || '';
|
||
lookedUpWaybillNo.value = no;
|
||
lookedUpServiceNo.value = info.serviceNo || no;
|
||
lookedUpNumberType.value = numberType.value;
|
||
candidates.value = [];
|
||
return true;
|
||
} catch (e: any) {
|
||
clearLookup();
|
||
showRequestError(e, t('operation.common.message.orderNotFound'));
|
||
refocus();
|
||
return false;
|
||
} finally {
|
||
lookingUp.value = false;
|
||
}
|
||
}
|
||
|
||
async function selectCandidate(c: OpsScanCandidate) {
|
||
const serviceNo = String(c.serviceNo || '').trim();
|
||
if (!serviceNo) {
|
||
showWarning(t('operation.common.message.orderNotFound'));
|
||
return;
|
||
}
|
||
form.waybillNumber = serviceNo;
|
||
numberType.value = 'waybill';
|
||
candidates.value = [];
|
||
await ensureLookup();
|
||
}
|
||
|
||
async function onDetect(code: string) {
|
||
form.waybillNumber = code;
|
||
await onScanEnter();
|
||
}
|
||
|
||
function onScanError(message: string) {
|
||
showError(message);
|
||
}
|
||
|
||
async function onScanEnter() {
|
||
form.waybillNumber = applyScanExtract(form.waybillNumber);
|
||
const ok = await ensureLookup();
|
||
if (!ok) return;
|
||
if (hasMetrics()) await submit();
|
||
else clearFeedback();
|
||
}
|
||
|
||
function buildSuccessMessage(result: any) {
|
||
const status = result?.orderStatus ?? result?.OrderStatus;
|
||
const statusName = result?.orderStatusName ?? result?.OrderStatusName;
|
||
if (status === 'pendingAllocation') {
|
||
return t('operation.inbound.message.inboundProcessing');
|
||
}
|
||
if (statusName) {
|
||
return t('operation.inbound.message.inboundSuccessWithStatus', { status: statusName });
|
||
}
|
||
return t('operation.inbound.message.inboundProcessing');
|
||
}
|
||
|
||
async function submit() {
|
||
if (!form.waybillNumber.trim()) {
|
||
showWarning(t('operation.inbound.message.waybillNumberRequired'));
|
||
refocus();
|
||
return;
|
||
}
|
||
const ok = await ensureLookup();
|
||
if (!ok) return;
|
||
if (!hasMetrics()) {
|
||
showWarning(t('operation.inbound.message.metricsRequired'));
|
||
return;
|
||
}
|
||
submitting.value = true;
|
||
try {
|
||
const result = await inboundCreate({
|
||
waybillNo: lookedUpServiceNo.value || form.waybillNumber.trim(),
|
||
numberType: lookedUpServiceNo.value ? 'waybill' : numberType.value,
|
||
weight: Number(form.weight),
|
||
length: Number(form.length),
|
||
width: Number(form.width),
|
||
height: Number(form.height),
|
||
warehouseId: currentWarehouseStore.warehouseId,
|
||
});
|
||
showSuccess(buildSuccessMessage(result));
|
||
form.waybillNumber = '';
|
||
clearLookup();
|
||
await loadRecent();
|
||
refocus();
|
||
} catch (e: any) {
|
||
showRequestError(e, t('operation.inbound.message.inboundFailed'));
|
||
refocus();
|
||
} finally {
|
||
submitting.value = false;
|
||
}
|
||
}
|
||
|
||
watch(numberType, () => {
|
||
form.orderId = undefined;
|
||
lookedUpWaybillNo.value = '';
|
||
lookedUpServiceNo.value = '';
|
||
candidates.value = [];
|
||
});
|
||
|
||
async function loadRecent() {
|
||
listLoading.value = true;
|
||
try {
|
||
const { items } = await inboundRecentList({
|
||
limit: 30,
|
||
warehouseId: currentWarehouseStore.warehouseId,
|
||
});
|
||
rows.value = (items || []).map((row: any, idx: number) => ({
|
||
key: String(row.id ?? row.Id ?? `${row.waybillNo ?? ''}-${idx}`),
|
||
waybillNumber: row.waybillNo ?? row.waybillNumber ?? '-',
|
||
weight: row.weight != null ? String(row.weight) : '-',
|
||
dimensions:
|
||
row.length != null && row.width != null && row.height != null
|
||
? `${row.length}×${row.width}×${row.height}`
|
||
: '-',
|
||
orderStatusName: row.orderStatusName ?? row.OrderStatusName ?? '',
|
||
operateTime: row.operateTime ?? row.createTime ?? '',
|
||
}));
|
||
} catch (e: any) {
|
||
showRequestError(e, t('operation.inbound.message.loadRecentFailed'));
|
||
rows.value = [];
|
||
} finally {
|
||
listLoading.value = false;
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
void ensureScanExtractBundle();
|
||
clearFeedback();
|
||
void loadRecent();
|
||
refocus();
|
||
});
|
||
</script>
|
||
|
||
<style lang="less" scoped>
|
||
@import './ops-shared.less';
|
||
</style>
|