|
|
@ -1111,7 +1111,7 @@ |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script> |
|
|
<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 { searchSrmSupplierAddressList, createSrmSupplierAddress, updateSrmSupplierAddress, searchSrmSupplierList } from '@/api/srm/srmSupplier.js' |
|
|
import { getPermissionValue } from '@/api/sys/specialSecurity.js' |
|
|
import { getPermissionValue } from '@/api/sys/specialSecurity.js' |
|
|
import Chooselist from '@/views/modules/common/Chooselist_eam' |
|
|
import Chooselist from '@/views/modules/common/Chooselist_eam' |
|
|
@ -2442,7 +2442,8 @@ export default { |
|
|
shipMethod: row.shipMethod || row.shipMothod || '', |
|
|
shipMethod: row.shipMethod || row.shipMothod || '', |
|
|
shipMothod: row.shipMethod || row.shipMothod || '', // 保持字段一致性 |
|
|
shipMothod: row.shipMethod || row.shipMothod || '', // 保持字段一致性 |
|
|
crd: row.crd || '', |
|
|
crd: row.crd || '', |
|
|
waitInspectQty: row.waitInspectQty || 0 |
|
|
|
|
|
|
|
|
waitInspectQty: row.waitInspectQty || 0, |
|
|
|
|
|
totalQty: row.waitInspectQty || 0 // 新增明细的未验货数量取PO的可用待验数量 |
|
|
})) |
|
|
})) |
|
|
|
|
|
|
|
|
// 将新PO明细添加到编辑列表中 |
|
|
// 将新PO明细添加到编辑列表中 |
|
|
@ -3419,7 +3420,7 @@ export default { |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 草稿编辑保存:先新增PO,再修改PO,最后更新基础信息 |
|
|
|
|
|
|
|
|
// 草稿编辑保存:将当前表格中所有PO明细(排除已删除的)作为最终状态一次性提交 |
|
|
handleSaveEdit () { |
|
|
handleSaveEdit () { |
|
|
this.$refs.addFormData.validate((valid) => { |
|
|
this.$refs.addFormData.validate((valid) => { |
|
|
if (!valid) { |
|
|
if (!valid) { |
|
|
@ -3427,25 +3428,17 @@ export default { |
|
|
return |
|
|
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 => { |
|
|
this.editPoDetailList.forEach(row => { |
|
|
const key = `${row.orderRef1 || ''}_${row.orderRef2 || ''}` |
|
|
const key = `${row.orderRef1 || ''}_${row.orderRef2 || ''}` |
|
|
|
|
|
|
|
|
// 如果这个key在被删除列表中,跳过(不新增也不修改) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 跳过已删除的 |
|
|
if (this.deletedPoKeys.has(key)) { |
|
|
if (this.deletedPoKeys.has(key)) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const itemData = { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allItems.push({ |
|
|
orderNo: row.poNo || row.orderNo || row.order_ref1 || row.orderRef1 || '', |
|
|
orderNo: row.poNo || row.orderNo || row.order_ref1 || row.orderRef1 || '', |
|
|
orderRef1: row.orderRef1 || row.order_ref1 || '', |
|
|
orderRef1: row.orderRef1 || row.order_ref1 || '', |
|
|
orderRef2: row.orderRef2 || row.order_ref2 || '', |
|
|
orderRef2: row.orderRef2 || row.order_ref2 || '', |
|
|
@ -3454,156 +3447,37 @@ export default { |
|
|
qty: row.qty || 0, |
|
|
qty: row.qty || 0, |
|
|
shipMethod: row.shipMethod || row.shipMothod || '', |
|
|
shipMethod: row.shipMethod || row.shipMothod || '', |
|
|
crd: row.crd || '' |
|
|
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, |
|
|
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, |
|
|
requestNo: this.addFormData.requestNo, |
|
|
site: this.$store.state.user.site, |
|
|
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 { |
|
|
} 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 || '保存失败,请稍后重试') |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|