index.vue 18 KB

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