vip.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. <scroll-view class="scroll-content" scroll-y>
  12. <!-- VIP套餐列表 -->
  13. <view class="vip-plans">
  14. <view
  15. class="plan-item"
  16. v-for="(plan, index) in vipPlans"
  17. :key="index"
  18. :class="{ active: selectedPlan === index }"
  19. @click="selectPlan(index)"
  20. >
  21. <view class="plan-header">
  22. <text class="plan-name">{{ plan.name }}</text>
  23. <text class="plan-price">¥{{ plan.price }}</text>
  24. </view>
  25. <text class="plan-desc">{{ plan.desc }}</text>
  26. <view class="plan-benefits">
  27. <text class="benefit-item" v-for="(benefit, i) in plan.benefits" :key="i">✓ {{ benefit }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. <!-- 底部购买栏 -->
  33. <view class="bottom-bar">
  34. <view class="price-info">
  35. <text class="price-text">{{ selectedPlanInfo.price }}元/月</text>
  36. </view>
  37. <button class="buy-btn" @click="goToPayment">立即购买</button>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { getVipPlans } from '@/utils/api.js'
  43. export default {
  44. data() {
  45. return {
  46. selectedPlan: 0,
  47. vipPlans: [],
  48. loading: false
  49. }
  50. },
  51. computed: {
  52. selectedPlanInfo() {
  53. return this.vipPlans[this.selectedPlan] || {}
  54. }
  55. },
  56. onLoad() {
  57. this.loadVipPlans()
  58. },
  59. methods: {
  60. async loadVipPlans() {
  61. this.loading = true
  62. try {
  63. const res = await getVipPlans()
  64. if (res && res.code === 200 && res.data) {
  65. this.vipPlans = res.data
  66. } else {
  67. // 如果后端返回失败,使用默认数据
  68. this.vipPlans = [
  69. {
  70. type: 'month',
  71. name: '月卡VIP',
  72. price: 30,
  73. desc: '适合短期阅读',
  74. benefits: ['无限阅读', '免费听书', '专属客服']
  75. },
  76. {
  77. type: 'quarter',
  78. name: '季卡VIP',
  79. price: 80,
  80. desc: '超值优惠',
  81. benefits: ['无限阅读', '免费听书', '专属客服', '优先更新']
  82. },
  83. {
  84. type: 'year',
  85. name: '年卡VIP',
  86. price: 288,
  87. desc: '最超值选择',
  88. benefits: ['无限阅读', '免费听书', '专属客服', '优先更新', '专属活动']
  89. }
  90. ]
  91. }
  92. } catch (error) {
  93. console.error('加载VIP套餐失败:', error)
  94. // 使用默认数据
  95. this.vipPlans = [
  96. {
  97. type: 'month',
  98. name: '月卡VIP',
  99. price: 30,
  100. desc: '适合短期阅读',
  101. benefits: ['无限阅读', '免费听书', '专属客服']
  102. },
  103. {
  104. type: 'quarter',
  105. name: '季卡VIP',
  106. price: 80,
  107. desc: '超值优惠',
  108. benefits: ['无限阅读', '免费听书', '专属客服', '优先更新']
  109. },
  110. {
  111. type: 'year',
  112. name: '年卡VIP',
  113. price: 288,
  114. desc: '最超值选择',
  115. benefits: ['无限阅读', '免费听书', '专属客服', '优先更新', '专属活动']
  116. }
  117. ]
  118. } finally {
  119. this.loading = false
  120. }
  121. },
  122. goBack() {
  123. uni.navigateBack()
  124. },
  125. selectPlan(index) {
  126. this.selectedPlan = index
  127. },
  128. goToPayment() {
  129. if (!this.selectedPlanInfo || !this.selectedPlanInfo.type) {
  130. uni.showToast({
  131. title: '请选择VIP套餐',
  132. icon: 'none'
  133. })
  134. return
  135. }
  136. const plan = this.selectedPlanInfo
  137. uni.navigateTo({
  138. url: `/pages/payment/payment?planId=${this.selectedPlan}&planType=${plan.type}&planName=${encodeURIComponent(plan.name)}&price=${plan.price}`
  139. })
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .container {
  146. width: 100%;
  147. height: 100vh;
  148. min-height: 100vh;
  149. background-color: #F5F5F5;
  150. display: flex;
  151. padding-top: 30px;
  152. box-sizing: border-box;
  153. flex-direction: column;
  154. box-sizing: border-box;
  155. overflow: hidden;
  156. }
  157. .header {
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-between;
  161. padding: 20rpx 30rpx;
  162. padding-top: calc(20rpx + env(safe-area-inset-top));
  163. background-color: #FFFFFF;
  164. border-bottom: 1rpx solid #F0F0F0;
  165. position: relative;
  166. flex-shrink: 0;
  167. box-sizing: border-box;
  168. }
  169. .back-btn {
  170. width: 60rpx;
  171. height: 60rpx;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. z-index: 10;
  176. }
  177. .back-icon {
  178. font-size: 40rpx;
  179. color: #333333;
  180. font-weight: bold;
  181. }
  182. .header-title {
  183. position: absolute;
  184. left: 50%;
  185. transform: translateX(-50%);
  186. font-size: 36rpx;
  187. font-weight: bold;
  188. color: #333333;
  189. }
  190. .header-right {
  191. width: 60rpx;
  192. }
  193. .scroll-content {
  194. flex: 1;
  195. width: 100%;
  196. height: 0;
  197. overflow: hidden;
  198. padding: 30rpx;
  199. padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
  200. box-sizing: border-box;
  201. }
  202. .vip-plans {
  203. display: flex;
  204. flex-direction: column;
  205. gap: 20rpx;
  206. }
  207. .plan-item {
  208. background-color: #FFFFFF;
  209. border-radius: 16rpx;
  210. padding: 30rpx;
  211. border: 2rpx solid transparent;
  212. transition: all 0.3s;
  213. }
  214. .plan-item.active {
  215. border-color: #FF6B35;
  216. box-shadow: 0 4rpx 12rpx rgba(255, 107, 53, 0.2);
  217. }
  218. .plan-header {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. margin-bottom: 15rpx;
  223. }
  224. .plan-name {
  225. font-size: 32rpx;
  226. font-weight: bold;
  227. color: #333333;
  228. }
  229. .plan-price {
  230. font-size: 36rpx;
  231. font-weight: bold;
  232. color: #FF6B35;
  233. }
  234. .plan-desc {
  235. font-size: 26rpx;
  236. color: #999999;
  237. margin-bottom: 20rpx;
  238. }
  239. .plan-benefits {
  240. display: flex;
  241. flex-direction: column;
  242. gap: 10rpx;
  243. }
  244. .benefit-item {
  245. font-size: 26rpx;
  246. color: #666666;
  247. }
  248. .bottom-bar {
  249. display: flex;
  250. align-items: center;
  251. background-color: #FFFFFF;
  252. border-top: 1rpx solid #F0F0F0;
  253. padding: 20rpx 30rpx;
  254. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  255. flex-shrink: 0;
  256. box-sizing: border-box;
  257. }
  258. .price-info {
  259. flex: 1;
  260. background-color: #333333;
  261. border-radius: 8rpx;
  262. padding: 25rpx 30rpx;
  263. margin-right: 20rpx;
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. }
  268. .price-text {
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #FFFFFF;
  272. }
  273. .buy-btn {
  274. flex: 1;
  275. height: 88rpx;
  276. background-color: #FF6B35;
  277. color: #FFFFFF;
  278. font-size: 32rpx;
  279. font-weight: bold;
  280. border: none;
  281. border-radius: 44rpx;
  282. display: flex;
  283. align-items: center;
  284. justify-content: center;
  285. }
  286. .buy-btn::after {
  287. border: none;
  288. }
  289. </style>