points-detail.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="points-detail">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-icon" @click="handleBack"></view>
  6. <text class="header-title">积分明细</text>
  7. <view class="header-right"></view>
  8. </view>
  9. <!-- 积分余额卡片 -->
  10. <view class="balance-card">
  11. <view class="balance-label">当前积分</view>
  12. <view class="balance-value">{{ balance }}</view>
  13. </view>
  14. <!-- 明细列表 -->
  15. <view class="records-section">
  16. <view class="section-title">积分记录</view>
  17. <view v-if="records.length === 0 && !loading" class="empty-tip">
  18. 暂无积分记录
  19. </view>
  20. <view class="record-list">
  21. <view class="record-item" v-for="(item, index) in records" :key="index">
  22. <view class="record-left">
  23. <view class="record-icon" :class="item.points > 0 ? 'income' : 'expense'">
  24. {{ item.points > 0 ? '+' : '-' }}
  25. </view>
  26. <view class="record-info">
  27. <view class="record-reason">{{ item.reason }}</view>
  28. <view class="record-time">{{ formatTime(item.createTime) }}</view>
  29. </view>
  30. </view>
  31. <view class="record-points" :class="item.points > 0 ? 'income' : 'expense'">
  32. {{ item.points > 0 ? '+' : '' }}{{ item.points }}
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 加载更多 -->
  37. <view class="load-more" v-if="hasMore" @click="loadMore">
  38. {{ loading ? '加载中...' : '加载更多' }}
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import api from '@/utils/api.js'
  45. export default {
  46. name: 'points-detail',
  47. data() {
  48. return {
  49. balance: 0,
  50. records: [],
  51. makerId: null,
  52. pageNum: 1,
  53. pageSize: 20,
  54. total: 0,
  55. loading: false
  56. }
  57. },
  58. computed: {
  59. hasMore() {
  60. return this.records.length < this.total
  61. }
  62. },
  63. onLoad() {
  64. this.initData()
  65. },
  66. onShow() {
  67. // 每次显示页面时刷新积分数据,确保数据同步
  68. if (this.makerId) {
  69. this.pageNum = 1
  70. this.loadRecords()
  71. }
  72. },
  73. methods: {
  74. async initData() {
  75. const userInfo = uni.getStorageSync('userInfo')
  76. if (userInfo && userInfo.matchmakerId) {
  77. this.makerId = userInfo.matchmakerId
  78. } else if (userInfo && userInfo.userId) {
  79. // 如果没有matchmakerId,通过API获取
  80. try {
  81. const res = await api.matchmaker.getByUserId(userInfo.userId)
  82. let matchmaker = res
  83. if (res && res.data) {
  84. matchmaker = res.data
  85. }
  86. if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
  87. this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
  88. // 保存到userInfo中
  89. userInfo.matchmakerId = this.makerId
  90. uni.setStorageSync('userInfo', userInfo)
  91. }
  92. } catch (e) {
  93. }
  94. }
  95. await this.loadRecords()
  96. },
  97. async loadRecords() {
  98. if (!this.makerId || this.loading) return
  99. this.loading = true
  100. try {
  101. const res = await api.pointsMall.getRecords(this.makerId, this.pageNum, this.pageSize)
  102. this.balance = res.balance || 0
  103. this.total = res.total || 0
  104. if (this.pageNum === 1) {
  105. this.records = res.list || []
  106. } else {
  107. this.records = [...this.records, ...(res.list || [])]
  108. }
  109. } catch (e) {
  110. uni.showToast({ title: '获取积分明细失败', icon: 'none' })
  111. } finally {
  112. this.loading = false
  113. }
  114. },
  115. loadMore() {
  116. if (this.hasMore && !this.loading) {
  117. this.pageNum++
  118. this.loadRecords()
  119. }
  120. },
  121. handleBack() {
  122. uni.navigateBack()
  123. },
  124. formatTime(timeStr) {
  125. if (!timeStr) return ''
  126. const date = new Date(timeStr)
  127. const year = date.getFullYear()
  128. const month = String(date.getMonth() + 1).padStart(2, '0')
  129. const day = String(date.getDate()).padStart(2, '0')
  130. const hour = String(date.getHours()).padStart(2, '0')
  131. const minute = String(date.getMinutes()).padStart(2, '0')
  132. return `${year}-${month}-${day} ${hour}:${minute}`
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .points-detail {
  139. min-height: 100vh;
  140. background: #F5F5F5;
  141. }
  142. .header {
  143. display: flex;
  144. align-items: center;
  145. justify-content: space-between;
  146. padding: 25rpx 30rpx;
  147. padding-top: calc(25rpx + env(safe-area-inset-top));
  148. background: #FFFFFF;
  149. .back-icon {
  150. width: 44rpx;
  151. height: 44rpx;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. font-size: 32rpx;
  156. color: #333;
  157. &::before { content: '‹'; }
  158. }
  159. .header-title {
  160. font-size: 36rpx;
  161. font-weight: bold;
  162. color: #333;
  163. }
  164. .header-right {
  165. width: 44rpx;
  166. }
  167. }
  168. .balance-card {
  169. background: linear-gradient(135deg, #9C27B0 0%, #E91E63 100%);
  170. margin: 30rpx;
  171. padding: 40rpx;
  172. border-radius: 20rpx;
  173. text-align: center;
  174. .balance-label {
  175. font-size: 28rpx;
  176. color: rgba(255, 255, 255, 0.8);
  177. margin-bottom: 15rpx;
  178. }
  179. .balance-value {
  180. font-size: 72rpx;
  181. font-weight: bold;
  182. color: #FFFFFF;
  183. }
  184. }
  185. .records-section {
  186. background: #FFFFFF;
  187. margin: 0 30rpx;
  188. border-radius: 20rpx;
  189. padding: 30rpx;
  190. .section-title {
  191. font-size: 30rpx;
  192. font-weight: bold;
  193. color: #333;
  194. margin-bottom: 30rpx;
  195. }
  196. .empty-tip {
  197. text-align: center;
  198. color: #999;
  199. font-size: 28rpx;
  200. padding: 60rpx 0;
  201. }
  202. }
  203. .record-list {
  204. .record-item {
  205. display: flex;
  206. align-items: center;
  207. justify-content: space-between;
  208. padding: 25rpx 0;
  209. border-bottom: 1rpx solid #F0F0F0;
  210. &:last-child {
  211. border-bottom: none;
  212. }
  213. .record-left {
  214. display: flex;
  215. align-items: center;
  216. .record-icon {
  217. width: 60rpx;
  218. height: 60rpx;
  219. border-radius: 50%;
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. font-size: 32rpx;
  224. font-weight: bold;
  225. margin-right: 20rpx;
  226. &.income {
  227. background: #E8F5E9;
  228. color: #4CAF50;
  229. }
  230. &.expense {
  231. background: #FFEBEE;
  232. color: #F44336;
  233. }
  234. }
  235. .record-info {
  236. .record-reason {
  237. font-size: 28rpx;
  238. color: #333;
  239. margin-bottom: 8rpx;
  240. }
  241. .record-time {
  242. font-size: 24rpx;
  243. color: #999;
  244. }
  245. }
  246. }
  247. .record-points {
  248. font-size: 32rpx;
  249. font-weight: bold;
  250. &.income {
  251. color: #4CAF50;
  252. }
  253. &.expense {
  254. color: #F44336;
  255. }
  256. }
  257. }
  258. }
  259. .load-more {
  260. text-align: center;
  261. padding: 30rpx;
  262. color: #9C27B0;
  263. font-size: 26rpx;
  264. }
  265. </style>