transaction-list.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="container">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="back-btn" @click="goBack">
  6. <image src="" mode="aspectFit"></image>
  7. </view>
  8. <view class="title">全部交易记录</view>
  9. </view>
  10. <!-- 交易记录列表 -->
  11. <view class="transaction-list">
  12. <view class="transaction-item" v-for="item in transactions" :key="item.id" @click="viewDetail(item)">
  13. <view class="left">
  14. <view class="type">{{getTypeText(item.transactionType)}}</view>
  15. <view class="time">{{item.createTime}}</view>
  16. <view class="order-no" v-if="item.orderNo">订单: {{item.orderNo}}</view>
  17. </view>
  18. <view class="right" :class="{'income': item.amount > 0, 'expense': item.amount < 0}">
  19. {{item.amount > 0 ? '+' : ''}}{{formatMoney(item.amount)}}
  20. </view>
  21. </view>
  22. <view class="load-more" @click="loadMore" v-if="hasMore">
  23. {{loading ? '加载中...' : '加载更多'}}
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. transactions: [],
  33. page: 1,
  34. pageSize: 15,
  35. loading: false,
  36. hasMore: true
  37. };
  38. },
  39. onLoad() {
  40. this.loadTransactions();
  41. },
  42. methods: {
  43. goBack() {
  44. uni.navigateBack();
  45. },
  46. loadTransactions() {
  47. if (this.loading) return;
  48. this.loading = true;
  49. this.request("get", "rider/wallet/transactions", this.$store.state.token, {
  50. page: this.page,
  51. size: this.pageSize
  52. }).then(res => {
  53. if (res.code === 200) {
  54. this.transactions = [...this.transactions, ...res.rows];
  55. this.hasMore = this.transactions.length < res.total;
  56. }
  57. }).finally(() => {
  58. this.loading = false;
  59. });
  60. },
  61. loadMore() {
  62. if (this.hasMore && !this.loading) {
  63. this.page++;
  64. this.loadTransactions();
  65. }
  66. },
  67. viewDetail(item) {
  68. uni.navigateTo({
  69. url: `/pages/wallet/detail?id=${item.id}`
  70. });
  71. },
  72. formatMoney(amount) {
  73. return Number(amount || 0).toFixed(2);
  74. },
  75. getTypeText(type) {
  76. const types = {
  77. 1: '收入',
  78. 2: '支出',
  79. 3: '提现',
  80. 4: '退款'
  81. };
  82. return types[type] || '交易';
  83. }
  84. }
  85. };
  86. </script>
  87. <style lang="scss" scoped>
  88. .container {
  89. background-color: #f7f7f7;
  90. min-height: 100vh;
  91. }
  92. .custom-navbar {
  93. display: flex;
  94. align-items: center;
  95. height: 88rpx;
  96. padding: 0 30rpx;
  97. background-color: #fff;
  98. border-bottom: 1rpx solid #f0f0f0;
  99. .back-btn {
  100. width: 40rpx;
  101. height: 40rpx;
  102. margin-right: 20rpx;
  103. image {
  104. width: 100%;
  105. height: 100%;
  106. }
  107. }
  108. .title {
  109. font-size: 34rpx;
  110. font-weight: bold;
  111. }
  112. }
  113. .transaction-list {
  114. padding: 20rpx;
  115. .transaction-item {
  116. display: flex;
  117. justify-content: space-between;
  118. align-items: center;
  119. padding: 30rpx;
  120. margin-bottom: 20rpx;
  121. background-color: #fff;
  122. border-radius: 12rpx;
  123. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  124. .left {
  125. flex: 1;
  126. .type {
  127. font-size: 30rpx;
  128. color: #333;
  129. margin-bottom: 10rpx;
  130. }
  131. .time,
  132. .order-no {
  133. font-size: 24rpx;
  134. color: #999;
  135. }
  136. .order-no {
  137. margin-top: 5rpx;
  138. }
  139. }
  140. .right {
  141. font-size: 32rpx;
  142. font-weight: bold;
  143. &.income {
  144. color: #4caf50;
  145. }
  146. &.expense {
  147. color: #f44336;
  148. }
  149. }
  150. }
  151. .load-more {
  152. text-align: center;
  153. padding: 30rpx;
  154. color: #4a90e2;
  155. font-size: 28rpx;
  156. }
  157. }
  158. </style>