VaultodyList.vue 12 KB

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