修改同步计费

This commit is contained in:
wuweihua
2026-10-13 10:21:28 +08:00
parent 26bdd3ba87
commit 4d27887d4a
14 changed files with 1231 additions and 12 deletions
@@ -1,5 +1,19 @@
<template>
<div class="app-container">
<div class="app-container order-source-page">
<div v-if="syncFloatVisible" class="retry-status-float">
<el-tooltip :content="syncFloatTooltip" placement="bottom">
<el-button class="retry-status-button" type="primary" plain size="small" @click="openFilterSync()">
<span class="retry-progress-ring" :style="{ '--retry-progress': syncProgressDegree + 'deg' }" aria-hidden="true">
<span class="retry-progress-value">{{ syncProgressText }}</span>
</span>
<span class="retry-status-text">
<strong>{{ syncFloatTitle }}</strong>
<small>{{ syncFloatSummary }}</small>
</span>
</el-button>
</el-tooltip>
</div>
<basic-table
ref="tableRef"
:columns="columns"
@@ -7,6 +21,7 @@
:query="queryList"
row-key="orderId"
:auto-load="false"
selection
search-action-align="center"
:search-per-row="4"
>
@@ -21,6 +36,36 @@
multiple
/>
</template>
<template #toolbar="{ selection }">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="Refresh"
v-hasPermi="['monitor:orderSource:sync']"
@click="openFilterSync()"
>同步计费</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="info"
plain
icon="Document"
@click="logDrawerRef.open()"
>操作记录</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Refresh"
:disabled="!selection.length"
:loading="batchLoading"
v-hasPermi="['monitor:orderSource:sync']"
@click="handleBatchSync(selection)"
>同步选中</el-button>
</el-col>
</template>
<template #col-product="{ row }">
{{ row.productName || '-' }} ({{ row.productCode || '-' }})
</template>
@@ -30,15 +75,40 @@
<template #col-orderStatus="{ row }">
{{ orderStatusLabel(row.orderStatus) }}
</template>
<template #col-action="{ row }">
<el-button
link
type="warning"
icon="Refresh"
:loading="syncingKey === rowKey(row)"
v-hasPermi="['monitor:orderSource:sync']"
@click="handleSyncOne(row)"
>同步计费</el-button>
</template>
</basic-table>
<order-source-sync-dialog
ref="syncDialogRef"
@progress="onSyncProgress"
@success="onSyncSuccess"
/>
<order-source-sync-log-drawer ref="logDrawerRef" />
</div>
</template>
<script setup name="OrderSource">
import { ElMessage } from 'element-plus'
import { listOrderSource } from '@/api/monitor/orderSource'
import { listOrderSource, syncOrderSourceSelected } from '@/api/monitor/orderSource'
import OrderSourceSyncDialog from './components/OrderSourceSyncDialog.vue'
import OrderSourceSyncLogDrawer from './components/OrderSourceSyncLogDrawer.vue'
const { proxy } = getCurrentInstance()
const tableRef = ref()
const syncDialogRef = ref()
const logDrawerRef = ref()
const syncingKey = ref(null)
const batchLoading = ref(false)
const syncFloat = ref(null)
const searchColumns = [
{ label: '客户', prop: 'customerCodes', placeholder: '客户代码' },
@@ -72,7 +142,8 @@ const columns = [
{ label: '计费重', prop: 'dimensionalWeightFactor', align: 'center', width: 100 },
{ label: '体积重', prop: 'volumeWeight', align: 'center', width: 100 },
{ label: '实重', prop: 'weight', align: 'center', width: 100 },
{ label: '提货时间', prop: 'pickupDate', align: 'center', width: 170 }
{ label: '提货时间', prop: 'pickupDate', align: 'center', width: 170 },
{ label: '操作', prop: 'action', align: 'center', width: 120, fixed: 'right', slot: 'action', showInToolbar: false }
]
const orderStatusMap = {
@@ -89,6 +160,25 @@ const orderStatusMap = {
10: '已删除'
}
const syncFloatVisible = computed(() => {
const p = syncFloat.value
return !!(p && (p.loading || p.finished))
})
const syncProgressDegree = computed(() => Math.round(((syncFloat.value?.percent || 0) / 100) * 360))
const syncProgressText = computed(() => (syncFloat.value?.percent || 0) + '%')
const syncFloatTitle = computed(() => {
const st = (syncFloat.value?.status || '').toUpperCase()
if (syncFloat.value?.loading) return '异步同步计费中'
if (st === 'SUCCESS') return '同步计费完成'
if (st === 'FAIL') return '同步计费失败'
return '异步同步计费'
})
const syncFloatSummary = computed(() => {
const p = syncFloat.value || {}
return '成功 ' + (p.ok || 0) + ' / 失败 ' + (p.fail || 0) + ' / 总数 ' + (p.total || 0)
})
const syncFloatTooltip = computed(() => syncFloat.value?.message || '点击查看详情')
function orderStatusLabel(status) {
if (status === null || status === undefined || status === '') return '-'
const key = Number(status)
@@ -98,6 +188,10 @@ function orderStatusLabel(status) {
return String(status)
}
function rowKey(row) {
return (row && (row.orderId || row.transferOrderId || row.orgOrderId)) || ''
}
function hasRequiredFilters(params) {
const codes = params && params.customerCodes
const hasCustomer = Array.isArray(codes) && codes.some(v => v != null && String(v).trim() !== '')
@@ -106,17 +200,168 @@ function hasRequiredFilters(params) {
return hasCustomer && hasTime
}
function queryList(params) {
if (!hasRequiredFilters(params)) {
ElMessage.warning('请先选择客户和提货时间')
return Promise.resolve({ rows: [], total: 0 })
}
const { dateRange, ...rest } = params
function buildFilterQuery(params) {
const src = params || tableRef.value?.getQueryParams?.() || {}
const { dateRange, pageNum, pageSize, ...rest } = src
const query = { ...rest }
if (Array.isArray(dateRange) && dateRange[0] && dateRange[1]) {
query.beginTime = dateRange[0]
query.endTime = dateRange[1]
}
return query
}
function queryList(params) {
if (!hasRequiredFilters(params)) {
ElMessage.warning('请先选择客户和提货时间')
return Promise.resolve({ rows: [], total: 0 })
}
const query = buildFilterQuery(params)
query.pageNum = params.pageNum
query.pageSize = params.pageSize
return listOrderSource(query)
}
function openFilterSync() {
const q = buildFilterQuery()
if (!q.customerCodes || !q.beginTime || !q.endTime) {
ElMessage.warning('请先选择客户和提货时间')
return
}
const codes = Array.isArray(q.customerCodes) ? q.customerCodes.filter(v => v != null && String(v).trim() !== '') : []
if (!codes.length) {
ElMessage.warning('请先选择客户和提货时间')
return
}
q.customerCodes = codes
proxy.$modal.confirm('确认按当前筛选分页查询并异步同步计费?', '二次确认').then(() => {
syncDialogRef.value?.open(q, true)
}).catch(() => {})
}
function onSyncProgress(payload) {
syncFloat.value = payload
if (payload && payload.finished && !payload.loading) {
window.setTimeout(() => {
if (syncFloat.value && syncFloat.value.finished && !syncFloat.value.loading) {
syncFloat.value = null
}
}, 8000)
}
}
function onSyncSuccess() {
tableRef.value?.refresh()
}
function toSyncRow(row) {
return {
orderId: row.orderId,
orgOrderId: row.orgOrderId,
transferOrderId: row.transferOrderId,
customerCode: row.customerCode,
pickupDate: row.pickupDate
}
}
function handleSyncOne(row) {
proxy.$modal.confirm('确认同步计费该订单?', '二次确认').then(() => {
syncingKey.value = rowKey(row)
return syncOrderSourceSelected([toSyncRow(row)])
}).then(res => {
const data = res.data || {}
if ((data.ok || 0) > 0 && !(data.fail || 0)) {
proxy.$modal.msgSuccess('同步成功')
} else {
proxy.$modal.msgError((data.details && data.details[0] && data.details[0].errorMessage) || '同步失败')
}
tableRef.value.refresh()
}).catch(() => {}).finally(() => {
syncingKey.value = null
})
}
function handleBatchSync(selection) {
if (!selection || !selection.length) return
proxy.$modal.confirm('确认同步选中的 ' + selection.length + ' 条订单?', '二次确认').then(() => {
batchLoading.value = true
return syncOrderSourceSelected(selection.map(toSyncRow))
}).then(res => {
const data = res.data || {}
proxy.$modal.msgSuccess('完成:成功 ' + (data.ok || 0) + ' / 失败 ' + (data.fail || 0))
tableRef.value.refresh()
}).catch(() => {}).finally(() => {
batchLoading.value = false
})
}
</script>
<style scoped>
.order-source-page .retry-status-float {
position: fixed;
top: 92px;
right: 24px;
z-index: 3001;
}
.order-source-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;
}
.order-source-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
);
}
.order-source-page .retry-progress-ring::after {
position: absolute;
inset: 5px;
content: '';
border-radius: 50%;
background: var(--el-bg-color);
}
.order-source-page .retry-progress-value {
position: relative;
z-index: 1;
color: var(--el-color-primary);
font-size: 12px;
font-weight: 600;
line-height: 1;
}
.order-source-page .retry-status-text {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 3px;
line-height: 1.2;
white-space: nowrap;
}
.order-source-page .retry-status-text strong {
font-size: 14px;
font-weight: 600;
}
.order-source-page .retry-status-text small {
color: var(--el-text-color-secondary);
font-size: 11px;
}
</style>