points-detail.vue 6.9 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. console.error('获取红娘信息失败:', e)
  94. }
  95. }
  96. await this.loadRecords()
  97. },
  98. async loadRecords() {
  99. if (!this.makerId || this.loading) return
  100. this.loading = true
  101. try {
  102. const res = await api.pointsMall.getRecords(this.makerId, this.pageNum, this.pageSize)
  103. this.balance = res.balance || 0
  104. this.total = res.total || 0
  105. if (this.pageNum === 1) {
  106. this.records = res.list || []
  107. } else {
  108. this.records = [...this.records, ...(res.list || [])]
  109. }
  110. } catch (e) {
  111. console.error('获取积分明细失败:', e)
  112. uni.showToast({ title: '获取积分明细失败', icon: 'none' })
  113. } finally {
  114. this.loading = false
  115. }
  116. },
  117. loadMore() {
  118. if (this.hasMore && !this.loading) {
  119. this.pageNum++
  120. this.loadRecords()
  121. }
  122. },
  123. handleBack() {
  124. uni.navigateBack()
  125. },
  126. formatTime(timeStr) {
  127. if (!timeStr) return ''
  128. const date = new Date(timeStr)
  129. const year = date.getFullYear()
  130. const month = String(date.getMonth() + 1).padStart(2, '0')
  131. const day = String(date.getDate()).padStart(2, '0')
  132. const hour = String(date.getHours()).padStart(2, '0')
  133. const minute = String(date.getMinutes()).padStart(2, '0')
  134. return `${year}-${month}-${day} ${hour}:${minute}`
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .points-detail {
  141. min-height: 100vh;
  142. background: #F5F5F5;
  143. }
  144. .header {
  145. display: flex;
  146. align-items: center;
  147. justify-content: space-between;
  148. padding: 25rpx 30rpx;
  149. padding-top: calc(25rpx + env(safe-area-inset-top));
  150. background: #FFFFFF;
  151. .back-icon {
  152. width: 44rpx;
  153. height: 44rpx;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. font-size: 32rpx;
  158. color: #333;
  159. &::before { content: '‹'; }
  160. }
  161. .header-title {
  162. font-size: 36rpx;
  163. font-weight: bold;
  164. color: #333;
  165. }
  166. .header-right {
  167. width: 44rpx;
  168. }
  169. }
  170. .balance-card {
  171. background: linear-gradient(135deg, #9C27B0 0%, #E91E63 100%);
  172. margin: 30rpx;
  173. padding: 40rpx;
  174. border-radius: 20rpx;
  175. text-align: center;
  176. .balance-label {
  177. font-size: 28rpx;
  178. color: rgba(255, 255, 255, 0.8);
  179. margin-bottom: 15rpx;
  180. }
  181. .balance-value {
  182. font-size: 72rpx;
  183. font-weight: bold;
  184. color: #FFFFFF;
  185. }
  186. }
  187. .records-section {
  188. background: #FFFFFF;
  189. margin: 0 30rpx;
  190. border-radius: 20rpx;
  191. padding: 30rpx;
  192. .section-title {
  193. font-size: 30rpx;
  194. font-weight: bold;
  195. color: #333;
  196. margin-bottom: 30rpx;
  197. }
  198. .empty-tip {
  199. text-align: center;
  200. color: #999;
  201. font-size: 28rpx;
  202. padding: 60rpx 0;
  203. }
  204. }
  205. .record-list {
  206. .record-item {
  207. display: flex;
  208. align-items: center;
  209. justify-content: space-between;
  210. padding: 25rpx 0;
  211. border-bottom: 1rpx solid #F0F0F0;
  212. &:last-child {
  213. border-bottom: none;
  214. }
  215. .record-left {
  216. display: flex;
  217. align-items: center;
  218. .record-icon {
  219. width: 60rpx;
  220. height: 60rpx;
  221. border-radius: 50%;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. font-size: 32rpx;
  226. font-weight: bold;
  227. margin-right: 20rpx;
  228. &.income {
  229. background: #E8F5E9;
  230. color: #4CAF50;
  231. }
  232. &.expense {
  233. background: #FFEBEE;
  234. color: #F44336;
  235. }
  236. }
  237. .record-info {
  238. .record-reason {
  239. font-size: 28rpx;
  240. color: #333;
  241. margin-bottom: 8rpx;
  242. }
  243. .record-time {
  244. font-size: 24rpx;
  245. color: #999;
  246. }
  247. }
  248. }
  249. .record-points {
  250. font-size: 32rpx;
  251. font-weight: bold;
  252. &.income {
  253. color: #4CAF50;
  254. }
  255. &.expense {
  256. color: #F44336;
  257. }
  258. }
  259. }
  260. }
  261. .load-more {
  262. text-align: center;
  263. padding: 30rpx;
  264. color: #9C27B0;
  265. font-size: 26rpx;
  266. }
  267. </style>