diff --git a/src/api/oa/erp/projectPurchase/index.ts b/src/api/oa/erp/projectPurchase/index.ts index 0596c8b..822c340 100644 --- a/src/api/oa/erp/projectPurchase/index.ts +++ b/src/api/oa/erp/projectPurchase/index.ts @@ -1,6 +1,7 @@ import request from '@/utils/request'; import { AxiosPromise } from 'axios'; import { ProjectPurchaseVO, ProjectPurchaseForm, ProjectPurchaseQuery } from '@/api/oa/erp/projectPurchase/types'; +import { ProjectPurchaseMaterialVO } from '@/api/oa/erp/projectPurchaseMaterial/types'; /** * 查询项目采购信息列表 @@ -86,3 +87,15 @@ export function getErpProjectPurchaseList (query) { params: query }); }; + +/** + * 根据项目ID和备件标识查询项目物料 + * @param projectId + * @param spareFlag + */ +export const getProjectMaterialsByProjectId = (projectId: string | number, spareFlag: string): AxiosPromise => { + return request({ + url: `/oa/erp/projectPurchase/getContractMaterialsByProjectId/${projectId}/${spareFlag}`, + method: 'get' + }); +}; diff --git a/src/api/oa/erp/projectPurchaseMaterial/types.ts b/src/api/oa/erp/projectPurchaseMaterial/types.ts index 65f9830..076d514 100644 --- a/src/api/oa/erp/projectPurchaseMaterial/types.ts +++ b/src/api/oa/erp/projectPurchaseMaterial/types.ts @@ -49,6 +49,22 @@ export interface ProjectPurchaseMaterialVO { */ materialName: string; + /** + * 关联物料编号 + */ + relationMaterialCode?: string; + + /** + * 关联物料名称 + */ + relationMaterialName?: string; + relationMaterialName?: string; + + /** + * 采购物料名称(来源) + */ + purchaseMaterialName?: string; + /** * 详细参数 */ diff --git a/src/views/oa/erp/contractInfo/edit.vue b/src/views/oa/erp/contractInfo/edit.vue index 87a59e5..382b913 100644 --- a/src/views/oa/erp/contractInfo/edit.vue +++ b/src/views/oa/erp/contractInfo/edit.vue @@ -532,7 +532,9 @@ const initFormData: ContractInfoFormEx = { const data = reactive<{ form: ContractInfoFormEx; rules: any }>({ form: { ...initFormData }, rules: { - contractId: [{ required: true, message: '合同ID不能为空', trigger: 'blur' }] + contractFlag: [{ required: true, message: '有无合同不能为空', trigger: 'blur' }], + contractName: [{ required: true, message: '合同名称不能为空', trigger: 'blur' }], + paymentMethod: [{ required: true, message: '付款方式不能为空', trigger: 'blur' }], } }); diff --git a/src/views/oa/erp/projectPurchase/edit.vue b/src/views/oa/erp/projectPurchase/edit.vue index 25702a5..15aff64 100644 --- a/src/views/oa/erp/projectPurchase/edit.vue +++ b/src/views/oa/erp/projectPurchase/edit.vue @@ -12,7 +12,7 @@ :mode="false" /> - + @@ -100,71 +100,84 @@ - + - - - - - + + + + + + + + - - - + + + - - + + - + - - - - - + + + + + + + + + - - - + + + - - + + @@ -180,21 +193,29 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + @@ -207,11 +228,6 @@ - - - - - @@ -221,27 +237,45 @@ - + - + + + + + + - + @@ -265,7 +299,7 @@ import { computed, reactive, ref, watch, getCurrentInstance, toRefs, onMounted, import type { ComponentInternalInstance } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import type { FormInstance } from 'element-plus'; -import { addProjectPurchase, getProjectPurchase, updateProjectPurchase, projectPurchaseSubmitAndFlowStart } from '@/api/oa/erp/projectPurchase'; +import { addProjectPurchase, getProjectPurchase, updateProjectPurchase, projectPurchaseSubmitAndFlowStart, getProjectMaterialsByProjectId } from '@/api/oa/erp/projectPurchase'; import type { ProjectPurchaseForm } from '@/api/oa/erp/projectPurchase/types'; import { getErpProjectPurchaseMaterialList } from '@/api/oa/erp/projectPurchaseMaterial'; import type { ProjectPurchaseMaterialVO, ProjectPurchaseMaterialForm } from '@/api/oa/erp/projectPurchaseMaterial/types'; @@ -346,6 +380,26 @@ const nonStandardMaterialList = computed(() => { return materialList.value.filter((item) => item.materialFlag === '2'); }); + +const loadProjectMaterialsFromSource = async (projectId?: string | number, spareFlag?: string) => { + if (!projectId || !spareFlag) { + return; + } + materialLoading.value = true; + try { + const res = await getProjectMaterialsByProjectId(projectId, spareFlag); + let data = res?.data || []; + data = data.map((item, index) => ({ + ...item, + purchasePlanFlag: '1', + serialNumber: index + 1 // 加序号 + })); + materialList.value = data; + } finally { + materialLoading.value = false; + } +}; + // 获取行类名,计划外的行显示黄色背景 const getRowClassName = ({ row }: { row: ProjectPurchaseMaterialVO }) => { // 计划外通常是 '2' 或 '否',根据实际字典值调整 @@ -493,15 +547,22 @@ const submitForm = async (status: string, mode?: boolean) => { buttonLoading.value = true; try { + const normalizedMaterials: ProjectPurchaseMaterialForm[] = materialList.value.map((item) => { + const payloadItem: ProjectPurchaseMaterialForm = { + ...item, + projectPurchaseId: form.value.projectPurchaseId + }; + if (typeof payloadItem.purchaseMaterialId === 'string') { + payloadItem.purchaseMaterialId = undefined; + } + return payloadItem; + }); const payload: ProjectPurchaseForm & { projectName?: string; purchaseMaterialList?: ProjectPurchaseMaterialForm[]; } = { ...form.value, - purchaseMaterialList: materialList.value.map((item) => ({ - ...item, - projectPurchaseId: form.value.projectPurchaseId - })) + purchaseMaterialList: normalizedMaterials }; if (status !== 'draft') { payload.flowCode = FlowCodeEnum.PROJECT_PURCHASE_CODE; @@ -548,29 +609,6 @@ const submitForm = async (status: string, mode?: boolean) => { } }; -/** - * 打开新增物料弹窗 - * @param isStandard 是否标准物料 - */ -const handleAddMaterial = (isStandard: boolean) => { - if (isReadOnly.value) { - return; - } - resetMaterialForm(); - materialForm.value.purchasePlanFlag = materialForm.value.purchasePlanFlag || (purchase_plan_flag.value?.[0]?.value ?? undefined); - // 根据 isStandard 设置 materialFlag - if (isStandard) { - materialForm.value.materialFlag = '1'; // 标准物料 - materialDialog.title = '添加标准物料'; - } else { - materialForm.value.materialFlag = '2'; // 非标准物料 - materialDialog.title = '添加非标准物料'; - } - materialForm.value.spareFlag = materialForm.value.spareFlag || (spare_flag.value?.[0]?.value ?? undefined); - materialForm.value.activeFlag = materialForm.value.activeFlag || (active_flag.value?.[0]?.value ?? undefined); - materialDialog.visible = true; -}; - /** * 编辑物料 */ @@ -625,6 +663,31 @@ const handleDeleteMaterial = async (row: ProjectPurchaseMaterialVO) => { } }; +/** + * 拆分物料为计划外 + */ +const splitMaterial = (row: ProjectPurchaseMaterialVO) => { + if (isReadOnly.value) { + return; + } + const newItem: ProjectPurchaseMaterialVO = { + ...row, + purchaseMaterialId: `split-${Date.now()}-${Math.random().toString(16).slice(2, 8)}`, + projectPurchaseId: form.value.projectPurchaseId ?? row.projectPurchaseId, + purchasePlanFlag: '2', + needPurchaseAmount: row.needPurchaseAmount, + purchaseAmount: row.purchaseAmount, + serialNumber: (materialList.value?.length || 0) + 1 + } as ProjectPurchaseMaterialVO; + const index = materialList.value.indexOf(row); + if (index >= 0) { + materialList.value.splice(index + 1, 0, newItem); + } else { + materialList.value.push(newItem); + } + proxy?.$modal?.msgSuccess('拆分成功'); +}; + /** * 打开审批弹窗 */ @@ -658,9 +721,6 @@ const submitCallback = async () => { }; // 打开项目选择框 -/** - * 打开项目选择弹窗 - */ const openProjectSelect = () => { if (isReadOnly.value) { return; @@ -669,9 +729,6 @@ const openProjectSelect = () => { }; // 项目选择回调,自动填充项目相关信息 -/** - * 项目选择回调 - */ const projectInfoSelectCallBack = (data: ProjectInfoVO[]) => { if (data && data.length > 0) { const project = data[0]; @@ -682,13 +739,11 @@ const projectInfoSelectCallBack = (data: ProjectInfoVO[]) => { form.value.chargeId = project.chargeId; form.value.deputyId = project.deputyId; form.value.spareFlag = project.spareFlag; + loadProjectMaterialsFromSource(project.projectId as string | number, project.spareFlag); } }; // 初始化调用 -/** - * 初始化下拉数据 - */ const loadSelectOptions = () => { getUserList(); getUnitInfoListSelect(); @@ -720,10 +775,37 @@ onMounted(async () => {