DeductionList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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="filteredRecords.length > 0" class="records-list">
  5. <view v-for="record in filteredRecords" :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 :text="t('empty-state.c2')" />
  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. cardNo: 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 getStatusValue = (index: number): NormalizedStatus | null => {
  109. if (index === 0) return null;
  110. const statusMap: NormalizedStatus[] = ['success', 'processing', 'failed'];
  111. return statusMap[index - 1];
  112. };
  113. const getDeductionTypeText = (type?: string | number): string => {
  114. if (!type) return '--';
  115. const typeNum = typeof type === 'string' ? parseInt(type) : type;
  116. if (WITHDRAW_TYPE_MAP[typeNum as keyof typeof WITHDRAW_TYPE_MAP]) {
  117. return t(WITHDRAW_TYPE_MAP[typeNum as keyof typeof WITHDRAW_TYPE_MAP]);
  118. }
  119. return String(type);
  120. };
  121. const getDeductionIcon = (type?: string | number): string => {
  122. const typeStr = String(type || '');
  123. if (typeStr.includes('服务费') || typeStr === '1') return 'servicefee';
  124. if (typeStr.includes('手续费') || typeStr === '2') return 'handlingfee';
  125. return 'servicefee';
  126. };
  127. const formatDateTime = (time?: string | number): string => {
  128. if (!time) return '--';
  129. try {
  130. let date: dayjs.Dayjs;
  131. if (typeof time === 'number') {
  132. if (time.toString().length === 10) {
  133. date = dayjs.unix(time);
  134. } else {
  135. date = dayjs(time);
  136. }
  137. } else {
  138. date = dayjs(time);
  139. }
  140. if (!date.isValid()) return '--';
  141. return date.format('YYYY-MM-DD HH:mm:ss');
  142. } catch (error) {
  143. return '--';
  144. }
  145. };
  146. const getDatePart = (time?: string | number): string => {
  147. if (!time) return '';
  148. try {
  149. let date: dayjs.Dayjs;
  150. if (typeof time === 'number') {
  151. if (time.toString().length === 10) {
  152. date = dayjs.unix(time);
  153. } else {
  154. date = dayjs(time);
  155. }
  156. } else {
  157. date = dayjs(time);
  158. }
  159. if (!date.isValid()) return '';
  160. return date.format('YYYY-MM-DD');
  161. } catch (error) {
  162. return '';
  163. }
  164. };
  165. const formatOrderNo = (orderNo?: string) => {
  166. if (!orderNo) return '--';
  167. if (orderNo.length <= 20) return orderNo;
  168. return orderNo.slice(0, 6) + '...' + orderNo.slice(-4);
  169. };
  170. const copyOrderNo = (orderNo?: string) => {
  171. if (!orderNo) return;
  172. uni.setClipboardData({
  173. data: orderNo,
  174. success: () => {
  175. uni.showToast({
  176. title: t('card.Msg.m8') || '复制成功',
  177. icon: 'success'
  178. });
  179. }
  180. });
  181. };
  182. const fetchRecords = async (isLoadMore = false) => {
  183. if (!props.cardNo || loading.value) return;
  184. if (isLoadMore && finished.value) return;
  185. loading.value = true;
  186. try {
  187. const res = await ucardApi.getCardWithdrawPage({
  188. cardNo: props.cardNo,
  189. beginDate: props.dateFilter ? dayjs(props.dateFilter).format('YYYY-MM-DD') : undefined,
  190. endDate: props.dateFilter ? dayjs(props.dateFilter).format('YYYY-MM-DD') : undefined,
  191. page: { current: page.value, row: pageSize },
  192. });
  193. const data = res.code === 200 && Array.isArray(res.data) ? res.data : [];
  194. if (isLoadMore) {
  195. records.value.push(...data);
  196. } else {
  197. records.value = data;
  198. }
  199. if (data.length < pageSize) {
  200. finished.value = true;
  201. } else {
  202. finished.value = false;
  203. }
  204. } catch (error: any) {
  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. const amount = Number(record.amount || 0);
  215. const fee = Number(record.fee || 0);
  216. const normalizedStatus = normalizeStatus(record.status);
  217. const detailPayload = {
  218. category: 'deduction' as const,
  219. type: getDeductionTypeText(record.type || record.typeStr),
  220. amount,
  221. fee,
  222. actualAmount: amount - fee,
  223. currency: record.currency || 'USD',
  224. orderStatus: normalizedStatus,
  225. statusMessage: getStatusText(record.status),
  226. createTime: formatDateTime(record.transactionTime),
  227. completeTime: '',
  228. merchant: '',
  229. bankCard: '',
  230. bankCard: record.cardNumber,
  231. remark: record.remark || record.reason || '',
  232. approvalSteps: [] as any[]
  233. };
  234. cardStore.saveOrderDetail(detailPayload);
  235. uni.navigateTo({
  236. url: '/pages/recharge-record/detail'
  237. });
  238. };
  239. const loadMore = () => {
  240. if (finished.value || loading.value) return;
  241. page.value++;
  242. fetchRecords(true);
  243. };
  244. const filteredRecords = computed(() => {
  245. return records.value.filter(record => {
  246. const type = record.typeStr || record.type;
  247. if (props.typeIndex > 0 && type !== props.typeOptions[props.typeIndex]) {
  248. return false;
  249. }
  250. const statusValue = getStatusValue(props.statusIndex);
  251. if (statusValue && normalizeStatus(record.status) !== statusValue) {
  252. return false;
  253. }
  254. if (props.dateFilter) {
  255. const time = record.addTime || record.time;
  256. const datePart = getDatePart(time);
  257. if (!datePart || datePart !== props.dateFilter) {
  258. return false;
  259. }
  260. }
  261. return true;
  262. });
  263. });
  264. watch([() => props.dateFilter], () => {
  265. page.value = 1;
  266. finished.value = false;
  267. fetchRecords();
  268. }, { immediate: false });
  269. const loadMoreWrapperRef = ref<any>(null);
  270. const refresh = async () => {
  271. page.value = 1;
  272. finished.value = false;
  273. await fetchRecords();
  274. };
  275. const handleRefresh = async () => {
  276. await refresh();
  277. // 停止下拉刷新动画
  278. if (loadMoreWrapperRef.value) {
  279. loadMoreWrapperRef.value.stopRefresh();
  280. }
  281. };
  282. onMounted(() => {
  283. fetchRecords();
  284. });
  285. defineExpose({
  286. refresh
  287. });
  288. </script>
  289. <style scoped lang="scss">
  290. @import "@/uni.scss";
  291. .records-list {
  292. display: flex;
  293. flex-direction: column;
  294. gap: px2rpx(12);
  295. padding: px2rpx(16);
  296. }
  297. .record-card {
  298. background-color: #ffffff;
  299. border-radius: px2rpx(12);
  300. border: 1px solid #e5e7eb;
  301. overflow: hidden;
  302. transition: box-shadow 0.3s;
  303. padding: px2rpx(16);
  304. }
  305. .record-card:active {
  306. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  307. }
  308. .record-main {
  309. display: flex;
  310. align-items: flex-start;
  311. justify-content: space-between;
  312. padding-bottom: px2rpx(16);
  313. }
  314. .record-left {
  315. display: flex;
  316. align-items: flex-start;
  317. gap: px2rpx(12);
  318. flex: 1;
  319. min-width: 0;
  320. }
  321. .type-icon {
  322. width: px2rpx(40);
  323. height: px2rpx(40);
  324. border-radius: px2rpx(10);
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. flex-shrink: 0;
  329. }
  330. .deduction-icon {
  331. background-color: #fef2f2;
  332. }
  333. .icons {
  334. width: px2rpx(20);
  335. height: px2rpx(20);
  336. }
  337. .record-info {
  338. flex: 1;
  339. min-width: 0;
  340. display: flex;
  341. flex-direction: column;
  342. gap: px2rpx(6);
  343. }
  344. .info-header {
  345. display: flex;
  346. align-items: center;
  347. gap: px2rpx(8);
  348. flex-wrap: wrap;
  349. }
  350. .record-type {
  351. font-size: px2rpx(15);
  352. color: #111827;
  353. }
  354. .status-badge {
  355. display: flex;
  356. align-items: center;
  357. gap: px2rpx(4);
  358. padding: px2rpx(3) px2rpx(2);
  359. border-radius: px2rpx(12);
  360. }
  361. .status-success {
  362. background-color: #f0fdf4;
  363. }
  364. .status-processing {
  365. background-color: #fefce8;
  366. }
  367. .status-failed {
  368. background-color: #fef2f2;
  369. }
  370. .status-text {
  371. font-size: px2rpx(11);
  372. }
  373. .status-text-success {
  374. color: #22c55e;
  375. }
  376. .status-text-processing {
  377. color: #eab308;
  378. }
  379. .status-text-failed {
  380. color: #ef4444;
  381. }
  382. .record-detail {
  383. font-size: px2rpx(13);
  384. color: #6b7280;
  385. overflow: hidden;
  386. text-overflow: ellipsis;
  387. white-space: nowrap;
  388. }
  389. .record-right {
  390. display: flex;
  391. flex-direction: column;
  392. align-items: flex-end;
  393. gap: px2rpx(4);
  394. margin-left: px2rpx(12);
  395. flex-shrink: 0;
  396. }
  397. .amount-deduction {
  398. font-size: px2rpx(18);
  399. color: #ef4444;
  400. }
  401. .fee-text {
  402. font-size: px2rpx(11);
  403. color: #9ca3af;
  404. }
  405. .record-footer {
  406. display: flex;
  407. align-items: center;
  408. justify-content: space-between;
  409. padding-top: px2rpx(16);
  410. border-top: 1px solid #f3f4f6;
  411. }
  412. .footer-time {
  413. font-size: px2rpx(11);
  414. color: #9ca3af;
  415. }
  416. .footer-actions {
  417. display: flex;
  418. align-items: center;
  419. gap: px2rpx(2);
  420. }
  421. .footer-detail {
  422. font-size: px2rpx(11);
  423. color: #2563eb;
  424. }
  425. </style>