From a26088a75637ea7c3d5aaa70f4b0ff6e3343a4b4 Mon Sep 17 00:00:00 2001 From: dj <1042039504@qq.com> Date: Mon, 4 Aug 2025 10:02:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(expense-management):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=90=8D=E7=A7=B0=E8=BF=9C=E7=A8=8B=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在项目需求概览页面添加主项目列表缓存到本地存储 -重构费用管理模块中项目名称远程搜索方法,提高代码复用性 - 优化主项目和子项目名称的加载和搜索逻辑 --- .../expense-management/cost-detail/index.vue | 67 +++++++++++-------- .../expend-detail/index.vue | 65 ++++++++++-------- .../expense-management/share-detail/index.vue | 67 +++++++++++-------- src/views/project-demand/summary/add.vue | 5 ++ 4 files changed, 119 insertions(+), 85 deletions(-) diff --git a/src/views/expense-management/cost-detail/index.vue b/src/views/expense-management/cost-detail/index.vue index f44ed49..aa5ef68 100644 --- a/src/views/expense-management/cost-detail/index.vue +++ b/src/views/expense-management/cost-detail/index.vue @@ -38,20 +38,8 @@ const searchConfig = ref([ remoteMethod:async (val)=>{ console.log('val',val) if(val){ - const res=await getExpenseMasterProjectNameOption(val) - if(res.code==1000){ - let optionObj={} - let optionsMap = new Map(); - res.data.forEach(item=>{ - optionObj={ - value:item.label, - label:item.label - } - optionsMap.set(optionObj.value, optionObj); - }) - // 将 Map 转换为数组 - searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values()) - } + await getMasterProjectName( val) + } } }, @@ -68,20 +56,7 @@ const searchConfig = ref([ remote: true, remoteMethod:async (val)=>{ if(val){ - const res=await getExpenseSubprojectNameOption(val) - if(res.code==1000){ - let optionObj={} - let optionsMap = new Map(); - res.data.forEach(item=>{ - optionObj={ - value:item.label, - label:item.label - } - optionsMap.set(optionObj.value, optionObj); - }) - // 将 Map 转换为数组 - searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values()) - } + await getSubprojectName(val) } } }, @@ -247,6 +222,42 @@ const tableConfig = reactive({ fileName:`研发费用明细表` } }) + +const getMasterProjectName =async (val) => { + const res=await getExpenseMasterProjectNameOption(val) + if(res.code==1000){ + let optionObj={} + let optionsMap = new Map(); + res.data.forEach(item=>{ + optionObj={ + value:item.label, + label:item.label + } + optionsMap.set(optionObj.value, optionObj); + }) + // 将 Map 转换为数组 + searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values()) + } +} +const getSubprojectName =async (val) => { + const res=await getExpenseSubprojectNameOption(val) + if(res.code==1000){ + let optionObj={} + let optionsMap = new Map(); + res.data.forEach(item=>{ + optionObj={ + value:item.label, + label:item.label + } + optionsMap.set(optionObj.value, optionObj); + }) + // 将 Map 转换为数组 + searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values()) + } +} +getMasterProjectName() +getSubprojectName() + const search = (val) => { tableConfig.params = {...val} tableIns.value.refresh() diff --git a/src/views/expense-management/expend-detail/index.vue b/src/views/expense-management/expend-detail/index.vue index 65aaf97..2d8005e 100644 --- a/src/views/expense-management/expend-detail/index.vue +++ b/src/views/expense-management/expend-detail/index.vue @@ -34,20 +34,7 @@ const searchConfig = ref( remoteMethod:async (val)=>{ console.log('val',val) if(val){ - const res=await getMasterProjectNameOption(val) - if(res.code==1000){ - let optionObj={} - let optionsMap = new Map(); - res.data.forEach(item=>{ - optionObj={ - value:item.label, - label:item.label - } - optionsMap.set(optionObj.value, optionObj); - }) - // 将 Map 转换为数组 - searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values()) - } + await getMasterProjectName( val) } } }, @@ -64,20 +51,7 @@ const searchConfig = ref( remote: true, remoteMethod:async (val)=>{ if(val){ - const res=await getSubprojectNameOption(val) - if(res.code==1000){ - let optionObj={} - let optionsMap = new Map(); - res.data.forEach(item=>{ - optionObj={ - value:item.label, - label:item.label - } - optionsMap.set(optionObj.value, optionObj); - }) - // 将 Map 转换为数组 - searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values()) - } + await getSubprojectName(val) } } }, @@ -242,6 +216,41 @@ const tableConfig = reactive({ fileName:`科研项日现金支出明细表` } }) + +const getMasterProjectName =async (val) => { + const res=await getMasterProjectNameOption(val) + if(res.code==1000){ + let optionObj={} + let optionsMap = new Map(); + res.data.forEach(item=>{ + optionObj={ + value:item.label, + label:item.label + } + optionsMap.set(optionObj.value, optionObj); + }) + // 将 Map 转换为数组 + searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values()) + } +} +const getSubprojectName =async (val) => { + const res=await getSubprojectNameOption(val) + if(res.code==1000){ + let optionObj={} + let optionsMap = new Map(); + res.data.forEach(item=>{ + optionObj={ + value:item.label, + label:item.label + } + optionsMap.set(optionObj.value, optionObj); + }) + // 将 Map 转换为数组 + searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values()) + } +} +getMasterProjectName() +getSubprojectName() const search = (val) => { tableConfig.params = {...val} tableIns.value.refresh() diff --git a/src/views/expense-management/share-detail/index.vue b/src/views/expense-management/share-detail/index.vue index 1c7b58c..f3e8a84 100644 --- a/src/views/expense-management/share-detail/index.vue +++ b/src/views/expense-management/share-detail/index.vue @@ -38,20 +38,8 @@ const searchConfig = ref([ remoteMethod:async (val)=>{ console.log('val',val) if(val){ - const res=await getCostMasterProjectNameOption(val) - if(res.code==1000){ - let optionObj={} - let optionsMap = new Map(); - res.data.forEach(item=>{ - optionObj={ - value:item.label, - label:item.label - } - optionsMap.set(optionObj.value, optionObj); - }) - // 将 Map 转换为数组 - searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values()) - } + + await getMasterProjectName( val) } } }, @@ -68,20 +56,8 @@ const searchConfig = ref([ remote: true, remoteMethod:async (val)=>{ if(val){ - const res=await getCostSubprojectNameOption(val) - if(res.code==1000){ - let optionObj={} - let optionsMap = new Map(); - res.data.forEach(item=>{ - optionObj={ - value:item.label, - label:item.label - } - optionsMap.set(optionObj.value, optionObj); - }) - // 将 Map 转换为数组 - searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values()) - } + await getSubprojectName(val) + } } }, @@ -202,7 +178,40 @@ const tableConfig = reactive({ open :false, } }) - +const getMasterProjectName =async (val) => { + const res=await getCostMasterProjectNameOption(val) + if(res.code==1000){ + let optionObj={} + let optionsMap = new Map(); + res.data.forEach(item=>{ + optionObj={ + value:item.label, + label:item.label + } + optionsMap.set(optionObj.value, optionObj); + }) + // 将 Map 转换为数组 + searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values()) + } +} +const getSubprojectName =async (val) => { + const res=await getCostSubprojectNameOption(val) + if(res.code==1000){ + let optionObj={} + let optionsMap = new Map(); + res.data.forEach(item=>{ + optionObj={ + value:item.label, + label:item.label + } + optionsMap.set(optionObj.value, optionObj); + }) + // 将 Map 转换为数组 + searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values()) + } +} +getMasterProjectName() +getSubprojectName() const search = (val) => { tableConfig.params = {...val} diff --git a/src/views/project-demand/summary/add.vue b/src/views/project-demand/summary/add.vue index 858f74b..d1e1cad 100644 --- a/src/views/project-demand/summary/add.vue +++ b/src/views/project-demand/summary/add.vue @@ -569,6 +569,7 @@ const changeCollectData = () => { } const filterMasterProject= (val)=>{ + masterProjectList.value= JSON.parse(localStorage.getItem("projectOption")) if(val){ getProjectList(val) } @@ -598,6 +599,10 @@ const getProjectList = (val) => { masterProjectList.value = res.data.filter(item => item.value!=route.query.projectId) }else{ masterProjectList.value = res.data + if(!val){ + + localStorage.setItem("projectOption", JSON.stringify(res.data)) + } } } })