GlobalList.vue 14 KB

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