GlobalList.vue 14 KB

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