增加可修改计费重功能
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import request from '@/utils/request'
|
||||
import { saveAs } from 'file-saver'
|
||||
import { blobValidate } from '@/utils/bms'
|
||||
import { ElLoading } from 'element-plus'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
|
||||
/** Quote trial for billing center */
|
||||
export function quoteBilling(data) {
|
||||
@@ -187,3 +191,89 @@ export function updateCreditArrears(billIds) {
|
||||
data: billIds
|
||||
})
|
||||
}
|
||||
|
||||
/** 计费列表:单票修改计费重(写 charge_weight,保留 weight)并重新计费 */
|
||||
export function updateChargeWeight(data) {
|
||||
return request({
|
||||
url: '/price/billing/bill/chargeWeight',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function getChargeWeightImportTask(taskId) {
|
||||
return request({
|
||||
url: '/price/billing/bill/chargeWeight/import/task/' + taskId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
function pickChargeWeightImportTaskId(res) {
|
||||
const d = res && res.data
|
||||
if (!d) return ''
|
||||
if (typeof d === 'string' || typeof d === 'number') return String(d)
|
||||
return String(d.taskId || d.id || '')
|
||||
}
|
||||
|
||||
async function pollChargeWeightImportTask(taskId, onProgress) {
|
||||
const started = Date.now()
|
||||
const maxMs = 30 * 60 * 1000
|
||||
while (Date.now() - started < maxMs) {
|
||||
const res = await getChargeWeightImportTask(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 || 'charge weight import failed')
|
||||
err.task = task
|
||||
throw err
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 800))
|
||||
}
|
||||
throw new Error('charge weight import timeout')
|
||||
}
|
||||
|
||||
/**
|
||||
* Async import charge weight + rebill; poll until done.
|
||||
* @param {File|Blob} file
|
||||
* @param {(task: object) => void} [onProgress]
|
||||
*/
|
||||
export async function importChargeWeightAsync(file, onProgress) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const submitRes = await request({
|
||||
url: '/price/billing/bill/chargeWeight/importData',
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: { 'Content-Type': 'multipart/form-data', repeatSubmit: false },
|
||||
// Backend parses Excel + validates rows before returning taskId
|
||||
timeout: 10 * 60 * 1000
|
||||
})
|
||||
const taskId = pickChargeWeightImportTaskId(submitRes)
|
||||
if (!taskId) throw new Error('missing charge weight import taskId')
|
||||
return pollChargeWeightImportTask(taskId, onProgress)
|
||||
}
|
||||
|
||||
/** Download charge-weight import template (optionally fill by list filters). */
|
||||
export async function downloadChargeWeightTemplate(data, filename) {
|
||||
const loading = ElLoading.service({ text: '正在下载模板,请稍候', background: 'rgba(0, 0, 0, 0.7)' })
|
||||
try {
|
||||
const blobData = await request({
|
||||
url: '/price/billing/bill/chargeWeight/importTemplate',
|
||||
method: 'post',
|
||||
data: data || {},
|
||||
responseType: 'blob',
|
||||
timeout: 120000
|
||||
})
|
||||
if (blobValidate(blobData)) {
|
||||
saveAs(new Blob([blobData]), filename || ('批量修改计费重导入模板_' + Date.now() + '.xlsx'))
|
||||
return
|
||||
}
|
||||
const resText = await blobData.text()
|
||||
const rspObj = JSON.parse(resText)
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'] || '下载模板失败'
|
||||
throw new Error(errMsg)
|
||||
} finally {
|
||||
loading.close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user