| | |
| | | const submitForm = () => { |
| | | proxy.$refs["formRef"].validate((valid) => { |
| | | if (valid) { |
| | | // 如果是批量操作,将所有合同的数据放在一个数组里,只调用一次接口 |
| | | if (selectedRows.value.length > 1) { |
| | | // 创建包含所有合同数据的数组 |
| | | const batchData = selectedRows.value.map(contract => { |
| | | // 筛选出属于当前合同的产品数据 |
| | | const contractProductData = productData.value.filter(item => |
| | | item.salesLedgerId === contract.id |
| | | ); |
| | | |
| | | // 为每个销售合同号创建独立的对象 |
| | | return { |
| | | // 基础表单数据 |
| | | issueDate: form.value.issueDate, |
| | | createTime: form.value.createTime, |
| | | createUer: form.value.createUer, |
| | | invoiceNo: form.value.invoiceNo, |
| | | |
| | | // 合同实际信息 |
| | | id: contract.id, // 使用id作为字段名,值为salesLedgerId |
| | | salesContractNo: contract.salesContractNo, // 使用实际的销售合同号 |
| | | customerName: contract.customerName, // 使用实际的客户名称 |
| | | customerId: contract.customerId, // 添加客户ID |
| | | customerContractNo: contract.customerContractNo, // 使用实际的客户合同号 |
| | | projectName: contract.projectName, // 使用实际的项目名称 |
| | | salesman: contract.salesman, // 使用实际的业务员 |
| | | |
| | | // 产品数据 |
| | | productData: proxy.HaveJson(contractProductData), |
| | | |
| | | // 批量标识 |
| | | isBatch: true |
| | | }; |
| | | }); |
| | | // 统一将所有合同的数据放在一个数组里,单个和批量都使用数组格式 |
| | | const submitData = selectedRows.value.map(contract => { |
| | | // 筛选出属于当前合同的产品数据 |
| | | const contractProductData = productData.value.filter(item => |
| | | item.salesLedgerId === contract.id |
| | | ); |
| | | |
| | | // 只调用一次接口,传递包含所有合同数据的数组 |
| | | invoiceRegistrationSave(batchData).then(() => { |
| | | proxy.$modal.msgSuccess("批量新增成功"); |
| | | closeDia(); |
| | | getList(); |
| | | }); |
| | | } else { |
| | | // 单个合同提交逻辑 |
| | | const singleContract = selectedRows.value[0]; |
| | | const singleForm = { |
| | | // 为每个销售合同号创建独立的对象 |
| | | return { |
| | | // 基础表单数据 |
| | | issueDate: form.value.issueDate, |
| | | createTime: form.value.createTime, |
| | |
| | | invoiceNo: form.value.invoiceNo, |
| | | |
| | | // 合同实际信息 |
| | | id: singleContract.id, // 使用id作为字段名,值为salesLedgerId |
| | | salesContractNo: singleContract.salesContractNo, // 使用实际的销售合同号 |
| | | customerName: singleContract.customerName, // 使用实际的客户名称 |
| | | customerId: singleContract.customerId, // 添加客户ID |
| | | customerContractNo: singleContract.customerContractNo, // 使用实际的客户合同号 |
| | | projectName: singleContract.projectName, // 使用实际的项目名称 |
| | | salesman: singleContract.salesman, // 使用实际的业务员 |
| | | id: contract.id, // 使用id作为字段名,值为salesLedgerId |
| | | salesContractNo: contract.salesContractNo, // 使用实际的销售合同号 |
| | | customerName: contract.customerName, // 使用实际的客户名称 |
| | | customerId: contract.customerId, // 添加客户ID |
| | | customerContractNo: contract.customerContractNo, // 使用实际的客户合同号 |
| | | projectName: contract.projectName, // 使用实际的项目名称 |
| | | salesman: contract.salesman, // 使用实际的业务员 |
| | | |
| | | // 产品数据 |
| | | productData: proxy.HaveJson(productData.value), |
| | | productData: proxy.HaveJson(contractProductData), |
| | | |
| | | // 批量标识 |
| | | isBatch: false |
| | | isBatch: selectedRows.value.length > 1 |
| | | }; |
| | | invoiceRegistrationSave(singleForm).then((res) => { |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | closeDia(); |
| | | getList(); |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | // 统一调用接口,传递数组格式的数据 |
| | | invoiceRegistrationSave(submitData).then(() => { |
| | | proxy.$modal.msgSuccess(selectedRows.value.length > 1 ? "批量新增成功" : "提交成功"); |
| | | closeDia(); |
| | | getList(); |
| | | }); |
| | | } |
| | | }); |
| | | }; |