| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <template>
- <main class="receipt-page">
- <header><h1>收款对账</h1><el-tag v-if="result" :type="statusColor">{{ labels[result.status] }}</el-tag></header>
- <p class="muted">按当前机构核对汇付、支付宝和微信的成功收款,不含退款。</p>
- <div class="toolbar">
- <span>当前机构:<strong>{{ tenantName || '未选择' }}</strong></span>
- <label>账单日期 <el-date-picker v-model="billDate" type="date" value-format="yyyy-MM-dd" :clearable="false" :editable="false" size="small" /></label>
- <el-button v-if="scopeBlocked" size="small" @click="refreshTenant">重新确认机构</el-button>
- <el-button v-else size="small" :disabled="!canRequest || !!busy" @click="load(false)">查询已存结果</el-button>
- <el-button size="small" type="primary" :disabled="!canRequest || !!busy" @click="load(true)">重新取账并核对</el-button>
- </div>
- <p v-if="!result" class="notice" role="status">{{ notice }}</p>
- <template v-else>
- <section class="panel">
- <div class="metrics">
- <div><span>系统成功收款</span><strong>{{ money(result.systemAmount) }}</strong><small>{{ count(result.systemCount) }}</small></div>
- <div><span>第三方实际收款</span><strong>{{ money(complete ? result.thirdAmount : null) }}</strong><small>{{ complete ? count(result.thirdCount) : '账单未齐,不展示合计' }}</small></div>
- <div><span>差异组数</span><strong>{{ complete && result.differenceCount != null ? result.differenceCount + ' 组' : '—' }}</strong><small>同组多条记录只计一次</small></div>
- </div>
- <div class="summary" role="status">{{ labels[result.status] }} · 最近核对:{{ result.checkedAt || '—' }}</div>
- </section>
- <section class="panel">
- <h2>渠道核对</h2>
- <div class="scroll"><table><thead><tr><th>渠道</th><th>取账状态</th><th>系统成功收款</th><th>第三方实际收款</th><th>可提现余额 / 快照时间</th><th>核查</th></tr></thead>
- <tbody><tr v-for="row in result.channels" :key="row.channel">
- <th>{{ labels[row.channel] }}</th><td>{{ channelStatuses[row.status] }}<small v-if="row.message">{{ row.message }}</small></td>
- <td>{{ money(row.systemAmount) }}<small>{{ count(row.systemCount) }}</small></td>
- <td>{{ money(row.status === 'READY' ? row.thirdAmount : null) }}<small>{{ count(row.status === 'READY' ? row.thirdCount : null) }}</small></td>
- <td>{{ money(row.availableBalance) }}<small>{{ row.balanceTime || '—' }}</small></td>
- <td><el-button v-if="result.differences.some(item => involves(item, row.channel))" type="text" @click="showChannel(row.channel)">查看差异</el-button><span v-else>{{ row.status === 'READY' && complete ? '无差异' : '待核对' }}</span></td>
- </tr></tbody>
- </table></div>
- </section>
- <section ref="details" class="panel">
- <h2>差异明细</h2>
- <p class="muted">切换分部仅筛选下方明细;汇总、余额和取账仍按当前机构。</p>
- <div class="filters">
- <label>切换分部 <el-select v-model="branch" size="small" aria-label="切换分部"><el-option label="全部分部" value="" /><el-option v-for="option in branchOptions" :key="option.id" :label="option.name" :value="option.id" /><el-option label="待确认分部" value="unknown" /></el-select></label>
- <el-select v-model="channel" size="small" aria-label="筛选渠道"><el-option label="全部渠道" value="" /><el-option v-for="key in channelKeys" :key="key" :label="labels[key]" :value="key" /></el-select>
- <el-input v-model.trim="search" size="small" clearable placeholder="搜索订单号或流水号" />
- </div>
- <div class="scroll"><table><thead><tr><th>商户订单号</th><th>所属分部</th><th>差异类型</th><th>系统渠道 / 金额</th><th>三方渠道 / 金额</th><th>操作</th></tr></thead>
- <tbody><tr v-for="(row, index) in pagedDifferences" :key="index">
- <td>{{ orderLabel(row) }}</td><td>{{ rowBranch(row).name }}</td><td>{{ labels[row.type] }}</td>
- <td v-for="side in sides" :key="side.key">{{ sideLabel(entries(row, side.key)) }}</td>
- <td><el-button type="text" @click="detail = row">详情</el-button></td>
- </tr><tr v-if="!filtered.length"><td colspan="6" class="empty">{{ branch || channel || search ? '当前筛选下没有差异记录' : complete ? '没有待核查的差异' : '取账未完成,暂无可展示的差异' }}</td></tr></tbody>
- </table></div>
- <el-pagination v-if="filtered.length > pageSize" :current-page.sync="pageNumber" :page-size="pageSize" :total="filtered.length" layout="prev, pager, next" />
- </section>
- <el-dialog v-if="detail" title="差异详情" :visible="true" width="min(720px, 94%)" @close="detail = null">
- <p>{{ tenantName }} · {{ rowBranch(detail).name }} · {{ billDate }} · {{ labels[detail.type] }}</p>
- <div class="columns"><div v-for="side in sides" :key="side.key"><h3>{{ side.title }}</h3>
- <dl v-for="(entry, index) in entries(detail, side.key)" :key="index"><template v-for="field in fields"><dt :key="field.key + 'Label'">{{ field.title }}</dt><dd :key="field.key">{{ entryValue(entry, field.key) }}</dd></template></dl>
- <p v-if="!entries(detail, side.key).length" class="muted">无对应记录</p>
- </div></div><p class="summary">差异原因:{{ detail.reason || '—' }}</p>
- </el-dialog>
- </template>
- </main>
- </template>
- <script>
- import dayjs from 'dayjs'
- import { getTenantId } from '@/utils/auth'
- import { getReceiptResult, runReceiptReconcile } from '@/api/receiptReconcile'
- const labels = {
- MATCHED: '已对平', DIFFERENT: '有差异', INCOMPLETE: '取账未完成', HUIFU: '汇付', ALIPAY: '支付宝', WECHAT: '微信',
- UNKNOWN: '未知渠道', SYSTEM_ONLY: '仅系统有', THIRD_ONLY: '仅第三方有',
- AMOUNT: '金额不一致', CHANNEL: '渠道不一致', AMBIGUOUS: '匹配不唯一'
- }
- function readScope() {
- try {
- const config = JSON.parse(sessionStorage.getItem('tenantConfig') || '{}')
- const id = String(config.tenantId || 0)
- if (id !== String(getTenantId() || 0) || !/^(0|[1-9]\d*)$/.test(id)) return null
- return { id, name: id === '0' ? '' : config.tenantName || '机构 ' + id }
- } catch (error) {
- return null
- }
- }
- export default {
- name: 'receiptReconcile',
- data() {
- return {
- labels, channelStatuses: { READY: '已取得', NOT_READY: '未就绪', ERROR: '取账失败', UNKNOWN: '无法判定渠道' },
- sides: [{ key: 'system', title: '系统成功订单' }, { key: 'third', title: '第三方交易记录' }],
- fields: [{ key: 'id', title: '记录编号' }, { key: 'orderNo', title: '商户订单号' }, { key: 'tradeNo', title: '交易流水号' }, { key: 'channel', title: '渠道' }, { key: 'time', title: '收款时间' }, { key: 'description', title: '项目说明' }, { key: 'amount', title: '金额' }],
- billDate: dayjs().subtract(1, 'day').format('YYYY-MM-DD'), tenantId: null, tenantName: '', sequence: 0,
- result: null, busy: '', error: '', scopeBlocked: false, branch: '', channel: '', search: '', detail: null, pageNumber: 1, pageSize: 20
- }
- },
- computed: {
- channelKeys() {
- const keys = ['HUIFU', 'ALIPAY', 'WECHAT']
- if (this.result && (this.result.channels.some(row => row.channel === 'UNKNOWN') ||
- this.result.differences.some(row => this.involves(row, 'UNKNOWN')))) keys.push('UNKNOWN')
- return keys
- },
- canRequest() { return Number(this.tenantId) > 0 && !!this.billDate },
- branchOptions() {
- const branches = new Map()
- for (const row of this.result ? this.result.differences : []) {
- const branch = this.rowBranch(row)
- if (branch.id !== 'unknown') branches.set(branch.id, branch)
- }
- return Array.from(branches.values()).sort((left, right) => left.name.localeCompare(right.name, 'zh-CN'))
- },
- complete() { return this.result && this.result.status !== 'INCOMPLETE' },
- statusColor() { return { MATCHED: 'success', DIFFERENT: 'danger', INCOMPLETE: 'warning' }[this.result.status] },
- notice() {
- if (this.scopeBlocked) return '当前管理机构信息不一致,已停止对账并清空结果。请完成机构切换后点击“重新确认机构”。'
- if (!this.canRequest) return '请先选择当前管理机构和账单日期。'
- return this.busy || this.error || '该日期尚未运行对账。可点击“重新取账并核对”获取结果。'
- },
- filtered() {
- if (!this.result) return []
- const term = this.search.toLowerCase()
- return this.result.differences.filter(row => (!this.branch || this.rowBranch(row).id === this.branch) &&
- (!this.channel || this.involves(row, this.channel)) &&
- (!term || this.allEntries(row).some(entry => [entry.orderNo, entry.tradeNo].some(value => String(value || '').toLowerCase().includes(term)))))
- },
- pagedDifferences() {
- const start = (this.pageNumber - 1) * this.pageSize
- return this.filtered.slice(start, start + this.pageSize)
- }
- },
- watch: {
- billDate() { this.load(false) },
- branch() { this.pageNumber = 1; this.detail = null },
- channel() { this.pageNumber = 1 },
- search() { this.pageNumber = 1 }
- },
- created() {
- this.$bus.$on('tenant-changed', this.refreshTenant)
- this.refreshTenant()
- },
- beforeDestroy() {
- this.sequence++
- this.$bus.$off('tenant-changed', this.refreshTenant)
- },
- methods: {
- money(value) { return value == null || value === '' || !Number.isFinite(Number(value)) ? '—' : '¥' + Number(value).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) },
- count(value) { return value == null ? '—' : value + ' 笔' },
- entryValue(entry, key) {
- if (key === 'amount') return this.money(entry.amount)
- if (key === 'channel') return labels[entry.channel] || '—'
- return entry[key] == null || entry[key] === '' ? '—' : entry[key]
- },
- entries(row, side) {
- const group = row[side + 'Entries']
- return Array.isArray(group) && group.length ? group : row[side] ? [row[side]] : []
- },
- allEntries(row) { return this.entries(row, 'system').concat(this.entries(row, 'third')) },
- rowBranch(row) {
- const orders = this.entries(row, 'system')
- const first = orders[0]
- if (!first || !(Number(first.organId) > 0) || !orders.every(order => String(order.organId) === String(first.organId))) {
- return { id: 'unknown', name: '待确认分部' }
- }
- return { id: String(first.organId), name: first.organName || '分部 ' + first.organId }
- },
- orderLabel(row) {
- const orders = [...new Set(this.allEntries(row).map(entry => entry.orderNo).filter(Boolean))]
- return orders.length > 1 ? orders[0] + ' 等 ' + orders.length + ' 个单号' : orders[0] || '—'
- },
- sideLabel(entries) {
- if (entries.length > 1) return entries.length + ' 条候选记录'
- return entries.length ? (labels[entries[0].channel] || '—') + ' / ' + this.money(entries[0].amount) : '—'
- },
- involves(row, channel) { return this.allEntries(row).some(entry => entry.channel === channel) },
- showChannel(channel) {
- this.pageNumber = 1
- this.branch = ''
- this.channel = channel
- this.search = ''
- this.$refs.details.scrollIntoView({ block: 'start' })
- },
- clearResults() {
- this.sequence++
- this.result = null
- this.detail = null
- this.pageNumber = 1
- this.branch = this.channel = this.search = this.error = this.busy = ''
- },
- blockScope() {
- this.clearResults()
- this.scopeBlocked = true
- this.tenantId = null
- this.tenantName = ''
- },
- refreshTenant() {
- const scope = readScope()
- if (!scope) return this.blockScope()
- this.scopeBlocked = false
- this.tenantId = scope.id
- this.tenantName = scope.name
- return this.load(false)
- },
- async load(run) {
- if (this.scopeBlocked) return
- const scope = readScope()
- if (!scope || scope.id !== this.tenantId) return this.blockScope()
- if (run && this.busy) return
- this.clearResults()
- if (!this.canRequest) return
- const sequence = this.sequence, date = this.billDate, tenant = scope.id
- this.busy = run ? '正在取账并核对…' : '正在查询已保存结果…'
- const current = () => {
- if (sequence !== this.sequence || date !== this.billDate) return false
- const active = readScope()
- if (active && active.id === tenant) return true
- this.blockScope()
- return false
- }
- const allowDispatch = headerTenant => {
- if (!current()) return false
- if (String(headerTenant) === tenant) return true
- this.blockScope()
- return false
- }
- try {
- const response = await (run ? runReceiptReconcile : getReceiptResult)(date, allowDispatch)
- if (!current()) return
- if (!response || Number(response.code) !== 200) throw new Error()
- const data = response.data
- if (!run && data === null) return
- if (!data || String(data.tenantId) !== tenant || data.billDate !== date || !['MATCHED', 'DIFFERENT', 'INCOMPLETE'].includes(data.status) || !Array.isArray(data.channels) || !Array.isArray(data.differences)) throw new Error()
- this.result = data
- } catch (error) {
- if (current()) this.error = run ? '本次对账未取得有效结果,请查询已存结果或重试。' : '未能读取该机构该日期的结果,请重新查询。'
- } finally {
- if (sequence === this.sequence) this.busy = ''
- }
- }
- }
- }
- </script>
- <style scoped>
- .receipt-page { padding: 24px; color: #263746; background: #f5f7fa; min-height: 100%; font-size: 14px; }
- header, .toolbar, .filters { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
- h1 { margin: 0; font-size: 24px; } h2 { margin: 0 0 16px; font-size: 17px; } h3 { font-size: 15px; }
- .muted, small, dt { color: #586b79; } .toolbar { margin: 22px 0; } .toolbar .el-button { margin: 0; }
- .panel, .notice { background: white; padding: 20px; margin: 14px 0; border: 1px solid #dfe5eb; border-radius: 6px; }
- .metrics, .columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
- .metrics strong { display: block; font-size: 24px; margin: 8px 0; font-variant-numeric: tabular-nums; }
- .summary { background: #f0f5f8; margin: 16px 0 0; padding: 10px 14px; line-height: 1.6; }
- .scroll { overflow-x: auto; } table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
- td, th { padding: 12px 10px; border-bottom: 1px solid #e7ebef; text-align: left; overflow-wrap: anywhere; min-width: 90px; }
- thead { background: #f6f8fa; } small { display: block; margin-top: 4px; } .empty { text-align: center; color: #586b79; }
- .filters { margin-bottom: 12px; } .filters .el-input { max-width: 260px; } .columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
- dl { display: grid; grid-template-columns: auto 1fr; gap: 8px; } dd { margin: 0; overflow-wrap: anywhere; }
- dl + dl { padding-top: 12px; border-top: 1px solid #dfe5eb; }
- @media (max-width: 700px) { .receipt-page { padding: 12px; } .metrics, .columns { grid-template-columns: 1fr; } }
- </style>
|