865 lines
34 KiB
Vue
865 lines
34 KiB
Vue
<template>
|
||
<div class="app-container pay-order-page">
|
||
<div v-if="recalcFloatVisible" class="retry-status-float">
|
||
<el-tooltip :content="recalcFloatTooltip" placement="bottom">
|
||
<el-button class="retry-status-button" type="primary" plain size="small" @click="openRecalcProgress">
|
||
<span class="retry-progress-ring" :style="{ '--retry-progress': recalcProgressDegree + 'deg' }" aria-hidden="true">
|
||
<span class="retry-progress-value">{{ recalcProgressText }}</span>
|
||
</span>
|
||
<span class="retry-status-text">
|
||
<strong>{{ recalcFloatTitle }}</strong>
|
||
<small>{{ recalcFloatSummary }}</small>
|
||
</span>
|
||
</el-button>
|
||
</el-tooltip>
|
||
</div>
|
||
<el-form :inline="true" :model="query" class="mb8">
|
||
<el-form-item label="订单号">
|
||
<el-input v-model="query.orderNo" type="textarea" :rows="2" clearable placeholder="多个订单号可用逗号、空格或换行分隔" style="width: 280px" />
|
||
</el-form-item>
|
||
<el-form-item label="提单号">
|
||
<el-input v-model="query.ladingNo" clearable placeholder="提单号" style="width: 180px" @keyup.enter="search" />
|
||
</el-form-item>
|
||
<el-form-item label="客户">
|
||
<el-input v-model="query.customerName" clearable placeholder="客户名称或代码" style="width: 180px" @keyup.enter="search" />
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" icon="Search" @click="search">查询</el-button>
|
||
<el-button icon="Refresh" @click="reset">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<el-row class="mb8">
|
||
<el-button type="primary" plain icon="RefreshRight" :loading="recalcRunning" v-hasPermi="['price:payOrder:recalc']" @click="openRecalc">费用重算</el-button>
|
||
</el-row>
|
||
|
||
<el-table v-loading="loading" :data="rows" border>
|
||
<el-table-column prop="orderNo" label="订单号" min-width="160" fixed="left" show-overflow-tooltip />
|
||
<el-table-column prop="ladingNo" label="提单号" min-width="150" fixed="left" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.ladingNo || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="trackingNo" label="运单号" min-width="150" show-overflow-tooltip />
|
||
<el-table-column prop="customerName" label="客户" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="productName" label="产品" min-width="160" show-overflow-tooltip />
|
||
<el-table-column prop="countryName" label="目的国" width="110" show-overflow-tooltip />
|
||
<el-table-column prop="destPostcode" label="邮编" width="120" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.destPostcode || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="channelName" label="渠道" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="chargeWeight" label="计费重" width="90" align="right" />
|
||
<el-table-column prop="payTotal" label="应付总额" width="110" align="right">
|
||
<template #default="{ row }">{{ money2(row.payTotal) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="currency" label="币种" width="80" align="center" />
|
||
<el-table-column label="计费状态" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<dict-tag v-if="row.payCalcStatus != null && row.payCalcStatus !== ''" :options="bms_pay_calc_status" :value="row.payCalcStatus" />
|
||
<span v-else>-</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="payCalcMsg" label="失败原因" min-width="180" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.payCalcMsg || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="bizDate" label="计费时间" width="170" align="center" />
|
||
<el-table-column prop="updateBy" label="更新人" width="110" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ actorName(row.updateBy) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="updateTime" label="更新时间" width="170" align="center">
|
||
<template #default="{ row }">{{ row.updateTime || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="190" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" v-hasPermi="['price:payOrder:query']" @click="openDetail(row)">详情</el-button>
|
||
<el-button link type="primary" v-hasPermi="['price:payOrder:fee']" @click="openFees(row)">费用</el-button>
|
||
<el-button link type="primary" v-hasPermi="['price:payOrder:log']" @click="openLogs(row)">日志</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<pagination v-show="total > 0" :total="total" v-model:page="query.pageNum" v-model:limit="query.pageSize" @pagination="loadList" />
|
||
|
||
<bill-detail v-model="detailOpen" title="订单详情" :loading="detailLoading" :detail="detail" :show-income="false" />
|
||
|
||
<el-dialog v-model="feeOpen" :title="feeTitle" width="1280px" append-to-body destroy-on-close>
|
||
<div v-loading="feeLoading" class="fee-board">
|
||
<section v-for="section in sections" :key="section.level" class="fee-section">
|
||
<div class="fee-head">{{ section.title }}</div>
|
||
<div class="fee-tools">
|
||
<el-button v-hasPermi="['price:payOrder:feeAdd']" type="primary" plain size="small" @click="addFeeRow(section)">增加费用</el-button>
|
||
</div>
|
||
<el-table class="fee-table" :data="section.fees" border table-layout="fixed" empty-text="无">
|
||
<el-table-column label="费用项" min-width="1" header-align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<el-select v-if="row.editing" v-model="row.pick" filterable allow-create default-first-option placeholder="选择或输入" @change="pickFee(row)">
|
||
<el-option v-for="item in (bms_fee_type || [])" :key="item.value" :label="item.label" :value="item.value" />
|
||
</el-select>
|
||
<span v-else>{{ row.feeName }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="金额" min-width="1" header-align="center" align="right" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<el-input-number v-if="row.editing" v-model="row.amount" :precision="3" :controls="false" />
|
||
<span v-else>{{ money3(row.amount) }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="币种" min-width="1" header-align="center" align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<el-select v-if="row.editing" v-model="row.currency" filterable>
|
||
<el-option v-for="item in (bms_currency || [])" :key="item.value" :label="item.label" :value="item.value" />
|
||
</el-select>
|
||
<span v-else>{{ row.currency }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="说明" min-width="1" header-align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<el-input v-if="row.editing" v-model="row.remark" maxlength="200" />
|
||
<span v-else>{{ row.remark }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="来源" min-width="1" header-align="center" align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ sourceText(row.feeSource) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="创建人" min-width="1" header-align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ actorName(row.createBy) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="createTime" label="创建时间" min-width="1" header-align="center" show-overflow-tooltip />
|
||
<el-table-column label="更新人" min-width="1" header-align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ actorName(row.updateBy) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="updateTime" label="更新时间" min-width="1" header-align="center" show-overflow-tooltip />
|
||
<el-table-column label="操作" min-width="1" header-align="center" align="center" class-name="fee-op">
|
||
<template #default="{ row }">
|
||
<el-button v-if="row.editing" link type="primary" @click="saveFeeRow(section, row)">保存</el-button>
|
||
<el-button v-if="row.editing" link type="danger" @click="removeFeeRow(section, row)">删除</el-button>
|
||
<el-button v-else v-hasPermi="['price:payOrder:feeRemove']" link type="danger" @click="removeFeeRow(section, row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</section>
|
||
</div>
|
||
</el-dialog>
|
||
|
||
<el-dialog v-model="logOpen" :title="logTitle" width="980px" append-to-body>
|
||
<el-table v-loading="logLoading" class="fee-log-table" :data="logRows" border empty-text="无">
|
||
<el-table-column label="变更前" min-width="200" header-align="center">
|
||
<template #default="{ row }">
|
||
<div v-if="logLines(row, 'before').length" class="log-change">
|
||
<div v-for="(line, index) in logLines(row, 'before')" :key="index">{{ line }}</div>
|
||
</div>
|
||
<span v-else class="log-empty">空</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="变更后" min-width="200" header-align="center">
|
||
<template #default="{ row }">
|
||
<div v-if="logLines(row, 'after').length" class="log-change">
|
||
<div v-for="(line, index) in logLines(row, 'after')" :key="index">{{ line }}</div>
|
||
</div>
|
||
<span v-else class="log-empty">空</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="remark" label="备注" min-width="180" header-align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.remark || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作类型" width="120" header-align="center" align="center">
|
||
<template #default="{ row }">
|
||
<dict-tag :options="bms_pay_fee_log_type" :value="row.operationType" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作人" width="120" header-align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ actorName(row.createBy) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="createTime" label="操作时间" width="170" header-align="center" align="center" />
|
||
</el-table>
|
||
<pagination v-show="logTotal > 0" :total="logTotal" v-model:page="logQuery.pageNum" v-model:limit="logQuery.pageSize" @pagination="loadLogs" />
|
||
</el-dialog>
|
||
|
||
<el-dialog v-model="recalcOpen" title="费用重算" width="720px" append-to-body :close-on-click-modal="false">
|
||
<el-form label-width="90px">
|
||
<el-form-item label="重算方式">
|
||
<el-radio-group v-model="recalcForm.sourceType" :disabled="recalcSaving">
|
||
<el-radio value="ORDER">订单号</el-radio>
|
||
<el-radio value="LADING">提单号</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item :label="recalcForm.sourceType === 'LADING' ? '提单号' : '订单号'">
|
||
<el-input v-model="recalcForm.text" type="textarea" :rows="6" :disabled="recalcSaving" :placeholder="recalcPlaceholder" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="recalcOpen = false">关闭</el-button>
|
||
<el-button type="primary" :loading="recalcSaving" @click="submitRecalc">确认</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
v-model="recalcProgressVisible"
|
||
:title="recalcDialogTitle"
|
||
width="560px"
|
||
append-to-body
|
||
:close-on-click-modal="false"
|
||
:close-on-press-escape="true"
|
||
:show-close="true"
|
||
>
|
||
<el-progress
|
||
:percentage="recalcProgressPercent"
|
||
:status="recalcProgressStatus"
|
||
:stroke-width="14"
|
||
striped
|
||
:striped-flow="recalcRunning"
|
||
/>
|
||
<div class="rebill-progress__msg">{{ recalcProgressMessage }}</div>
|
||
<div v-if="!recalcRunning && recalcFinished" class="rebill-result-stats">
|
||
<div class="rebill-result-stats__item">
|
||
<span class="rebill-result-stats__label">总数</span>
|
||
<strong>{{ recalcProgressTotal }}</strong>
|
||
</div>
|
||
<div class="rebill-result-stats__item is-success">
|
||
<span class="rebill-result-stats__label">成功</span>
|
||
<strong>{{ recalcProgressSuccess }}</strong>
|
||
</div>
|
||
<div class="rebill-result-stats__item is-fail">
|
||
<span class="rebill-result-stats__label">失败</span>
|
||
<strong>{{ recalcProgressFail }}</strong>
|
||
</div>
|
||
</div>
|
||
<div v-else class="rebill-progress__text">
|
||
总数 {{ recalcProgressTotal }}
|
||
/ 成功 {{ recalcProgressSuccess }}
|
||
/ 失败 {{ recalcProgressFail }}
|
||
</div>
|
||
<el-table v-if="!recalcRunning && recalcFails.length" :data="recalcFails" border size="small" max-height="220" class="rebill-progress__error" empty-text="没有失败记录">
|
||
<el-table-column prop="orderNo" label="订单号" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="ladingNo" label="提单号" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="message" label="原因" min-width="180" show-overflow-tooltip />
|
||
</el-table>
|
||
<p v-if="recalcRunning" class="rebill-progress__hint">重算在后台进行,可收起弹窗继续操作;请勿关闭或刷新本页</p>
|
||
<template #footer>
|
||
<el-button v-if="recalcRunning" @click="recalcProgressVisible = false">收起</el-button>
|
||
<el-button
|
||
v-if="recalcRunning"
|
||
v-hasPermi="['price:payOrder:recalc']"
|
||
type="danger"
|
||
plain
|
||
:loading="recalcCancelLoading"
|
||
@click="handleCancelRecalc"
|
||
>取消重算</el-button>
|
||
<template v-else>
|
||
<el-button v-if="recalcFails.length" v-hasPermi="['price:payOrder:recalc']" type="warning" plain @click="viewRecalcFailed">查看失败订单</el-button>
|
||
<el-button type="primary" @click="recalcProgressVisible = false">关闭</el-button>
|
||
</template>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup name="PayOrderList">
|
||
import { addPayOrderFee, cancelPayOrderRecalc, getPayOrder, getPayOrderRecalcTask, listPayOrder, listPayOrderFeeLogs, listPayOrderFees, pollPayOrderRecalc, removePayOrderFee, submitPayOrderRecalc } from '@/api/price/payOrder'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import BillDetail from '../components/BillDetail.vue'
|
||
|
||
const { proxy } = getCurrentInstance()
|
||
const { bms_pay_calc_status, bms_fee_type, bms_currency, bms_pay_fee_log_type } = useDict('bms_pay_calc_status', 'bms_fee_type', 'bms_currency', 'bms_pay_fee_log_type')
|
||
|
||
const loading = ref(false)
|
||
const rows = ref([])
|
||
const total = ref(0)
|
||
const query = reactive({ orderNo: '', ladingNo: '', customerName: '', pageNum: 1, pageSize: 20 })
|
||
|
||
const detailOpen = ref(false)
|
||
const detailLoading = ref(false)
|
||
const detail = ref(null)
|
||
|
||
const feeOpen = ref(false)
|
||
const feeLoading = ref(false)
|
||
const feeTitle = ref('应付费用')
|
||
const feeBillId = ref('')
|
||
const sections = ref([])
|
||
const logOpen = ref(false)
|
||
const logLoading = ref(false)
|
||
const logTitle = ref('费用日志')
|
||
const logBillId = ref('')
|
||
const logRows = ref([])
|
||
const logTotal = ref(0)
|
||
const logQuery = reactive({ pageNum: 1, pageSize: 10 })
|
||
const recalcOpen = ref(false)
|
||
const recalcSaving = ref(false)
|
||
const recalcForm = reactive({ sourceType: 'ORDER', text: '' })
|
||
const recalcPlaceholder = computed(() => recalcForm.sourceType === 'LADING'
|
||
? '多个提单号可用逗号、空格或换行分隔,一次最多10个'
|
||
: '多个订单号可用逗号、空格或换行分隔,一次最多500个')
|
||
const recalcRunning = ref(false)
|
||
const recalcFinished = ref(false)
|
||
const recalcProgressVisible = ref(false)
|
||
const recalcProgressPercent = ref(0)
|
||
const recalcProgressMessage = ref('')
|
||
const recalcProgressStatus = ref(undefined)
|
||
const recalcProgressTotal = ref(0)
|
||
const recalcProgressSuccess = ref(0)
|
||
const recalcProgressFail = ref(0)
|
||
const recalcLines = ref([])
|
||
const recalcTaskId = ref('')
|
||
const recalcCancelLoading = ref(false)
|
||
let recalcFloatHideTimer = null
|
||
const RECALC_TASK_STORAGE_KEY = 'price:payOrder:recalcTaskId'
|
||
const recalcFails = computed(() => (recalcLines.value || []).filter(line => line && line.finished && !line.success))
|
||
const recalcFloatVisible = computed(() => recalcRunning.value || recalcFinished.value)
|
||
const recalcProgressDegree = computed(() => Math.round(((recalcProgressPercent.value || 0) / 100) * 360))
|
||
const recalcProgressText = computed(() => (recalcProgressPercent.value || 0) + '%')
|
||
const recalcDialogTitle = computed(() => {
|
||
if (recalcRunning.value) return '费用重算进行中'
|
||
if (recalcFinished.value) return '费用重算完成'
|
||
return '费用重算'
|
||
})
|
||
const recalcFloatTitle = computed(() => {
|
||
if (recalcRunning.value) return '费用重算中'
|
||
if (recalcProgressStatus.value === 'exception') return '费用重算失败'
|
||
if (recalcProgressStatus.value === 'warning' && String(recalcProgressMessage.value || '').includes('已取消')) return '费用重算已取消'
|
||
if (recalcFinished.value) return '费用重算完成'
|
||
return '费用重算'
|
||
})
|
||
const recalcFloatSummary = computed(() =>
|
||
'成功 ' + (recalcProgressSuccess.value || 0) +
|
||
' / 失败 ' + (recalcProgressFail.value || 0) +
|
||
' / 总数 ' + (recalcProgressTotal.value || 0)
|
||
)
|
||
const recalcFloatTooltip = computed(() => recalcProgressMessage.value || '点击查看详情')
|
||
|
||
const sources = {
|
||
CALC: '尾程计算',
|
||
LADING: '提单分摊',
|
||
MANUAL: '手工'
|
||
}
|
||
|
||
function money2(value) {
|
||
if (value === null || value === undefined || value === '') return '-'
|
||
const num = Number(value)
|
||
return Number.isNaN(num) ? value : num.toFixed(2)
|
||
}
|
||
|
||
function money3(value) {
|
||
if (value === null || value === undefined || value === '') return '-'
|
||
const num = Number(value)
|
||
return Number.isNaN(num) ? value : num.toFixed(3)
|
||
}
|
||
|
||
function sourceText(value) {
|
||
return sources[value] || value || '-'
|
||
}
|
||
|
||
function actorName(value) {
|
||
const text = value == null ? '' : String(value).trim()
|
||
if (!text) {
|
||
return '-'
|
||
}
|
||
return text.toLowerCase() === 'system' ? '系统自动' : text
|
||
}
|
||
|
||
function logLines(row, side) {
|
||
const name = row?.[side + 'FeeName']
|
||
const amount = row?.[side + 'Amount']
|
||
const currency = row?.[side + 'Currency']
|
||
const blank = (name == null || name === '') && (amount == null || amount === '') && (currency == null || currency === '')
|
||
if (blank) {
|
||
return []
|
||
}
|
||
return [
|
||
'费用项:' + (name || '空'),
|
||
'金额:' + (amount == null || amount === '' ? '空' : amount),
|
||
'币种:' + (currency || '空')
|
||
]
|
||
}
|
||
|
||
function loadLogPage(billId, query, rows, total, loading) {
|
||
if (!billId) {
|
||
rows.value = []
|
||
total.value = 0
|
||
return
|
||
}
|
||
loading.value = true
|
||
listPayOrderFeeLogs(billId, { pageNum: query.pageNum, pageSize: query.pageSize }).then(res => {
|
||
rows.value = res.rows || []
|
||
total.value = res.total || 0
|
||
}).catch(() => {
|
||
proxy.$modal.msgError('费用日志加载失败')
|
||
}).finally(() => {
|
||
loading.value = false
|
||
})
|
||
}
|
||
|
||
function search() {
|
||
query.pageNum = 1
|
||
loadList()
|
||
}
|
||
|
||
function reset() {
|
||
query.orderNo = ''
|
||
query.ladingNo = ''
|
||
query.customerName = ''
|
||
search()
|
||
}
|
||
|
||
function loadList() {
|
||
loading.value = true
|
||
listPayOrder(query).then(res => {
|
||
rows.value = res.rows || []
|
||
total.value = res.total || 0
|
||
}).finally(() => {
|
||
loading.value = false
|
||
})
|
||
}
|
||
|
||
function openDetail(row) {
|
||
detail.value = null
|
||
detailOpen.value = true
|
||
detailLoading.value = true
|
||
getPayOrder(row.billId).then(res => {
|
||
detail.value = res.data || null
|
||
}).finally(() => {
|
||
detailLoading.value = false
|
||
})
|
||
}
|
||
|
||
function openFees(row) {
|
||
feeTitle.value = (row.orderNo || '订单') + '的应付费用'
|
||
feeBillId.value = row.billId
|
||
sections.value = []
|
||
feeOpen.value = true
|
||
loadFees()
|
||
}
|
||
|
||
function openLogs(row) {
|
||
logTitle.value = (row.orderNo || '订单') + '的费用日志'
|
||
logBillId.value = row.billId
|
||
logQuery.pageNum = 1
|
||
logRows.value = []
|
||
logOpen.value = true
|
||
loadLogs()
|
||
}
|
||
|
||
function loadLogs() {
|
||
loadLogPage(logBillId.value, logQuery, logRows, logTotal, logLoading)
|
||
}
|
||
|
||
function loadFees() {
|
||
if (!feeBillId.value) {
|
||
return
|
||
}
|
||
feeLoading.value = true
|
||
listPayOrderFees(feeBillId.value).then(res => {
|
||
sections.value = res.data?.sections || []
|
||
}).catch(() => {
|
||
proxy.$modal.msgError('费用加载失败')
|
||
}).finally(() => {
|
||
feeLoading.value = false
|
||
})
|
||
}
|
||
|
||
function addFeeRow(section) {
|
||
if ((section.fees || []).some(item => item.editing)) {
|
||
proxy.$modal.msgWarning('请先保存当前新增的费用')
|
||
return
|
||
}
|
||
if (!section.fees) {
|
||
section.fees = []
|
||
}
|
||
section.fees.push({
|
||
editing: true,
|
||
pick: '',
|
||
feeType: '',
|
||
feeName: '',
|
||
amount: null,
|
||
currency: 'CNY',
|
||
remark: '',
|
||
feeSource: 'MANUAL'
|
||
})
|
||
}
|
||
|
||
function pickFee(row) {
|
||
const dict = (bms_fee_type.value || []).find(item => item.value === row.pick)
|
||
if (dict) {
|
||
row.feeType = dict.value
|
||
row.feeName = dict.label
|
||
return
|
||
}
|
||
row.feeType = row.pick
|
||
row.feeName = row.pick
|
||
}
|
||
|
||
function saveFeeRow(section, row) {
|
||
if (!row.feeName) {
|
||
proxy.$modal.msgWarning('请填写费用项')
|
||
return
|
||
}
|
||
if (row.amount === null || row.amount === undefined || row.amount === '') {
|
||
proxy.$modal.msgWarning('请填写金额')
|
||
return
|
||
}
|
||
feeLoading.value = true
|
||
addPayOrderFee(feeBillId.value, {
|
||
feeType: row.feeType,
|
||
feeName: row.feeName,
|
||
level: section.level,
|
||
amount: row.amount,
|
||
currency: row.currency || 'CNY',
|
||
remark: row.remark
|
||
}).then(() => {
|
||
proxy.$modal.msgSuccess('已增加费用')
|
||
loadFees()
|
||
loadList()
|
||
}).catch(() => {
|
||
feeLoading.value = false
|
||
})
|
||
}
|
||
|
||
function removeFeeRow(section, row) {
|
||
if (row.editing) {
|
||
section.fees = section.fees.filter(item => item !== row)
|
||
return
|
||
}
|
||
proxy.$modal.confirm('确认删除这条费用?').then(() => {
|
||
feeLoading.value = true
|
||
return removePayOrderFee(row.feeId)
|
||
}).then(() => {
|
||
proxy.$modal.msgSuccess('已删除')
|
||
loadFees()
|
||
loadList()
|
||
}).catch(() => {
|
||
feeLoading.value = false
|
||
})
|
||
}
|
||
|
||
function saveRecalcTaskId(taskId) {
|
||
recalcTaskId.value = taskId ? String(taskId) : ''
|
||
try {
|
||
if (recalcTaskId.value) sessionStorage.setItem(RECALC_TASK_STORAGE_KEY, recalcTaskId.value)
|
||
else sessionStorage.removeItem(RECALC_TASK_STORAGE_KEY)
|
||
} catch (e) { /* 刷新后恢复不了进度,不影响重算本身 */ }
|
||
}
|
||
|
||
function clearRecalcTaskId() {
|
||
saveRecalcTaskId('')
|
||
}
|
||
|
||
function readStoredRecalcTaskId() {
|
||
try {
|
||
return String(sessionStorage.getItem(RECALC_TASK_STORAGE_KEY) || '').trim()
|
||
} catch (e) {
|
||
return ''
|
||
}
|
||
}
|
||
|
||
function openRecalcProgress() {
|
||
recalcProgressVisible.value = true
|
||
}
|
||
|
||
function scheduleHideRecalcFloat() {
|
||
if (recalcFloatHideTimer) {
|
||
clearTimeout(recalcFloatHideTimer)
|
||
recalcFloatHideTimer = null
|
||
}
|
||
recalcFloatHideTimer = window.setTimeout(() => {
|
||
if (!recalcRunning.value && recalcFinished.value) recalcFinished.value = false
|
||
recalcFloatHideTimer = null
|
||
}, 8000)
|
||
}
|
||
|
||
function applyRecalcProgress(task) {
|
||
const total = Number(task.total) || 0
|
||
const success = Number(task.successCount) || 0
|
||
const fail = Number(task.failCount) || 0
|
||
recalcProgressPercent.value = Math.min(100, Number(task.percent) || 0)
|
||
recalcProgressTotal.value = total
|
||
recalcProgressSuccess.value = success
|
||
recalcProgressFail.value = fail
|
||
recalcLines.value = Array.isArray(task.lines) ? task.lines : []
|
||
const status = String(task.status || '').toUpperCase()
|
||
if (status === 'PENDING') {
|
||
recalcProgressMessage.value = '排队中…'
|
||
} else if (status === 'RUNNING' && String(task.message || '').includes('取消')) {
|
||
recalcProgressMessage.value = '正在取消,等待当前订单结束… ' + (success + fail) + '/' + total
|
||
} else if (status === 'RUNNING') {
|
||
recalcProgressMessage.value = '正在重算 ' + (success + fail) + '/' + total + (fail ? ('(失败 ' + fail + ')') : '')
|
||
}
|
||
}
|
||
|
||
function finishRecalcFromTask(task, cancelled) {
|
||
const success = Number(task && task.successCount) || 0
|
||
const fail = Number(task && task.failCount) || 0
|
||
const total = Number(task && task.total) || recalcProgressTotal.value || 0
|
||
recalcProgressPercent.value = Math.min(100, Number(task && task.percent) || 100)
|
||
recalcProgressStatus.value = cancelled ? 'warning' : (fail > 0 ? 'warning' : 'success')
|
||
recalcProgressTotal.value = total
|
||
recalcProgressSuccess.value = success
|
||
recalcProgressFail.value = fail
|
||
recalcLines.value = task && Array.isArray(task.lines) ? task.lines : recalcLines.value
|
||
if (cancelled) {
|
||
recalcProgressMessage.value = '费用重算已取消:成功 ' + success + ' / 失败 ' + fail + ' / 总数 ' + total
|
||
} else if (fail > 0) {
|
||
recalcProgressMessage.value = '费用重算完成(含失败):成功 ' + success + ' / 失败 ' + fail + ' / 总数 ' + total
|
||
} else {
|
||
recalcProgressMessage.value = '费用重算完成:成功 ' + success + ' / 失败 ' + fail + ' / 总数 ' + total
|
||
}
|
||
recalcFinished.value = true
|
||
clearRecalcTaskId()
|
||
loadList()
|
||
recalcProgressVisible.value = true
|
||
if (cancelled) ElMessage.warning(recalcProgressMessage.value)
|
||
else if (fail > 0) ElMessage.warning(recalcProgressMessage.value)
|
||
else ElMessage.success(recalcProgressMessage.value)
|
||
scheduleHideRecalcFloat()
|
||
}
|
||
|
||
async function resumeRecalcTask(taskId) {
|
||
if (!taskId || recalcRunning.value) return
|
||
recalcRunning.value = true
|
||
recalcFinished.value = false
|
||
recalcCancelLoading.value = false
|
||
saveRecalcTaskId(taskId)
|
||
recalcProgressVisible.value = false
|
||
recalcProgressPercent.value = 0
|
||
recalcProgressStatus.value = undefined
|
||
recalcProgressMessage.value = '恢复进度中…'
|
||
recalcProgressTotal.value = 0
|
||
recalcProgressSuccess.value = 0
|
||
recalcProgressFail.value = 0
|
||
recalcLines.value = []
|
||
let superseded = false
|
||
try {
|
||
const result = await pollPayOrderRecalc(taskId, applyRecalcProgress)
|
||
finishRecalcFromTask(result && result.task, !!(result && result.cancelled))
|
||
} catch (e) {
|
||
if (e && e.superseded) {
|
||
superseded = true
|
||
return
|
||
}
|
||
failRecalc(e)
|
||
} finally {
|
||
if (!superseded) recalcRunning.value = false
|
||
}
|
||
}
|
||
|
||
function failRecalc(e) {
|
||
const task = e && e.task
|
||
recalcProgressStatus.value = 'exception'
|
||
recalcProgressMessage.value = (e && e.message) || '费用重算失败'
|
||
recalcFinished.value = true
|
||
if (task) {
|
||
recalcProgressPercent.value = Math.min(100, Number(task.percent) || 100)
|
||
recalcProgressTotal.value = Number(task.total) || 0
|
||
recalcProgressSuccess.value = Number(task.successCount) || 0
|
||
recalcProgressFail.value = Number(task.failCount) || 0
|
||
recalcLines.value = Array.isArray(task.lines) ? task.lines : []
|
||
loadList()
|
||
}
|
||
clearRecalcTaskId()
|
||
recalcProgressVisible.value = true
|
||
scheduleHideRecalcFloat()
|
||
}
|
||
|
||
async function tryRestoreRecalcProgress() {
|
||
const taskId = readStoredRecalcTaskId()
|
||
if (!taskId) return
|
||
try {
|
||
const res = await getPayOrderRecalcTask(taskId)
|
||
const task = (res && res.data) || {}
|
||
const status = String(task.status || '').toUpperCase()
|
||
if (status === 'PENDING' || status === 'RUNNING') {
|
||
applyRecalcProgress(task)
|
||
resumeRecalcTask(taskId)
|
||
return
|
||
}
|
||
clearRecalcTaskId()
|
||
} catch (e) {
|
||
clearRecalcTaskId()
|
||
}
|
||
}
|
||
|
||
async function runRecalc(payload) {
|
||
if (recalcRunning.value) {
|
||
openRecalcProgress()
|
||
return
|
||
}
|
||
if (recalcFloatHideTimer) {
|
||
clearTimeout(recalcFloatHideTimer)
|
||
recalcFloatHideTimer = null
|
||
}
|
||
recalcRunning.value = true
|
||
recalcFinished.value = false
|
||
recalcCancelLoading.value = false
|
||
clearRecalcTaskId()
|
||
recalcProgressVisible.value = true
|
||
recalcProgressPercent.value = 0
|
||
recalcProgressStatus.value = undefined
|
||
recalcProgressMessage.value = '任务提交中…'
|
||
recalcProgressTotal.value = 0
|
||
recalcProgressSuccess.value = 0
|
||
recalcProgressFail.value = 0
|
||
recalcLines.value = []
|
||
window.setTimeout(() => {
|
||
if (recalcRunning.value) recalcProgressVisible.value = false
|
||
}, 600)
|
||
let superseded = false
|
||
try {
|
||
const res = await submitPayOrderRecalc(payload)
|
||
const taskId = res.data && res.data.taskId
|
||
if (!taskId) throw new Error('没有拿到重算任务')
|
||
saveRecalcTaskId(taskId)
|
||
const result = await pollPayOrderRecalc(taskId, applyRecalcProgress)
|
||
finishRecalcFromTask(result && result.task, !!(result && result.cancelled))
|
||
} catch (e) {
|
||
if (e && e.superseded) {
|
||
superseded = true
|
||
return
|
||
}
|
||
failRecalc(e)
|
||
} finally {
|
||
if (!superseded) recalcRunning.value = false
|
||
}
|
||
}
|
||
|
||
function openRecalc() {
|
||
if (recalcRunning.value) {
|
||
openRecalcProgress()
|
||
return
|
||
}
|
||
recalcForm.sourceType = 'ORDER'
|
||
recalcForm.text = ''
|
||
recalcOpen.value = true
|
||
}
|
||
|
||
async function submitRecalc() {
|
||
const text = String(recalcForm.text || '').trim()
|
||
if (!text) {
|
||
proxy.$modal.msgWarning(recalcForm.sourceType === 'LADING' ? '请填写提单号' : '请填写订单号')
|
||
return
|
||
}
|
||
if (recalcRunning.value) {
|
||
recalcOpen.value = false
|
||
openRecalcProgress()
|
||
return
|
||
}
|
||
const label = recalcForm.sourceType === 'LADING' ? '提单号' : '订单号'
|
||
const count = text.split(/[\s,,;;]+/).filter(Boolean).length
|
||
try {
|
||
await ElMessageBox.confirm('将按 ' + count + ' 个' + label + '重算应付费用,确认继续?', '二次确认', { type: 'warning' })
|
||
} catch (e) {
|
||
return
|
||
}
|
||
const payload = { sourceType: recalcForm.sourceType, text }
|
||
recalcOpen.value = false
|
||
runRecalc(payload)
|
||
}
|
||
|
||
async function handleCancelRecalc() {
|
||
if (!recalcRunning.value || !recalcTaskId.value || recalcCancelLoading.value) return
|
||
try {
|
||
await ElMessageBox.confirm('确认取消当前费用重算?已经算完的订单会保留,未开始的将停止。', '取消重算', { type: 'warning' })
|
||
} catch (e) {
|
||
return
|
||
}
|
||
recalcCancelLoading.value = true
|
||
try {
|
||
const res = await cancelPayOrderRecalc(recalcTaskId.value)
|
||
const task = (res && res.data) || {}
|
||
applyRecalcProgress(task)
|
||
recalcProgressMessage.value = '取消请求已提交,等待当前订单结束…'
|
||
ElMessage.success('已提交取消')
|
||
} catch (e) {
|
||
/* 全局拦截器会提示 */
|
||
} finally {
|
||
recalcCancelLoading.value = false
|
||
}
|
||
}
|
||
|
||
function viewRecalcFailed() {
|
||
recalcProgressVisible.value = false
|
||
const orderNos = [...new Set(recalcFails.value.map(item => item.orderNo).filter(Boolean))]
|
||
const ladingNos = [...new Set(recalcFails.value.map(item => item.ladingNo).filter(Boolean))]
|
||
if (orderNos.length) {
|
||
query.orderNo = orderNos.join('\n')
|
||
query.ladingNo = ''
|
||
} else if (ladingNos.length) {
|
||
query.orderNo = ''
|
||
query.ladingNo = ladingNos.join(',')
|
||
}
|
||
search()
|
||
}
|
||
|
||
onMounted(() => {
|
||
tryRestoreRecalcProgress()
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
if (recalcFloatHideTimer) {
|
||
clearTimeout(recalcFloatHideTimer)
|
||
recalcFloatHideTimer = null
|
||
}
|
||
})
|
||
|
||
loadList()
|
||
</script>
|
||
|
||
<style scoped>
|
||
.fee-board { max-height: 68vh; overflow: auto; }
|
||
.fee-section { margin-bottom: 16px; }
|
||
.fee-table :deep(.cell) {
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.fee-table :deep(.el-table__header .cell) {
|
||
text-align: center;
|
||
}
|
||
.fee-log-table :deep(.el-table__header .cell) {
|
||
text-align: center;
|
||
}
|
||
.fee-table :deep(.el-select),
|
||
.fee-table :deep(.el-input),
|
||
.fee-table :deep(.el-input-number) {
|
||
width: 100%;
|
||
}
|
||
.fee-table :deep(.fee-op .cell) {
|
||
overflow: visible;
|
||
text-overflow: clip;
|
||
}
|
||
.fee-head {
|
||
margin-bottom: 8px;
|
||
padding: 8px 12px;
|
||
text-align: center;
|
||
font-weight: 600;
|
||
font-size: 15px;
|
||
background: var(--el-fill-color-light);
|
||
border: 1px solid var(--el-border-color);
|
||
}
|
||
.fee-tools { margin-bottom: 8px; text-align: right; }
|
||
.log-change { line-height: 1.6; }
|
||
.log-empty { color: var(--el-text-color-secondary); }
|
||
.rebill-progress__msg { margin-top: 12px; color: var(--el-text-color-regular); }
|
||
.rebill-result-stats { display: flex; gap: 12px; margin-top: 14px; }
|
||
.rebill-result-stats__item { flex: 1; padding: 10px 12px; border-radius: 8px; background: var(--el-fill-color-light); text-align: center; }
|
||
.rebill-result-stats__item.is-success { background: var(--el-color-success-light-9); }
|
||
.rebill-result-stats__item.is-fail { background: var(--el-color-warning-light-9); }
|
||
.rebill-result-stats__label { display: block; font-size: 12px; color: var(--el-text-color-secondary); margin-bottom: 4px; }
|
||
.rebill-result-stats__item strong { font-size: 20px; line-height: 1.2; color: var(--el-text-color-primary); }
|
||
.rebill-progress__text { margin-top: 8px; font-size: 13px; color: var(--el-text-color-secondary); }
|
||
.rebill-progress__hint { margin-top: 12px; font-size: 12px; color: var(--el-color-warning); }
|
||
.rebill-progress__error { margin-top: 12px; }
|
||
.pay-order-page .retry-status-float { position: fixed; top: 92px; right: 24px; z-index: 3001; }
|
||
.pay-order-page .retry-status-button { display: inline-flex; align-items: center; gap: 10px; min-width: 200px; min-height: 68px; padding: 6px 16px 6px 7px; border-radius: 36px; }
|
||
.pay-order-page .retry-progress-ring {
|
||
position: relative;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex: 0 0 54px;
|
||
width: 54px;
|
||
height: 54px;
|
||
border-radius: 50%;
|
||
background: conic-gradient(var(--el-color-primary) 0deg var(--retry-progress, 45deg), var(--el-color-primary-light-8) var(--retry-progress, 45deg) 360deg);
|
||
}
|
||
.pay-order-page .retry-progress-ring::after { position: absolute; inset: 5px; content: ''; border-radius: 50%; background: var(--el-bg-color); }
|
||
.pay-order-page .retry-progress-value { position: relative; z-index: 1; color: var(--el-color-primary); font-size: 12px; font-weight: 600; line-height: 1; }
|
||
.pay-order-page .retry-status-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; line-height: 1.2; white-space: nowrap; }
|
||
.pay-order-page .retry-status-text strong { font-size: 14px; font-weight: 600; }
|
||
.pay-order-page .retry-status-text small { color: var(--el-text-color-secondary); font-size: 11px; }
|
||
</style>
|