|
@@ -24,60 +24,102 @@ export const initProjectContract = async () => {
|
|
|
//获取默认项目信息
|
|
|
export const getProjectContract = async () => {
|
|
|
const { error, data } = await projectApi.getProjectAndContract()
|
|
|
- const projectList = getArrValue(data)
|
|
|
- if (error || projectList.length <= 0) {
|
|
|
- window.$message?.error('没有相关项目权限')
|
|
|
+ let projectList = await getProjectArr(error, data)
|
|
|
+ if (projectList.length <= 0) {
|
|
|
return { error: true, data: [] }
|
|
|
}
|
|
|
- //获取默认项目合同段数据
|
|
|
- const defaultProject = await getDefaultProject()
|
|
|
- let projectInfo = {}, contractInfo = {}
|
|
|
- if (defaultProject.code === 200) {
|
|
|
- projectInfo = defaultProject.project
|
|
|
- contractInfo = defaultProject.contract
|
|
|
- } else {
|
|
|
- //过滤空合同段的项目合同段数据
|
|
|
- const projectArr = projectList.filter(({ contractInfoList }) => {
|
|
|
- const contractList = getArrValue(contractInfoList)
|
|
|
- return contractList.length > 0
|
|
|
- })
|
|
|
- if (projectArr.length <= 0) {
|
|
|
- window.$message?.error('没有相关项目权限')
|
|
|
- return { error: true, data: [] }
|
|
|
- }
|
|
|
- //获取第一个项目的第一个合同段数据
|
|
|
- const contractList = projectArr[0].contractInfoList
|
|
|
- projectInfo = projectList[0]
|
|
|
- contractInfo = contractList[0]
|
|
|
+ //获取缓存的项目合同段数据
|
|
|
+ const isStore = await getStoreProjecInfo(projectList)
|
|
|
+ if (!isStore) {
|
|
|
+ const isDefault = await getDefaultProject(projectList)
|
|
|
+ if (!isDefault) return { error: true, data: [] }
|
|
|
}
|
|
|
//获取按钮权限
|
|
|
await initButtons()
|
|
|
- //设置项目合同段数据
|
|
|
- store.setProjectInfo(projectInfo)
|
|
|
- store.setProjectId(projectInfo.id)
|
|
|
- store.setContractInfo(contractInfo)
|
|
|
- store.setContractId(contractInfo.id)
|
|
|
- store.setProjectContract(projectList)
|
|
|
+ //返回数据
|
|
|
return { error: false, data: projectList }
|
|
|
}
|
|
|
|
|
|
+//根据缓存获取项目合同段数据
|
|
|
+const getStoreProjecInfo = async (arr) => {
|
|
|
+ const projectId = store.projectId //项目ID
|
|
|
+ const contractId = store.contractId //合同段ID
|
|
|
+ //查询缓存的选中ID是否存在
|
|
|
+ const pid = arr.findIndex(item => Number(item.id) === Number(projectId))
|
|
|
+ const contractList = getArrValue(arr[pid]?.contractInfoList)
|
|
|
+ const cid = contractList.findIndex(item => Number(item.id) === Number(contractId))
|
|
|
+ //如果缓存的选中ID不存在
|
|
|
+ if (cid === -1) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //获取项目合同段数据
|
|
|
+ const projectInfo = await getProjectInfo(projectId)
|
|
|
+ const contractInfo = await getContractInfo(contractId)
|
|
|
+ if (isNullES(projectInfo) || isNullES(contractInfo)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ setProjectStore(projectInfo, contractInfo)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
//获取默认项目信息
|
|
|
-const getDefaultProject = async () => {
|
|
|
+const getDefaultProject = async (projectList) => {
|
|
|
const { error, status, data } = await projectApi.getDefaultProject()
|
|
|
if (!error && status === 200 && !isNullES(data)) {
|
|
|
const { projectId, contractId } = getObjValue(data)
|
|
|
if (!projectId || !contractId) {
|
|
|
- return { code: 300 }
|
|
|
+ return false
|
|
|
}
|
|
|
const projectInfo = await getProjectInfo(projectId)
|
|
|
const contractInfo = await getContractInfo(contractId)
|
|
|
if (isNullES(projectInfo) || isNullES(contractInfo)) {
|
|
|
- return { code: 300 }
|
|
|
+ return false
|
|
|
}
|
|
|
- return { code: 200, project: projectInfo, contract: contractInfo }
|
|
|
- } else {
|
|
|
- return { code: 300 }
|
|
|
+ setProjectStore(projectInfo, contractInfo)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ //获取第一个项目的第一个合同段数据
|
|
|
+ const contractList = getArrValue(projectList[0]?.contractInfoList)
|
|
|
+ const projectInfo = projectList[0]
|
|
|
+ const contractInfo = contractList[0]
|
|
|
+ //缓存数据
|
|
|
+ setProjectStore(projectInfo, contractInfo)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+//缓存数据
|
|
|
+const setProjectStore = (project, contract) => {
|
|
|
+ store.setProjectInfo(project)
|
|
|
+ store.setProjectId(project.id)
|
|
|
+ store.setContractInfo(contract)
|
|
|
+ store.setContractId(contract.id)
|
|
|
+}
|
|
|
+
|
|
|
+const getProjectArr = async (error, data) => {
|
|
|
+ let projectList = getArrValue(data)
|
|
|
+ if (error || projectList.length <= 0) {
|
|
|
+ window.$message?.error('没有相关项目权限')
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ //处理合同段的别名
|
|
|
+ projectList.forEach(item => {
|
|
|
+ let contractArr = item['contractInfoList'] || []
|
|
|
+ contractArr.forEach(items => {
|
|
|
+ items['projectAlias'] = items['name']
|
|
|
+ })
|
|
|
+ })
|
|
|
+ //过滤空合同段的项目合同段数据
|
|
|
+ const projectArr = projectList.filter(({ contractInfoList }) => {
|
|
|
+ const contractList = getArrValue(contractInfoList)
|
|
|
+ return contractList.length > 0
|
|
|
+ })
|
|
|
+ if (projectArr.length <= 0) {
|
|
|
+ window.$message?.error('没有相关项目权限')
|
|
|
+ return []
|
|
|
}
|
|
|
+ store.setProjectContract(projectArr)
|
|
|
+ //返回数据
|
|
|
+ return projectArr
|
|
|
}
|
|
|
|
|
|
//获取项目信息
|