RechargeList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. cardNo: 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.cardNo || loading.value) return;
  181. if (isLoadMore && finished.value) return;
  182. loading.value = true;
  183. try {
  184. const res = await ucardApi.rechargeList({
  185. cardNo: props.cardNo,
  186. rechargeType: props.typeIndex || undefined,
  187. status: props.statusIndex || undefined,
  188. startDate: props.dateFilter ? dayjs(props.dateFilter).format('YYYY-MM-DD') : undefined,
  189. endDate: props.dateFilter ? dayjs(props.dateFilter).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) 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. const loadMoreWrapperRef = ref<any>(null);
  260. const refresh = async () => {
  261. page.value = 1;
  262. finished.value = false;
  263. await fetchRecords();
  264. };
  265. const handleRefresh = async () => {
  266. await refresh();
  267. // 停止下拉刷新动画
  268. if (loadMoreWrapperRef.value) {
  269. loadMoreWrapperRef.value.stopRefresh();
  270. }
  271. };
  272. onMounted(() => {
  273. fetchRecords();
  274. });
  275. defineExpose({
  276. refresh
  277. });
  278. </script>
  279. <style scoped lang="scss">
  280. @import "@/uni.scss";
  281. .records-list {
  282. display: flex;
  283. flex-direction: column;
  284. gap: px2rpx(12);
  285. padding: px2rpx(16);
  286. }
  287. .records-list1 {
  288. gap: px2rpx(12);
  289. padding: px2rpx(16) 0;
  290. }
  291. .record-card {
  292. background-color: #ffffff;
  293. border-radius: px2rpx(12);
  294. border: 1px solid #e5e7eb;
  295. overflow: hidden;
  296. transition: box-shadow 0.3s;
  297. padding: px2rpx(16);
  298. }
  299. .record-card:active {
  300. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  301. }
  302. .record-main {
  303. display: flex;
  304. align-items: flex-start;
  305. justify-content: space-between;
  306. padding-bottom: px2rpx(16);
  307. }
  308. .record-left {
  309. display: flex;
  310. align-items: flex-start;
  311. gap: px2rpx(12);
  312. flex: 1;
  313. min-width: 0;
  314. }
  315. .type-icon {
  316. width: px2rpx(40);
  317. height: px2rpx(40);
  318. border-radius: px2rpx(10);
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. flex-shrink: 0;
  323. }
  324. .recharge-icon {
  325. background-color: #f0fdf4;
  326. }
  327. .icons {
  328. width: px2rpx(20);
  329. height: px2rpx(20);
  330. }
  331. .record-info {
  332. flex: 1;
  333. min-width: 0;
  334. display: flex;
  335. flex-direction: column;
  336. gap: px2rpx(6);
  337. }
  338. .info-header {
  339. display: flex;
  340. align-items: center;
  341. gap: px2rpx(8);
  342. flex-wrap: wrap;
  343. }
  344. .record-type {
  345. font-size: px2rpx(15);
  346. color: #111827;
  347. }
  348. .status-success {
  349. background-color: #f0fdf4;
  350. }
  351. .status-processing {
  352. background-color: #fefce8;
  353. }
  354. .status-failed {
  355. background-color: #fef2f2;
  356. }
  357. .status-text {
  358. font-size: px2rpx(11);
  359. }
  360. .status-text-success {
  361. color: #22c55e;
  362. }
  363. .status-text-processing {
  364. color: #eab308;
  365. }
  366. .status-text-failed {
  367. color: #ef4444;
  368. }
  369. .record-detail {
  370. font-size: px2rpx(13);
  371. color: #6b7280;
  372. overflow: hidden;
  373. text-overflow: ellipsis;
  374. white-space: nowrap;
  375. }
  376. .record-right {
  377. display: flex;
  378. flex-direction: column;
  379. align-items: flex-end;
  380. gap: px2rpx(4);
  381. margin-left: px2rpx(12);
  382. flex-shrink: 0;
  383. }
  384. .amount-recharge {
  385. font-size: px2rpx(18);
  386. color: #22c55e;
  387. }
  388. .fee-text {
  389. font-size: px2rpx(11);
  390. color: #9ca3af;
  391. }
  392. .record-footer {
  393. display: flex;
  394. align-items: center;
  395. justify-content: space-between;
  396. padding-top: px2rpx(16);
  397. border-top: 1px solid #f3f4f6;
  398. }
  399. .footer-actions {
  400. display: flex;
  401. align-items: center;
  402. gap: px2rpx(8);
  403. }
  404. .footer-time {
  405. font-size: px2rpx(11);
  406. color: #9ca3af;
  407. }
  408. .footer-actions {
  409. display: flex;
  410. align-items: center;
  411. gap: px2rpx(2);
  412. }
  413. .footer-order {
  414. font-size: px2rpx(11);
  415. color: #9ca3af;
  416. }
  417. .footer-detail {
  418. font-size: px2rpx(11);
  419. color: #2563eb;
  420. }
  421. </style>