front/src/views/finance/accountFlow/index.vue
zzh 50aed33e19 feat: 客户余额人工调整留痕,并修复 OMS 代登 SSO 链路
编辑客户余额改为只读;列表「调整余额」写账户流水。代登改为落到 /login,守卫优先消费 sso,避免官网首页吞掉 token。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 17:34:43 +08:00

343 lines
10 KiB
Vue

<template>
<div class="account-flow-page">
<div class="account-flow-page-card">
<div class="table-toolbar">
<div class="toolbar-left">
<a-space wrap :size="12">
<a-input
v-model="keyword"
allow-clear
:placeholder="t('user.accountFlow.search.keywordPlaceholder')"
style="width: 220px"
@press-enter="handleSearch"
/>
<a-select
v-model="bizTypeFilter"
:placeholder="t('user.accountFlow.search.bizTypePlaceholder')"
allow-clear
style="width: 140px"
>
<a-option value="all">{{ t('user.accountFlow.search.bizTypeAll') }}</a-option>
<a-option value="recharge">{{ t('user.accountFlow.bizType.recharge') }}</a-option>
<a-option value="orderPay">{{ t('user.accountFlow.bizType.orderPay') }}</a-option>
<a-option value="pickupPay">{{ t('user.accountFlow.bizType.pickupPay') }}</a-option>
<a-option value="manualAdjust">{{ t('user.accountFlow.bizType.manualAdjust') }}</a-option>
</a-select>
<a-input-number
v-model="customerIdFilter"
:placeholder="t('user.accountFlow.search.customerIdPlaceholder')"
:min="1"
:precision="0"
allow-clear
hide-button
style="width: 140px"
/>
<a-range-picker
v-model="dateRange"
show-time
format="YYYY-MM-DD HH:mm:ss"
:placeholder="[
t('user.accountFlow.search.dateRange'),
t('user.accountFlow.search.dateRange'),
]"
style="width: 380px"
/>
<a-button class="app-btn-search" @click="handleSearch">
{{ t('user.accountFlow.search.actions.search') }}
</a-button>
<a-button @click="handleReset">
{{ t('user.accountFlow.search.actions.reset') }}
</a-button>
</a-space>
</div>
<div class="toolbar-right">
<div class="pagination-controls">
<PaginationPro
:total-count="totalCount"
v-model:current-page="currentPage"
v-model:page-size="pageSize"
@page-change="handlePageChange"
@page-size-change="handlePageSizeChange"
/>
</div>
</div>
</div>
<a-spin class="list-spin" :loading="listLoading">
<div ref="tableContainerRef" class="list-wrap">
<HandsontablePro
:columns="hotColumns"
:data="tableRows"
:total="totalCount"
:current-page="currentPage"
:page-size="pageSize"
:read-only="true"
:stretch-columns="true"
:custom-cell-renderer="customCellRenderer"
:height="handsontableHeight"
:search-params="headerSearchParams"
sort-mode="remote"
:sort-field="listSortField"
:sort-order="listSortOrder"
@search="handleHeaderSearch"
@sort-change="handleSortChange"
/>
</div>
</a-spin>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, computed, onMounted, reactive } from 'vue'
import { useI18n } from 'vue-i18n'
import { Message } from '@arco-design/web-vue'
import HandsontablePro from '@/components/HandsontablePro/index.vue'
import PaginationPro from '@/components/PaginationPro/index.vue'
import { useTableContainerHeight } from '@/composables/useTableContainerHeight'
import dayjs from 'dayjs'
import { getAccountFlowList } from '@/api/customer/accountFlow'
import { getMoneyToneColor } from '@/utils/statusTag'
import {
adaptAccountFlowHeaderFilters,
withServerFilterColumns,
withSortableColumns,
} from '@/utils/headerFilterAdapter'
defineOptions({
name: 'FinanceAccountFlow',
})
const { t } = useI18n()
const { tableContainerRef, tableHeight } = useTableContainerHeight()
const handsontableHeight = computed(() => Math.max(tableHeight.value || 0, 400))
interface AccountFlowRow {
serialNumber: string
createTime: string
bizTypeName: string
bizNo: string
amount: number
balanceBefore: number
balanceAfter: number
remark: string
customerCode: string
}
function mapRow(item: any): AccountFlowRow {
return {
serialNumber: item.serialNumber ?? '',
createTime: item.createTime ?? '',
bizTypeName: item.bizTypeName ?? item.bizType ?? '',
bizNo: item.bizNo ?? '--',
amount: Number(item.amount ?? 0),
balanceBefore: Number(item.balanceBefore ?? 0),
balanceAfter: Number(item.balanceAfter ?? 0),
remark: item.remark ?? '',
customerCode: item.customerCode ?? '',
}
}
const tableRows = ref<AccountFlowRow[]>([])
const totalCount = ref(0)
const listLoading = ref(false)
const keyword = ref('')
const bizTypeFilter = ref('all')
const customerIdFilter = ref<number | undefined>(undefined)
const dateRange = ref<any[]>([])
const headerSearchParams = reactive<Record<string, string>>({})
const listSortField = ref<string | null>(null)
const listSortOrder = ref<'asc' | 'desc' | null>(null)
const currentPage = ref(1)
const pageSize = ref(50)
const FLOW_SERVER_KEYS = ['serialNumber', 'bizNo', 'amount', 'createTime', 'remark'] as const
const FLOW_SORTABLE_KEYS = ['createTime', 'amount'] as const
const hotColumns = computed(() =>
withSortableColumns(
withServerFilterColumns(
[
{ key: 'serialNumber', label: t('user.accountFlow.table.serialNumber'), width: 180 },
{ key: 'createTime', label: t('user.accountFlow.table.createTime'), width: 170 },
{ key: 'bizTypeName', label: t('user.accountFlow.table.bizType'), width: 110 },
{ key: 'bizNo', label: t('user.accountFlow.table.bizNo'), width: 160 },
{ key: 'amount', label: t('user.accountFlow.table.amount'), width: 110 },
{ key: 'balanceBefore', label: t('user.accountFlow.table.balanceBefore'), width: 110 },
{ key: 'balanceAfter', label: t('user.accountFlow.table.balanceAfter'), width: 110 },
{ key: 'remark', label: t('user.accountFlow.table.remark'), width: 160 },
{ key: 'customerCode', label: t('user.accountFlow.table.customerCode'), width: 110 },
],
FLOW_SERVER_KEYS,
(col) => {
if (col.key === 'createTime') {
return { filterType: 'date' as const, headerMode: 'icon' as const }
}
if (col.key === 'amount') {
return { filterType: 'number' as const, headerMode: 'icon' as const }
}
return {}
},
),
FLOW_SORTABLE_KEYS,
),
)
function formatMoney(value: unknown) {
const num = Number(value)
return Number.isFinite(num) ? num.toFixed(2) : '--'
}
const customCellRenderer = (rowData: any, colKey: string, value: any) => {
if (colKey === 'amount') {
const num = Number(value ?? 0)
const color = getMoneyToneColor(num >= 0)
const prefix = num > 0 ? '+' : ''
return `<span style="color:${color};font-weight:500;">${prefix}${formatMoney(num)}</span>`
}
if (colKey === 'balanceBefore' || colKey === 'balanceAfter') {
return formatMoney(value)
}
return null
}
function buildListParams() {
const adapted = adaptAccountFlowHeaderFilters(headerSearchParams)
const params: Record<string, any> = {
page: currentPage.value,
pageSize: pageSize.value,
}
const kw = (adapted.keyword || keyword.value.trim() || '').trim()
if (kw) params.keyword = kw
if (adapted.bizType && adapted.bizType !== 'all') {
params.bizType = adapted.bizType
} else if (bizTypeFilter.value && bizTypeFilter.value !== 'all') {
params.bizType = bizTypeFilter.value
}
if (customerIdFilter.value != null && !Number.isNaN(customerIdFilter.value)) {
params.customerId = customerIdFilter.value
}
if (adapted.createTimeStart || adapted.createTimeEnd) {
params.startTime = adapted.createTimeStart
params.endTime = adapted.createTimeEnd
} else if (dateRange.value?.length === 2 && dateRange.value[0] && dateRange.value[1]) {
params.startTime = dayjs(dateRange.value[0]).format('YYYY-MM-DD HH:mm:ss')
params.endTime = dayjs(dateRange.value[1]).format('YYYY-MM-DD HH:mm:ss')
}
if (adapted.amountMin != null) params.amountMin = adapted.amountMin
if (adapted.amountMax != null) params.amountMax = adapted.amountMax
if (listSortField.value) params.sortField = listSortField.value
if (listSortOrder.value) params.sortOrder = listSortOrder.value
return params
}
async function loadList() {
listLoading.value = true
try {
const { items, total } = await getAccountFlowList(buildListParams() as any)
totalCount.value = total
tableRows.value = (items || []).map(mapRow)
} catch (e: any) {
Message.error(e?.message || t('user.accountFlow.message.loadError'))
tableRows.value = []
totalCount.value = 0
} finally {
listLoading.value = false
}
}
function handleHeaderSearch() {
currentPage.value = 1
loadList()
}
function handleSortChange(payload: { field: string | null; order: 'asc' | 'desc' | null }) {
listSortField.value = payload.field
listSortOrder.value = payload.order
currentPage.value = 1
loadList()
}
function handleSearch() {
currentPage.value = 1
loadList()
}
function handleReset() {
keyword.value = ''
bizTypeFilter.value = 'all'
customerIdFilter.value = undefined
dateRange.value = []
Object.keys(headerSearchParams).forEach((k) => {
headerSearchParams[k] = ''
})
listSortField.value = null
listSortOrder.value = null
currentPage.value = 1
loadList()
}
function handlePageChange(page: number) {
currentPage.value = page
loadList()
}
function handlePageSizeChange(size: number) {
pageSize.value = size
currentPage.value = 1
loadList()
}
onMounted(() => {
loadList()
})
</script>
<style lang="less" scoped>
.account-flow-page {
padding: 16px;
background: var(--app-page-bg);
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.account-flow-page-card {
background: var(--app-card-bg);
border-radius: 4px;
padding: 16px;
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.table-toolbar {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
margin-bottom: 12px;
flex-shrink: 0;
}
.list-spin {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.list-wrap {
flex: 1;
min-height: 0;
box-sizing: border-box;
display: flex;
flex-direction: column;
overflow: hidden;
}
</style>