GlobalList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <cwg-load-more-wrapper ref="loadMoreWrapperRef" :loading="loading" :finished="finished" :height='108'
  3. :refresher-enabled="true" @reach-bottom="loadMore" @refresh="handleRefresh">
  4. <view v-if="filteredRecords.length > 0" class="records-list">
  5. <view v-for="record in filteredRecords" :key="record.id" class="record-card"
  6. @click="goToDeductionDetail(record)">
  7. <view class="record-main">
  8. <view class="record-left">
  9. <view class="type-icon deduction-icon">
  10. <cwg-icon class="icons" :name="getDeductionIcon(record.type || record.typeStr)" :size="20"
  11. color="#ef4444" />
  12. </view>
  13. <view class="record-info">
  14. <view class="info-header">
  15. <text class="record-type">{{ t('global.title1')}}</text>
  16. <view :class="['status-badge', getStatusBadgeClass(record.status)]">
  17. <cwg-icon class="icons" :name="getStatusIcon(record.status)" :size="12"
  18. :color="getStatusColor(record.status)" />
  19. <text :class="['status-text', getStatusTextClass(record.status)]">
  20. {{ getStatusText(record.status) }}
  21. </text>
  22. </view>
  23. </view>
  24. <text class="record-detail" v-if="record.deductionAccountType == 1">{{ record.cardNumber || '--' }}</text>
  25. <text class="record-detail" v-if="record.deductionAccountType == 2">{{ t('global.GlobalOrder.bagBal') }}</text>
  26. </view>
  27. </view>
  28. <view class="record-right">
  29. <text class="amount-deduction">{{ Math.abs(Number(record.deductionAmount || 0)).toFixed(2) }}
  30. {{
  31. record.sendCurrency
  32. || 'USD' }}</text>
  33. <text class="fee-text">{{ t('card.Form.f30') }} {{ Number(record.deductionFee || 0).toFixed(2)
  34. }}</text>
  35. </view>
  36. </view>
  37. <view class="record-footer">
  38. <text class="footer-time">{{ formatDateTime(record.addTime || record.time) }}</text>
  39. <view class="footer-actions">
  40. <text class="footer-order">
  41. {{ t('card.Form.f35') }}: {{ formatOrderNo(record.merchantOrderNo) }}
  42. </text>
  43. <cwg-icon class="footer-order-icon" name="copy" :size="14" color="#9ca3af"
  44. @click.stop="copyOrderNo(record.merchantOrderNo)" />
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <cwg-empty-state v-else :text="t('empty-state.c2')" />
  50. </cwg-load-more-wrapper>
  51. </template>
  52. <script setup lang="ts">
  53. import { ref, computed, watch, onMounted } from 'vue';
  54. import dayjs from 'dayjs';
  55. import { useI18n } from 'vue-i18n';
  56. import { showToast } from '@/utils/toast';
  57. import { ucardApi, TransactionInfo } from '@/api/ucard';
  58. import { transactionStatusMap, WITHDRAW_TYPE_MAP } from '@/utils/dataMap';
  59. import useCardStore from '@/stores/use-card-store';
  60. interface RecordItem extends TransactionInfo {
  61. type?: string | number;
  62. typeStr?: string;
  63. remark?: string;
  64. status?: string | number;
  65. addTime?: string | number;
  66. fee?: number;
  67. currency?: string;
  68. merchantOrderNo?: string;
  69. reason?: string;
  70. time?: string | number;
  71. }
  72. type NormalizedStatus = 'success' | 'processing' | 'failed';
  73. const props = defineProps<{
  74. cardNo: string;
  75. typeIndex: number;
  76. statusIndex: number;
  77. dateFilter: string;
  78. typeOptions: string[];
  79. }>();
  80. const { t } = useI18n();
  81. const records = ref<RecordItem[]>([]);
  82. const page = ref(1);
  83. const pageSize = 10;
  84. const loading = ref(false);
  85. const finished = ref(false);
  86. const cardStore = useCardStore();
  87. const normalizeStatus = (status?: string | number): NormalizedStatus => {
  88. if (!status) return 'success';
  89. const statusStr = String(status).toLowerCase();
  90. if (statusStr === 'processing' || statusStr === 'wait_process') return 'processing';
  91. if (statusStr === 'fail' || statusStr === 'failed') return 'failed';
  92. if (statusStr === 'succeed' || statusStr === 'success') return 'success';
  93. return 'success';
  94. };
  95. const getStatusText = (status?: string | number): string => {
  96. if (!status) return '';
  97. const statusKey = String(status).toLowerCase();
  98. if (transactionStatusMap[statusKey as keyof typeof transactionStatusMap]) {
  99. return t(transactionStatusMap[statusKey as keyof typeof transactionStatusMap]);
  100. }
  101. const normalized = normalizeStatus(status);
  102. if (normalized === 'success') return t('card.Status.t1');
  103. if (normalized === 'processing') return t('card.Status.t3');
  104. return t('card.Status.t2');
  105. };
  106. const getStatusIcon = (status?: string | number): string => {
  107. const normalized = normalizeStatus(status);
  108. if (normalized === 'success') return 'checkmarkempty1';
  109. if (normalized === 'processing') return 'info1';
  110. return 'closeempty1';
  111. };
  112. const getStatusColor = (status?: string | number): string => {
  113. const normalized = normalizeStatus(status);
  114. if (normalized === 'success') return '#22c55e';
  115. if (normalized === 'processing') return '#eab308';
  116. return '#ef4444';
  117. };
  118. const getStatusBadgeClass = (status?: string | number) => `status-${normalizeStatus(status)}`;
  119. const getStatusTextClass = (status?: string | number) => `status-text-${normalizeStatus(status)}`;
  120. const getStatusValue = (index: number): NormalizedStatus | null => {
  121. if (index === 0) return null;
  122. const statusMap: NormalizedStatus[] = ['success', 'processing', 'failed'];
  123. return statusMap[index - 1];
  124. };
  125. const getDeductionTypeText = (type?: string | number): string => {
  126. if (!type) return '--';
  127. const typeNum = typeof type === 'string' ? parseInt(type) : type;
  128. if (WITHDRAW_TYPE_MAP[typeNum as keyof typeof WITHDRAW_TYPE_MAP]) {
  129. return t(WITHDRAW_TYPE_MAP[typeNum as keyof typeof WITHDRAW_TYPE_MAP]);
  130. }
  131. return String(type);
  132. };
  133. const getDeductionIcon = (type?: string | number): string => {
  134. const typeStr = String(type || '');
  135. if (typeStr.includes('服务费') || typeStr === '1') return 'servicefee';
  136. if (typeStr.includes('手续费') || typeStr === '2') return 'handlingfee';
  137. return 'handlingfee';
  138. };
  139. const formatDateTime = (time?: string | number): string => {
  140. if (!time) return '--';
  141. try {
  142. let date: dayjs.Dayjs;
  143. if (typeof time === 'number') {
  144. if (time.toString().length === 10) {
  145. date = dayjs.unix(time);
  146. } else {
  147. date = dayjs(time);
  148. }
  149. } else {
  150. date = dayjs(time);
  151. }
  152. if (!date.isValid()) return '--';
  153. return date.format('YYYY-MM-DD HH:mm:ss');
  154. } catch (error) {
  155. return '--';
  156. }
  157. };
  158. const getDatePart = (time?: string | number): string => {
  159. if (!time) return '';
  160. try {
  161. let date: dayjs.Dayjs;
  162. if (typeof time === 'number') {
  163. if (time.toString().length === 10) {
  164. date = dayjs.unix(time);
  165. } else {
  166. date = dayjs(time);
  167. }
  168. } else {
  169. date = dayjs(time);
  170. }
  171. if (!date.isValid()) return '';
  172. return date.format('YYYY-MM-DD');
  173. } catch (error) {
  174. return '';
  175. }
  176. };
  177. const formatOrderNo = (orderNo?: string) => {
  178. if (!orderNo) return '--';
  179. if (orderNo.length <= 20) return orderNo;
  180. return orderNo.slice(0, 6) + '...' + orderNo.slice(-4);
  181. };
  182. const copyOrderNo = (orderNo?: string) => {
  183. if (!orderNo) return;
  184. uni.setClipboardData({
  185. data: orderNo,
  186. success: () => {
  187. uni.showToast({
  188. title: t('card.Msg.m8') || '复制成功',
  189. icon: 'success'
  190. });
  191. }
  192. });
  193. };
  194. const fetchRecords = async (isLoadMore = false) => {
  195. // if (!props.cardNo || loading.value) return;
  196. if (isLoadMore && finished.value) return;
  197. loading.value = true;
  198. try {
  199. const res = await ucardApi.globalOrdersList({
  200. cardNo: props.cardNo,
  201. beginDate: props.dateFilter ? dayjs(props.dateFilter).format('YYYY-MM-DD') : undefined,
  202. endDate: props.dateFilter ? dayjs(props.dateFilter).format('YYYY-MM-DD') : undefined,
  203. page: { current: page.value, row: pageSize },
  204. });
  205. const data = res.code === 200 && Array.isArray(res.data) ? res.data : [];
  206. if (isLoadMore) {
  207. records.value.push(...data);
  208. } else {
  209. records.value = data;
  210. }
  211. if (data.length < pageSize) {
  212. finished.value = true;
  213. } else {
  214. finished.value = false;
  215. }
  216. } catch (error: any) {
  217. if (!isLoadMore) {
  218. records.value = [];
  219. }
  220. showToast(error?.message || String(error));
  221. } finally {
  222. loading.value = false;
  223. }
  224. };
  225. const goToDeductionDetail = (record: RecordItem) => {
  226. const amount = Number(record.amount || 0);
  227. const fee = Number(record.fee || 0);
  228. const normalizedStatus = normalizeStatus(record.status);
  229. const detailPayload = {
  230. category: 'deduction' as const,
  231. type: getDeductionTypeText(record.type || record.typeStr),
  232. amount,
  233. fee,
  234. actualAmount: amount - fee,
  235. currency: record.currency || 'USD',
  236. orderStatus: normalizedStatus,
  237. statusMessage: getStatusText(record.status),
  238. createTime: formatDateTime(record.transactionTime),
  239. completeTime: '',
  240. merchant: '',
  241. bankCard: '',
  242. bankCard: record.cardNumber,
  243. remark: record.remark || record.reason || '',
  244. approvalSteps: [] as any[]
  245. };
  246. cardStore.saveOrderDetail(detailPayload);
  247. uni.navigateTo({
  248. url: '/pages/recharge-record/detail'
  249. });
  250. };
  251. const loadMore = () => {
  252. if (finished.value || loading.value) return;
  253. page.value++;
  254. fetchRecords(true);
  255. };
  256. const filteredRecords = computed(() => {
  257. return records.value.filter(record => {
  258. const type = record.typeStr || record.type;
  259. if (props.typeIndex > 0 && type !== props.typeOptions[props.typeIndex]) {
  260. return false;
  261. }
  262. const statusValue = getStatusValue(props.statusIndex);
  263. if (statusValue && normalizeStatus(record.status) !== statusValue) {
  264. return false;
  265. }
  266. if (props.dateFilter) {
  267. const time = record.addTime || record.time;
  268. const datePart = getDatePart(time);
  269. if (!datePart || datePart !== props.dateFilter) {
  270. return false;
  271. }
  272. }
  273. return true;
  274. });
  275. });
  276. watch([() => props.dateFilter], () => {
  277. page.value = 1;
  278. finished.value = false;
  279. fetchRecords();
  280. }, { immediate: false });
  281. const loadMoreWrapperRef = ref<any>(null);
  282. const refresh = async () => {
  283. page.value = 1;
  284. finished.value = false;
  285. await fetchRecords();
  286. };
  287. const handleRefresh = async () => {
  288. await refresh();
  289. // 停止下拉刷新动画
  290. if (loadMoreWrapperRef.value) {
  291. loadMoreWrapperRef.value.stopRefresh();
  292. }
  293. };
  294. onMounted(() => {
  295. fetchRecords();
  296. });
  297. defineExpose({
  298. refresh
  299. });
  300. </script>
  301. <style scoped lang="scss">
  302. @import "@/uni.scss";
  303. .records-list {
  304. display: flex;
  305. flex-direction: column;
  306. gap: px2rpx(12);
  307. padding: px2rpx(16);
  308. }
  309. .record-card {
  310. background-color: #ffffff;
  311. border-radius: px2rpx(12);
  312. border: 1px solid #e5e7eb;
  313. overflow: hidden;
  314. transition: box-shadow 0.3s;
  315. padding: px2rpx(16);
  316. }
  317. .record-card:active {
  318. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  319. }
  320. .record-main {
  321. display: flex;
  322. align-items: flex-start;
  323. justify-content: space-between;
  324. padding-bottom: px2rpx(16);
  325. }
  326. .record-left {
  327. display: flex;
  328. align-items: flex-start;
  329. gap: px2rpx(12);
  330. flex: 1;
  331. min-width: 0;
  332. }
  333. .type-icon {
  334. width: px2rpx(40);
  335. height: px2rpx(40);
  336. border-radius: px2rpx(10);
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. flex-shrink: 0;
  341. }
  342. .deduction-icon {
  343. background-color: #fef2f2;
  344. }
  345. .icons {
  346. width: px2rpx(20);
  347. height: px2rpx(20);
  348. }
  349. .record-info {
  350. flex: 1;
  351. min-width: 0;
  352. display: flex;
  353. flex-direction: column;
  354. gap: px2rpx(6);
  355. }
  356. .info-header {
  357. display: flex;
  358. align-items: center;
  359. gap: px2rpx(8);
  360. flex-wrap: wrap;
  361. }
  362. .record-type {
  363. font-size: px2rpx(15);
  364. color: #111827;
  365. }
  366. .status-badge {
  367. display: flex;
  368. align-items: center;
  369. gap: px2rpx(4);
  370. padding: px2rpx(3) px2rpx(2);
  371. border-radius: px2rpx(12);
  372. }
  373. .status-success {
  374. background-color: #f0fdf4;
  375. }
  376. .status-processing {
  377. background-color: #fefce8;
  378. }
  379. .status-failed {
  380. background-color: #fef2f2;
  381. }
  382. .status-text {
  383. font-size: px2rpx(11);
  384. }
  385. .status-text-success {
  386. color: #22c55e;
  387. }
  388. .status-text-processing {
  389. color: #eab308;
  390. }
  391. .status-text-failed {
  392. color: #ef4444;
  393. }
  394. .record-detail {
  395. font-size: px2rpx(13);
  396. color: #6b7280;
  397. overflow: hidden;
  398. text-overflow: ellipsis;
  399. white-space: nowrap;
  400. }
  401. .record-right {
  402. display: flex;
  403. flex-direction: column;
  404. align-items: flex-end;
  405. gap: px2rpx(4);
  406. margin-left: px2rpx(12);
  407. flex-shrink: 0;
  408. }
  409. .amount-deduction {
  410. font-size: px2rpx(18);
  411. color: #ef4444;
  412. }
  413. .fee-text {
  414. font-size: px2rpx(11);
  415. color: #9ca3af;
  416. }
  417. .record-footer {
  418. display: flex;
  419. align-items: center;
  420. justify-content: space-between;
  421. padding-top: px2rpx(16);
  422. border-top: 1px solid #f3f4f6;
  423. }
  424. .footer-time {
  425. font-size: px2rpx(11);
  426. color: #9ca3af;
  427. }
  428. .footer-actions {
  429. display: flex;
  430. align-items: center;
  431. gap: px2rpx(2);
  432. }
  433. .footer-detail {
  434. font-size: px2rpx(11);
  435. color: #2563eb;
  436. }
  437. </style>