fix: 修复绿植租赁可选多次相同产品bug

This commit is contained in:
fyy
2025-07-15 16:45:51 +08:00
parent e590eaf58d
commit b6ea9bc5bb
2 changed files with 31 additions and 9 deletions

View File

@@ -26,6 +26,9 @@ const title = computed(() => {
let plantListData: any[] = []; let plantListData: any[] = [];
const detailIndex = ref<number>();//传index对应详情的某条数据,对该条数据进行编辑修改 const detailIndex = ref<number>();//传index对应详情的某条数据,对该条数据进行编辑修改
// 新增接收已选产品id
const selectedIds = ref<any[]>([]);
// 添加数量最大值 // 添加数量最大值
const productNumMax = ref<any>(0); const productNumMax = ref<any>(0);
@@ -39,7 +42,9 @@ const detailSchema = [
api: async () => { api: async () => {
const res = await plantsProductList({state:1,inventory:0}); const res = await plantsProductList({state:1,inventory:0});
plantListData = res.rows || []; plantListData = res.rows || [];
return res; // 过滤掉已选产品
const filtered = plantListData.filter(item => !selectedIds.value.includes(item.id));
return { ...res, rows: filtered };
}, },
resultField: 'rows', resultField: 'rows',
labelField: 'plantName', labelField: 'plantName',
@@ -82,6 +87,7 @@ const detailSchema = [
componentProps: { componentProps: {
min: 1, min: 1,
max: productNumMax, max: productNumMax,
disabled: isView,
}, },
rules: 'required', rules: 'required',
}, },
@@ -197,19 +203,25 @@ const [BasicModal, modalApi] = useVbenModal({
} }
modalApi.modalLoading(true); modalApi.modalLoading(true);
const data = modalApi.getData(); const data = modalApi.getData();
detailIndex.value = modalApi.getData().index; console.log(data);
if(!data || Object.keys(data).length === 0){
//modalApi.getData()为空时表示添加 detailIndex.value = data.index;
isAdd.value = true; // 新增:弹窗打开时同步 selectedIds
}else if(data.readonly){ selectedIds.value = data.selectedIds || [];
if(data.readonly){
//不存在detailIndex.value时表示查看 //不存在detailIndex.value时表示查看
isView.value = true; isView.value = true;
} else if(data.add){
//modalApi.getData()为空时表示添加
isAdd.value = true;
console.log(123);
}else{ }else{
//表示编辑 //表示编辑
isUpdate.value = true; isUpdate.value = true;
} }
// TODO: 获取详情数据 // TODO: 获取详情数据
await formApi.setValues(modalApi.getData()); await formApi.setValues(data);
await markInitialized(); await markInitialized();
modalApi.modalLoading(false); modalApi.modalLoading(false);
}, },
@@ -223,6 +235,8 @@ async function handleConfirm() {
return; return;
} }
const data = cloneDeep(await formApi.getValues()); const data = cloneDeep(await formApi.getValues());
console.log(data);
// 获取选中的产品 // 获取选中的产品
const selectedService = plantListData.find(item => item.id === data.plantName); const selectedService = plantListData.find(item => item.id === data.plantName);
if (selectedService) { if (selectedService) {
@@ -231,8 +245,12 @@ async function handleConfirm() {
} }
if (isUpdate.value) { if (isUpdate.value) {
data.index = detailIndex.value; data.index = detailIndex.value;
console.log(data);
emit('editReload', data); emit('editReload', data);
}else if(isAdd.value){ }else if(isAdd.value){
console.log(12);
emit('reload', data); emit('reload', data);
} }
handleClosed() handleClosed()

View File

@@ -146,7 +146,9 @@ const detailColumns = [
}, },
]; ];
function handleAddDetail() { function handleAddDetail() {
detailModalApi.setData({}); // 传递已选产品id列表
const selectedIds = detailTable.value.map((item: any) => item.productId || item.plantName);
detailModalApi.setData({ selectedIds,add:true });
detailModalApi.open(); detailModalApi.open();
} }
//添加植物组合包产品 //添加植物组合包产品
@@ -169,7 +171,9 @@ function handleViewDetail(record: any) {
} }
// 编辑产品详情 // 编辑产品详情
function handleEditDetail(record: any, index: number) { function handleEditDetail(record: any, index: number) {
detailModalApi.setData({ ...record, index, readonly: false }); // 编辑时排除当前项id
const selectedIds = detailTable.value.filter((_: any, i: number) => i !== index).map((item: any) => item.productId || item.plantName);
detailModalApi.setData({ ...record, index, selectedIds,edit:true });
detailModalApi.open(); detailModalApi.open();
} }
//分类字典 //分类字典