diff --git a/src/views/expense-management/share-detail/add.vue b/src/views/expense-management/share-detail/add.vue index 3253efb..9e56200 100644 --- a/src/views/expense-management/share-detail/add.vue +++ b/src/views/expense-management/share-detail/add.vue @@ -386,7 +386,47 @@ const handleSubmit = (instance) => { apportionmentMonth: formData.value.apportionmentMonth, usrAllocations: formData.value.tableData, } - console.log('params', params, formData.value.tableData) + console.log('params', params.usrAllocations, formData.value.tableData) + const resultMap = params.usrAllocations.reduce((acc, item) => { + if (!acc[item.researchPersonnelId]) { + acc[item.researchPersonnelId] = []; + } + acc[item.researchPersonnelId].push(item); + return acc; + }, {}); + const exceedList = []; + + Object.entries(resultMap).forEach(([id, items]) => { + const totalDuration = items.reduce((sum, item) => sum + (item.researchDuration || 0), 0); + const preciseTotalDuration = parseFloat(totalDuration.toFixed(2)); + + if (preciseTotalDuration > 21.75) { + // 收集超出的研发人员ID及总工时 + exceedList.push({ id, totalDuration: preciseTotalDuration }); + } + }); +// 从 resultMap 中获取 researchPersonnel + const exceedResearchPersonnel = exceedList.map(item => { + const id = item.id; + const personnelItems = resultMap[id]; + // 获取第一个对象中的 researchPersonnel(假设所有对象的 researchPersonnel 相同) + const researchPersonnel = personnelItems[0].researchPersonnel; + return { id, researchPersonnel, totalDuration: item.totalDuration }; + }); + + console.log('超过21.75的研发人员:', exceedResearchPersonnel); + + if (exceedResearchPersonnel.length > 0) { + console.log('以下研发人员的总研发工时超过21.75天:', exceedResearchPersonnel); + + ElNotification({ + title: '提示', + message: `以下研发人员的总研发工时超过21.75天:${exceedResearchPersonnel.map(e => e.researchPersonnel).join(',')}`, + type: 'warning' + }); + } +// 调用函数 + console.log('是大V',resultMap) const {code, msg} = await addShare(params) ElNotification({ title: '提示',