index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <template>
  2. <div :class="prefixCls" class="trade-frequency-page">
  3. <div class="page-header">
  4. <div class="page-title">交易频次</div>
  5. <div class="page-subtitle">按交易时间段汇总对象与对手方的往来频次,并支持下钻查看交易记录明细。</div>
  6. </div>
  7. <div class="filter-bar">
  8. <div class="qj-filter-head">
  9. <div class="qj-card-title">查询条件</div>
  10. <div class="filter-actions">
  11. <Button type="primary" :loading="queryLoading" @click="handleSearch">查询</Button>
  12. <Button @click="handleReset">重置</Button>
  13. <!-- <Button @click="handlePreviewModal">预览弹窗</Button> -->
  14. </div>
  15. </div>
  16. <div class="qj-filter-grid">
  17. <div class="filter-item">
  18. <span class="filter-label">选择对象:</span>
  19. <Select
  20. v-model:value="filters.target"
  21. mode="multiple"
  22. allow-clear
  23. max-tag-count="responsive"
  24. class="filter-input"
  25. :options="targetOptions"
  26. placeholder="全部"
  27. />
  28. </div>
  29. <div class="filter-item">
  30. <span class="filter-label">交易次数:</span>
  31. <Select v-model:value="filters.countOp" class="filter-op" :options="countOpOptions" />
  32. <Input v-model:value="filters.countValue" class="filter-mini" :status="countValueStatus" />
  33. </div>
  34. <div class="filter-item">
  35. <span class="filter-label">交易日期:</span>
  36. <RangePicker v-model:value="filters.dateRange" class="filter-date" />
  37. </div>
  38. <div class="filter-item">
  39. <span class="filter-label">对方姓名:</span>
  40. <Input v-model:value="filters.otherName" class="filter-input" placeholder="请输入对方姓名" />
  41. </div>
  42. <div class="filter-item">
  43. <span class="filter-label">对方卡号:</span>
  44. <Input v-model:value="filters.otherCardNo" class="filter-input" placeholder="请输入对方卡号" />
  45. </div>
  46. </div>
  47. </div>
  48. <div class="content-panel">
  49. <div class="table-card">
  50. <div class="panel-header">
  51. <div>
  52. <div class="panel-title">频次结果列表</div>
  53. <div class="panel-desc">统计汇总与对象有交易的人或卡</div>
  54. </div>
  55. </div>
  56. <div v-if="!hasSearched" class="query-state-panel">
  57. <EmptyState
  58. variant="query"
  59. title="请点击查询"
  60. description="设置条件精细查询,也可点击查询展示所有信息"
  61. min-height="100%"
  62. description-width="min(100%, 420px)"
  63. />
  64. </div>
  65. <div v-else class="table-panel">
  66. <div class="table-wrapper">
  67. <BasicTable
  68. :columns="columns"
  69. :action-column="actionColumn"
  70. :data-source="tableData"
  71. :pagination="false"
  72. :show-table-setting="false"
  73. :table-setting="{ setting: true, size: true, redo: false, fullScreen: false }"
  74. :can-resize="true"
  75. :is-can-resize-parent="true"
  76. :resize-height-offset="32"
  77. row-key="id"
  78. @change="handleTableChange"
  79. >
  80. <template #action="{ record }">
  81. <Button type="link" size="small" @click="handleViewDetail(record)">查看详情</Button>
  82. </template>
  83. </BasicTable>
  84. </div>
  85. </div>
  86. <div v-if="hasSearched" class="pagination-bar">
  87. <AnalysisPagination
  88. :total="pagination.total"
  89. :current="pagination.current"
  90. :page-size="pagination.pageSize"
  91. :page-size-options="pageSizeOptions"
  92. :loading="queryLoading"
  93. @change="handlePaginationChange"
  94. />
  95. </div>
  96. </div>
  97. </div>
  98. <TransRecordModal v-model:open="transRecordModalOpen" :base-query="transRecordBaseQuery" />
  99. </div>
  100. </template>
  101. <script lang="ts" setup name="ViewsTradeFrequencyIndex">
  102. import { computed, onMounted, ref, watch } from 'vue';
  103. import { useRoute } from 'vue-router';
  104. import { Select, Input, Button, DatePicker } from 'ant-design-vue';
  105. import dayjs, { Dayjs } from 'dayjs';
  106. import AnalysisPagination from '@/core/components/AnalysisPagination/src/AnalysisPagination.vue';
  107. import { EmptyState } from '@/core/components/EmptyState';
  108. import { BasicTable } from '@/core/components/Table';
  109. import { useAnalysisRefreshPrompt } from '@/core/hooks/web/useAnalysisRefreshPrompt';
  110. import { useDesign } from '@/core/hooks/web/useDesign';
  111. import { useTableSkill } from '@/core/hooks/web/useTableSkill';
  112. import { useMessage } from '@/core/hooks/web/useMessage';
  113. import {
  114. COMPARE_OPERATOR_OPTIONS,
  115. DEFAULT_COMPARE_OPERATOR,
  116. normalizeCompareOperator,
  117. } from '@/core/utils/compareOperator';
  118. import { mergeDetailDateRange, pickDetailValue } from '@/core/utils/detailQuery';
  119. import componentSetting from '@/core/settings/componentSetting';
  120. import { statFirstTransFrequency } from '@/trans/api/transApi';
  121. import TransRecordModal from '../components/TransRecordModal.vue';
  122. import { getPersonOptions } from '@/person/api/personApi';
  123. import type { TransFrequencyDTO } from '@/trans/api/types/dto';
  124. import type { TransFrequencyQuery, TransRecordQuery } from '@/trans/api/types/query';
  125. const RangePicker = DatePicker.RangePicker;
  126. const { prefixCls } = useDesign('trade-frequency');
  127. const { queryLoading, runWithQueryLoading } = useTableSkill();
  128. const { createMessage } = useMessage();
  129. const route = useRoute();
  130. const PAGE_PATH = '/tradeFrequency/index';
  131. type RangeValue = [Dayjs, Dayjs] | null;
  132. const createDefaultFilters = () => ({
  133. target: [] as string[],
  134. countOp: DEFAULT_COMPARE_OPERATOR,
  135. countValue: '',
  136. dateRange: null as RangeValue,
  137. otherName: '',
  138. otherCardNo: '',
  139. orderKey: 'transCount',
  140. sort: 'DESC' as '' | 'ASC' | 'DESC',
  141. });
  142. const filters = ref(createDefaultFilters());
  143. const pagination = ref({
  144. current: 1,
  145. pageSize: componentSetting.table.defaultPageSize,
  146. total: 0,
  147. });
  148. const jumpPage = ref('1');
  149. const tableData = ref<any[]>([]);
  150. const hasSearched = ref(false);
  151. const { syncAnalysisDataRefreshState } = useAnalysisRefreshPrompt({
  152. refresh: () => fetchTable(),
  153. hasData: () => hasSearched.value && tableData.value.length > 0,
  154. });
  155. const transRecordModalOpen = ref(false);
  156. const transRecordBaseQuery = ref<Record<string, any>>({});
  157. const lastExecutedQuery = ref<Partial<TransFrequencyQuery>>({});
  158. const targetOptions = ref<Array<{ label: string; value: string }>>([]);
  159. const countValuePattern = /^[1-9]\d*$/;
  160. const normalizeSelectedTargets = (value?: string[] | string | null) => {
  161. if (Array.isArray(value)) {
  162. const list = value.map((item) => String(item).trim()).filter(Boolean);
  163. return list.length ? Array.from(new Set(list)) : [];
  164. }
  165. if (!value) return [];
  166. const list = String(value)
  167. .split(',')
  168. .map((item) => item.trim())
  169. .filter(Boolean);
  170. return list.length ? Array.from(new Set(list)) : [];
  171. };
  172. const countOpOptions = COMPARE_OPERATOR_OPTIONS.filter((o) => o.value === 'GE' || o.value === 'LE');
  173. const pageSizeOptions = componentSetting.table.pageSizeOptions.map((value) => ({
  174. label: value,
  175. value: Number(value),
  176. }));
  177. const totalPages = computed(() => {
  178. if (!pagination.value.total) return 1;
  179. return Math.max(1, Math.ceil(pagination.value.total / pagination.value.pageSize));
  180. });
  181. const normalizedCountValue = computed(() => String(filters.value.countValue ?? '').trim());
  182. const countValueStatus = computed<'error' | undefined>(() => {
  183. if (!normalizedCountValue.value) return undefined;
  184. return countValuePattern.test(normalizedCountValue.value) ? undefined : 'error';
  185. });
  186. const columns = [
  187. { title: '交易时间段', dataIndex: 'timeRange', key: 'timeRange', width: 220, align: 'center' },
  188. { title: '本方姓名', dataIndex: 'selfName', key: 'selfName', width: 120, align: 'center' },
  189. { title: '对方姓名', dataIndex: 'otherName', key: 'otherName', width: 180, align: 'center' },
  190. { title: '对方卡号', dataIndex: 'otherCard', key: 'otherCard', width: 200, align: 'center' },
  191. {
  192. title: '交易次数',
  193. dataIndex: 'transCount',
  194. key: 'transCount',
  195. width: 120,
  196. align: 'center',
  197. sorter: true,
  198. defaultSortOrder: 'descend',
  199. },
  200. {
  201. title: '交易金额',
  202. dataIndex: 'transTotalAmount',
  203. key: 'transTotalAmount',
  204. width: 140,
  205. align: 'center',
  206. sorter: true,
  207. },
  208. ];
  209. const actionColumn = {
  210. title: '操作',
  211. dataIndex: 'action',
  212. key: 'action',
  213. width: 120,
  214. align: 'center',
  215. fixed: 'right' as const,
  216. slot: 'action',
  217. };
  218. const normalizeList = (resp: any): TransFrequencyDTO[] => {
  219. if (Array.isArray(resp)) return resp;
  220. if (Array.isArray(resp?.list)) return resp.list;
  221. if (Array.isArray(resp?.data)) return resp.data;
  222. if (Array.isArray(resp?.data?.list)) return resp.data.list;
  223. if (Array.isArray(resp?.records)) return resp.records;
  224. if (Array.isArray(resp?.data?.records)) return resp.data.records;
  225. return [];
  226. };
  227. const normalizeTotal = (resp: any, listLen: number) => {
  228. const t = resp?.total ?? resp?.data?.total ?? resp?.count ?? resp?.data?.count ?? listLen;
  229. return Number.isFinite(Number(t)) ? Number(t) : listLen;
  230. };
  231. const mapRow = (item: TransFrequencyDTO, index: number) => ({
  232. id: (pagination.value.current - 1) * pagination.value.pageSize + index + 1,
  233. timeRange: `${item.startTransDate || '-'} 至 ${item.endTransDate || '-'}`,
  234. selfName: item.personName || '-',
  235. otherName: item.otherName || '-',
  236. otherCard: item.otherCardNo || '-',
  237. transCount: item.transCount ?? 0,
  238. transTotalAmount: item.transTotalAmount ?? 0,
  239. raw: item,
  240. });
  241. const resolveFilterTransCount = (showMessage = false) => {
  242. if (!normalizedCountValue.value) return undefined;
  243. if (countValuePattern.test(normalizedCountValue.value)) {
  244. return Number(normalizedCountValue.value);
  245. }
  246. if (showMessage) {
  247. createMessage.warning('交易次数请输入大于 0 的整数');
  248. }
  249. return null;
  250. };
  251. const buildQuery = (transCount?: number): TransFrequencyQuery => {
  252. const range = filters.value.dateRange as [Dayjs, Dayjs] | null;
  253. const otherName = String(filters.value.otherName || '').trim();
  254. const otherCardNo = String(filters.value.otherCardNo || '').trim();
  255. return {
  256. page: pagination.value.current,
  257. limit: pagination.value.pageSize,
  258. startDate: range?.[0] ? dayjs(range[0]).format('YYYY-MM-DD') : undefined,
  259. endDate: range?.[1] ? dayjs(range[1]).format('YYYY-MM-DD') : undefined,
  260. personNames: (() => {
  261. const personNames = normalizeSelectedTargets(filters.value.target);
  262. return personNames.length ? personNames : undefined;
  263. })(),
  264. transCount,
  265. transCountSymbol:
  266. transCount !== undefined
  267. ? normalizeCompareOperator(filters.value.countOp, DEFAULT_COMPARE_OPERATOR)
  268. : undefined,
  269. otherName: otherName || undefined,
  270. otherCardNo: otherCardNo || undefined,
  271. orderKey: filters.value.orderKey || 'transCount',
  272. sort: filters.value.sort || 'DESC',
  273. };
  274. };
  275. const buildTransRecordBaseQuery = (record: any): Partial<TransRecordQuery> => {
  276. const currentQuery = lastExecutedQuery.value;
  277. const { startDate, endDate } = mergeDetailDateRange(
  278. {
  279. startDate: currentQuery.startDate,
  280. endDate: currentQuery.endDate,
  281. },
  282. {
  283. startDate: record?.raw?.startTransDate || undefined,
  284. endDate: record?.raw?.endTransDate || undefined,
  285. },
  286. );
  287. return {
  288. personName: pickDetailValue(record?.raw?.personName, currentQuery.personNames?.[0]),
  289. otherName: pickDetailValue(record?.raw?.otherName, currentQuery.otherName),
  290. otherCardNo: pickDetailValue(record?.raw?.otherCardNo, currentQuery.otherCardNo),
  291. startDate,
  292. endDate,
  293. };
  294. };
  295. const fetchTable = async () => {
  296. const transCount = resolveFilterTransCount(true);
  297. if (transCount === null) return;
  298. await runWithQueryLoading(async () => {
  299. const query = buildQuery(transCount);
  300. const resp = await statFirstTransFrequency(query);
  301. const list = normalizeList(resp);
  302. tableData.value = list.map(mapRow);
  303. pagination.value.total = normalizeTotal(resp, list.length);
  304. hasSearched.value = true;
  305. syncAnalysisDataRefreshState(list.length > 0);
  306. lastExecutedQuery.value = { ...query };
  307. const current = Number((resp as any)?.data?.current || pagination.value.current);
  308. const size = Number((resp as any)?.data?.size || pagination.value.pageSize);
  309. if (Number.isFinite(current) && current > 0) pagination.value.current = current;
  310. if (Number.isFinite(size) && size > 0) pagination.value.pageSize = size;
  311. jumpPage.value = String(pagination.value.current);
  312. });
  313. };
  314. const handleSearch = async () => {
  315. pagination.value.current = 1;
  316. await fetchTable();
  317. };
  318. const handleReset = async () => {
  319. filters.value = createDefaultFilters();
  320. pagination.value.current = 1;
  321. await fetchTable();
  322. };
  323. const handlePrevPage = async () => {
  324. if (queryLoading.value || pagination.value.current <= 1) return;
  325. pagination.value.current -= 1;
  326. await fetchTable();
  327. };
  328. const handleNextPage = async () => {
  329. if (queryLoading.value || pagination.value.current >= totalPages.value) return;
  330. pagination.value.current += 1;
  331. await fetchTable();
  332. };
  333. const handlePaginationChange = async (page: number, pageSize: number) => {
  334. if (queryLoading.value) return;
  335. if (pageSize !== pagination.value.pageSize) {
  336. pagination.value.pageSize = pageSize;
  337. await handlePageSizeChange();
  338. return;
  339. }
  340. if (page === pagination.value.current - 1) {
  341. await handlePrevPage();
  342. return;
  343. }
  344. if (page === pagination.value.current + 1) {
  345. await handleNextPage();
  346. return;
  347. }
  348. if (page === pagination.value.current) return;
  349. jumpPage.value = String(page);
  350. await handleJumpPage();
  351. };
  352. const handlePageSizeChange = async () => {
  353. pagination.value.current = 1;
  354. await fetchTable();
  355. };
  356. const handleJumpPage = async () => {
  357. const next = Number(jumpPage.value);
  358. if (!Number.isInteger(next) || next < 1) {
  359. createMessage.warning('请输入正确页码');
  360. jumpPage.value = String(pagination.value.current);
  361. return;
  362. }
  363. pagination.value.current = Math.min(next, totalPages.value);
  364. await fetchTable();
  365. };
  366. const resolveSorterValue = (sorter: any) => {
  367. if (Array.isArray(sorter)) {
  368. return sorter[0];
  369. }
  370. return sorter;
  371. };
  372. const handleTableChange = async (_pagination: any, _filters: any, sorter: any) => {
  373. const currentSorter = resolveSorterValue(sorter);
  374. const order = currentSorter?.order;
  375. const columnKey = String(currentSorter?.columnKey || '');
  376. filters.value.orderKey = order && columnKey ? columnKey : 'transCount';
  377. filters.value.sort = order === 'ascend' ? 'ASC' : order === 'descend' ? 'DESC' : 'DESC';
  378. pagination.value.current = 1;
  379. await fetchTable();
  380. };
  381. const applyRouteQuery = (targetOptions: Array<{ label: string; value: string }>) => {
  382. filters.value = createDefaultFilters();
  383. const personNames = normalizeSelectedTargets(
  384. (route.query.personNames as string | string[] | null | undefined) ??
  385. (route.query.personName as string | string[] | null | undefined),
  386. );
  387. const otherName = String(route.query.otherName || '').trim();
  388. const otherCardNo = String(route.query.otherCardNo || '').trim();
  389. if (personNames.length) {
  390. filters.value.target = personNames.map((personName) => {
  391. const matched = targetOptions.find((item) => String(item.label).trim() === personName);
  392. return matched ? matched.value : personName;
  393. });
  394. }
  395. if (otherName) {
  396. filters.value.otherName = otherName;
  397. }
  398. if (otherCardNo) {
  399. filters.value.otherCardNo = otherCardNo;
  400. }
  401. return !!(personNames.length || otherName || otherCardNo);
  402. };
  403. const syncFromRoute = async () => {
  404. if (route.path !== PAGE_PATH) return;
  405. if (applyRouteQuery(targetOptions.value)) {
  406. pagination.value.current = 1;
  407. await fetchTable();
  408. }
  409. };
  410. const handleViewDetail = (record: any) => {
  411. transRecordBaseQuery.value = buildTransRecordBaseQuery(record);
  412. transRecordModalOpen.value = true;
  413. };
  414. const fetchTargetOptions = async () => {
  415. try {
  416. targetOptions.value = await getPersonOptions(false);
  417. } catch (error) {
  418. targetOptions.value = [];
  419. }
  420. };
  421. onMounted(async () => {
  422. await fetchTargetOptions();
  423. await syncFromRoute();
  424. });
  425. watch(
  426. () => route.fullPath,
  427. async (next, prev) => {
  428. if (next === prev) return;
  429. await syncFromRoute();
  430. },
  431. );
  432. </script>
  433. <style lang="less">
  434. @import '../styles/trans-analysis-table-ui.less';
  435. @import (reference) '../styles/analysis-card-ui.less';
  436. @prefix-cls: ~'jeesite-trade-frequency';
  437. .@{prefix-cls}.trade-frequency-page {
  438. .analysis-single-panel-frame();
  439. .filter-input {
  440. width: 180px;
  441. }
  442. .filter-mini {
  443. width: 88px;
  444. }
  445. .filter-date {
  446. width: 360px;
  447. }
  448. .panel-header {
  449. display: flex;
  450. align-items: flex-start;
  451. justify-content: space-between;
  452. gap: 12px;
  453. }
  454. .query-state-panel {
  455. flex: 1 1 auto;
  456. min-height: 0;
  457. display: flex;
  458. align-items: center;
  459. justify-content: center;
  460. padding: 12px 0 0;
  461. }
  462. .table-wrapper .ant-table-thead > tr > th {
  463. background: #f8fafc;
  464. font-weight: 600;
  465. color: #374151;
  466. }
  467. .table-wrapper .ant-table-tbody > tr > td {
  468. color: #374151;
  469. }
  470. .table-wrapper .ant-table-tbody > tr:hover > td {
  471. background: #f5f7ff;
  472. }
  473. .pagination-input {
  474. width: 48px;
  475. }
  476. :deep(.ant-select-selector),
  477. :deep(.ant-input),
  478. :deep(.ant-picker),
  479. :deep(.ant-btn) {
  480. border-radius: 8px;
  481. }
  482. @media screen and (max-width: 992px) {
  483. .filter-input,
  484. .filter-date {
  485. width: 100%;
  486. }
  487. }
  488. }
  489. /* 统一卡片视觉:对齐「持续联系 / 夜间联系 / 敏感日期联系」 */
  490. .@{prefix-cls}.trade-frequency-page {
  491. .analysis-card-ui();
  492. }
  493. </style>