diff --git a/src/api/oa/erp/projectInfo/index.ts b/src/api/oa/erp/projectInfo/index.ts index c2b87a1..5c5030f 100644 --- a/src/api/oa/erp/projectInfo/index.ts +++ b/src/api/oa/erp/projectInfo/index.ts @@ -101,3 +101,14 @@ export function getErpProjectWithContractList(query) { }); } +/** + * 根据合同ID查询关联项目信息列表 + * @param contractId + */ +export const listProjectInfoByContractId = (contractId: string | number): AxiosPromise => { + return request({ + url: '/oa/erp/projectInfo/listByContractId/' + contractId, + method: 'get' + }); +}; + diff --git a/src/api/oa/erp/projectPurchase/index.ts b/src/api/oa/erp/projectPurchase/index.ts index 822c340..1d173b3 100644 --- a/src/api/oa/erp/projectPurchase/index.ts +++ b/src/api/oa/erp/projectPurchase/index.ts @@ -3,6 +3,11 @@ import { AxiosPromise } from 'axios'; import { ProjectPurchaseVO, ProjectPurchaseForm, ProjectPurchaseQuery } from '@/api/oa/erp/projectPurchase/types'; import { ProjectPurchaseMaterialVO } from '@/api/oa/erp/projectPurchaseMaterial/types'; +export interface ProjectMaterialsSourceDTO { + relationId?: string | number; + materialList?: ProjectPurchaseMaterialVO[]; +} + /** * 查询项目采购信息列表 * @param query @@ -93,9 +98,14 @@ export function getErpProjectPurchaseList (query) { * @param projectId * @param spareFlag */ -export const getProjectMaterialsByProjectId = (projectId: string | number, spareFlag: string): AxiosPromise => { +export const getProjectMaterialsByProjectId = ( + projectId: string | number, + spareFlag: string, + contractId?: string | number +): AxiosPromise => { return request({ url: `/oa/erp/projectPurchase/getContractMaterialsByProjectId/${projectId}/${spareFlag}`, - method: 'get' + method: 'get', + params: contractId ? { contractId } : {} }); }; diff --git a/src/router/index.ts b/src/router/index.ts index 76cc1a8..bd67bc8 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -145,7 +145,7 @@ export const constantRoutes: RouteRecordRaw[] = [ path: 'orderLedger/:projectId', component: () => import('@/views/oa/erp/orderLedger/index.vue'), name: 'OrderLedger', - meta: { title: '订单管理台账', activeMenu: '/contract/contractInfo/contractOrder' } + meta: { title: '合同订单台账', activeMenu: '/contract/contractInfo/contractOrder' } } ] }, diff --git a/src/views/oa/erp/orderLedger/index.vue b/src/views/oa/erp/orderLedger/index.vue index afc853a..b705fd8 100644 --- a/src/views/oa/erp/orderLedger/index.vue +++ b/src/views/oa/erp/orderLedger/index.vue @@ -3,7 +3,7 @@ @@ -80,6 +80,7 @@ {{ purchaseTotal }} 条
+ 新增采购 前往采购页面 刷新
@@ -358,7 +359,13 @@ const loadingInvoice = ref(false); const shippingTotal = ref(0); const shippingQuery = reactive({ pageNum: 1, pageSize: 10 }); const purchaseTotal = ref(0); -const purchaseQuery = reactive({ pageNum: 1, pageSize: 10, projectId: undefined as string | number | undefined }); +const purchaseQuery = reactive({ + pageNum: 1, + pageSize: 10, + projectId: undefined as string | number | undefined, + relationId: undefined as string | number | undefined, + spareFlag: undefined as string | undefined +}); const invoiceTotal = ref(0); const invoiceQuery = reactive({ pageNum: 1, pageSize: 10, projectId: undefined as string | number | undefined, contractId: undefined as string | number | undefined }); @@ -392,6 +399,20 @@ const viewPurchase = (row: ProjectPurchaseVO) => { }); }; +/** 从台账新增采购,并携带项目信息 */ +const addPurchaseFromLedger = () => { + const contractId = orderInfo.value?.contractId ?? contractInfo.value?.contractId; + if (!contractId) { + proxy?.$modal.msgWarning('合同信息未加载完成,请稍后重试'); + return; + } + proxy?.$tab.openPage('/purchase/projectPurchase/edit', '采购信息', { + type: 'add', + source: 'orderLedger', + contractId + }); +}; + /** 查看开票信息 */ const viewInvoice = (row: FinInvoiceInfoVO) => { if (!row?.invoiceId) return; @@ -421,16 +442,18 @@ const loadOrderAndContract = async () => { /** 加载采购信息 */ const loadPurchaseList = async () => { - if (!projectId.value) { + const contractId = orderInfo.value.contractId; + if (!contractId && !projectId.value) { purchaseList.value = []; purchaseTotal.value = 0; return; } + // 优先按合同ID查询采购 + purchaseQuery.relationId = contractId ? contractId : undefined; loadingPurchase.value = true; try { const res: any = await listProjectPurchase({ - ...purchaseQuery, - projectId: projectId.value + ...purchaseQuery }); purchaseList.value = res.rows || []; purchaseTotal.value = res.total || 0; @@ -538,7 +561,6 @@ const handleTabChange = (tabName: string) => { break; case 'purchase': purchaseQuery.pageNum = 1; - purchaseQuery.projectId = projectId.value; loadPurchaseList(); break; case 'shipping': diff --git a/src/views/oa/erp/projectPurchase/edit.vue b/src/views/oa/erp/projectPurchase/edit.vue index 8ac3b30..d12ca3c 100644 --- a/src/views/oa/erp/projectPurchase/edit.vue +++ b/src/views/oa/erp/projectPurchase/edit.vue @@ -323,6 +323,7 @@ import { useUserStore } from '@/store/modules/user'; import { getBaseUnitInfoList } from '@/api/oa/base/unitInfo'; import { getInfo } from '@/api/login'; import type { MaterialInfoVO } from '@/api/oa/base/materialInfo/types'; +import { listProjectInfoByContractId } from '@/api/oa/erp/projectInfo'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; const router = useRouter(); @@ -394,14 +395,22 @@ const nonStandardMaterialList = computed(() => { return materialList.value.filter((item) => item.materialFlag === '2'); }); -const loadProjectMaterialsFromSource = async (projectId?: string | number, spareFlag?: string) => { +const loadProjectMaterialsFromSource = async ( + projectId?: string | number, + spareFlag?: string, + contractId?: string | number +) => { if (!projectId || !spareFlag) { return; } materialLoading.value = true; try { - const res = await getProjectMaterialsByProjectId(projectId, spareFlag); - let data = res?.data || []; + const res = await getProjectMaterialsByProjectId(projectId, spareFlag, contractId); + const relationId = res?.data?.relationId; + if (relationId !== undefined && relationId !== null) { + form.value.relationId = relationId as any; + } + let data = res?.data?.materialList || []; data = data.map((item, index) => ({ ...item, purchasePlanFlag: '1', @@ -790,6 +799,38 @@ const projectInfoSelectCallBack = (data: ProjectInfoVO[]) => { } }; +const initFromRouteQuery = async () => { + const queryType = (routeParams.type as string) || 'add'; + const contractId = routeParams.contractId as string | number | undefined; + if ( + routeParams.id || + queryType !== 'add' || + (routeParams.source as string) !== 'orderLedger' || + !contractId + ) { + return; + } + const res = await listProjectInfoByContractId(contractId); + const projectList = res?.data || []; + if (!projectList.length) { + proxy?.$modal.msgWarning('该合同未查询到关联系项目信息'); + return; + } + if (projectList.length > 1) { + proxy?.$modal.msgWarning('该合同关联了多个项目,系统将默认带出第一个项目,请确认后再提交'); + } + const project = projectList[0]; + form.value.projectId = project.projectId; + form.value.projectCode = project.projectCode; + form.value.projectName = project.projectName; + form.value.managerId = project.managerId; + form.value.chargeId = project.chargeId; + form.value.deputyId = project.deputyId; + form.value.deptId = project.deptId; + form.value.spareFlag = project.spareFlag; + await loadProjectMaterialsFromSource(project.projectId as string | number, project.spareFlag, contractId); +}; + const handleExportSingle = () => { proxy?.download( `oa/erp/projectPurchase/exportSingle/${form.value.projectPurchaseId}`, @@ -821,7 +862,13 @@ onMounted(async () => { userRoles.value = []; } const shouldLoadDetail = !!id && (type === 'update' || type === 'view' || type === 'approval'); - await loadDetail(shouldLoadDetail ? (id as string | number) : undefined); + if (shouldLoadDetail) { + await loadDetail(id as string | number); + } else { + resetForm(); + materialList.value = []; + await initFromRouteQuery(); + } pageLoading.value = false; }); });