feat: 商品查询库存样式与移库页优化
This commit is contained in:
parent
ebc955a7aa
commit
4bc4120c55
@ -139,6 +139,18 @@ export default {
|
||||
}
|
||||
},
|
||||
inventory: {
|
||||
list: {
|
||||
path: "storage.inventory.list",
|
||||
auth: true,
|
||||
method: "POST",
|
||||
isSystemApi: true
|
||||
},
|
||||
transferByProduct: {
|
||||
path: "storage.inventory.transferByProduct",
|
||||
auth: true,
|
||||
method: "POST",
|
||||
isSystemApi: true
|
||||
},
|
||||
transferLocation: {
|
||||
path: "storage.inventory.transferLocation",
|
||||
auth: true,
|
||||
|
||||
@ -756,6 +756,7 @@
|
||||
|
||||
const values = [
|
||||
item.id,
|
||||
item.stock_id,
|
||||
item.goods_id,
|
||||
item.item_id,
|
||||
item.product_id,
|
||||
@ -773,7 +774,7 @@
|
||||
.filter(Boolean)
|
||||
)];
|
||||
},
|
||||
mergeProductResultLists(searchList, detailList) {
|
||||
mergeProductResultLists(searchList, warehouseList, detailList) {
|
||||
const mergedMap = new Map();
|
||||
const upsert = (sourceItem, preferSource = false) => {
|
||||
if (!sourceItem || typeof sourceItem !== 'object') {
|
||||
@ -792,8 +793,9 @@
|
||||
});
|
||||
};
|
||||
|
||||
(detailList || []).forEach(item => upsert(item, false));
|
||||
(searchList || []).forEach(item => upsert(item, true));
|
||||
(searchList || []).forEach(item => upsert(item, false));
|
||||
(warehouseList || []).forEach(item => upsert(item, true));
|
||||
(detailList || []).forEach(item => upsert(item, true));
|
||||
|
||||
const uniqueItems = [];
|
||||
const seen = new Set();
|
||||
@ -850,31 +852,94 @@
|
||||
is_batch: this.queryMode === 'batch'
|
||||
};
|
||||
},
|
||||
buildListWhereParams(keyword) {
|
||||
const where = {};
|
||||
buildWarehouseListWhereParams(keyword) {
|
||||
const normalized = this.normalizeKeyword(keyword);
|
||||
if (!normalized) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (this.isBarcodeLike(keyword)) {
|
||||
where.barcode = {
|
||||
operator: 'like',
|
||||
value: keyword,
|
||||
type: 'string'
|
||||
};
|
||||
} else if (keyword) {
|
||||
where.item_name = {
|
||||
operator: 'like',
|
||||
value: keyword,
|
||||
type: 'string'
|
||||
if (this.isBarcodeLike(normalized)) {
|
||||
return {
|
||||
barcode: {
|
||||
operator: 'like',
|
||||
value: normalized,
|
||||
type: 'string'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return where;
|
||||
},
|
||||
buildListQueryParams(keyword) {
|
||||
return {
|
||||
keyword,
|
||||
item_name: {
|
||||
operator: 'like',
|
||||
value: normalized,
|
||||
type: 'string'
|
||||
}
|
||||
};
|
||||
},
|
||||
buildWarehouseListQueryParams(keyword) {
|
||||
return {
|
||||
with_stock: true,
|
||||
is_batch: this.queryMode === 'batch',
|
||||
where: this.buildListWhereParams(keyword)
|
||||
where: this.buildWarehouseListWhereParams(keyword),
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 20
|
||||
}
|
||||
};
|
||||
},
|
||||
buildListWhereParams(stockIdList) {
|
||||
const normalizedStockIdList = this.extractStockIdList(stockIdList);
|
||||
if (!normalizedStockIdList.length) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
stock_id: {
|
||||
field: 'stock_id',
|
||||
operator: 'in',
|
||||
type: 'array',
|
||||
value: normalizedStockIdList
|
||||
}
|
||||
};
|
||||
},
|
||||
extractStockIdList(source) {
|
||||
const sourceList = Array.isArray(source) ? source : [];
|
||||
const idSet = new Set();
|
||||
sourceList.forEach(item => {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
const stockIdCandidates = [
|
||||
item.stock_id,
|
||||
item.goods_id,
|
||||
item.item_id,
|
||||
item.product_id,
|
||||
item.id
|
||||
];
|
||||
|
||||
stockIdCandidates.forEach(candidate => {
|
||||
const normalized = this.normalizePositiveId(candidate);
|
||||
if (normalized) {
|
||||
idSet.add(normalized);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return [...idSet];
|
||||
},
|
||||
buildListQueryParams(stockIdList) {
|
||||
return {
|
||||
where: this.buildListWhereParams(stockIdList),
|
||||
pagination: {
|
||||
page: 1,
|
||||
pageSize: 20
|
||||
},
|
||||
sort: {
|
||||
sortField: 'created_at',
|
||||
sortOrder: 'DESC'
|
||||
},
|
||||
group_by_batch: this.queryMode === 'batch'
|
||||
};
|
||||
},
|
||||
setQueryMode(nextMode) {
|
||||
@ -1132,13 +1197,7 @@
|
||||
|
||||
const directCandidates = [
|
||||
item.storage_id,
|
||||
item.inventory_id,
|
||||
item.stock_id,
|
||||
item.storage_record_id,
|
||||
item.stock_record_id,
|
||||
item.warehouse_storage_id,
|
||||
item.warehouse_stock_id,
|
||||
item.record_id
|
||||
item.id
|
||||
];
|
||||
|
||||
for (let i = 0; i < directCandidates.length; i++) {
|
||||
@ -1148,17 +1207,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackId = this.normalizePositiveId(item.id);
|
||||
if (!fallbackId) {
|
||||
return null;
|
||||
},
|
||||
getRelocationProductStockId(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const spaceId = this.normalizePositiveId(item.space_id || item.space?.id);
|
||||
if (spaceId && fallbackId === spaceId) {
|
||||
return null;
|
||||
const directCandidates = [
|
||||
item.stock_id,
|
||||
item.goods_id,
|
||||
item.item_id,
|
||||
item.product_id,
|
||||
item.id
|
||||
];
|
||||
|
||||
for (let i = 0; i < directCandidates.length; i++) {
|
||||
const normalized = this.normalizePositiveId(directCandidates[i]);
|
||||
if (normalized) {
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
|
||||
return fallbackId;
|
||||
return null;
|
||||
},
|
||||
openRelocationPage(productItem, storageItem, quantityType = 'available') {
|
||||
if (!productItem || typeof productItem !== 'object' || !storageItem || typeof storageItem !== 'object') {
|
||||
@ -1169,8 +1240,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const isNonBatchMode = this.queryMode === 'nonBatch';
|
||||
const relocationStorageId = this.getRelocationStorageId(storageItem) || this.getRelocationStorageId(productItem);
|
||||
if (!relocationStorageId) {
|
||||
const relocationProductStockId = this.getRelocationProductStockId(storageItem) || this.getRelocationProductStockId(productItem);
|
||||
const sourceSpaceId = this.normalizePositiveId(
|
||||
storageItem.space_id || storageItem.space?.id || productItem.space_id || productItem.space?.id
|
||||
);
|
||||
|
||||
if (!isNonBatchMode && !relocationStorageId) {
|
||||
uni.showToast({
|
||||
title: '未获取到库存记录ID',
|
||||
icon: 'none'
|
||||
@ -1178,15 +1255,25 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNonBatchMode && (!sourceSpaceId || !relocationProductStockId)) {
|
||||
uni.showToast({
|
||||
title: '未获取到库位或商品ID',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const cacheKey = `relocation_prefill_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
uni.setStorageSync(cacheKey, {
|
||||
stock: {
|
||||
...productItem,
|
||||
...storageItem,
|
||||
relocation_storage_id: relocationStorageId
|
||||
relocation_storage_id: relocationStorageId,
|
||||
relocation_product_stock_id: relocationProductStockId,
|
||||
relocation_query_mode: this.queryMode
|
||||
},
|
||||
sourceSpace: {
|
||||
id: storageItem.space_id || storageItem.space?.id || null,
|
||||
id: sourceSpaceId || null,
|
||||
name: this.getStorageSpaceText(storageItem),
|
||||
code: this.getStorageSpaceCode(storageItem)
|
||||
},
|
||||
@ -1247,27 +1334,36 @@
|
||||
|
||||
const isBarcodeKeyword = this.isBarcodeLike(keyword);
|
||||
const queryParams = this.buildQueryParams(keyword);
|
||||
const listQueryParams = this.buildListQueryParams(keyword);
|
||||
let listQueryParams = null;
|
||||
console.log('[ProductQuery] 搜索参数:', queryParams);
|
||||
console.log('[ProductQuery] 列表参数:', listQueryParams);
|
||||
|
||||
this.loading = true;
|
||||
try {
|
||||
const [searchRes, listRes] = await Promise.all([
|
||||
this.$http('stock.warehouse.search', queryParams),
|
||||
this.$http('stock.warehouse.list', listQueryParams).catch(error => {
|
||||
console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error);
|
||||
return null;
|
||||
})
|
||||
]);
|
||||
const searchRes = await this.$http('stock.warehouse.search', queryParams);
|
||||
const warehouseRes = await this.$http('stock.warehouse.list', this.buildWarehouseListQueryParams(keyword)).catch(error => {
|
||||
console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error);
|
||||
return null;
|
||||
});
|
||||
|
||||
const searchOk = searchRes && searchRes.code === 200;
|
||||
const warehouseOk = warehouseRes && warehouseRes.code === 200;
|
||||
const nextList = searchOk ? this.extractListFromResponse(searchRes) : [];
|
||||
const warehouseList = warehouseOk ? this.extractListFromResponse(warehouseRes) : [];
|
||||
const stockIdList = this.extractStockIdList([].concat(nextList || [], warehouseList || []));
|
||||
listQueryParams = this.buildListQueryParams(stockIdList);
|
||||
console.log('[ProductQuery] 列表参数:', listQueryParams);
|
||||
|
||||
const listRes = stockIdList.length
|
||||
? await this.$http('storage.inventory.list', listQueryParams).catch(error => {
|
||||
console.warn('[ProductQuery] storage.inventory.list 调用失败:', error);
|
||||
return null;
|
||||
})
|
||||
: null;
|
||||
const listOk = listRes && listRes.code === 200;
|
||||
|
||||
if (searchOk || listOk) {
|
||||
const nextList = searchOk ? this.extractListFromResponse(searchRes) : [];
|
||||
if (searchOk || warehouseOk || listOk) {
|
||||
const detailList = listOk ? this.extractListFromResponse(listRes) : [];
|
||||
const mergedList = this.mergeProductResultLists(nextList, detailList);
|
||||
const mergedList = this.mergeProductResultLists(nextList, warehouseList, detailList);
|
||||
|
||||
this.rawList = mergedList;
|
||||
this.updateDisplayListByMode(mergedList, keyword, isBarcodeKeyword);
|
||||
@ -1278,7 +1374,7 @@
|
||||
this.list = [];
|
||||
console.log('[ProductQuery] 搜索失败响应:', searchRes || listRes);
|
||||
uni.showToast({
|
||||
title: (searchRes && searchRes.message) || (listRes && listRes.message) || '查询失败',
|
||||
title: (searchRes && searchRes.message) || (warehouseRes && warehouseRes.message) || (listRes && listRes.message) || '查询失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
@ -1693,15 +1789,15 @@
|
||||
}
|
||||
|
||||
.storage-table--batch .storage-col {
|
||||
font-size: 28rpx;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.storage-table--batch .storage-col--batch {
|
||||
flex: 0.78;
|
||||
flex: 0.62;
|
||||
}
|
||||
|
||||
.storage-table--batch .storage-col--space {
|
||||
flex: 0.82;
|
||||
flex: 0.68;
|
||||
}
|
||||
|
||||
.storage-table__row {
|
||||
@ -1718,7 +1814,7 @@
|
||||
}
|
||||
|
||||
.storage-table--batch .storage-table__row {
|
||||
grid-template-columns: minmax(0, 0.78fr) minmax(0, 0.82fr) minmax(0, 0.42fr) minmax(0, 0.42fr);
|
||||
grid-template-columns: minmax(0, 0.62fr) minmax(0, 0.68fr) minmax(0, 0.46fr) minmax(0, 0.46fr);
|
||||
}
|
||||
|
||||
.storage-table__row:last-child {
|
||||
@ -1757,7 +1853,7 @@
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
font-size: 33rpx;
|
||||
font-size: 35rpx;
|
||||
color: #606266;
|
||||
line-height: 1.2;
|
||||
padding: 8rpx 4rpx;
|
||||
|
||||
@ -1,34 +1,35 @@
|
||||
<template>
|
||||
<view class="relocation-page">
|
||||
<view class="normar_container">
|
||||
<page-nav title="移库作业"></page-nav>
|
||||
<page-nav title="移库作业">
|
||||
<template #right>
|
||||
<u-button
|
||||
class="nav-submit-btn"
|
||||
size="mini"
|
||||
type="primary"
|
||||
text="确认移库"
|
||||
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }"
|
||||
:loading="submitting"
|
||||
:disabled="submitting"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
<text class="nav-submit-btn__text">确认移库</text>
|
||||
</u-button>
|
||||
</template>
|
||||
</page-nav>
|
||||
|
||||
<scroll-view class="container" scroll-y>
|
||||
<u-form class="form-box" :model="formData" ref="formRef" label-width="170rpx">
|
||||
<view class="section">
|
||||
|
||||
<u-form-item label="移库模式" required>
|
||||
<u-radio-group v-model="formData.relocationMode" @change="handleModeChange">
|
||||
<u-radio v-for="item in relocationModeOptions" :key="item.value" :name="item.value" :label="item.label"></u-radio>
|
||||
</u-radio-group>
|
||||
</u-form-item>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">库位信息</view>
|
||||
|
||||
<u-form-item label="移出库位" required>
|
||||
<view class="scan-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.sourceSpaceKeyword"
|
||||
placeholder="请扫描或输入移出库位"
|
||||
clearable
|
||||
@focus="setActiveScanField('sourceSpace')"
|
||||
@blur="handleSpaceBlur('sourceSpace')"
|
||||
:value="formData.sourceSpaceKeyword || formData.sourceSpaceName"
|
||||
disabled
|
||||
placeholder="自动带出移出库位"
|
||||
/>
|
||||
<view class="scan-camera-btn" @click="handleFieldScan('sourceSpace')">
|
||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
|
||||
@ -46,35 +47,43 @@
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
|
||||
<u-form-item class="move-quantity-item" label="移库数量" required>
|
||||
<view class="quantity-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.moveQuantity"
|
||||
type="number"
|
||||
fontSize="36rpx"
|
||||
placeholder="请输入移库数量"
|
||||
@input="handleMoveQuantityInput"
|
||||
@blur="handleMoveQuantityBlur"
|
||||
></u-input>
|
||||
<view class="quantity-all-view-btn" @click="handleFillAllQuantity">
|
||||
<text>全部</text>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">商品信息</view>
|
||||
|
||||
<u-form-item v-if="formData.relocationMode === 'product'" label="商品/条码" required>
|
||||
<view class="scan-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.productKeyword"
|
||||
placeholder="请扫描商品条码或输入关键字"
|
||||
clearable
|
||||
@focus="setActiveScanField('productKeyword')"
|
||||
@blur="handleProductBlur"
|
||||
/>
|
||||
<view class="scan-camera-btn" @click="handleFieldScan('productKeyword')">
|
||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
|
||||
<view v-if="formData.relocationMode === 'product' && selectedStock" class="stock-card">
|
||||
<view v-if="selectedStock" class="stock-card">
|
||||
<view class="stock-card__header">
|
||||
<text class="stock-card__title">{{ getStockName(selectedStock) }}</text>
|
||||
<u-tag text="已选中" type="success" size="mini"></u-tag>
|
||||
</view>
|
||||
<view class="stock-card__row">
|
||||
<text class="label">货主:</text>
|
||||
<text class="value">{{ getStockOwnerText(selectedStock) }}</text>
|
||||
</view>
|
||||
<view class="stock-card__row">
|
||||
<text class="label">条码:</text>
|
||||
<text class="value">{{ getStockBarcode(selectedStock) }}</text>
|
||||
</view>
|
||||
<view v-if="shouldShowStockBatch(selectedStock)" class="stock-card__row">
|
||||
<text class="label">批次号:</text>
|
||||
<text class="value">{{ getStockBatchNumber(selectedStock) }}</text>
|
||||
</view>
|
||||
<view class="stock-card__row">
|
||||
<text class="label">当前库位:</text>
|
||||
<text class="value">{{ getStockSpace(selectedStock) }}</text>
|
||||
@ -85,37 +94,12 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<u-form-item v-if="formData.relocationMode === 'product'" label="移库数量" required>
|
||||
<view class="quantity-input-wrap">
|
||||
<u-input
|
||||
v-model="formData.moveQuantity"
|
||||
type="number"
|
||||
placeholder="请输入移库数量"
|
||||
@input="handleMoveQuantityInput"
|
||||
@blur="handleMoveQuantityBlur"
|
||||
></u-input>
|
||||
<view class="quantity-all-view-btn" @click="handleFillAllQuantity">
|
||||
<text>全部</text>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
|
||||
<view v-else class="mode-tip-card">
|
||||
<text class="mode-tip-card__title">按仓位移库</text>
|
||||
<text class="mode-tip-card__desc">当前模式下无需选择商品和数量,提交时默认按原库位整体移至目标库位。</text>
|
||||
</view>
|
||||
|
||||
<u-form-item label="备注">
|
||||
<u-input v-model="formData.remark" type="textarea" placeholder="请输入备注信息" height="120"></u-input>
|
||||
</u-form-item>
|
||||
</view>
|
||||
</u-form>
|
||||
</scroll-view>
|
||||
|
||||
<view class="submit-area">
|
||||
<u-button type="primary" :loading="submitting" @click="handleSubmit">确认移库</u-button>
|
||||
<u-button @click="handleReset">重置</u-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<u-popup :show="selectorVisible" mode="bottom" :closeable="true" border-radius="20" @close="selectorVisible = false">
|
||||
@ -155,17 +139,12 @@
|
||||
loading: false,
|
||||
submitting: false,
|
||||
activeScanField: 'productKeyword',
|
||||
relocationModeOptions: [
|
||||
{ label: '按商品', value: 'product' },
|
||||
{ label: '按仓位', value: 'space' }
|
||||
],
|
||||
selectorVisible: false,
|
||||
selectorType: '',
|
||||
selectorField: '',
|
||||
selectorList: [],
|
||||
selectedStock: null,
|
||||
formData: {
|
||||
relocationMode: 'product',
|
||||
sourceSpaceKeyword: '',
|
||||
sourceSpaceId: null,
|
||||
sourceSpaceName: '',
|
||||
@ -251,18 +230,6 @@
|
||||
setActiveScanField(field) {
|
||||
this.activeScanField = field;
|
||||
},
|
||||
handleModeChange(mode) {
|
||||
this.formData.relocationMode = mode;
|
||||
if (mode === 'space') {
|
||||
this.selectedStock = null;
|
||||
this.formData.productKeyword = '';
|
||||
this.formData.moveQuantity = '';
|
||||
this.activeScanField = 'sourceSpace';
|
||||
return;
|
||||
}
|
||||
|
||||
this.activeScanField = 'productKeyword';
|
||||
},
|
||||
handleBroadcastResult(result) {
|
||||
const rawCode = this.normalizeUniScanResult(result);
|
||||
if (!rawCode) {
|
||||
@ -438,7 +405,6 @@
|
||||
}
|
||||
|
||||
uni.removeStorageSync(cacheKey);
|
||||
this.formData.relocationMode = 'product';
|
||||
this.activeScanField = 'productKeyword';
|
||||
|
||||
if (prefillData.stock && typeof prefillData.stock === 'object') {
|
||||
@ -488,6 +454,54 @@
|
||||
}
|
||||
return item?.barcode || item?.goods_code || item?.item_code || '--';
|
||||
},
|
||||
getStockOwnerText(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return '--';
|
||||
}
|
||||
|
||||
const candidates = [
|
||||
item.owner_name,
|
||||
item.owner,
|
||||
item.ownerTitle,
|
||||
item.owner_title,
|
||||
item.store_remask,
|
||||
item['store.store_remask'],
|
||||
item['store_stock.store_remask'],
|
||||
item.store_stock && item.store_stock.store_remask,
|
||||
item.store && item.store.store_remask,
|
||||
item.store && item.store.name,
|
||||
item.store && item.store.store_name,
|
||||
item.store_name
|
||||
];
|
||||
|
||||
for (let i = 0; i < candidates.length; i++) {
|
||||
const value = candidates[i];
|
||||
if (value !== null && value !== undefined && String(value).trim()) {
|
||||
return String(value).trim();
|
||||
}
|
||||
}
|
||||
|
||||
return '--';
|
||||
},
|
||||
getStockBatchNumber(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return '--';
|
||||
}
|
||||
|
||||
return item.batch_no
|
||||
|| item.batch_number
|
||||
|| item.lot_no
|
||||
|| item.lot_number
|
||||
|| '--';
|
||||
},
|
||||
shouldShowStockBatch(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return false;
|
||||
}
|
||||
const isBatchMode = item.relocation_query_mode === 'batch';
|
||||
const batchText = this.getStockBatchNumber(item);
|
||||
return isBatchMode && batchText && batchText !== '--';
|
||||
},
|
||||
getStockSpace(item) {
|
||||
return item?.space?.name
|
||||
|| item?.space_name
|
||||
@ -511,14 +525,7 @@
|
||||
|
||||
const directCandidates = [
|
||||
item.relocation_storage_id,
|
||||
item.storage_id,
|
||||
item.inventory_id,
|
||||
item.stock_id,
|
||||
item.storage_record_id,
|
||||
item.stock_record_id,
|
||||
item.warehouse_storage_id,
|
||||
item.warehouse_stock_id,
|
||||
item.record_id
|
||||
item.id
|
||||
];
|
||||
|
||||
for (let i = 0; i < directCandidates.length; i++) {
|
||||
@ -528,17 +535,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackId = this.normalizePositiveId(item.id);
|
||||
if (!fallbackId) {
|
||||
return null;
|
||||
},
|
||||
getProductStockId(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const spaceId = this.normalizePositiveId(item.space_id || item.space?.id);
|
||||
if (spaceId && fallbackId === spaceId) {
|
||||
return null;
|
||||
const directCandidates = [
|
||||
item.relocation_product_stock_id,
|
||||
item.stock_id,
|
||||
item.goods_id,
|
||||
item.item_id,
|
||||
item.product_id,
|
||||
item.id
|
||||
];
|
||||
|
||||
for (let i = 0; i < directCandidates.length; i++) {
|
||||
const normalized = this.normalizePositiveId(directCandidates[i]);
|
||||
if (normalized) {
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
|
||||
return fallbackId;
|
||||
return null;
|
||||
},
|
||||
getAvailableStockNumber() {
|
||||
if (!this.selectedStock) {
|
||||
@ -565,10 +585,6 @@
|
||||
this.validateMoveQuantity(true);
|
||||
},
|
||||
validateMoveQuantity(showToast = false) {
|
||||
if (this.formData.relocationMode !== 'product') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const quantity = String(this.formData.moveQuantity || '').trim();
|
||||
if (!quantity) {
|
||||
if (showToast) {
|
||||
@ -623,15 +639,11 @@
|
||||
uni.showToast({ title: '请先识别移入库位', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (this.formData.relocationMode === 'product' && !this.selectedStock) {
|
||||
if (!this.selectedStock) {
|
||||
uni.showToast({ title: '请选择移库商品', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (this.formData.relocationMode !== 'product') {
|
||||
uni.showToast({ title: '当前仅支持按商品移库', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (this.formData.moveQuantity && !this.validateMoveQuantity(true)) {
|
||||
if (!this.validateMoveQuantity(true)) {
|
||||
return;
|
||||
}
|
||||
if (this.formData.sourceSpaceId && this.formData.targetSpaceId && this.formData.sourceSpaceId === this.formData.targetSpaceId) {
|
||||
@ -639,35 +651,60 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const storageId = this.getStockStorageId(this.selectedStock);
|
||||
if (!storageId) {
|
||||
uni.showToast({ title: '未获取到库存记录ID', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.formData.targetSpaceId) {
|
||||
uni.showToast({ title: '请先识别移入库位', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
storage_id: storageId,
|
||||
target_space_id: Number(this.formData.targetSpaceId)
|
||||
};
|
||||
|
||||
const quantity = String(this.formData.moveQuantity || '').trim();
|
||||
if (quantity) {
|
||||
payload.quantity = Number(quantity);
|
||||
const isNonBatchMode = this.selectedStock && this.selectedStock.relocation_query_mode === 'nonBatch';
|
||||
let apiName = 'storage.inventory.transferLocation';
|
||||
let payload = {};
|
||||
|
||||
if (isNonBatchMode) {
|
||||
const sourceSpaceId = this.normalizePositiveId(this.formData.sourceSpaceId);
|
||||
const productStockId = this.getProductStockId(this.selectedStock);
|
||||
if (!sourceSpaceId) {
|
||||
uni.showToast({ title: '请先识别移出库位', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!productStockId) {
|
||||
uni.showToast({ title: '未获取到商品ID', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
apiName = 'storage.inventory.transferByProduct';
|
||||
payload = {
|
||||
space_id: Number(sourceSpaceId),
|
||||
stock_id: Number(productStockId),
|
||||
target_space_id: Number(this.formData.targetSpaceId),
|
||||
quantity: Number(quantity)
|
||||
};
|
||||
} else {
|
||||
const storageId = this.getStockStorageId(this.selectedStock);
|
||||
if (!storageId) {
|
||||
uni.showToast({ title: '未获取到库存记录ID', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
payload = {
|
||||
storage_id: storageId,
|
||||
target_space_id: Number(this.formData.targetSpaceId)
|
||||
};
|
||||
if (quantity) {
|
||||
payload.quantity = Number(quantity);
|
||||
}
|
||||
}
|
||||
|
||||
this.submitting = true;
|
||||
try {
|
||||
const res = await this.$http('storage.inventory.transferLocation', payload);
|
||||
const res = await this.$http(apiName, payload);
|
||||
if (res && Number(res.code) === 200) {
|
||||
const storageId = this.getStockStorageId(this.selectedStock);
|
||||
uni.setStorageSync('product_query_need_refresh', Date.now());
|
||||
uni.$emit('storage:relocation:success', {
|
||||
timestamp: Date.now(),
|
||||
storageId: Number(storageId)
|
||||
storageId: storageId ? Number(storageId) : null
|
||||
});
|
||||
uni.showToast({
|
||||
title: res.message || '移库成功',
|
||||
@ -703,7 +740,6 @@
|
||||
},
|
||||
handleReset() {
|
||||
this.formData = {
|
||||
relocationMode: 'product',
|
||||
sourceSpaceKeyword: '',
|
||||
sourceSpaceId: null,
|
||||
sourceSpaceName: '',
|
||||
@ -731,6 +767,31 @@
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
::v-deep .nav-title .right {
|
||||
width: auto;
|
||||
min-width: 140rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
::v-deep .nav-submit-btn {
|
||||
height: 64rpx;
|
||||
padding: 0 18rpx;
|
||||
}
|
||||
|
||||
.nav-submit-btn__text {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
::v-deep .nav-submit-btn .u-button__text {
|
||||
font-size: 30rpx !important;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.container {
|
||||
flex: 1;
|
||||
height: 100rpx;
|
||||
@ -778,6 +839,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
.move-quantity-item {
|
||||
::v-deep .u-form-item__body__left__content__label,
|
||||
::v-deep .u-form-item__body__left__content__label-text {
|
||||
font-size: 36rpx !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
::v-deep .u-input__content__field-wrapper__field {
|
||||
font-size: 36rpx !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
::v-deep .u-input__content {
|
||||
min-height: 76rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.quantity-all-view-btn {
|
||||
width: 76rpx;
|
||||
height: 76rpx;
|
||||
@ -824,29 +902,6 @@
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.mode-tip-card {
|
||||
margin: 10rpx 0 24rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #f6fdf8;
|
||||
border: 1rpx solid #d7f0df;
|
||||
|
||||
&__title {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #2e7d32;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
&__desc {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
color: #606266;
|
||||
}
|
||||
}
|
||||
|
||||
.stock-card {
|
||||
margin: 10rpx 0 24rpx;
|
||||
padding: 24rpx;
|
||||
@ -888,15 +943,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.submit-area {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding: 20rpx;
|
||||
gap: 20rpx;
|
||||
border-top: 1px solid rgba(0, 0, 0, .08);
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.selector-popup {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user