优化
This commit is contained in:
@@ -382,9 +382,24 @@ describe('InboundMeasurementPanel', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('does not submit a second count update when the full draft already saved the changed count', async () => {
|
||||
const wrapper = await mountPanel()
|
||||
await wrapper.find('.measurement-count-editor input').setValue('9')
|
||||
await wrapper.find('input[aria-label="仓库修改外箱长"]').setValue('55')
|
||||
const save = wrapper.findAll('button').find((button) => button.text().includes('保存测量数据'))
|
||||
await save?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(saveInboundMeasurementDraft).toHaveBeenCalledWith('10001', '7001', expect.objectContaining({
|
||||
version: 2,
|
||||
items: [expect.objectContaining({ packageCount: 9, outerLengthCm: 55 })],
|
||||
}))
|
||||
expect(updateConfirmedPackageCount).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('preserves the edited form when the backend reports a version conflict', async () => {
|
||||
vi.mocked(updateConfirmedPackageCount).mockRejectedValueOnce(
|
||||
new ApiResponseError('数据版本已变化,请刷新后重试', 'A0409', 200, null, 'req-conflict', 'trace-conflict'),
|
||||
new ApiResponseError('测量数据已被其他人修改,请刷新后重试', 'A0409', 200, null, 'req-conflict', 'trace-conflict'),
|
||||
)
|
||||
const wrapper = await mountPanel()
|
||||
const countInput = wrapper.find('.measurement-count-editor input')
|
||||
|
||||
@@ -410,6 +410,7 @@ function setOperationError(error: unknown, fallback: string) {
|
||||
} : source
|
||||
const conflict = details.message.includes('版本已变化')
|
||||
|| details.message.includes('并发修改')
|
||||
|| details.message.includes('已被其他人修改')
|
||||
conflictDetected.value = conflict
|
||||
operationError.value = conflict ? details : null
|
||||
if (!conflict) {
|
||||
@@ -453,12 +454,14 @@ async function saveDraft() {
|
||||
})
|
||||
version = saved.version
|
||||
}
|
||||
for (const item of changedItems) {
|
||||
const saved = await updateConfirmedPackageCount(customerId.value, props.inboundId, item.itemId, {
|
||||
measurementVersion: version,
|
||||
confirmedPackageCount: item.packageCount,
|
||||
})
|
||||
version = saved.measurementVersion
|
||||
if (!draftChanged) {
|
||||
for (const item of changedItems) {
|
||||
const saved = await updateConfirmedPackageCount(customerId.value, props.inboundId, item.itemId, {
|
||||
measurementVersion: version,
|
||||
confirmedPackageCount: item.packageCount,
|
||||
})
|
||||
version = saved.measurementVersion
|
||||
}
|
||||
}
|
||||
form.version = version
|
||||
ElMessage.success('确认箱数已保存,计算结果已由服务端更新')
|
||||
|
||||
Reference in New Issue
Block a user