diff --git a/src/views/oa/erp/orderLedger/index.vue b/src/views/oa/erp/orderLedger/index.vue index bc832d1..3856e39 100644 --- a/src/views/oa/erp/orderLedger/index.vue +++ b/src/views/oa/erp/orderLedger/index.vue @@ -184,6 +184,18 @@
+
+
+ + 发货信息 + {{ shippingTotal }} 条 +
+
+ 新增发货 + 前往发货页面 + 刷新 +
+
@@ -453,6 +465,11 @@ const openPurchasePage = () => { proxy?.$tab.openPage('/purchase/projectPurchase', '采购管理'); }; +/** 前往发货页面 */ +const openShippingPage = () => { + proxy?.$tab.openPage('/shipping/wmsShippingBill', '发货管理'); +}; + /** 查看采购信息 */ const viewPurchase = (row: ProjectPurchaseVO) => { if (!row?.projectPurchaseId) return; @@ -476,6 +493,22 @@ const addPurchaseFromLedger = () => { }); }; +/** 从台账新增发货,并携带合同信息 */ +const addShippingFromLedger = () => { + const contractId = orderInfo.value?.contractId ?? contractInfo.value?.contractId; + if (!contractId) { + proxy?.$modal.msgWarning('合同信息未加载完成,请稍后重试'); + return; + } + proxy?.$tab.openPage('/shipping/wmsShippingBill/edit', '发货信息', { + type: 'add', + source: 'orderLedger', + bindType: '2', + contractId, + projectId: projectId.value + }); +}; + /** 查看开票信息 */ const viewInvoice = (row: FinInvoiceInfoVO) => { if (!row?.invoiceId) return; diff --git a/src/views/wms/wmsShippingBill/edit.vue b/src/views/wms/wmsShippingBill/edit.vue index 0c6071e..67bbd9b 100644 --- a/src/views/wms/wmsShippingBill/edit.vue +++ b/src/views/wms/wmsShippingBill/edit.vue @@ -186,8 +186,9 @@ @@ -480,6 +481,7 @@ import type { CustomerContactVO } from '@/api/oa/crm/customerContact/types'; import { getCrmSupplierInfoList } from '@/api/oa/crm/crmSupplierInfo'; import { listUser } from '@/api/system/user'; import type { UserQuery } from '@/api/system/user/types'; +import { getContractOrder } from '@/api/oa/erp/contractOrder'; import MaterialSelect from '@/components/MaterialSelect/index.vue'; import SubmitVerify from '@/components/Process/submitVerify.vue'; import ApprovalRecord from '@/components/Process/approvalRecord.vue'; @@ -489,6 +491,7 @@ import type { ProjectInfoVO } from '@/api/oa/erp/projectInfo/types'; import { getProjectInfo } from '@/api/oa/erp/projectInfo'; import { getContractInfo, listContractInfo } from '@/api/oa/erp/contractInfo'; import type { ContractInfoQuery, ContractInfoVO } from '@/api/oa/erp/contractInfo/types'; +import type { ContractOrderPurchaseMaterialVO } from '@/api/oa/erp/contractOrder/types'; import { FlowCodeEnum } from '@/enums/OAEnum'; import { Search, Warning } from '@element-plus/icons-vue'; @@ -668,6 +671,14 @@ const wmsMaterialQueryParams = ref({ warehouseId: undefined }); +const getTodayDateString = () => { + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +}; + // 表单初始数据 const initFormData: WmsShippingBillForm = { shippingBillId: undefined, @@ -693,7 +704,7 @@ const initFormData: WmsShippingBillForm = { logisticsPhone: undefined, directions: undefined, planArrivalTime: undefined, - shippingTime: undefined, + shippingTime: getTodayDateString(), warehouseId: undefined, warehouseName: undefined, outStockBillStatus: '1', // 默认暂存 @@ -757,6 +768,11 @@ const syncMaterialSourceTypeByDetails = () => { } }; +const toNumberOrDefault = (value: unknown, defaultValue = 0) => { + const result = Number(value); + return Number.isFinite(result) ? result : defaultValue; +}; + const normalizeWorkflowUserIds = (value: unknown): string | undefined => { if (Array.isArray(value)) { const ids = value.map((item) => String(item ?? '').trim()).filter((item) => item.length > 0); @@ -873,20 +889,117 @@ const handleContractRowClick = (row: ContractInfoVO) => { const submitContractSelect = () => { if (selectedContract.value) { - const contract = selectedContract.value; - form.value.contractId = contract.contractId as any; - form.value.contractCode = contract.contractCode || ''; - form.value.contractName = contract.contractName || ''; - const contractManagerId = normalizeWorkflowUserIds((contract as any).contractManagerId); - (form.value as any).contractManagerId = contractManagerId; - (form.value as any).tManagerId = toWorkflowUserIdArray(contractManagerId); - selectedContractName.value = contract.contractName || ''; - // SAP订单号来自合同的 orderContractCode - selectedSapOrderCode.value = (contract as any).orderContractCode || ''; + applyContractInfoToForm(selectedContract.value); } contractDialog.visible = false; }; +const applyProjectInfoToForm = (project: Partial & Record) => { + form.value.bindType = '1'; + form.value.projectId = project.projectId; + form.value.projectCode = project.projectCode || ''; + form.value.projectName = project.projectName || ''; + selectedProjectName.value = project.projectName || ''; + const peopleId = normalizeWorkflowUserIds(project.peopleId); + (form.value as any).peopleId = peopleId; + (form.value as any).tManagerId = toWorkflowUserIdArray(peopleId); +}; + +const syncCustomerById = async (customerId?: string | number) => { + if (!customerId) { + return; + } + form.value.customerId = customerId; + await handleCustomerChange(customerId); +}; + +const applyContractInfoToForm = (contract: ContractInfoVO) => { + form.value.bindType = '2'; + form.value.contractId = contract.contractId as any; + form.value.contractCode = contract.contractCode || ''; + form.value.contractName = contract.contractName || ''; + selectedContractName.value = contract.contractName || ''; + selectedSapOrderCode.value = (contract as any).orderContractCode || ''; + const contractManagerId = normalizeWorkflowUserIds((contract as any).contractManagerId); + (form.value as any).contractManagerId = contractManagerId; + (form.value as any).tManagerId = toWorkflowUserIdArray(contractManagerId); +}; + +const mapContractMaterialToShippingDetail = (material: ContractOrderPurchaseMaterialVO | Record): WmsShippingDetailsForm => { + const rawMaterial = material as Record; + const shippingStockAmount = toNumberOrDefault(rawMaterial.amount ?? rawMaterial.contractAmount, 0); + const unitPrice = toNumberOrDefault(rawMaterial.includingPrice ?? rawMaterial.beforePrice, 0); + return { + shippingDetailsId: undefined, + shippingBillId: form.value.shippingBillId, + materialSourceType: '1', + erpMaterialId: rawMaterial.materialId, + wmsMaterialId: undefined, + sourceDetailType: 'CONTRACT_DETAIL', + sourceDetailId: rawMaterial.contractMaterialId, + warehouseId: undefined, + materielId: rawMaterial.materialId, + materialCode: rawMaterial.materialCode, + materialName: rawMaterial.saleMaterialName || rawMaterial.materialName || rawMaterial.productName, + materielSpecification: rawMaterial.specificationDescription, + batchNumber: undefined, + unitPrice, + shippingStockAmount, + unitId: rawMaterial.unitId, + unitName: rawMaterial.unitName, + totalPrice: unitPrice * shippingStockAmount, + remark: rawMaterial.remark + }; +}; + +const initShippingDetailsFromContract = (contractMaterialList: ContractOrderPurchaseMaterialVO[] | any[]) => { + detailsList.value = (contractMaterialList || []).map((item) => mapContractMaterialToShippingDetail(item)); + materialSourceType.value = '1'; + syncMaterialSourceTypeByDetails(); +}; + +const initFromContractSource = async (contractId: string | number, projectId?: string | number) => { + const [contractRes, projectRes] = await Promise.all([ + getContractInfo(contractId), + projectId ? getContractOrder(projectId).catch((error) => { + console.error('加载合同订单项目数据失败:', error); + return null; + }) : Promise.resolve(null) + ]); + const contract = contractRes.data; + applyContractInfoToForm(contract); + await syncCustomerById((contract as any).finalCustomerId ?? (contract as any).oneCustomerId); + if (projectRes?.data) { + applyProjectInfoToForm(projectRes.data as any); + form.value.bindType = '2'; + } + initShippingDetailsFromContract((contract as any)?.contractMaterialList || []); +}; + +const initFromProjectSource = async (projectId: string | number) => { + const projectRes = await getProjectInfo(projectId); + const project = projectRes.data as any; + applyProjectInfoToForm(project); + await syncCustomerById(project.customerId ?? project.finalCustomerId); +}; + +const initFormByRouteSource = async () => { + if (routeParams.value.type !== 'add') { + return; + } + const source = String(routeParams.value.source || '').trim(); + const bindType = String(routeParams.value.bindType || '').trim(); + const contractId = routeParams.value.contractId as string | number | undefined; + const projectId = routeParams.value.projectId as string | number | undefined; + if ((source === 'orderLedger' || bindType === '2') && contractId) { + await initFromContractSource(contractId, projectId); + return; + } + if (bindType === '1' && projectId) { + await initFromProjectSource(projectId); + } +}; + /** 打开项目选择弹窗 */ const openProjectSelect = () => { if (!canEditBusinessFields.value) return; @@ -904,14 +1017,8 @@ const openContractSelect = () => { /** 项目选择回调 */ const projectInfoSelectCallBack = (data: ProjectInfoVO[]) => { if (data && data.length > 0) { - const project = data[0]; - form.value.projectId = project.projectId; - form.value.projectCode = project.projectCode || ''; - form.value.projectName = project.projectName || ''; - const peopleId = normalizeWorkflowUserIds((project as any).peopleId); - (form.value as any).peopleId = peopleId; - (form.value as any).tManagerId = toWorkflowUserIdArray(peopleId); - selectedProjectName.value = project.projectName || ''; + const project = data[0] as ProjectInfoVO & Record; + applyProjectInfoToForm(project); // 如果项目有关联客户,自动带入 if (project.customerId) { form.value.customerId = project.customerId; @@ -1301,6 +1408,8 @@ onMounted(async () => { if (id && (routeParams.value.type === 'update' || routeParams.value.type === 'view' || routeParams.value.type === 'approval')) { // 编辑/查看/审批场景加载后端数据,避免覆盖草稿 await loadFormData(id); + } else { + await initFormByRouteSource(); } await loadCurrentTask();