fix: 修复绿植租赁可选多次相同产品bug
This commit is contained in:
parent
e590eaf58d
commit
b6ea9bc5bb
@ -26,6 +26,9 @@ const title = computed(() => {
|
||||
let plantListData: any[] = [];
|
||||
const detailIndex = ref<number>();//传index对应详情的某条数据,对该条数据进行编辑修改
|
||||
|
||||
// 新增:接收已选产品id
|
||||
const selectedIds = ref<any[]>([]);
|
||||
|
||||
// 添加数量最大值
|
||||
const productNumMax = ref<any>(0);
|
||||
|
||||
@ -39,7 +42,9 @@ const detailSchema = [
|
||||
api: async () => {
|
||||
const res = await plantsProductList({state:1,inventory:0});
|
||||
plantListData = res.rows || [];
|
||||
return res;
|
||||
// 过滤掉已选产品
|
||||
const filtered = plantListData.filter(item => !selectedIds.value.includes(item.id));
|
||||
return { ...res, rows: filtered };
|
||||
},
|
||||
resultField: 'rows',
|
||||
labelField: 'plantName',
|
||||
@ -82,6 +87,7 @@ const detailSchema = [
|
||||
componentProps: {
|
||||
min: 1,
|
||||
max: productNumMax,
|
||||
disabled: isView,
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
@ -197,19 +203,25 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
}
|
||||
modalApi.modalLoading(true);
|
||||
const data = modalApi.getData();
|
||||
detailIndex.value = modalApi.getData().index;
|
||||
if(!data || Object.keys(data).length === 0){
|
||||
//modalApi.getData()为空时表示添加
|
||||
isAdd.value = true;
|
||||
}else if(data.readonly){
|
||||
console.log(data);
|
||||
|
||||
detailIndex.value = data.index;
|
||||
// 新增:弹窗打开时同步 selectedIds
|
||||
selectedIds.value = data.selectedIds || [];
|
||||
if(data.readonly){
|
||||
//不存在detailIndex.value时表示查看
|
||||
isView.value = true;
|
||||
} else if(data.add){
|
||||
//modalApi.getData()为空时表示添加
|
||||
isAdd.value = true;
|
||||
console.log(123);
|
||||
|
||||
}else{
|
||||
//表示编辑
|
||||
isUpdate.value = true;
|
||||
}
|
||||
// TODO: 获取详情数据
|
||||
await formApi.setValues(modalApi.getData());
|
||||
await formApi.setValues(data);
|
||||
await markInitialized();
|
||||
modalApi.modalLoading(false);
|
||||
},
|
||||
@ -223,6 +235,8 @@ async function handleConfirm() {
|
||||
return;
|
||||
}
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
console.log(data);
|
||||
|
||||
// 获取选中的产品
|
||||
const selectedService = plantListData.find(item => item.id === data.plantName);
|
||||
if (selectedService) {
|
||||
@ -231,8 +245,12 @@ async function handleConfirm() {
|
||||
}
|
||||
if (isUpdate.value) {
|
||||
data.index = detailIndex.value;
|
||||
console.log(data);
|
||||
|
||||
emit('editReload', data);
|
||||
}else if(isAdd.value){
|
||||
console.log(12);
|
||||
|
||||
emit('reload', data);
|
||||
}
|
||||
handleClosed()
|
||||
|
@ -146,7 +146,9 @@ const detailColumns = [
|
||||
},
|
||||
];
|
||||
function handleAddDetail() {
|
||||
detailModalApi.setData({});
|
||||
// 传递已选产品id列表
|
||||
const selectedIds = detailTable.value.map((item: any) => item.productId || item.plantName);
|
||||
detailModalApi.setData({ selectedIds,add:true });
|
||||
detailModalApi.open();
|
||||
}
|
||||
//添加植物组合包产品
|
||||
@ -169,7 +171,9 @@ function handleViewDetail(record: any) {
|
||||
}
|
||||
// 编辑产品详情
|
||||
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();
|
||||
}
|
||||
//分类字典
|
||||
|
Loading…
Reference in New Issue
Block a user