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();
} }
// //