score_list.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="page-container">
  3. <view class="sticky-header">
  4. <view class="points-summary">
  5. <view class="summary-left">
  6. <text class="label">我的积分</text>
  7. <text class="value">{{totalPoints}}</text>
  8. </view>
  9. <button class="use-points-btn" @click="goToUsagePage">去使用</button>
  10. </view>
  11. </view>
  12. <scroll-view class="records-list" scroll-y="true" @scrolltolower="loadMore">
  13. <view v-if="recordList.length === 0 && loadStatus !== 'loading'" class="empty-list">
  14. <text>暂无积分记录</text>
  15. </view>
  16. <view v-for="record in recordList" :key="record.id" class="record-card">
  17. <view class="record-info">
  18. <text class="record-type">{{ record.type }}</text>
  19. <text class="record-detail">门店名称:{{ record.storeName }}</text>
  20. <text class="record-detail">获得时间:{{ record.time }}</text>
  21. </view>
  22. <view class="record-points" :class="record.amount > 0 ? 'income' : 'expense'">
  23. {{ record.amount > 0 ? '+' : '' }}{{ record.amount }}
  24. </view>
  25. </view>
  26. <uni-load-more :status="loadStatus"></uni-load-more>
  27. </scroll-view>
  28. </view>
  29. </template>
  30. <script>
  31. import {scoreRecord} from "@/api/hexiao";
  32. export default {
  33. data() {
  34. return {
  35. totalPoints: 0,
  36. recordList: [],
  37. pagination: { page: 1, limit: 15 },
  38. loadStatus: 'more', // 'more', 'loading', 'noMore'
  39. isLoading: false,
  40. };
  41. },
  42. onLoad(opt) {
  43. this.totalPoints = opt.pointsCount;
  44. this.fetchRecords(true);
  45. },
  46. onPullDownRefresh() {
  47. this.fetchRecords(true);
  48. },
  49. methods: {
  50. // 格式化数字,添加千位分隔符
  51. formatNumber(num) {
  52. return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  53. },
  54. // 模拟获取积分记录
  55. async fetchRecords(isRefresh = false) {
  56. if (this.isLoading || (this.loadStatus === 'noMore' && !isRefresh)) {
  57. return;
  58. }
  59. if (isRefresh) {
  60. this.pagination.page = 1;
  61. this.recordList = [];
  62. this.loadStatus = 'more';
  63. }
  64. this.isLoading = true;
  65. this.loadStatus = 'loading';
  66. // --- 模拟API请求 ---
  67. console.log(`请求第 ${this.pagination.page} 页...`);
  68. scoreRecord(this.pagination.page,this.pagination.limit).then(res=>{
  69. let data = res.data;
  70. let mockData = data.records;
  71. if(mockData == null){
  72. mockData = [];
  73. }
  74. uni.stopPullDownRefresh();
  75. if (mockData.length > 0 ) {
  76. this.recordList = [...this.recordList, ...mockData];
  77. this.pagination.page++;
  78. this.loadStatus = 'more';
  79. } else {
  80. this.loadStatus = 'noMore';
  81. }
  82. this.isLoading = false;
  83. })
  84. // --- 模拟结束 ---
  85. },
  86. // 上拉加载更多
  87. loadMore() {
  88. this.fetchRecords();
  89. },
  90. // 跳转到积分使用页面
  91. goToUsagePage() {
  92. console.log('跳转到积分商城或使用页面');
  93. // uni.navigateTo({ url: '/pages/points/shop' });
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .page-container {
  100. display: flex;
  101. flex-direction: column;
  102. height: 100vh;
  103. background: linear-gradient(to bottom, #e4efff, #f5f6fa 30%);
  104. }
  105. .sticky-header {
  106. position: sticky;
  107. top: 0;
  108. z-index: 100;
  109. background: linear-gradient(to bottom, #e4efff, #f5f6fa);
  110. padding-bottom: 20rpx;
  111. }
  112. .points-summary {
  113. display: flex;
  114. justify-content: space-between;
  115. align-items: center;
  116. padding: 30rpx;
  117. margin: 20rpx;
  118. background: linear-gradient(to right, #6ca1ff, #3c82f8);
  119. border-radius: 20rpx;
  120. color: #ffffff;
  121. box-shadow: 0 8rpx 20rpx rgba(60, 130, 248, 0.3);
  122. .summary-left {
  123. display: flex;
  124. flex-direction: column;
  125. }
  126. .label {
  127. font-size: 28rpx;
  128. opacity: 0.9;
  129. }
  130. .value {
  131. font-size: 52rpx;
  132. font-weight: bold;
  133. margin-top: 10rpx;
  134. }
  135. .use-points-btn {
  136. margin: 0;
  137. background-color: rgba(255, 255, 255, 0.9);
  138. color: #3c82f8;
  139. font-size: 26rpx;
  140. padding: 0 30rpx;
  141. height: 60rpx;
  142. line-height: 60rpx;
  143. border-radius: 30rpx;
  144. font-weight: 500;
  145. &::after {
  146. border: none;
  147. }
  148. }
  149. }
  150. .records-list {
  151. flex: 1;
  152. height: 100%;
  153. padding: 0 20rpx;
  154. }
  155. .empty-list {
  156. text-align: center;
  157. color: #999;
  158. padding-top: 150rpx;
  159. }
  160. .record-card {
  161. display: flex;
  162. justify-content: space-between;
  163. align-items: center;
  164. background-color: #ffffff;
  165. border-radius: 16rpx;
  166. padding: 30rpx;
  167. margin-bottom: 20rpx;
  168. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  169. }
  170. .record-info {
  171. display: flex;
  172. flex-direction: column;
  173. .record-type {
  174. font-size: 30rpx;
  175. font-weight: 500;
  176. color: #333;
  177. }
  178. .record-detail {
  179. font-size: 24rpx;
  180. color: #999;
  181. margin-top: 12rpx;
  182. }
  183. }
  184. .record-points {
  185. font-size: 36rpx;
  186. font-weight: bold;
  187. &.income {
  188. color: #4caf50; // 绿色代表收入
  189. }
  190. &.expense {
  191. color: #e54d42; // 红色代表支出
  192. }
  193. }
  194. </style>