增加产品价和红线价重计费功能
This commit is contained in:
@@ -286,3 +286,48 @@ export function listChargeWeightImportAttachments(query) {
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
/** Submit async recalc (PRODUCT / REDLINE) */
|
||||
export function submitRecalcBillPrice(mode, data) {
|
||||
const path = mode === 'REDLINE' ? 'recalcRedline' : 'recalcProduct'
|
||||
return request({
|
||||
url: '/price/billing/bill/' + path,
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function getRecalcBillPriceTask(taskId) {
|
||||
return request({
|
||||
url: '/price/billing/bill/recalcPrice/task/' + taskId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Async recalc product/redline amount; poll until done.
|
||||
* @param {'PRODUCT'|'REDLINE'} mode
|
||||
* @param {object} data
|
||||
* @param {(task: object) => void} [onProgress]
|
||||
*/
|
||||
export async function recalcBillPriceAsync(mode, data, onProgress) {
|
||||
const submitRes = await submitRecalcBillPrice(mode, data)
|
||||
const d = submitRes && submitRes.data
|
||||
const taskId = d && (d.taskId || d)
|
||||
if (!taskId) throw new Error('missing recalc taskId')
|
||||
const started = Date.now()
|
||||
const maxMs = 30 * 60 * 1000
|
||||
while (Date.now() - started < maxMs) {
|
||||
const res = await getRecalcBillPriceTask(String(taskId))
|
||||
const task = res.data || {}
|
||||
if (typeof onProgress === 'function') onProgress(task)
|
||||
if (task.status === 'SUCCESS') return { task }
|
||||
if (task.status === 'FAIL') {
|
||||
const err = new Error(task.error || task.message || 'recalc price failed')
|
||||
err.task = task
|
||||
throw err
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 800))
|
||||
}
|
||||
throw new Error('recalc price timeout')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user