WithdrawList.vue 12 KB

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