index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <template>
  2. <div :class="prefixCls" class="continuous-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. <Input v-model:value="filters.monthValue" class="filter-input" :status="monthValueStatus" />
  23. </div>
  24. <div class="filter-item">
  25. <span class="filter-label">联系日期:</span>
  26. <RangePicker
  27. v-model:value="filters.dateRange"
  28. class="filter-input filter-date"
  29. :format="DATE_FORMAT"
  30. :value-format="DATE_FORMAT"
  31. :placeholder="['开始日期', '结束日期']"
  32. />
  33. </div>
  34. <div class="filter-item">
  35. <span class="filter-label">对方姓名:</span>
  36. <Input v-model:value="filters.otherName" class="filter-input" placeholder="请输入对方姓名" />
  37. </div>
  38. <div class="filter-item">
  39. <span class="filter-label">对方号码:</span>
  40. <Input v-model:value="filters.otherPhone" class="filter-input" placeholder="请输入对方号码" />
  41. </div>
  42. <div class="filter-actions">
  43. <Button type="primary" :loading="queryLoading" @click="handleSearch">查询</Button>
  44. <Button @click="handleReset">重置</Button>
  45. </div>
  46. </div>
  47. <div class="content-panel">
  48. <div class="table-card">
  49. <div class="panel-header">
  50. <div class="panel-title-wrap">
  51. <div class="panel-title">持续联系对象汇总</div>
  52. <div class="panel-desc">找出与被调查对象持续保持联系的人员。</div>
  53. </div>
  54. </div>
  55. <div v-if="!hasSearched" class="query-state-panel">
  56. <EmptyState
  57. variant="query"
  58. title="请点击查询"
  59. description="设置条件精细查询,也可点击查询展示所有信息"
  60. min-height="100%"
  61. description-width="min(100%, 420px)"
  62. />
  63. </div>
  64. <div v-else class="table-panel">
  65. <div class="table-wrapper">
  66. <BasicTable
  67. :columns="columns"
  68. :data-source="tableData"
  69. :loading="false"
  70. :pagination="false"
  71. :show-table-setting="false"
  72. :table-setting="{ setting: true, size: true, redo: false, fullScreen: false }"
  73. :can-resize="true"
  74. :is-can-resize-parent="true"
  75. :resize-height-offset="32"
  76. row-key="id"
  77. />
  78. </div>
  79. </div>
  80. <div v-if="hasSearched" class="pagination-bar">
  81. <AnalysisPagination
  82. :total="total"
  83. :current="pagination.page"
  84. :page-size="pagination.limit"
  85. :page-size-options="pageSizeOptions"
  86. :loading="queryLoading"
  87. @change="handlePaginationChange"
  88. />
  89. </div>
  90. </div>
  91. </div>
  92. <CallRecordModal v-model:open="callRecordModalOpen" title="通信记录" :base-query="callRecordBaseQuery" />
  93. </div>
  94. </template>
  95. <script lang="ts" setup name="ViewsContinuousIndex">
  96. import { computed, onMounted, reactive, ref, watch } from 'vue';
  97. import { useRoute } from 'vue-router';
  98. import { Select, Input, DatePicker, Button } from 'ant-design-vue';
  99. import AnalysisPagination from '@jeesite/core/components/AnalysisPagination/src/AnalysisPagination.vue';
  100. import { EmptyState } from '@jeesite/core/components/EmptyState';
  101. import { BasicTable } from '@jeesite/core/components/Table';
  102. import CallRecordModal from '@jeesite/call/views/components/CallRecordModal.vue';
  103. import { useAnalysisRefreshPrompt } from '@jeesite/core/hooks/web/useAnalysisRefreshPrompt';
  104. import { useDesign } from '@jeesite/core/hooks/web/useDesign';
  105. import { useTableSkill, buildTableActionColumn } from '@jeesite/core/hooks/web/useTableSkill';
  106. import componentSetting from '@jeesite/core/settings/componentSetting';
  107. import { useMessage } from '@jeesite/core/hooks/web/useMessage';
  108. import { statFirstCallContinuous } from '@jeesite/call/api/callApi';
  109. import { getPersonOptions } from '@jeesite/person/api/personApi';
  110. import type { CallContinuousDTO } from '@jeesite/call/api/types/dto';
  111. import type { CallContinuousQuery, CallRecordQuery } from '@jeesite/call/api/types/query';
  112. const { prefixCls } = useDesign('continuous');
  113. const { createMessage } = useMessage();
  114. const { queryLoading, runWithQueryLoading } = useTableSkill();
  115. const route = useRoute();
  116. const RangePicker = DatePicker.RangePicker;
  117. const DATE_FORMAT = 'YYYY-MM-DD';
  118. const DEFAULT_MONTH_VALUE = '2';
  119. const PAGE_PATH = '/continuous/index';
  120. const DEFAULT_SORT_KEY = 'pairContMonthCount';
  121. const DEFAULT_SORT_ORDER = 'DESC' as const;
  122. type RangeValue = [string, string] | undefined;
  123. const createDefaultFilters = () => ({
  124. target: [] as string[],
  125. monthValue: DEFAULT_MONTH_VALUE,
  126. dateRange: undefined as RangeValue,
  127. otherName: '',
  128. otherPhone: '',
  129. });
  130. const filters = ref(createDefaultFilters());
  131. const targetOptions = ref<Array<{ label: string; value: string }>>([]);
  132. const monthValuePattern = /^[1-9]\d*$/;
  133. const callRecordModalOpen = ref(false);
  134. const callRecordBaseQuery = reactive<Partial<CallRecordQuery>>({});
  135. const normalizeSelectedTargets = (value?: string[] | string | null) => {
  136. if (Array.isArray(value)) {
  137. const list = value.map((item) => String(item).trim()).filter(Boolean);
  138. return list.length ? Array.from(new Set(list)) : [];
  139. }
  140. if (!value) return [];
  141. const list = String(value)
  142. .split(',')
  143. .map((item) => item.trim())
  144. .filter(Boolean);
  145. return list.length ? Array.from(new Set(list)) : [];
  146. };
  147. const resolveFilterMonthVal = () => {
  148. if (!monthValuePattern.test(normalizedMonthValue.value)) return undefined;
  149. const monthVal = Number(normalizedMonthValue.value);
  150. return Number.isFinite(monthVal) ? monthVal : undefined;
  151. };
  152. const validateMonthValue = () => {
  153. if (resolveFilterMonthVal() !== undefined) return true;
  154. createMessage.warning('持续联系月数必须是大于 0 的整数');
  155. return false;
  156. };
  157. const normalizeDetailDate = (value?: string) => {
  158. const raw = String(value || '').trim();
  159. if (!raw) return undefined;
  160. const matchedDate = raw.match(/\d{4}-\d{2}-\d{2}/)?.[0];
  161. if (matchedDate) return matchedDate;
  162. const matchedMonth = raw.match(/\d{4}-\d{2}/)?.[0];
  163. return matchedMonth ? `${matchedMonth}-01` : undefined;
  164. };
  165. const openDetailModal = (record: any) => {
  166. const raw = record?.raw || {};
  167. callRecordBaseQuery.personName = raw.personName || undefined;
  168. callRecordBaseQuery.otherName = raw.otherName || undefined;
  169. callRecordBaseQuery.otherPhones = raw.otherPhone ? [raw.otherPhone] : undefined;
  170. callRecordBaseQuery.startDate = normalizeDetailDate(raw.continuousStartMonth);
  171. callRecordBaseQuery.endDate = normalizeDetailDate(raw.continuousEndMonth);
  172. callRecordModalOpen.value = true;
  173. };
  174. const columns = [
  175. { title: '本方姓名', dataIndex: 'selfName', key: 'selfName', width: 140 },
  176. { title: '对方姓名', dataIndex: 'otherName', key: 'otherName', width: 140 },
  177. { title: '对方号码', dataIndex: 'otherNumber', key: 'otherNumber', width: 220 },
  178. { title: '共持续联系次数', dataIndex: 'count', key: 'count', width: 160 },
  179. {
  180. title: '持续联系月数',
  181. dataIndex: 'duration',
  182. key: 'duration',
  183. width: 140,
  184. },
  185. buildTableActionColumn(openDetailModal, { buttonText: '查看详情', width: 120 }),
  186. ];
  187. const tableData = ref<any[]>([]);
  188. const total = ref(0);
  189. const jumpPage = ref('1');
  190. const hasSearched = ref(false);
  191. const { syncAnalysisDataRefreshState } = useAnalysisRefreshPrompt({
  192. refresh: () => fetchFirstLevelTable(),
  193. hasData: () => hasSearched.value && tableData.value.length > 0,
  194. });
  195. const pagination = ref({
  196. page: 1,
  197. limit: componentSetting.table.defaultPageSize,
  198. });
  199. const pageSizeOptions = componentSetting.table.pageSizeOptions.map((value) => ({
  200. label: value,
  201. value,
  202. }));
  203. const totalPages = computed(() => {
  204. if (!total.value) return 1;
  205. return Math.max(1, Math.ceil(total.value / pagination.value.limit));
  206. });
  207. const normalizedMonthValue = computed(() => String(filters.value.monthValue ?? '').trim());
  208. const monthValueStatus = computed<'error' | undefined>(() => {
  209. return monthValuePattern.test(normalizedMonthValue.value) ? undefined : 'error';
  210. });
  211. const normalizeList = (resp: any): CallContinuousDTO[] => {
  212. if (Array.isArray(resp)) return resp;
  213. if (Array.isArray(resp?.list)) return resp.list;
  214. if (Array.isArray(resp?.data)) return resp.data;
  215. if (Array.isArray(resp?.data?.list)) return resp.data.list;
  216. if (Array.isArray(resp?.records)) return resp.records;
  217. if (Array.isArray(resp?.data?.records)) return resp.data.records;
  218. return [];
  219. };
  220. const normalizeTotal = (resp: any, listLen: number) => {
  221. const t = resp?.total ?? resp?.data?.total ?? resp?.count ?? resp?.data?.count ?? resp?.data?.records?.length;
  222. return Number.isFinite(Number(t)) ? Number(t) : listLen;
  223. };
  224. const mapRow = (item: CallContinuousDTO, index: number) => ({
  225. id: (pagination.value.page - 1) * pagination.value.limit + index + 1,
  226. selfName: item.personName || '-',
  227. otherName: item.otherName || '-',
  228. otherNumber: item.otherPhone || '-',
  229. count: String(item.pairTotalCalls ?? (item as any).pairTotalCall ?? (item as any).totalCalls ?? 0),
  230. duration: `${item.pairContMonthCount ?? (item as any).contMonthCount ?? 0}个月`,
  231. durationValue: Number(item.pairContMonthCount ?? (item as any).contMonthCount ?? 0) || 0,
  232. raw: item,
  233. });
  234. const sortByDurationDesc = (list: CallContinuousDTO[]) =>
  235. [...list].sort((left, right) => {
  236. const leftValue = Number(left.pairContMonthCount ?? (left as any).contMonthCount ?? 0) || 0;
  237. const rightValue = Number(right.pairContMonthCount ?? (right as any).contMonthCount ?? 0) || 0;
  238. if (rightValue !== leftValue) return rightValue - leftValue;
  239. const leftCount =
  240. Number(left.pairTotalCalls ?? (left as any).pairTotalCall ?? (left as any).totalCalls ?? 0) || 0;
  241. const rightCount =
  242. Number(right.pairTotalCalls ?? (right as any).pairTotalCall ?? (right as any).totalCalls ?? 0) || 0;
  243. return rightCount - leftCount;
  244. });
  245. const buildQuery = (): CallContinuousQuery | null => {
  246. const monthVal = resolveFilterMonthVal();
  247. if (monthVal === undefined) return null;
  248. const range = filters.value.dateRange as RangeValue;
  249. const personNames = normalizeSelectedTargets(filters.value.target);
  250. const otherName = String(filters.value.otherName || '').trim();
  251. const otherPhone = String(filters.value.otherPhone || '').trim();
  252. return {
  253. page: pagination.value.page,
  254. limit: pagination.value.limit,
  255. monthVal,
  256. startDate: range?.[0] || undefined,
  257. endDate: range?.[1] || undefined,
  258. personNames: personNames.length ? personNames : undefined,
  259. otherName: otherName || undefined,
  260. otherPhone: otherPhone || undefined,
  261. orderKey: DEFAULT_SORT_KEY,
  262. sort: DEFAULT_SORT_ORDER,
  263. };
  264. };
  265. const fetchFirstLevelTable = async () => {
  266. const query = buildQuery();
  267. if (!query) {
  268. validateMonthValue();
  269. return;
  270. }
  271. await runWithQueryLoading(async () => {
  272. const resp = await statFirstCallContinuous(query);
  273. const list = sortByDurationDesc(normalizeList(resp));
  274. tableData.value = list.map(mapRow);
  275. total.value = normalizeTotal(resp, list.length);
  276. hasSearched.value = true;
  277. syncAnalysisDataRefreshState(list.length > 0);
  278. const current = Number((resp as any)?.data?.current || pagination.value.page);
  279. const size = Number((resp as any)?.data?.size || pagination.value.limit);
  280. if (Number.isFinite(current) && current > 0) pagination.value.page = current;
  281. if (Number.isFinite(size) && size > 0) pagination.value.limit = size;
  282. jumpPage.value = String(pagination.value.page);
  283. });
  284. };
  285. const handleSearch = async () => {
  286. pagination.value.page = 1;
  287. await fetchFirstLevelTable();
  288. };
  289. const handleReset = async () => {
  290. filters.value = createDefaultFilters();
  291. pagination.value.page = 1;
  292. await fetchFirstLevelTable();
  293. };
  294. const handlePrevPage = async () => {
  295. if (queryLoading.value || pagination.value.page <= 1) return;
  296. pagination.value.page -= 1;
  297. await fetchFirstLevelTable();
  298. };
  299. const handleNextPage = async () => {
  300. if (queryLoading.value || pagination.value.page >= totalPages.value) return;
  301. pagination.value.page += 1;
  302. await fetchFirstLevelTable();
  303. };
  304. const handlePaginationChange = async (page: number, pageSize: number) => {
  305. if (queryLoading.value) return;
  306. if (pageSize !== pagination.value.limit) {
  307. pagination.value.limit = pageSize;
  308. await handlePageSizeChange();
  309. return;
  310. }
  311. if (page === pagination.value.page - 1) {
  312. await handlePrevPage();
  313. return;
  314. }
  315. if (page === pagination.value.page + 1) {
  316. await handleNextPage();
  317. return;
  318. }
  319. if (page === pagination.value.page) return;
  320. jumpPage.value = String(page);
  321. await handleJumpPage();
  322. };
  323. const handlePageSizeChange = async () => {
  324. pagination.value.page = 1;
  325. await fetchFirstLevelTable();
  326. };
  327. const handleJumpPage = async () => {
  328. const next = Number(jumpPage.value);
  329. if (!Number.isInteger(next) || next < 1) {
  330. createMessage.warning('请输入正确页码');
  331. jumpPage.value = String(pagination.value.page);
  332. return;
  333. }
  334. pagination.value.page = Math.min(next, totalPages.value);
  335. await fetchFirstLevelTable();
  336. };
  337. const fetchTargetOptions = async () => {
  338. try {
  339. targetOptions.value = await getPersonOptions(false);
  340. } catch (error) {
  341. targetOptions.value = [];
  342. }
  343. };
  344. const applyRouteQuery = (targetOptions: Array<{ label: string; value: string }>) => {
  345. filters.value = createDefaultFilters();
  346. const personNames = normalizeSelectedTargets(
  347. (route.query.personNames as string | string[] | null | undefined) ??
  348. (route.query.personName as string | string[] | null | undefined),
  349. );
  350. const otherName = String(route.query.otherName || '').trim();
  351. const otherPhone = String(route.query.otherPhone || '').trim();
  352. const routeMonthValue = String(route.query.monthValue ?? route.query.monthVal ?? '').trim();
  353. const hasRouteMonthValue = monthValuePattern.test(routeMonthValue);
  354. filters.value.target = personNames.map((personName) => {
  355. const matched = targetOptions.find((item) => String(item.label).trim() === personName);
  356. return matched ? matched.value : personName;
  357. });
  358. if (hasRouteMonthValue) {
  359. filters.value.monthValue = routeMonthValue;
  360. }
  361. if (otherName) {
  362. filters.value.otherName = otherName;
  363. }
  364. if (otherPhone) {
  365. filters.value.otherPhone = otherPhone;
  366. }
  367. return !!(filters.value.target.length || otherName || otherPhone || hasRouteMonthValue);
  368. };
  369. const syncFromRoute = async () => {
  370. if (route.path !== PAGE_PATH) return;
  371. if (applyRouteQuery(targetOptions.value)) {
  372. pagination.value.page = 1;
  373. await fetchFirstLevelTable();
  374. }
  375. };
  376. onMounted(async () => {
  377. await fetchTargetOptions();
  378. await syncFromRoute();
  379. });
  380. watch(
  381. () => route.fullPath,
  382. async (next, prev) => {
  383. if (next === prev) return;
  384. await syncFromRoute();
  385. },
  386. );
  387. </script>
  388. <style lang="less">
  389. @prefix-cls: ~'jeesite-continuous';
  390. @import '../../../trans/views/styles/trans-analysis-table-ui.less';
  391. .@{prefix-cls}.continuous-page {
  392. .trans-analysis-table-ui();
  393. background: #fff;
  394. padding: 0 8px 2px;
  395. min-height: 100%;
  396. height: 100%;
  397. display: flex;
  398. flex-direction: column;
  399. overflow: hidden;
  400. box-sizing: border-box;
  401. width: calc(100% + 24px);
  402. margin: 0 -12px;
  403. padding-left: 0;
  404. padding-right: 0;
  405. .filter-input {
  406. width: 160px;
  407. }
  408. .filter-date {
  409. width: 360px;
  410. }
  411. .filter-bar {
  412. display: flex;
  413. align-items: center;
  414. gap: 8px;
  415. padding: 6px;
  416. min-height: 40px;
  417. border: 0;
  418. background: transparent;
  419. flex-wrap: wrap;
  420. flex-shrink: 0;
  421. box-sizing: border-box;
  422. }
  423. .filter-item {
  424. display: flex;
  425. align-items: center;
  426. gap: 4px;
  427. }
  428. .filter-label {
  429. color: #6b7280;
  430. font-size: 12px;
  431. white-space: nowrap;
  432. }
  433. .filter-actions {
  434. display: flex;
  435. align-items: center;
  436. gap: 8px;
  437. margin-left: auto;
  438. }
  439. .filter-input,
  440. .filter-date,
  441. .filter-actions :deep(.ant-btn) {
  442. align-self: center;
  443. }
  444. .panel-title-wrap {
  445. display: flex;
  446. flex-direction: column;
  447. gap: 4px;
  448. min-width: 0;
  449. }
  450. .panel-title {
  451. font-size: 14px;
  452. font-weight: 600;
  453. color: #111827;
  454. line-height: 22px;
  455. }
  456. .panel-desc {
  457. color: #6b7280;
  458. font-size: 12px;
  459. line-height: 20px;
  460. }
  461. .content-panel {
  462. display: flex;
  463. flex: 1 1 auto;
  464. min-height: 0;
  465. padding: 2px;
  466. background: #edf2f7;
  467. box-sizing: border-box;
  468. overflow: hidden;
  469. }
  470. .table-card {
  471. flex: 1 1 auto;
  472. min-height: 0;
  473. display: flex;
  474. flex-direction: column;
  475. overflow: hidden;
  476. padding: 8px;
  477. border: 0;
  478. border-radius: 12px;
  479. background: #fff;
  480. box-shadow: inset 0 0 0 1px #e2e8f0;
  481. box-sizing: border-box;
  482. }
  483. .panel-header {
  484. flex: 0 0 auto;
  485. padding: 0 0 8px;
  486. width: 100%;
  487. box-sizing: border-box;
  488. border-bottom: 1px solid #f1f5f9;
  489. }
  490. .table-panel {
  491. flex: 1 1 auto;
  492. min-height: 0;
  493. display: flex;
  494. flex-direction: column;
  495. overflow: hidden;
  496. padding: 0;
  497. }
  498. .query-state-panel {
  499. flex: 1 1 auto;
  500. min-height: 0;
  501. display: flex;
  502. align-items: center;
  503. justify-content: center;
  504. padding: 12px 0 0;
  505. }
  506. .table-wrapper {
  507. flex: 1 1 auto;
  508. min-height: 0;
  509. display: flex;
  510. flex-direction: column;
  511. overflow: hidden;
  512. }
  513. .table-wrapper .jeesite-basic-table {
  514. height: 100%;
  515. min-height: 0;
  516. display: flex;
  517. flex-direction: column;
  518. }
  519. .table-wrapper > .ant-table-wrapper,
  520. .table-wrapper .ant-spin-nested-loading,
  521. .table-wrapper .ant-spin-container,
  522. .table-wrapper .ant-table,
  523. .table-wrapper .ant-table-container {
  524. flex: 1 1 auto;
  525. min-height: 0;
  526. height: 100%;
  527. }
  528. .table-wrapper .ant-spin-container,
  529. .table-wrapper .ant-table,
  530. .table-wrapper .ant-table-container {
  531. display: flex;
  532. flex-direction: column;
  533. }
  534. .table-wrapper .ant-table-body {
  535. max-height: 100% !important;
  536. }
  537. .pagination-bar {
  538. display: flex;
  539. align-items: center;
  540. justify-content: flex-end;
  541. gap: 8px;
  542. flex: 0 0 auto;
  543. flex-wrap: wrap;
  544. padding: 8px 0 0;
  545. width: 100%;
  546. box-sizing: border-box;
  547. border-top: 1px solid #f1f5f9;
  548. }
  549. .pagination-total {
  550. margin-right: 0;
  551. color: #4b5563;
  552. }
  553. .pagination-size {
  554. :deep(.ant-select) {
  555. width: 88px;
  556. }
  557. }
  558. .pagination-input {
  559. width: 56px;
  560. }
  561. @media screen and (max-width: 992px) {
  562. .filter-actions {
  563. width: 100%;
  564. margin-left: 0;
  565. }
  566. .filter-input,
  567. .filter-date {
  568. width: 100%;
  569. }
  570. }
  571. }
  572. </style>