vip-records.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">开通VIP记录</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <!-- VIP记录列表 -->
  12. <scroll-view class="scroll-content" scroll-y>
  13. <view
  14. class="record-item"
  15. v-for="(record, index) in vipRecords"
  16. :key="index"
  17. >
  18. <view class="record-header">
  19. <text class="vip-type">{{ record.type }}</text>
  20. <text class="vip-price">¥{{ record.price }}</text>
  21. </view>
  22. <view class="record-details">
  23. <text class="detail-label">开通时间:</text>
  24. <text class="detail-value">{{ record.activateTime }}</text>
  25. </view>
  26. <view class="record-details">
  27. <text class="detail-label">有效期至:</text>
  28. <text class="detail-value">{{ record.expireTime }}</text>
  29. </view>
  30. </view>
  31. <!-- 空状态 -->
  32. <view class="empty-state" v-if="vipRecords.length === 0">
  33. <text class="empty-text">暂无VIP记录</text>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. </template>
  38. <script>
  39. import { getVipRecords } from '@/utils/api.js'
  40. export default {
  41. data() {
  42. return {
  43. vipRecords: [],
  44. loading: false,
  45. page: 1,
  46. size: 20,
  47. hasMore: true
  48. }
  49. },
  50. onLoad() {
  51. this.loadVipRecords()
  52. },
  53. onPullDownRefresh() {
  54. this.page = 1
  55. this.vipRecords = []
  56. this.hasMore = true
  57. this.loadVipRecords().finally(() => {
  58. uni.stopPullDownRefresh()
  59. })
  60. },
  61. onReachBottom() {
  62. if (this.hasMore && !this.loading) {
  63. this.page++
  64. this.loadVipRecords()
  65. }
  66. },
  67. methods: {
  68. async loadVipRecords() {
  69. const userInfo = uni.getStorageSync('userInfo')
  70. if (!userInfo || !userInfo.id) {
  71. uni.showToast({
  72. title: '请先登录',
  73. icon: 'none'
  74. })
  75. setTimeout(() => {
  76. uni.navigateTo({
  77. url: '/pages/login/login'
  78. })
  79. }, 1500)
  80. return
  81. }
  82. if (this.loading) return
  83. this.loading = true
  84. try {
  85. const res = await getVipRecords(userInfo.id, 1, this.page, this.size) // 只查询已支付的记录
  86. if (res && res.code === 200 && res.data) {
  87. const newRecords = res.data.list || []
  88. if (this.page === 1) {
  89. this.vipRecords = newRecords
  90. } else {
  91. this.vipRecords = this.vipRecords.concat(newRecords)
  92. }
  93. // 判断是否还有更多数据
  94. this.hasMore = newRecords.length >= this.size
  95. } else {
  96. if (this.page === 1) {
  97. this.vipRecords = []
  98. }
  99. this.hasMore = false
  100. }
  101. } catch (error) {
  102. console.error('加载VIP记录失败:', error)
  103. if (this.page === 1) {
  104. this.vipRecords = []
  105. }
  106. if (this.page > 1) {
  107. this.page--
  108. }
  109. } finally {
  110. this.loading = false
  111. }
  112. },
  113. goBack() {
  114. uni.navigateBack()
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .container {
  121. width: 100%;
  122. height: 100vh;
  123. min-height: 100vh;
  124. background-color: #FFFFFF;
  125. display: flex;
  126. padding-top: 30px;
  127. box-sizing: border-box;
  128. flex-direction: column;
  129. box-sizing: border-box;
  130. overflow: hidden;
  131. }
  132. .header {
  133. display: flex;
  134. align-items: center;
  135. justify-content: space-between;
  136. padding: 20rpx 30rpx;
  137. padding-top: calc(20rpx + env(safe-area-inset-top));
  138. background-color: #FFFFFF;
  139. border-bottom: 1rpx solid #F0F0F0;
  140. position: relative;
  141. flex-shrink: 0;
  142. box-sizing: border-box;
  143. }
  144. .back-btn {
  145. width: 60rpx;
  146. height: 60rpx;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. z-index: 10;
  151. }
  152. .back-icon {
  153. font-size: 40rpx;
  154. color: #333333;
  155. font-weight: bold;
  156. }
  157. .header-title {
  158. position: absolute;
  159. left: 50%;
  160. transform: translateX(-50%);
  161. font-size: 36rpx;
  162. font-weight: bold;
  163. color: #333333;
  164. }
  165. .header-right {
  166. width: 60rpx;
  167. }
  168. .scroll-content {
  169. flex: 1;
  170. width: 100%;
  171. height: 0;
  172. overflow: hidden;
  173. padding: 20rpx 30rpx;
  174. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  175. background-color: #FFFFFF;
  176. box-sizing: border-box;
  177. }
  178. .record-item {
  179. padding: 30rpx 0;
  180. border-bottom: 1rpx solid #F0F0F0;
  181. width: 100%;
  182. box-sizing: border-box;
  183. }
  184. .record-item:last-child {
  185. border-bottom: none;
  186. }
  187. .record-header {
  188. display: flex;
  189. justify-content: space-between;
  190. align-items: center;
  191. margin-bottom: 20rpx;
  192. }
  193. .vip-type {
  194. font-size: 32rpx;
  195. font-weight: bold;
  196. color: #FF1744;
  197. }
  198. .vip-price {
  199. font-size: 32rpx;
  200. font-weight: bold;
  201. color: #FF1744;
  202. }
  203. .record-details {
  204. display: flex;
  205. align-items: center;
  206. margin-bottom: 10rpx;
  207. }
  208. .record-details:last-child {
  209. margin-bottom: 0;
  210. }
  211. .detail-label {
  212. font-size: 26rpx;
  213. color: #999999;
  214. margin-right: 10rpx;
  215. }
  216. .detail-value {
  217. font-size: 26rpx;
  218. color: #999999;
  219. }
  220. .empty-state {
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. padding: 200rpx 0;
  225. }
  226. .empty-text {
  227. font-size: 28rpx;
  228. color: #999999;
  229. }
  230. </style>