WithdrawList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 :text="t('empty-state.c2')" />
  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. cardNo: 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 <= 20) 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. cardNo: props.cardNo,
  181. payoutCurrency: props.payoutCurrency,
  182. transactionStatus: props.statusIndex == 0 ? undefined : props.statusIndex,
  183. beginDate: props.dateFilter ? dayjs(props.dateFilter).format('YYYY-MM-DD') : undefined,
  184. endDate: props.dateFilter ? dayjs(props.dateFilter).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. console.log(records.value, 1112212);
  194. if (data.length < pageSize) {
  195. finished.value = true;
  196. } else {
  197. finished.value = false;
  198. }
  199. } catch (error: any) {
  200. console.log(error, 11111);
  201. if (!isLoadMore) {
  202. records.value = [];
  203. }
  204. showToast(error?.message || String(error));
  205. } finally {
  206. loading.value = false;
  207. }
  208. };
  209. const goToDeductionDetail = (record: RecordItem) => {
  210. cardStore.saveOrderDetail(record);
  211. router.push({
  212. path: '/pages/wallet/withdraw-detail',
  213. query: { id: record.id }
  214. });
  215. };
  216. const loadMore = () => {
  217. if (finished.value || loading.value) return;
  218. page.value++;
  219. fetchRecords(true);
  220. };
  221. watch([() => props.dateFilter], () => {
  222. page.value = 1;
  223. finished.value = false;
  224. fetchRecords();
  225. }, { immediate: false });
  226. watch([() => props.payoutCurrency], () => {
  227. page.value = 1;
  228. finished.value = false;
  229. fetchRecords();
  230. }, { immediate: false });
  231. watch([() => props.statusIndex], () => {
  232. page.value = 1;
  233. finished.value = false;
  234. fetchRecords();
  235. }, { immediate: false });
  236. const loadMoreWrapperRef = ref<any>(null);
  237. const refresh = async () => {
  238. page.value = 1;
  239. finished.value = false;
  240. await fetchRecords();
  241. };
  242. const handleRefresh = async () => {
  243. await refresh();
  244. // 停止下拉刷新动画
  245. if (loadMoreWrapperRef.value) {
  246. loadMoreWrapperRef.value.stopRefresh();
  247. }
  248. };
  249. onMounted(() => {
  250. fetchRecords();
  251. });
  252. defineExpose({
  253. refresh
  254. });
  255. </script>
  256. <style scoped lang="scss">
  257. @import "@/uni.scss";
  258. .records-list {
  259. display: flex;
  260. flex-direction: column;
  261. gap: px2rpx(12);
  262. padding: px2rpx(16);
  263. }
  264. .record-card {
  265. background-color: #ffffff;
  266. border-radius: px2rpx(12);
  267. border: 1px solid #e5e7eb;
  268. overflow: hidden;
  269. transition: box-shadow 0.3s;
  270. padding: px2rpx(16);
  271. position: relative;
  272. }
  273. .record-card:active {
  274. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  275. }
  276. .record-main {
  277. display: flex;
  278. align-items: flex-start;
  279. justify-content: space-between;
  280. padding-bottom: px2rpx(16);
  281. }
  282. .record-left {
  283. display: flex;
  284. align-items: flex-start;
  285. gap: px2rpx(12);
  286. min-width: 0;
  287. }
  288. .type-icon {
  289. width: px2rpx(40);
  290. height: px2rpx(40);
  291. border-radius: px2rpx(10);
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. flex-shrink: 0;
  296. }
  297. .deduction-icon {
  298. background-color: #fef2f2;
  299. }
  300. .icons {
  301. width: px2rpx(20);
  302. height: px2rpx(20);
  303. }
  304. .record-info {
  305. flex: 1;
  306. min-width: 0;
  307. display: flex;
  308. flex-direction: column;
  309. gap: px2rpx(6);
  310. }
  311. .info-header {
  312. display: flex;
  313. align-items: center;
  314. gap: px2rpx(4);
  315. flex-wrap: wrap;
  316. }
  317. .record-type {
  318. font-size: px2rpx(15);
  319. color: #111827;
  320. }
  321. .status-badge {
  322. display: flex;
  323. align-items: center;
  324. gap: px2rpx(4);
  325. padding: px2rpx(3) px2rpx(8) px2rpx(3) px2rpx(3);
  326. border-radius: px2rpx(12);
  327. position: absolute;
  328. top: px2rpx(1);
  329. right: px2rpx(1);
  330. }
  331. .status-success {
  332. background-color: #f0fdf4;
  333. }
  334. .status-wait_process {
  335. background-color: #fefce8;
  336. }
  337. .status-fail {
  338. background-color: #fef2f2;
  339. }
  340. .status-text {
  341. font-size: px2rpx(11);
  342. }
  343. .status-text-success {
  344. color: #22c55e;
  345. }
  346. .status-text-wait_process {
  347. color: #eab308;
  348. }
  349. .status-text-fail {
  350. color: #ef4444;
  351. }
  352. .record-detail {
  353. font-size: px2rpx(13);
  354. color: #6b7280;
  355. overflow: hidden;
  356. text-overflow: ellipsis;
  357. white-space: nowrap;
  358. }
  359. .record-right {
  360. flex: 1;
  361. display: flex;
  362. flex-direction: column;
  363. align-items: flex-start;
  364. gap: px2rpx(4);
  365. margin-left: px2rpx(12);
  366. flex-shrink: 0;
  367. .row {
  368. width: 100%;
  369. display: flex;
  370. align-items: center;
  371. justify-content: space-around;
  372. }
  373. .l {
  374. flex: 1;
  375. }
  376. .r {
  377. display: flex;
  378. flex-direction: column;
  379. align-items: flex-start;
  380. gap: px2rpx(4);
  381. margin-left: px2rpx(12);
  382. flex-shrink: 0;
  383. }
  384. }
  385. .amount-deduction {
  386. font-size: px2rpx(18);
  387. color: #ef4444;
  388. }
  389. .fee-text {
  390. font-size: px2rpx(11);
  391. color: #9ca3af;
  392. }
  393. .record-footer {
  394. display: flex;
  395. align-items: center;
  396. justify-content: space-between;
  397. padding-top: px2rpx(16);
  398. border-top: 1px solid #f3f4f6;
  399. }
  400. .footer-time {
  401. font-size: px2rpx(11);
  402. color: #9ca3af;
  403. }
  404. .footer-actions {
  405. display: flex;
  406. align-items: center;
  407. gap: px2rpx(2);
  408. }
  409. .footer-detail {
  410. font-size: px2rpx(11);
  411. color: #2563eb;
  412. }
  413. </style>