DeductionList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. 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 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.cardNo || loading.value) return;
  143. if (isLoadMore && finished.value) return;
  144. loading.value = true;
  145. try {
  146. const res = await ucardApi.getCardWithdrawPage({
  147. cardNo: props.cardNo,
  148. type: props.typeIndex || undefined,
  149. status: props.statusIndex || undefined,
  150. beginDate: props.dateFilter,
  151. endDate: (() => {
  152. // 兼容时间戳和日期字符串
  153. if (!props.dateFilter) return props.dateFilter;
  154. let date = props.dateFilter;
  155. if (/^\d+$/.test(String(date))) {
  156. // 时间戳
  157. return Number(date) + 24 * 60 * 60 * 1000;
  158. } else {
  159. // 日期字符串
  160. const d = new Date(date);
  161. if (!isNaN(d.getTime())) {
  162. d.setDate(d.getDate() + 1);
  163. return d.toISOString().slice(0, 10);
  164. }
  165. return date;
  166. }
  167. })(),
  168. page: { current: page.value, row: pageSize },
  169. });
  170. const data = res.code === 200 && Array.isArray(res.data) ? res.data : [];
  171. if (isLoadMore) {
  172. records.value.push(...data);
  173. } else {
  174. records.value = data;
  175. }
  176. if (data.length < pageSize) {
  177. finished.value = true;
  178. } else {
  179. finished.value = false;
  180. }
  181. } catch (error: any) {
  182. if (!isLoadMore) {
  183. records.value = [];
  184. }
  185. showToast(error?.message || String(error));
  186. } finally {
  187. loading.value = false;
  188. }
  189. };
  190. const goToDeductionDetail = (record: RecordItem) => {
  191. const amount = Number(record.amount || 0);
  192. const fee = Number(record.fee || 0);
  193. const normalizedStatus = normalizeStatus(record.status);
  194. const detailPayload = {
  195. category: 'deduction' as const,
  196. type: getDeductionTypeText(record.type || record.typeStr),
  197. amount,
  198. fee,
  199. actualAmount: amount - fee,
  200. currency: record.currency || 'USD',
  201. orderStatus: normalizedStatus,
  202. statusMessage: getStatusText(record.status),
  203. createTime: formatDateTime(record.transactionTime),
  204. completeTime: '',
  205. merchant: '',
  206. bankCard: '',
  207. bankCard: record.cardNumber,
  208. remark: record.remark || record.reason || '',
  209. approvalSteps: [] as any[]
  210. };
  211. cardStore.saveOrderDetail(detailPayload);
  212. uni.navigateTo({
  213. url: '/pages/recharge-record/detail'
  214. });
  215. };
  216. const loadMore = () => {
  217. if (finished.value || loading.value) return;
  218. page.value++;
  219. fetchRecords(true);
  220. };
  221. watch([() => props.dateFilter], () => {
  222. page.value = 1;
  223. finished.value = false;
  224. fetchRecords();
  225. }, { immediate: false });
  226. watch([() => props.typeIndex], () => {
  227. page.value = 1;
  228. finished.value = false;
  229. fetchRecords();
  230. }, { immediate: false });
  231. watch([() => props.statusIndex], () => {
  232. page.value = 1;
  233. finished.value = false;
  234. fetchRecords();
  235. }, { immediate: false });
  236. const loadMoreWrapperRef = ref<any>(null);
  237. const refresh = async () => {
  238. page.value = 1;
  239. finished.value = false;
  240. await fetchRecords();
  241. };
  242. const handleRefresh = async () => {
  243. await refresh();
  244. // 停止下拉刷新动画
  245. if (loadMoreWrapperRef.value) {
  246. loadMoreWrapperRef.value.stopRefresh();
  247. }
  248. };
  249. onMounted(() => {
  250. fetchRecords();
  251. });
  252. defineExpose({
  253. refresh
  254. });
  255. </script>
  256. <style scoped lang="scss">
  257. @import "@/uni.scss";
  258. .records-list {
  259. display: flex;
  260. flex-direction: column;
  261. gap: px2rpx(12);
  262. padding: px2rpx(16);
  263. }
  264. .record-card {
  265. background-color: #ffffff;
  266. border-radius: px2rpx(12);
  267. border: 1px solid #e5e7eb;
  268. overflow: hidden;
  269. transition: box-shadow 0.3s;
  270. padding: px2rpx(16);
  271. }
  272. .record-card:active {
  273. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  274. }
  275. .record-main {
  276. display: flex;
  277. align-items: flex-start;
  278. justify-content: space-between;
  279. padding-bottom: px2rpx(16);
  280. }
  281. .record-left {
  282. display: flex;
  283. align-items: flex-start;
  284. gap: px2rpx(12);
  285. flex: 1;
  286. min-width: 0;
  287. }
  288. .type-icon {
  289. width: px2rpx(40);
  290. height: px2rpx(40);
  291. border-radius: px2rpx(10);
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. flex-shrink: 0;
  296. }
  297. .deduction-icon {
  298. background-color: #fef2f2;
  299. }
  300. .icons {
  301. width: px2rpx(20);
  302. height: px2rpx(20);
  303. }
  304. .record-info {
  305. flex: 1;
  306. min-width: 0;
  307. display: flex;
  308. flex-direction: column;
  309. gap: px2rpx(6);
  310. }
  311. .info-header {
  312. display: flex;
  313. align-items: center;
  314. gap: px2rpx(8);
  315. flex-wrap: wrap;
  316. }
  317. .record-type {
  318. font-size: px2rpx(15);
  319. color: #111827;
  320. }
  321. .status-success {
  322. background-color: #f0fdf4;
  323. }
  324. .status-processing {
  325. background-color: #fefce8;
  326. }
  327. .status-failed {
  328. background-color: #fef2f2;
  329. }
  330. .status-text {
  331. font-size: px2rpx(11);
  332. }
  333. .status-text-success {
  334. color: #22c55e;
  335. }
  336. .status-text-processing {
  337. color: #eab308;
  338. }
  339. .status-text-failed {
  340. color: #ef4444;
  341. }
  342. .record-detail {
  343. font-size: px2rpx(13);
  344. color: #6b7280;
  345. overflow: hidden;
  346. text-overflow: ellipsis;
  347. white-space: nowrap;
  348. }
  349. .record-right {
  350. display: flex;
  351. flex-direction: column;
  352. align-items: flex-end;
  353. gap: px2rpx(4);
  354. margin-left: px2rpx(12);
  355. flex-shrink: 0;
  356. }
  357. .amount-deduction {
  358. font-size: px2rpx(18);
  359. color: #ef4444;
  360. }
  361. .fee-text {
  362. font-size: px2rpx(11);
  363. color: #9ca3af;
  364. }
  365. .record-footer {
  366. display: flex;
  367. align-items: center;
  368. justify-content: space-between;
  369. padding-top: px2rpx(16);
  370. border-top: 1px solid #f3f4f6;
  371. }
  372. .footer-time {
  373. font-size: px2rpx(11);
  374. color: #9ca3af;
  375. }
  376. .footer-actions {
  377. display: flex;
  378. align-items: center;
  379. gap: px2rpx(2);
  380. }
  381. .footer-detail {
  382. font-size: px2rpx(11);
  383. color: #2563eb;
  384. }
  385. </style>