From 29e0d17d6008ce8f5728f9ec25c9bf20e6be7a21 Mon Sep 17 00:00:00 2001 From: hwj Date: Thu, 9 Jul 2026 09:36:46 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E5=BA=93=E5=AD=98=E8=B0=83?= =?UTF-8?q?=E6=8B=A8-=E4=BA=A7=E5=93=81/=E7=89=A9=E6=96=99/=E5=A4=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E6=8B=89=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=9F=A5=E8=AF=A2=E9=87=8C=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../move/components/StockMoveItemForm.vue | 135 ++++++++++++++---- 1 file changed, 109 insertions(+), 26 deletions(-) diff --git a/src/views/erp/stock/move/components/StockMoveItemForm.vue b/src/views/erp/stock/move/components/StockMoveItemForm.vue index 24aad8f7..aa501f8c 100644 --- a/src/views/erp/stock/move/components/StockMoveItemForm.vue +++ b/src/views/erp/stock/move/components/StockMoveItemForm.vue @@ -51,7 +51,11 @@ @@ -166,7 +175,12 @@ + 添加调拨产品 - + - + +
@@ -229,6 +252,7 @@ import { ProductApi } from '@/api/erp/product/product' import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse' import { StockMoveApi } from '@/api/erp/stock/move' +import { StockApi } from '@/api/erp/stock/stock' import { erpCountInputFormatter, getSumValue } from '@/utils' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' @@ -245,17 +269,31 @@ const formData = ref([]) const sameAreaMessage = '调出库区和调入库区不能相同' const formRules = reactive({ inId: [{ required: true, message: '调度编号不能为空', trigger: 'submit' }], - fromWarehouseId: [{ required: true, message: t('ErpStock.Move.item.validatorFromWarehouseRequired'), trigger: 'submit' }], + fromWarehouseId: [ + { + required: true, + message: t('ErpStock.Move.item.validatorFromWarehouseRequired'), + trigger: 'submit' + } + ], fromAreaId: [ { required: true, message: t('ErpStock.Item.validatorAreaRequired'), trigger: 'submit' }, { validator: validateDifferentArea, trigger: ['change', 'submit'] } ], - toWarehouseId: [{ required: true, message: t('ErpStock.Move.item.validatorToWarehouseRequired'), trigger: 'submit' }], + toWarehouseId: [ + { + required: true, + message: t('ErpStock.Move.item.validatorToWarehouseRequired'), + trigger: 'submit' + } + ], toAreaId: [ { required: true, message: t('ErpStock.Item.validatorAreaRequired'), trigger: 'submit' }, { validator: validateDifferentArea, trigger: ['change', 'submit'] } ], - productId: [{ required: true, message: t('ErpStock.Item.validatorProductRequired'), trigger: 'submit' }], + productId: [ + { required: true, message: t('ErpStock.Item.validatorProductRequired'), trigger: 'submit' } + ], count: [ { required: true, message: t('ErpStock.Item.validatorCountRequired'), trigger: 'submit' }, { validator: validateStockMoveCount, trigger: ['change', 'submit'] } @@ -269,11 +307,12 @@ const productDialogVisible = ref(false) const productDialogLoading = ref(false) const productDialogList = ref([]) const productDialogTotal = ref(0) -const selectedProductId = ref() +const selectedProductId = ref() const productQueryParams = reactive({ pageNo: 1, pageSize: 10, categoryType: undefined as number | undefined, + stockNotZero: true, barCode: undefined as string | undefined, name: undefined as string | undefined }) @@ -319,7 +358,9 @@ function getSummaries(param: SummaryMethodProps) { return } if (column.property === 'count') { - sums[index] = erpCountInputFormatter(getSumValue(data.map((item) => Number(item[column.property])))) + sums[index] = erpCountInputFormatter( + getSumValue(data.map((item) => Number(item[column.property]))) + ) } else { sums[index] = '' } @@ -359,7 +400,11 @@ function handleDelete(index) { } function isSameMoveArea(row) { - return row.fromAreaId !== undefined && row.toAreaId !== undefined && String(row.fromAreaId) === String(row.toAreaId) + return ( + row.fromAreaId !== undefined && + row.toAreaId !== undefined && + String(row.fromAreaId) === String(row.toAreaId) + ) } function validateDifferentArea(rule, _value, callback) { @@ -427,7 +472,9 @@ function warnIfSameArea(row) { function validateAreaFields(row) { const rowIndex = formData.value.indexOf(row) if (rowIndex < 0) return - formRef.value?.validateField([`${rowIndex}.fromAreaId`, `${rowIndex}.toAreaId`]).catch(() => undefined) + formRef.value + ?.validateField([`${rowIndex}.fromAreaId`, `${rowIndex}.toAreaId`]) + .catch(() => undefined) } async function handleFromAreaChange(row) { @@ -491,8 +538,9 @@ async function getProductDialogList() { productDialogLoading.value = true try { productQueryParams.categoryType = props.categoryType - const data = await ProductApi.getProductPage(productQueryParams) - productDialogList.value = data?.list || [] + productQueryParams.stockNotZero = true + const data = await StockApi.getStockPage(productQueryParams) + productDialogList.value = normalizeStockProductOptions(data?.list || []) productDialogTotal.value = data?.total || 0 } finally { productDialogLoading.value = false @@ -505,12 +553,14 @@ function handleProductDialogQuery() { } function handleProductDialogRowClick(row: any) { - selectedProductId.value = row.id + selectedProductId.value = getProductOptionId(row) } async function confirmProductSelect() { if (props.disabled) return - const product = productDialogList.value.find((item) => item.id === selectedProductId.value) + const product = productDialogList.value.find( + (item) => String(getProductOptionId(item)) === String(selectedProductId.value) + ) if (!product || !currentSelectRow.value) return fillRowByProduct(currentSelectRow.value, product) await loadProductStockList(currentSelectRow.value) @@ -518,11 +568,11 @@ async function confirmProductSelect() { } function fillRowByProduct(row, product) { - row.productId = product.id - row.productName = product.name - row.productUnitName = product.unitName + row.productId = getProductOptionId(product) + row.productName = product.name || product.productName + row.productUnitName = product.unitName || product.purchaseUnitName row.purchaseUnitName = product.purchaseUnitName - row.unitName = product.unitName + row.unitName = product.unitName || product.purchaseUnitName row.productBarCode = product.barCode row.fromWarehouseId = undefined row.fromAreaId = undefined @@ -564,6 +614,33 @@ async function loadOptions() { } } +function getProductOptionId(item) { + return item?.productId ?? item?.id +} + +function getProductOptionRowKey(row) { + return [getProductOptionId(row), row.warehouseId, row.areaId, row.stockId || row.id] + .filter((item) => item !== undefined && item !== null && item !== '') + .join('-') +} + +function normalizeStockProductOptions(list) { + return (list || []) + .map((item) => { + const productId = getProductOptionId(item) + return { + ...item, + id: productId, + productId, + name: item.name || item.productName, + unitName: item.unitName || item.purchaseUnitName, + subCategoryName: item.subCategoryName || item.categoryName, + stockDisplay: item.stockDisplay || item.totalBaseCount || item.count || item.stockCount + } + }) + .filter((item) => item.productId) +} + function normalizeProductStockList(data) { if (Array.isArray(data)) return data if (Array.isArray(data?.list)) return data.list @@ -597,7 +674,9 @@ async function fillProductStockAreaInfo(stockList) { stockList .filter((item) => Number(getStockWarehouseId(item)) === Number(warehouseId)) .forEach((item) => { - const area = areaList.find((areaItem) => Number(areaItem.id) === Number(getStockAreaId(item))) + const area = areaList.find( + (areaItem) => Number(areaItem.id) === Number(getStockAreaId(item)) + ) if (!area) return item.areaCode = area.areaCode item.areaName = area.areaName @@ -624,7 +703,9 @@ function getFromWarehouseOptions(row) { return appendOptionIfMissing( Array.from(warehouseMap.values()), row.fromWarehouseId, - row.fromWarehouseName ? { warehouseId: row.fromWarehouseId, warehouseName: row.fromWarehouseName } : undefined, + row.fromWarehouseName + ? { warehouseId: row.fromWarehouseId, warehouseName: row.fromWarehouseName } + : undefined, getStockWarehouseId ) } @@ -668,9 +749,11 @@ function getToWarehouseOptions(row) { } function getToAreaOptions(row) { - const areaOptions = Array.isArray(row.toAreaList) && row.toAreaList.length > 0 - ? row.toAreaList - : warehouseList.value.find((item) => Number(item.id) === Number(row.toWarehouseId))?.areaList || [] + const areaOptions = + Array.isArray(row.toAreaList) && row.toAreaList.length > 0 + ? row.toAreaList + : warehouseList.value.find((item) => Number(item.id) === Number(row.toWarehouseId)) + ?.areaList || [] return appendOptionIfMissing( areaOptions, row.toAreaId,