RechargeList.vue 12 KB

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