Browse Source

feat(inspection): 添加草稿编辑保存功能并优化验货申请明细处理

- 新增 editSaveInspectionRequest 接口用于草稿编辑保存
- 在验货申请列表组件中引入新的草稿编辑保存接口
- 新增 totalQty 字段用于记录明细的未验货数量
- 重构草稿编辑保存逻辑,改为一次性提交全量数据
- 移除区分新增/修改/删除的复杂处理逻辑
- 简化为直接提交当前表格中的所有PO明细作为最终状态
- 移除相关的辅助方法 addNewPoDetails、editModifiedPoDetails、deletePoDetails
master
qiankanghui 2 weeks ago
parent
commit
3402ffeca1
  1. 3
      src/api/inspection/inspectionRequestHeader.js
  2. 180
      src/views/modules/inspection/inspectionRequestList.vue

3
src/api/inspection/inspectionRequestHeader.js

@ -96,3 +96,6 @@ export const editInspectionDetails = (data) => createAPI(`/inspection/editDetail
// 删除验货申请明细
export const deleteInspectionDetails = (data) => createAPI(`/inspection/deleteDetails`, 'post', data)
// 草稿编辑保存(合并删除/修改/新增/更新基础信息)
export const editSaveInspectionRequest = (data) => createAPI(`/inspection/editSave`, 'post', data)

180
src/views/modules/inspection/inspectionRequestList.vue

@ -1111,7 +1111,7 @@
</template>
<script>
import { searchInspectionRequestHeaderList, queryPoPage, queryPoPageExclude, queryPoSupplierPage, queryPoSupplierOrderPage, saveInspectionRequest, deleteInspectionRequest, confirmInspectionRequest, applyChangeInspectionRequest, getInspectionRequestDetailSubList, updateInspectionRequest, downloadTemplate, previewUpload, batchSave, addInspectionDetails, editInspectionDetails, deleteInspectionDetails } from '@/api/inspection/inspectionRequestHeader.js'
import { searchInspectionRequestHeaderList, queryPoPage, queryPoPageExclude, queryPoSupplierPage, queryPoSupplierOrderPage, saveInspectionRequest, deleteInspectionRequest, confirmInspectionRequest, applyChangeInspectionRequest, getInspectionRequestDetailSubList, updateInspectionRequest, downloadTemplate, previewUpload, batchSave, addInspectionDetails, editInspectionDetails, deleteInspectionDetails, editSaveInspectionRequest } from '@/api/inspection/inspectionRequestHeader.js'
import { searchSrmSupplierAddressList, createSrmSupplierAddress, updateSrmSupplierAddress, searchSrmSupplierList } from '@/api/srm/srmSupplier.js'
import { getPermissionValue } from '@/api/sys/specialSecurity.js'
import Chooselist from '@/views/modules/common/Chooselist_eam'
@ -2442,7 +2442,8 @@ export default {
shipMethod: row.shipMethod || row.shipMothod || '',
shipMothod: row.shipMethod || row.shipMothod || '', //
crd: row.crd || '',
waitInspectQty: row.waitInspectQty || 0
waitInspectQty: row.waitInspectQty || 0,
totalQty: row.waitInspectQty || 0 // PO
}))
// PO
@ -3419,7 +3420,7 @@ export default {
})
},
// 稿POPO
// 稿PO
handleSaveEdit () {
this.$refs.addFormData.validate((valid) => {
if (!valid) {
@ -3427,25 +3428,17 @@ export default {
return
}
// PO
const originalPoKeys = new Set()
this.originalEditPoDetailList.forEach(item => {
const key = `${item.orderRef1 || ''}_${item.orderRef2 || ''}`
originalPoKeys.add(key)
})
const newPoItems = [] // PO
const modifiedPoItems = [] // PO
// PO
const allItems = []
this.editPoDetailList.forEach(row => {
const key = `${row.orderRef1 || ''}_${row.orderRef2 || ''}`
// key
//
if (this.deletedPoKeys.has(key)) {
return
}
const itemData = {
allItems.push({
orderNo: row.poNo || row.orderNo || row.order_ref1 || row.orderRef1 || '',
orderRef1: row.orderRef1 || row.order_ref1 || '',
orderRef2: row.orderRef2 || row.order_ref2 || '',
@ -3454,156 +3447,37 @@ export default {
qty: row.qty || 0,
shipMethod: row.shipMethod || row.shipMothod || '',
crd: row.crd || ''
}
if (originalPoKeys.has(key)) {
// PO
modifiedPoItems.push(itemData)
} else {
// PO
newPoItems.push(itemData)
}
})
console.log('=== 区分新增和修改 ===', {
'新增PO数量': newPoItems.length,
'修改PO数量': modifiedPoItems.length,
'新增PO': newPoItems,
'修改PO': modifiedPoItems
})
// 1. -> 2. -> 3. -> 4.
let promiseChain = Promise.resolve()
// 0. PO deleteInspectionDetails
if (this.deletedPoKeys.size > 0) {
const deletedItemNos = []
this.deletedPoKeys.forEach(itemStr => {
try {
const item = JSON.parse(itemStr)
if (item.itemNo) {
deletedItemNos.push(item.itemNo)
}
} catch (e) {
console.error('解析删除项失败:', itemStr, e)
}
})
if (deletedItemNos.length > 0) {
promiseChain = promiseChain.then(() => {
return this.deletePoDetails(deletedItemNos)
})
}
}
// 1. PO editInspectionDetails
if (modifiedPoItems.length > 0) {
promiseChain = promiseChain.then(() => {
return this.editModifiedPoDetails(modifiedPoItems)
})
}
// 2. PO addInspectionDetails
if (newPoItems.length > 0) {
promiseChain = promiseChain.then(() => {
return this.addNewPoDetails(newPoItems)
})
}
// 3.
promiseChain = promiseChain.then(() => {
const baseSubmitData = {
requestNo: this.addFormData.requestNo,
needInspectDate: this.addFormData.needInspectDate,
inspectAddress: this.addFormData.inspectAddressId || this.addFormData.inspectAddress,
inspectAddressId: this.addFormData.inspectAddressId || '',
inspectContract: this.addFormData.contact
}
return updateInspectionRequest(baseSubmitData).then(({ data }) => {
if (data.code === 0) {
this.$message.success('修改成功')
this.handleCloseAddDialog()
this.getMainData()
} else {
this.$message.error(data.msg || '基础信息保存失败')
}
})
}).catch((error) => {
console.error('保存失败:', error)
this.$message.error(error.message || '保存失败,请稍后重试')
})
})
},
// PO
addNewPoDetails (items) {
return new Promise((resolve, reject) => {
const params = {
console.log('=== 草稿编辑保存提交数据 ===', {
requestNo: this.addFormData.requestNo,
site: this.$store.state.user.site,
items: items
}
console.log('=== 调用 addInspectionDetails ===', params)
addInspectionDetails(params).then(({ data }) => {
if (data && data.code === 0) {
console.log('新增PO明细成功')
resolve()
} else {
reject(new Error(data.msg || '新增PO明细失败'))
}
}).catch(error => {
reject(error)
明细数量: allItems.length,
明细: allItems
})
})
},
// PO
editModifiedPoDetails (items) {
return new Promise((resolve, reject) => {
const params = {
// +
const submitData = {
requestNo: this.addFormData.requestNo,
site: this.$store.state.user.site,
items: items
items: allItems,
needInspectDate: this.addFormData.needInspectDate,
inspectAddress: this.addFormData.inspectAddressId || this.addFormData.inspectAddress,
inspectAddressId: this.addFormData.inspectAddressId || '',
inspectContract: this.addFormData.contact
}
console.log('=== 调用 editInspectionDetails ===', params)
editInspectionDetails(params).then(({ data }) => {
if (data && data.code === 0) {
console.log('修改PO明细成功')
resolve()
} else {
reject(new Error(data.msg || '修改PO明细失败'))
}
}).catch(error => {
reject(error)
})
})
},
// PO
deletePoDetails (itemNos) {
return new Promise((resolve, reject) => {
const params = {
requestNo: this.addFormData.requestNo,
site: this.$store.state.user.site,
itemNos: itemNos
}
console.log('=== 调用 deleteInspectionDetails ===', params)
deleteInspectionDetails(params).then(({ data }) => {
if (data && data.code === 0) {
console.log('删除PO明细成功')
resolve()
editSaveInspectionRequest(submitData).then(({ data }) => {
if (data.code === 0) {
this.$message.success('修改成功')
this.handleCloseAddDialog()
this.getMainData()
} else {
reject(new Error(data.msg || '删除PO明细失败'))
this.$message.error(data.msg || '修改失败')
}
}).catch(error => {
reject(error)
}).catch((error) => {
console.error('保存失败:', error)
this.$message.error(error.message || '保存失败,请稍后重试')
})
})
},

Loading…
Cancel
Save