From a241b66efcc41e973290a6722fb7a4d79b833ea1 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 13 十月 2026 09:54:32 +0800
Subject: [PATCH] feat(bi): 为图表配置接口添加名称字段
---
src/views/erp/sale/return/modules/item-form.vue | 92 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 85 insertions(+), 7 deletions(-)
diff --git a/src/views/erp/sale/return/modules/item-form.vue b/src/views/erp/sale/return/modules/item-form.vue
index e927e43..1664f09 100644
--- a/src/views/erp/sale/return/modules/item-form.vue
+++ b/src/views/erp/sale/return/modules/item-form.vue
@@ -1,4 +1,6 @@
<script lang="ts" setup>
+import type { MdmItemApi } from '#/api/mdm/item';
+import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
import type { ErpSaleReturnApi } from '#/api/erp/sale/return';
import { computed, nextTick, onMounted, ref, watch } from 'vue';
@@ -7,14 +9,14 @@
erpCountInputFormatter,
erpPriceInputFormatter,
erpPriceMultiply,
-} from '../../../../../packages/utils/src';
+} from '@vben/utils';
import { Input, InputNumber, Select } from 'ant-design-vue';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
-import { getProductSimpleList } from '#/api/erp/product/product';
import { getWarehouseStockCount } from '#/api/erp/stock/stock';
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
+import { MdmItemSelect } from '#/views/basicData/mdm/components';
import { useFormItemColumns } from '../data';
@@ -23,6 +25,7 @@
disabled?: boolean;
discountPercent?: number;
otherPrice?: number;
+ orderItems?: ErpSaleOrderApi.SaleOrderItem[];
}
const props = withDefaults(defineProps<Props>(), {
@@ -30,6 +33,7 @@
disabled: false,
discountPercent: 0,
otherPrice: 0,
+ orderItems: () => [],
});
const emit = defineEmits([
@@ -40,7 +44,6 @@
]);
const tableData = ref<ErpSaleReturnApi.SaleReturnItem[]>([]); // 琛ㄦ牸鏁版嵁
-const productOptions = ref<any[]>([]); // 浜у搧涓嬫媺閫夐」
const warehouseOptions = ref<any[]>([]); // 浠撳簱涓嬫媺閫夐」
/** 鑾峰彇琛ㄦ牸鍚堣鏁版嵁 */
@@ -140,6 +143,58 @@
emit('update:items', [...tableData.value]);
}
+/** 澶勭悊鏂板鐗╂枡琛� */
+function handleAdd() {
+ const newRow: ErpSaleReturnApi.SaleReturnItem = {
+ seq: Date.now(),
+ productId: undefined,
+ productName: '',
+ productPrice: 0,
+ productUnitId: undefined,
+ productUnitName: '',
+ count: 0,
+ totalProductPrice: 0,
+ taxPercent: 0,
+ taxPrice: 0,
+ totalPrice: 0,
+ remark: '',
+ };
+ tableData.value.push(newRow);
+ emit('update:items', [...tableData.value]);
+}
+
+/** 澶勭悊浜у搧鍙樻洿锛氫紭鍏堜粠鍏宠仈璁㈠崟鐗╂枡涓~鍏咃紝鍏滃簳浣跨敤寮规閫変腑鐨勭墿鏂� */
+function handleProductChange(
+ row: ErpSaleReturnApi.SaleReturnItem,
+ item?: MdmItemApi.Item,
+) {
+ // 浼樺厛浠庡叧鑱旇鍗曠殑鐗╂枡涓煡鎵�
+ const orderItem = props.orderItems.find(
+ (order) => order.productId === row.productId,
+ );
+ if (orderItem) {
+ row.productName = orderItem.productName;
+ row.productPrice = orderItem.productPrice ?? 0;
+ row.productUnitId = orderItem.productUnitId;
+ row.productUnitName = orderItem.productUnitName;
+ row.productBarCode = orderItem.productBarCode;
+ row.taxPercent = orderItem.taxPercent ?? 0;
+ row.count = row.count || 1;
+ handleRowChange(row);
+ return;
+ }
+ if (item) {
+ row.productName = item.name || '';
+ row.productPrice = item.salesPrice ?? 0;
+ row.productUnitId = item.unitMeasureId;
+ row.productUnitName = item.unitMeasureName;
+ row.productBarCode = item.barCode;
+ row.taxPercent = 0;
+ row.count = row.count || 1;
+ handleRowChange(row);
+ }
+}
+
/** 澶勭悊浠撳簱鍙樻洿 */
async function handleWarehouseChange(row: ErpSaleReturnApi.SaleReturnItem) {
const stockCount = await getWarehouseStockCount({
@@ -176,6 +231,9 @@
for (let i = 0; i < tableData.value.length; i++) {
const item = tableData.value[i];
if (item) {
+ if (!item.productId) {
+ throw new Error(`绗� ${i + 1} 琛岋細浜у搧涓嶈兘涓虹┖`);
+ }
if (!item.warehouseId) {
throw new Error(`绗� ${i + 1} 琛岋細浠撳簱涓嶈兘涓虹┖`);
}
@@ -192,7 +250,6 @@
/** 鍒濆鍖� */
onMounted(async () => {
- productOptions.value = await getProductSimpleList();
warehouseOptions.value = await getWarehouseSimpleList();
});
</script>
@@ -213,13 +270,23 @@
</template>
<template #productId="{ row }">
<Select
- disabled
+ v-if="orderItems?.length"
+ :disabled="disabled"
v-model:value="row.productId"
- :options="productOptions"
- :field-names="{ label: 'name', value: 'id' }"
+ :options="orderItems"
+ :field-names="{ label: 'productName', value: 'productId' }"
class="w-full"
placeholder="璇烽�夋嫨浜у搧"
show-search
+ @change="handleProductChange(row)"
+ />
+ <MdmItemSelect
+ v-else
+ v-model:model-value="row.productId"
+ :label="row.productName"
+ :disabled="disabled"
+ placeholder="璇烽�夋嫨浜у搧"
+ @change="(item) => handleProductChange(row, item)"
/>
</template>
<template #count="{ row }">
@@ -289,6 +356,17 @@
</div>
</div>
</div>
+ <TableAction
+ v-if="!disabled"
+ class="mt-2 flex justify-center"
+ :actions="[
+ {
+ label: '娣诲姞閫�璐т骇鍝�',
+ type: 'default',
+ onClick: handleAdd,
+ },
+ ]"
+ />
</template>
</Grid>
</template>
--
Gitblit v1.9.3