front/src/views/h5/admin-center/ops/relocate.vue
zzh 3ce8955472
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m11s
feat: 经营地图放大下钻与中美口岸标注,并完善扫码/品牌/培训
地图支持全屏漫游、美国邮编港口与中国城市口岸图层;同步入出库扫码与培训手册等改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 13:55:47 +08:00

519 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="h5-ops">
<H5OpsPageHeader :title="t('h5Admin.ops.relocate')" @change="onWarehouseChange" />
<div class="h5-ops__scan-row">
<H5ScanInput
ref="scanRef"
v-model="scanCode"
:placeholder="t('h5Admin.ops.relocate.scanPlaceholder')"
: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="lookup"
@detect="onDetect"
@error="onScanError"
/>
<button
type="button"
class="h5-ops__primary"
:disabled="lookingUp || submitting"
@click="lookup"
>
{{ t('h5Admin.ops.relocate.lookup') }}
</button>
</div>
<p v-if="feedbackMessage" class="h5-ops__feedback" :class="`is-${feedbackType}`">
{{ feedbackMessage }}
</p>
<section v-if="candidates.length > 1 && !activeSku" class="h5-ops__recent">
<h2>{{ t('h5Admin.ops.relocate.pickSku') }}</h2>
<article
v-for="row in candidates"
:key="`${row.customerId}-${row.skuId}`"
class="h5-ops__card"
@click="selectSku(row)"
>
<strong>{{ row.skuCode }}</strong>
<span>{{ row.skuName || '-' }} · {{ row.customerName || '-' }}</span>
<em>{{ row.availableQty }} / {{ row.totalQty }} · {{ row.binCount }} bin</em>
</article>
</section>
<section v-if="activeSku" class="h5-ops__panel h5-relocate__panel">
<p class="h5-ops__waybill">{{ activeSku.skuCode }}</p>
<p class="h5-ops__meta">
{{ activeSku.skuName || '-' }}
· {{ activeSku.customerName || activeSku.customerCode || '-' }}
· {{ activeSku.availableQty }} / {{ activeSku.totalQty }}
</p>
<label class="h5-relocate__field">
{{ t('h5Admin.ops.relocate.sourceBin') }}
<a-select
v-model="form.sourceBinLocationId"
:options="sourceBinOptions"
allow-search
allow-clear
:placeholder="t('h5Admin.ops.relocate.selectSource')"
@change="onSourceBinChange"
/>
</label>
<label class="h5-relocate__field">
{{ t('h5Admin.ops.relocate.targetBin') }}
<a-select
v-model="form.targetBinLocationId"
:options="targetBinOptions"
allow-search
allow-clear
:placeholder="t('h5Admin.ops.relocate.selectTarget')"
/>
</label>
<label class="h5-relocate__field">
{{ t('h5Admin.ops.relocate.qty') }}
<span class="h5-relocate__qty-hint">max {{ sourceMaxQty }}</span>
<input
v-model.number="form.qty"
type="number"
inputmode="numeric"
min="1"
:max="sourceMaxQty"
/>
</label>
<button
type="button"
class="h5-ops__primary h5-relocate__submit"
:disabled="submitting || lookingUp"
@click="submit"
>
{{ t('h5Admin.ops.relocate.confirm') }}
</button>
</section>
<section class="h5-ops__recent">
<div class="h5-ops__queue-head">
<h2>{{ t('h5Admin.ops.relocate.stockList') }}</h2>
<button type="button" @click="loadStockList">{{ t('h5Admin.ops.refresh') }}</button>
</div>
<a-spin :loading="listLoading" style="width: 100%">
<p v-if="!listLoading && !stockRows.length" class="h5-ops__empty">
{{ t('h5Admin.ops.relocate.emptyStock') }}
</p>
<article
v-for="row in stockRows"
:key="`${row.customerId}-${row.skuId}`"
class="h5-ops__card"
:class="{
'is-active':
activeSku?.skuId === row.skuId && activeSku?.customerId === row.customerId,
}"
@click="selectSku(row)"
>
<strong>{{ row.skuCode }}</strong>
<span>{{ row.skuName || '-' }} · {{ row.customerName || '-' }}</span>
<em>{{ row.availableQty }} / {{ row.totalQty }} · {{ row.binCount }} bin</em>
</article>
</a-spin>
</section>
</div>
</template>
<script lang="ts" setup>
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import H5ScanInput from '@/components/h5/H5ScanInput.vue';
import H5OpsPageHeader from './H5OpsPageHeader.vue';
import {
getWarehouseBinLocationList,
getWarehouseInventoryBinDetail,
getWarehouseInventoryList,
relocateWarehouseInventory,
} from '@/api/warehouse';
import { useCurrentWarehouseStore } from '@/store';
import { useOperationScanFeedback } from '@/composables/useOperationScanFeedback';
import { hasPermission } from '@/utils/rbac-permission';
import { normalizeListRow, pickField } from '@/utils/warehouseListMapper';
defineOptions({ name: 'H5AdminOpsRelocate' });
type StockRow = {
customerId: number;
customerName: string;
customerCode: string;
skuId: number;
skuCode: string;
skuName: string;
warehouseId: number;
availableQty: number;
totalQty: number;
binCount: number;
};
type BinOpt = { label: string; value: number; qty?: number };
const { t } = useI18n();
const scanRef = ref<InstanceType<typeof H5ScanInput> | null>(null);
const currentWarehouseStore = useCurrentWarehouseStore();
const {
feedbackType,
feedbackMessage,
clearFeedback,
showError,
showRequestError,
showSuccess,
showWarning,
} = useOperationScanFeedback('h5Relocate');
const scanCode = ref('');
const lookingUp = ref(false);
const submitting = ref(false);
const listLoading = ref(false);
const candidates = ref<StockRow[]>([]);
const activeSku = ref<StockRow | null>(null);
const stockRows = ref<StockRow[]>([]);
const sourceBinOptions = ref<BinOpt[]>([]);
const targetBinOptions = ref<BinOpt[]>([]);
const form = reactive({
sourceBinLocationId: undefined as number | undefined,
targetBinLocationId: undefined as number | undefined,
qty: 1,
});
const sourceMaxQty = computed(() => {
const sourceId = form.sourceBinLocationId;
if (!sourceId) return activeSku.value?.totalQty || 1;
const hit = sourceBinOptions.value.find((b) => b.value === sourceId);
return hit?.qty || 1;
});
function canMutate() {
return hasPermission('Warehouse.Inventory.Relocate');
}
function refocus() {
nextTick(() => scanRef.value?.focus());
}
function mapStockRow(raw: Record<string, unknown>): StockRow {
const row = normalizeListRow(raw);
return {
customerId: Number(pickField(row, 'customerId', 'CustomerId') || 0),
customerName: String(pickField(row, 'customerName', 'CustomerName') || ''),
customerCode: String(pickField(row, 'customerCode', 'CustomerCode') || ''),
skuId: Number(pickField(row, 'skuId', 'SkuId') || 0),
skuCode: String(pickField(row, 'skuCode', 'SkuCode') || '-'),
skuName: String(pickField(row, 'skuName', 'SkuName') || ''),
warehouseId: Number(pickField(row, 'warehouseId', 'WarehouseId') || 0),
availableQty: Number(pickField(row, 'availableQty', 'AvailableQty') || 0),
totalQty: Number(pickField(row, 'totalQty', 'TotalQty') || 0),
binCount: Number(pickField(row, 'binCount', 'BinCount') || 0),
};
}
function resetForm() {
activeSku.value = null;
candidates.value = [];
sourceBinOptions.value = [];
form.sourceBinLocationId = undefined;
form.targetBinLocationId = undefined;
form.qty = 1;
}
async function loadTargetBins(warehouseId?: number) {
if (!warehouseId) {
targetBinOptions.value = [];
return;
}
try {
const { items } = await getWarehouseBinLocationList({
warehouseId,
isEnabled: true,
});
targetBinOptions.value = (items || []).map((b: Record<string, unknown>) => {
const row = normalizeListRow(b);
const code = String(pickField(row, 'binCode', 'BinCode') || '');
const name = String(pickField(row, 'binName', 'BinName') || '');
return {
label: name ? `${code} - ${name}` : code,
value: Number(pickField(row, 'id', 'Id') || 0),
};
});
} catch {
targetBinOptions.value = [];
}
}
async function loadSourceBins(sku: StockRow) {
try {
const data = (await getWarehouseInventoryBinDetail(
sku.skuId,
sku.warehouseId,
sku.customerId > 0 ? sku.customerId : undefined,
)) as Record<string, unknown>;
const itemsRaw = pickField(data, 'items', 'Items');
const items = Array.isArray(itemsRaw)
? itemsRaw
: Array.isArray(data)
? data
: [];
sourceBinOptions.value = items
.map((item: Record<string, unknown>) => {
const row = normalizeListRow(item);
const qty = Number(pickField(row, 'qty', 'Qty') || 0);
const code = String(pickField(row, 'binCode', 'BinCode') || '-');
const name = String(pickField(row, 'binName', 'BinName') || '');
return {
label: `${code}${name ? ` - ${name}` : ''}(${qty})`,
value: Number(pickField(row, 'binLocationId', 'BinLocationId') || 0),
qty,
};
})
.filter((b: BinOpt) => b.value > 0 && (b.qty || 0) > 0);
} catch {
sourceBinOptions.value = [];
}
}
function onSourceBinChange(binId?: number) {
form.sourceBinLocationId = binId;
const hit = sourceBinOptions.value.find((b) => b.value === binId);
if (hit && form.qty > (hit.qty || 0)) {
form.qty = hit.qty || 1;
}
}
async function selectSku(row: StockRow) {
if (!canMutate()) {
showWarning(t('h5Admin.ops.noPermission'));
return;
}
lookingUp.value = true;
clearFeedback();
try {
activeSku.value = row;
candidates.value = [];
form.sourceBinLocationId = undefined;
form.targetBinLocationId = undefined;
form.qty = 1;
await Promise.all([
loadSourceBins(row),
loadTargetBins(row.warehouseId || currentWarehouseStore.warehouseId),
]);
if (sourceBinOptions.value.length === 1) {
form.sourceBinLocationId = sourceBinOptions.value[0].value;
form.qty = Math.min(1, sourceBinOptions.value[0].qty || 1) || 1;
}
} catch (e: any) {
showRequestError(e, t('h5Admin.ops.relocate.loadFailed'));
} finally {
lookingUp.value = false;
}
}
async function onDetect(code: string) {
scanCode.value = code;
await lookup();
}
function onScanError(message: string) {
showError(message);
}
async function onWarehouseChange() {
clearFeedback();
scanCode.value = '';
resetForm();
await loadStockList();
refocus();
}
async function lookup() {
if (!canMutate()) {
showWarning(t('h5Admin.ops.noPermission'));
return;
}
const code = scanCode.value.trim();
if (!code) {
showWarning(t('h5Admin.ops.relocate.codeRequired'));
refocus();
return;
}
const warehouseId = currentWarehouseStore.warehouseId;
if (!warehouseId) {
showWarning(t('warehouse.common.noCurrentWarehouse'));
return;
}
lookingUp.value = true;
clearFeedback();
try {
const { items } = await getWarehouseInventoryList({
page: 1,
pageSize: 30,
warehouseId,
keyword: code,
});
const rows = (items || [])
.map((x) => mapStockRow(x as Record<string, unknown>))
.filter((x) => x.skuId > 0);
const exact = rows.filter(
(x) => x.skuCode.toLowerCase() === code.toLowerCase(),
);
const matched = exact.length ? exact : rows;
if (!matched.length) {
resetForm();
showWarning(t('h5Admin.ops.relocate.notFound'));
refocus();
return;
}
if (matched.length === 1) {
scanCode.value = '';
await selectSku(matched[0]);
return;
}
activeSku.value = null;
candidates.value = matched;
scanCode.value = '';
} catch (e: any) {
resetForm();
showRequestError(e, t('h5Admin.ops.relocate.loadFailed'));
refocus();
} finally {
lookingUp.value = false;
}
}
async function loadStockList() {
const warehouseId = currentWarehouseStore.warehouseId;
if (!warehouseId) {
stockRows.value = [];
return;
}
listLoading.value = true;
try {
const { items } = await getWarehouseInventoryList({
page: 1,
pageSize: 30,
warehouseId,
});
stockRows.value = (items || [])
.map((x) => mapStockRow(x as Record<string, unknown>))
.filter((x) => x.skuId > 0);
} catch (e: any) {
stockRows.value = [];
showRequestError(e, t('h5Admin.ops.relocate.loadFailed'));
} finally {
listLoading.value = false;
}
}
async function submit() {
if (!canMutate()) {
showWarning(t('h5Admin.ops.noPermission'));
return;
}
const sku = activeSku.value;
if (
!sku
|| !form.sourceBinLocationId
|| !form.targetBinLocationId
|| !form.qty
) {
showWarning(t('warehouse.inventory.message.relocateRequired'));
return;
}
if (form.sourceBinLocationId === form.targetBinLocationId) {
showWarning(t('warehouse.inventory.message.sameBin'));
return;
}
if (form.qty > sourceMaxQty.value) {
showWarning(t('warehouse.inventory.message.qtyExceed'));
return;
}
submitting.value = true;
try {
await relocateWarehouseInventory({
warehouseId: sku.warehouseId,
skuId: sku.skuId,
customerId: sku.customerId > 0 ? sku.customerId : undefined,
sourceBinLocationId: form.sourceBinLocationId,
targetBinLocationId: form.targetBinLocationId,
qty: Number(form.qty) || 0,
});
showSuccess(t('warehouse.inventory.message.relocateSuccess'));
resetForm();
scanCode.value = '';
await loadStockList();
refocus();
} catch (e: any) {
showRequestError(e, t('warehouse.inventory.message.relocateFailed'));
} finally {
submitting.value = false;
}
}
onMounted(async () => {
clearFeedback();
await loadStockList();
refocus();
});
</script>
<style lang="less" scoped>
@import './ops-shared.less';
.h5-relocate__panel {
display: grid;
gap: 12px;
}
.h5-relocate__field {
display: grid;
gap: 6px;
font-size: 12px;
color: var(--h5-text-2, #4e5969);
position: relative;
input {
height: 36px;
padding: 0 10px;
border: none;
border-radius: 10px;
background: var(--h5-well-bg, #f0f3f4);
font-size: 14px;
outline: none;
}
}
.h5-relocate__qty-hint {
position: absolute;
top: 0;
right: 0;
font-size: 11px;
color: var(--h5-text-3, #86909c);
}
.h5-relocate__submit {
width: 100%;
height: 44px;
margin-top: 4px;
}
.h5-ops__card {
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
</style>