Ver Fonte

feat: 收款对账差异明细支持按分部筛选

yonge há 3 horas atrás
pai
commit
21bdcd7cce

+ 30 - 8
src/views/businessManager/orderManager/receiptReconcile.vue

@@ -33,20 +33,23 @@
       </section>
       <section ref="details" class="panel">
         <h2>差异明细</h2>
-        <div class="filters"><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>
+        <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></tr></thead>
+        <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>{{ labels[row.type] }}</td>
+            <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="5" class="empty">{{ channel || search ? '当前筛选下没有差异记录' : complete ? '没有待核查的差异' : '取账未完成,暂无可展示的差异' }}</td></tr></tbody>
+          </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 }} · {{ billDate }} · {{ labels[detail.type] }}</p>
+        <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>
@@ -86,7 +89,7 @@ export default {
       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, channel: '', search: '', detail: null, pageNumber: 1, pageSize: 20
+      result: null, busy: '', error: '', scopeBlocked: false, branch: '', channel: '', search: '', detail: null, pageNumber: 1, pageSize: 20
     }
   },
   computed: {
@@ -97,6 +100,14 @@ export default {
       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() {
@@ -107,7 +118,8 @@ export default {
     filtered() {
       if (!this.result) return []
       const term = this.search.toLowerCase()
-      return this.result.differences.filter(row => (!this.channel || this.involves(row, this.channel)) &&
+      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() {
@@ -117,6 +129,7 @@ export default {
   },
   watch: {
     billDate() { this.load(false) },
+    branch() { this.pageNumber = 1; this.detail = null },
     channel() { this.pageNumber = 1 },
     search() { this.pageNumber = 1 }
   },
@@ -141,6 +154,14 @@ export default {
       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] || '—'
@@ -152,6 +173,7 @@ export default {
     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' })
@@ -161,7 +183,7 @@ export default {
       this.result = null
       this.detail = null
       this.pageNumber = 1
-      this.channel = this.search = this.error = this.busy = ''
+      this.branch = this.channel = this.search = this.error = this.busy = ''
     },
     blockScope() {
       this.clearResults()

+ 35 - 0
tests/unit/components/receiptReconcile.spec.js

@@ -106,6 +106,41 @@ test('changed date discards late results; rejection and wrong-scope responses ne
   }
 })
 
+test('branch selection filters only differences, combines with search and channel, and resets on tenant change', async() => {
+  const order = (organId, organName, orderNo) => ({ organId, organName, orderNo, channel: 'ALIPAY' })
+  const east = order(11, '东城', 'E-01'), west = order(12, '西城', 'W-01')
+  const differences = [
+    { type: 'SYSTEM_ONLY', system: east }, { type: 'SYSTEM_ONLY', system: west },
+    { type: 'THIRD_ONLY', third: { channel: 'WECHAT', orderNo: 'WX-01' }},
+    { type: 'SYSTEM_ONLY', system: { orderNo: 'LEGACY' }},
+    { type: 'AMBIGUOUS', system: east, systemEntries: [east, west] }
+  ]
+  request.mockImplementationOnce(({ params }) => Promise.resolve(response(result(params.billDate, {
+    status: 'DIFFERENT', differences, differenceCount: 5, systemAmount: 250,
+    channels: [{ channel: 'WECHAT', status: 'READY', availableBalance: 129 }]
+  }))))
+  const page = open(); await flush()
+  const summary = wrapper.find('.metrics').text(), channels = wrapper.findAll('table').at(0).text()
+  const selector = wrapper.findAll({ name: 'ElSelect' }).wrappers.find(select => select.attributes('aria-label') === '切换分部')
+  expect(page.branchOptions.map(item => item.id).sort()).toEqual(['11', '12'])
+  page.pageNumber = 2
+  selector.vm.$emit('input', '11'); await Vue.nextTick()
+  expect(page.pageNumber).toBe(1)
+  expect(page.filtered).toEqual([differences[0]])
+  expect(wrapper.find('.metrics').text()).toBe(summary)
+  expect(wrapper.findAll('table').at(0).text()).toBe(channels)
+  selector.vm.$emit('input', 'unknown'); await Vue.nextTick()
+  expect(page.filtered).toEqual(differences.slice(2))
+  await wrapper.setData({ channel: 'WECHAT', search: 'wx-' })
+  expect(page.filtered).toEqual([differences[2]])
+  expect(request).toHaveBeenCalledTimes(1)
+  request.mockResolvedValueOnce(response(null))
+  tenant(2); bus.$emit('tenant-changed'); await flush()
+  expect(page.branch).toBe('')
+  expect(page.branchOptions).toEqual([])
+  expect(page.tenantName).toBe('机构2')
+})
+
 test('missing management tenant never sends a read or run', async() => {
   sessionStorage.clear()
   const page = open(); await page.load(true)