DeductionList.vue 11 KB

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