2 changed files with 427 additions and 0 deletions
@ -0,0 +1,417 @@ |
|||||||
|
<template> |
||||||
|
<div class="app-container points-query"> |
||||||
|
<data-list-panel modern-table> |
||||||
|
<template #filters> |
||||||
|
<el-form ref="queryForm" :model="queryParams" size="small" :inline="true" class="data-list-filter-form"> |
||||||
|
<el-form-item label="用户" prop="userId"> |
||||||
|
<el-select v-model="queryParams.userId" clearable filterable placeholder="全部用户(姓名/账号)" @change="handleQuery"> |
||||||
|
<el-option v-for="item in userOptions" :key="item.value" :label="item.label" :value="item.value" /> |
||||||
|
</el-select> |
||||||
|
</el-form-item> |
||||||
|
<el-form-item label="单位" prop="deptName"> |
||||||
|
<el-select v-model="queryParams.deptName" clearable filterable placeholder="全部单位" @change="handleQuery"> |
||||||
|
<el-option v-for="item in deptOptions" :key="item" :label="item" :value="item" /> |
||||||
|
</el-select> |
||||||
|
</el-form-item> |
||||||
|
<el-form-item label="关键字" prop="keyword"> |
||||||
|
<el-input v-model.trim="queryParams.keyword" clearable placeholder="姓名 / 账号 / 手机号" @keyup.enter.native="handleQuery" /> |
||||||
|
</el-form-item> |
||||||
|
<el-form-item> |
||||||
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> |
||||||
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> |
||||||
|
</el-form-item> |
||||||
|
</el-form> |
||||||
|
</template> |
||||||
|
|
||||||
|
<template #actions> |
||||||
|
<el-button icon="el-icon-refresh" size="mini" @click="loadData">刷新</el-button> |
||||||
|
</template> |
||||||
|
|
||||||
|
<template #header> |
||||||
|
<div class="query-heading"> |
||||||
|
<div class="query-heading__title">积分查询</div> |
||||||
|
<div class="query-heading__description"> |
||||||
|
查看所有用户的积分账户(含未开通账户的用户);可按用户/单位/关键字筛选,点「明细」查看该用户的积分流水。 |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<el-table v-loading="loading" :data="pageList" size="mini" class="data-list-table" empty-text="暂无用户"> |
||||||
|
<el-table-column label="用户" min-width="120" show-overflow-tooltip> |
||||||
|
<template slot-scope="scope">{{ userLabel(scope.row) }}</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="账号" prop="userName" width="130" show-overflow-tooltip /> |
||||||
|
<el-table-column label="单位" prop="deptName" min-width="150" show-overflow-tooltip> |
||||||
|
<template slot-scope="scope">{{ scope.row.deptName || '—' }}</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="可用积分" width="100" align="right"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span class="points-strong">{{ numberText(scope.row.availableBalance) }}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="冻结积分" width="100" align="right"> |
||||||
|
<template slot-scope="scope">{{ numberText(scope.row.frozenBalance) }}</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="累计入账" width="100" align="right"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span class="points-in">{{ numberText(scope.row.totalIncome) }}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="累计出账" width="100" align="right"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span class="points-out">{{ numberText(scope.row.totalOutcome) }}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="账户状态" width="100" align="center"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<el-tag :type="scope.row.hasAccount ? 'success' : 'info'" size="mini"> |
||||||
|
{{ scope.row.hasAccount ? '已开通' : '未开通' }} |
||||||
|
</el-tag> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="更新时间" width="160"> |
||||||
|
<template slot-scope="scope">{{ formatTime(scope.row.updateTime) }}</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="操作" width="90" align="center" fixed="right" class-name="data-list-operation-column"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<el-button type="text" size="mini" @click="openDetail(scope.row)">明细</el-button> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
</el-table> |
||||||
|
|
||||||
|
<template #footer> |
||||||
|
<el-pagination |
||||||
|
background |
||||||
|
layout="total, sizes, prev, pager, next, jumper" |
||||||
|
:total="filteredList.length" |
||||||
|
:current-page.sync="queryParams.pageNum" |
||||||
|
:page-size.sync="queryParams.pageSize" |
||||||
|
:page-sizes="[10, 20, 50]" |
||||||
|
/> |
||||||
|
<div class="query-summary"> |
||||||
|
共 {{ filteredList.length }} 人 · 已开通账户 {{ openedCount }} 人 · 可用积分合计 {{ totalAvailable }} |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
</data-list-panel> |
||||||
|
|
||||||
|
<!-- 积分明细 --> |
||||||
|
<el-dialog :title="detailTitle" :visible.sync="detailVisible" width="880px" append-to-body> |
||||||
|
<el-descriptions v-if="detailUser" :column="3" border size="small" class="query-detail-meta"> |
||||||
|
<el-descriptions-item label="用户">{{ userLabel(detailUser) }}</el-descriptions-item> |
||||||
|
<el-descriptions-item label="账号">{{ detailUser.userName || '—' }}</el-descriptions-item> |
||||||
|
<el-descriptions-item label="单位">{{ detailUser.deptName || '—' }}</el-descriptions-item> |
||||||
|
<el-descriptions-item label="可用积分">{{ numberText(detailUser.availableBalance) }}</el-descriptions-item> |
||||||
|
<el-descriptions-item label="冻结积分">{{ numberText(detailUser.frozenBalance) }}</el-descriptions-item> |
||||||
|
<el-descriptions-item label="累计入账 / 出账">{{ numberText(detailUser.totalIncome) }} / {{ numberText(detailUser.totalOutcome) }}</el-descriptions-item> |
||||||
|
</el-descriptions> |
||||||
|
<el-table v-loading="txnLoading" :data="txnList" size="mini" border empty-text="暂无积分流水"> |
||||||
|
<el-table-column label="流水号" prop="txnNo" min-width="160" show-overflow-tooltip /> |
||||||
|
<el-table-column label="业务类型" width="110" align="center"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<el-tag :type="bizTypeTag(scope.row)" size="mini">{{ bizTypeLabel(scope.row) }}</el-tag> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="变动" width="90" align="right"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<span :style="{ color: amountColor(scope.row) }">{{ amountLabel(scope.row) }}</span> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="变动前 → 后" width="140"> |
||||||
|
<template slot-scope="scope">{{ balanceText(scope.row) }}</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="状态" width="90" align="center"> |
||||||
|
<template slot-scope="scope"> |
||||||
|
<el-tag :type="statusTagType(scope.row)" size="mini">{{ statusLabel(scope.row) }}</el-tag> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="备注" prop="remark" min-width="160" show-overflow-tooltip /> |
||||||
|
<el-table-column label="时间" width="160"> |
||||||
|
<template slot-scope="scope">{{ formatTime(scope.row.createTime) }}</template> |
||||||
|
</el-table-column> |
||||||
|
</el-table> |
||||||
|
<el-pagination |
||||||
|
background |
||||||
|
layout="total, prev, pager, next" |
||||||
|
:total="txnTotal" |
||||||
|
:current-page.sync="txnParams.pageNum" |
||||||
|
:page-size="txnParams.pageSize" |
||||||
|
@current-change="getTransactions" |
||||||
|
/> |
||||||
|
<span slot="footer"> |
||||||
|
<el-button @click="detailVisible = false">关闭</el-button> |
||||||
|
</span> |
||||||
|
</el-dialog> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
import { listAllBalances } from '@/api/points/balance' |
||||||
|
import { listTransactions } from '@/api/points/transaction' |
||||||
|
import { listUser } from '@/api/system/user' |
||||||
|
|
||||||
|
const BIZ_TYPES = [ |
||||||
|
{ value: 'REPORT', label: '上报奖励' }, |
||||||
|
{ value: 'EXCHANGE', label: '兑换扣减' }, |
||||||
|
{ value: 'REFUND', label: '退款回滚' }, |
||||||
|
{ value: 'FREEZE', label: '冻结' }, |
||||||
|
{ value: 'UNFREEZE', label: '解冻' }, |
||||||
|
{ value: 'APPEAL_ADD', label: '申诉补发' }, |
||||||
|
{ value: 'APPEAL_DEDUCT', label: '申诉扣减' }, |
||||||
|
{ value: 'MALL_DEDUCT', label: '商城扣减' }, |
||||||
|
{ value: 'MALL_REFUND', label: '商城退款' }, |
||||||
|
{ value: 'MANUAL_ADD', label: '手动补发' }, |
||||||
|
{ value: 'MANUAL_DEDUCT', label: '手动扣减' } |
||||||
|
] |
||||||
|
|
||||||
|
export default { |
||||||
|
name: 'PointsQuery', |
||||||
|
data() { |
||||||
|
return { |
||||||
|
loading: false, |
||||||
|
rows: [], |
||||||
|
deptOptions: [], |
||||||
|
userOptions: [], |
||||||
|
queryParams: { pageNum: 1, pageSize: 10, userId: undefined, deptName: undefined, keyword: undefined }, |
||||||
|
detailVisible: false, |
||||||
|
detailUser: null, |
||||||
|
txnLoading: false, |
||||||
|
txnList: [], |
||||||
|
txnTotal: 0, |
||||||
|
txnParams: { pageNum: 1, pageSize: 10 } |
||||||
|
} |
||||||
|
}, |
||||||
|
computed: { |
||||||
|
filteredList() { |
||||||
|
const userId = this.queryParams.userId |
||||||
|
const deptName = this.queryParams.deptName |
||||||
|
const keyword = String(this.queryParams.keyword || '').trim().toLowerCase() |
||||||
|
return this.rows.filter(row => { |
||||||
|
if (userId && row.userId !== String(userId)) return false |
||||||
|
if (deptName && row.deptName !== deptName) return false |
||||||
|
if (keyword) { |
||||||
|
const haystack = [row.nickName, row.userName, row.phonenumber, row.deptName].join(' ').toLowerCase() |
||||||
|
if (haystack.indexOf(keyword) === -1) return false |
||||||
|
} |
||||||
|
return true |
||||||
|
}) |
||||||
|
}, |
||||||
|
pageList() { |
||||||
|
const start = (this.queryParams.pageNum - 1) * this.queryParams.pageSize |
||||||
|
return this.filteredList.slice(start, start + this.queryParams.pageSize) |
||||||
|
}, |
||||||
|
openedCount() { |
||||||
|
return this.filteredList.filter(row => row.hasAccount).length |
||||||
|
}, |
||||||
|
totalAvailable() { |
||||||
|
const sum = this.filteredList.reduce((total, row) => total + Number(row.availableBalance || 0), 0) |
||||||
|
return sum.toLocaleString() |
||||||
|
}, |
||||||
|
detailTitle() { |
||||||
|
return this.detailUser ? `${this.userLabel(this.detailUser)} · 积分明细` : '积分明细' |
||||||
|
} |
||||||
|
}, |
||||||
|
created() { |
||||||
|
this.loadData() |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
// 用户目录 + 积分账户在前端做一次关联:账户接口只返回 userId,没有姓名/单位 |
||||||
|
loadData() { |
||||||
|
this.loading = true |
||||||
|
Promise.all([this.loadUsers(), listAllBalances().then(res => res.data || res).catch(() => [])]) |
||||||
|
.then(([users, balances]) => { |
||||||
|
this.rows = this.mergeRows(users, Array.isArray(balances) ? balances : []) |
||||||
|
}) |
||||||
|
.catch(() => { |
||||||
|
this.rows = [] |
||||||
|
this.$modal.msgError('积分数据加载失败,请检查后端服务和登录状态') |
||||||
|
}) |
||||||
|
.finally(() => { |
||||||
|
this.loading = false |
||||||
|
}) |
||||||
|
}, |
||||||
|
loadUsers() { |
||||||
|
// 用户目录(含 nickName / dept),用于 userId → 姓名/单位;无权限时降级为只显示 userId |
||||||
|
return listUser({ pageNum: 1, pageSize: 500 }) |
||||||
|
.then(res => { |
||||||
|
const page = res.data || res |
||||||
|
const users = page.rows || page.list || page.records || [] |
||||||
|
this.userOptions = users.map(user => ({ |
||||||
|
value: String(user.userId), |
||||||
|
label: this.userLabel(user) |
||||||
|
})) |
||||||
|
this.deptOptions = users |
||||||
|
.map(user => (user.dept && user.dept.deptName) || '') |
||||||
|
.filter((name, index, list) => name && list.indexOf(name) === index) |
||||||
|
.sort() |
||||||
|
return users |
||||||
|
}) |
||||||
|
.catch(() => { |
||||||
|
this.userOptions = [] |
||||||
|
this.deptOptions = [] |
||||||
|
this.$modal.msgWarning('用户目录加载失败,用户名/单位可能显示为 —') |
||||||
|
return [] |
||||||
|
}) |
||||||
|
}, |
||||||
|
mergeRows(users, balances) { |
||||||
|
const balanceMap = {} |
||||||
|
balances.forEach(item => { |
||||||
|
if (item && item.userId !== undefined && item.userId !== null) balanceMap[String(item.userId)] = item |
||||||
|
}) |
||||||
|
const used = {} |
||||||
|
const rows = users.map(user => { |
||||||
|
const key = String(user.userId) |
||||||
|
used[key] = true |
||||||
|
return this.buildRow(key, user, balanceMap[key]) |
||||||
|
}) |
||||||
|
// 兜底:有积分账户但不在用户目录(如已停用/删除的用户),避免数据漏展示 |
||||||
|
Object.keys(balanceMap).forEach(key => { |
||||||
|
if (used[key]) return |
||||||
|
rows.push(this.buildRow(key, null, balanceMap[key])) |
||||||
|
}) |
||||||
|
return rows |
||||||
|
}, |
||||||
|
buildRow(userId, user, balance) { |
||||||
|
return { |
||||||
|
userId, |
||||||
|
userName: (user && user.userName) || '', |
||||||
|
nickName: (user && user.nickName) || '', |
||||||
|
deptName: (user && user.dept && user.dept.deptName) || '', |
||||||
|
phonenumber: (user && user.phonenumber) || '', |
||||||
|
availableBalance: balance ? balance.availableBalance : 0, |
||||||
|
frozenBalance: balance ? balance.frozenBalance : 0, |
||||||
|
totalIncome: balance ? balance.totalIncome : 0, |
||||||
|
totalOutcome: balance ? balance.totalOutcome : 0, |
||||||
|
updateTime: balance ? balance.updateTime : null, |
||||||
|
hasAccount: Boolean(balance) |
||||||
|
} |
||||||
|
}, |
||||||
|
handleQuery() { |
||||||
|
this.queryParams.pageNum = 1 |
||||||
|
}, |
||||||
|
resetQuery() { |
||||||
|
this.$refs.queryForm.resetFields() |
||||||
|
this.queryParams.pageNum = 1 |
||||||
|
}, |
||||||
|
openDetail(row) { |
||||||
|
this.detailUser = row |
||||||
|
this.detailVisible = true |
||||||
|
this.txnParams.pageNum = 1 |
||||||
|
this.getTransactions() |
||||||
|
}, |
||||||
|
getTransactions() { |
||||||
|
if (!this.detailUser) return |
||||||
|
this.txnLoading = true |
||||||
|
listTransactions(Object.assign({ userId: this.detailUser.userId }, this.txnParams)) |
||||||
|
.then(res => { |
||||||
|
const page = res.data || res |
||||||
|
this.txnList = page.list || page.rows || page.records || [] |
||||||
|
this.txnTotal = Number(page.total || page.totalCount || this.txnList.length) |
||||||
|
}) |
||||||
|
.catch(() => { |
||||||
|
this.txnList = [] |
||||||
|
this.txnTotal = 0 |
||||||
|
}) |
||||||
|
.finally(() => { |
||||||
|
this.txnLoading = false |
||||||
|
}) |
||||||
|
}, |
||||||
|
userLabel(row) { |
||||||
|
if (!row) return '—' |
||||||
|
const name = row.nickName || '' |
||||||
|
const account = row.userName || '' |
||||||
|
if (name && account && name !== account) return `${name}(${account})` |
||||||
|
return name || account || `userId=${row.userId}` |
||||||
|
}, |
||||||
|
numberText(value) { |
||||||
|
if (value === undefined || value === null || value === '') return '0' |
||||||
|
const number = Number(value) |
||||||
|
return Number.isNaN(number) ? String(value) : number.toLocaleString() |
||||||
|
}, |
||||||
|
formatTime(value) { |
||||||
|
return value ? String(value).replace('T', ' ').slice(0, 19) : '—' |
||||||
|
}, |
||||||
|
bizTypeLabel(row) { |
||||||
|
const item = BIZ_TYPES.find(option => option.value === row.bizType) |
||||||
|
return item ? item.label : (row.bizType || '—') |
||||||
|
}, |
||||||
|
bizTypeTag(row) { |
||||||
|
return { REPORT: 'success', EXCHANGE: 'primary', REFUND: 'warning' }[row.bizType] || 'info' |
||||||
|
}, |
||||||
|
amountLabel(row) { |
||||||
|
const value = row.amount |
||||||
|
if (value === undefined || value === null || value === '') return '—' |
||||||
|
const number = Number(value) |
||||||
|
if (Number.isNaN(number)) return String(value) |
||||||
|
return `${number > 0 ? '+' : ''}${number}` |
||||||
|
}, |
||||||
|
amountColor(row) { |
||||||
|
const number = Number(row.amount) |
||||||
|
if (Number.isNaN(number) || number === 0) return 'var(--prototype-text, #1a1a2e)' |
||||||
|
return number > 0 ? '#2d8a4e' : '#d64550' |
||||||
|
}, |
||||||
|
balanceText(row) { |
||||||
|
const before = row.beforeBalance |
||||||
|
const after = row.afterBalance |
||||||
|
if ((before === undefined || before === null) && (after === undefined || after === null)) return '—' |
||||||
|
return `${before === undefined || before === null ? '—' : before} → ${after === undefined || after === null ? '—' : after}` |
||||||
|
}, |
||||||
|
statusLabel(row) { |
||||||
|
const value = String(row.status) |
||||||
|
return { '1': '有效', '2': '已冲正' }[value] || (row.status === undefined || row.status === null ? '—' : value) |
||||||
|
}, |
||||||
|
statusTagType(row) { |
||||||
|
return String(row.status) === '2' ? 'info' : 'success' |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<style lang="scss" scoped> |
||||||
|
.points-query { |
||||||
|
min-height: calc(100vh - 52px); |
||||||
|
background: #f0f2f5; |
||||||
|
} |
||||||
|
|
||||||
|
.query-heading { |
||||||
|
min-width: 0; |
||||||
|
} |
||||||
|
|
||||||
|
.query-heading__title { |
||||||
|
color: #1a1a2e; |
||||||
|
font-size: 14px; |
||||||
|
font-weight: 600; |
||||||
|
line-height: 20px; |
||||||
|
} |
||||||
|
|
||||||
|
.query-heading__description { |
||||||
|
margin-top: 6px; |
||||||
|
color: #9898ae; |
||||||
|
font-size: 11px; |
||||||
|
font-weight: 400; |
||||||
|
line-height: 18px; |
||||||
|
} |
||||||
|
|
||||||
|
.points-strong { |
||||||
|
color: #3b5fd9; |
||||||
|
font-weight: 600; |
||||||
|
} |
||||||
|
|
||||||
|
.points-in { |
||||||
|
color: #2d8a4e; |
||||||
|
} |
||||||
|
|
||||||
|
.points-out { |
||||||
|
color: #d64550; |
||||||
|
} |
||||||
|
|
||||||
|
.query-summary { |
||||||
|
margin-top: 10px; |
||||||
|
color: #9898ae; |
||||||
|
font-size: 12px; |
||||||
|
line-height: 18px; |
||||||
|
} |
||||||
|
|
||||||
|
.query-detail-meta { |
||||||
|
margin-bottom: 12px; |
||||||
|
} |
||||||
|
</style> |
||||||
Loading…
Reference in new issue