index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <template>
  2. <scroll-view scroll-y class="vip-page">
  3. <!-- 顶部背景 -->
  4. <view class="header-bg">
  5. <!-- 返回按钮 -->
  6. <view class="back-btn" @click="goBack">
  7. <text class="back-icon">←</text>
  8. </view>
  9. <text class="crown-icon">👑</text>
  10. <text class="title">VIP会员特权</text>
  11. <text class="subtitle">开通会员,享受专属服务</text>
  12. </view>
  13. <!-- 特权列表 -->
  14. <view class="privileges-section">
  15. <view class="privilege-item" v-for="(item, index) in privileges" :key="index">
  16. <view class="privilege-icon">{{ item.icon }}</view>
  17. <view class="privilege-content">
  18. <text class="privilege-title">{{ item.title }}</text>
  19. <text class="privilege-desc">{{ item.desc }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- VIP套餐 -->
  24. <view class="packages-section">
  25. <view class="section-title">选择套餐</view>
  26. <view class="packages-list">
  27. <view
  28. class="package-card"
  29. v-for="(pkg, index) in packages"
  30. :key="index"
  31. :class="{ 'active': selectedPackage === index }"
  32. @click="selectPackage(index)"
  33. >
  34. <text class="package-name">{{ pkg.name }}</text>
  35. <view class="package-price">
  36. <text class="price-symbol">¥</text>
  37. <text class="price-value">{{ pkg.price }}</text>
  38. <text class="price-unit">/{{ pkg.duration }}</text>
  39. </view>
  40. <text class="package-original" v-if="pkg.originalPrice">原价 ¥{{ pkg.originalPrice }}</text>
  41. <view class="package-benefits">
  42. <text class="benefit-item" v-for="(benefit, idx) in pkg.benefits" :key="idx">
  43. {{ benefit }}
  44. </text>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 底部占位 -->
  50. <view class="bottom-placeholder"></view>
  51. <!-- 底部购买按钮 -->
  52. <view class="bottom-bar">
  53. <view class="total-info">
  54. <text class="total-label">合计:</text>
  55. <text class="total-price" v-if="selectedPackagePrice > 0">¥{{ selectedPackagePrice }}</text>
  56. <text class="total-price-hint" v-else>请选择套餐</text>
  57. </view>
  58. <button class="buy-btn" @click="handlePurchase">立即开通</button>
  59. </view>
  60. </scroll-view>
  61. </template>
  62. <script>
  63. import userAuth from '@/utils/userAuth.js'
  64. export default {
  65. data() {
  66. return {
  67. gatewayURL: 'http://localhost:8083',
  68. currentUserId: null,
  69. selectedPackage: null, // 默认不选中任何套餐
  70. isVip: false,
  71. vipExpireTime: null,
  72. remainingDays: 0,
  73. privileges: [
  74. {
  75. icon: '👑',
  76. title: '专属身份标识',
  77. desc: '尊贵VIP标识,提升个人魅力'
  78. },
  79. {
  80. icon: '💎',
  81. title: '优先推荐',
  82. desc: '优先展示给优质用户,提高匹配率'
  83. },
  84. {
  85. icon: '💌',
  86. title: '无限查看联系方式',
  87. desc: '查看心仪对象的联系方式,无限制'
  88. },
  89. {
  90. icon: '👀',
  91. title: '查看访客记录',
  92. desc: '查看谁看过你,主动出击'
  93. },
  94. {
  95. icon: '📞',
  96. title: '专属红娘服务',
  97. desc: '一对一专属红娘,贴心服务'
  98. },
  99. {
  100. icon: '🎉',
  101. title: '线下活动优先',
  102. desc: '优先参加平台举办的线下活动'
  103. }
  104. ],
  105. packages: []
  106. }
  107. },
  108. onLoad() {
  109. // 获取登录用户ID - 使用修复后的工具类
  110. this.currentUserId = userAuth.getUserId()
  111. console.log('=== VIP页面调试信息 ===')
  112. console.log('获取到的用户ID:', this.currentUserId)
  113. console.log('存储的userId:', uni.getStorageSync('userId'))
  114. console.log('存储的userInfo:', uni.getStorageSync('userInfo'))
  115. console.log('存储的token:', uni.getStorageSync('token'))
  116. // 加载VIP信息
  117. this.loadVipInfo()
  118. },
  119. computed: {
  120. selectedPackagePrice() {
  121. if (this.selectedPackage === null || this.selectedPackage === undefined) {
  122. return 0
  123. }
  124. return this.packages[this.selectedPackage]?.price || 0
  125. }
  126. },
  127. methods: {
  128. // 加载VIP信息
  129. loadVipInfo() {
  130. const params = {}
  131. if (this.currentUserId) {
  132. params.userId = this.currentUserId
  133. }
  134. uni.request({
  135. url: this.gatewayURL + '/api/vip/info',
  136. method: 'GET',
  137. data: params,
  138. success: (res) => {
  139. console.log('VIP信息:', res.data)
  140. if (res.data && res.data.code === 200) {
  141. const data = res.data.data
  142. // 更新VIP状态
  143. this.isVip = data.isVip
  144. this.vipExpireTime = data.vipExpireTime
  145. this.remainingDays = data.remainingDays
  146. // 更新套餐列表
  147. this.packages = data.packages.map(pkg => ({
  148. packageId: pkg.packageId,
  149. name: pkg.name,
  150. price: pkg.price,
  151. originalPrice: pkg.originalPrice,
  152. duration: pkg.duration,
  153. benefits: pkg.benefits,
  154. recommend: pkg.recommend
  155. }))
  156. // 不自动选中任何套餐,让用户手动选择
  157. }
  158. },
  159. fail: (err) => {
  160. console.error('获取VIP信息失败:', err)
  161. uni.showToast({
  162. title: '加载VIP信息失败',
  163. icon: 'none'
  164. })
  165. }
  166. })
  167. },
  168. goBack() {
  169. uni.navigateBack({
  170. delta: 1
  171. })
  172. },
  173. selectPackage(index) {
  174. this.selectedPackage = index
  175. },
  176. handlePurchase() {
  177. // 检查是否选择了套餐
  178. if (this.selectedPackage === null || this.selectedPackage === undefined) {
  179. uni.showToast({
  180. title: '请先选择一个套餐',
  181. icon: 'none'
  182. })
  183. return
  184. }
  185. const pkg = this.packages[this.selectedPackage]
  186. if (!pkg) {
  187. uni.showToast({
  188. title: '请选择套餐',
  189. icon: 'none'
  190. })
  191. return
  192. }
  193. // 获取用户ID
  194. const userId = this.currentUserId || 1
  195. uni.showModal({
  196. title: '确认开通',
  197. content: `确认开通${pkg.name}(¥${pkg.price})?`,
  198. success: (res) => {
  199. if (res.confirm) {
  200. // 调用后端购买接口
  201. uni.showLoading({
  202. title: '处理中...'
  203. })
  204. uni.request({
  205. url: this.gatewayURL + '/api/vip/purchase?userId=' + userId + '&packageId=' + pkg.packageId,
  206. method: 'POST',
  207. success: (res) => {
  208. uni.hideLoading()
  209. if (res.data && res.data.code === 200) {
  210. console.log('✅ VIP购买成功')
  211. uni.showToast({
  212. title: 'VIP开通成功!',
  213. icon: 'success',
  214. duration: 2000
  215. })
  216. // 延迟返回上一页,并触发页面刷新
  217. setTimeout(() => {
  218. // 通过事件通知个人页面刷新数据
  219. uni.$emit('vipPurchased')
  220. // 返回上一页
  221. uni.navigateBack({
  222. success: () => {
  223. console.log('✅ 返回个人页面')
  224. }
  225. })
  226. }, 2000)
  227. } else {
  228. uni.showToast({
  229. title: res.data?.message || 'VIP开通失败',
  230. icon: 'none'
  231. })
  232. }
  233. },
  234. fail: (err) => {
  235. uni.hideLoading()
  236. console.error('VIP购买失败:', err)
  237. uni.showToast({
  238. title: '网络请求失败',
  239. icon: 'none'
  240. })
  241. }
  242. })
  243. }
  244. }
  245. })
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. /* 扁平化设计 - 金色VIP主题 */
  252. .vip-page {
  253. height: 100vh;
  254. background: #F5F5F5;
  255. }
  256. .bottom-placeholder {
  257. height: 180rpx;
  258. }
  259. /* 顶部背景 - 金色主题 */
  260. .header-bg {
  261. background: linear-gradient(135deg, #FFB300 0%, #FFA000 100%);
  262. padding: 60rpx 60rpx 120rpx;
  263. padding-top: calc(60rpx + env(safe-area-inset-top));
  264. text-align: center;
  265. position: relative;
  266. border-bottom: 4rpx solid #FF8F00;
  267. .back-btn {
  268. position: absolute;
  269. left: 30rpx;
  270. top: calc(60rpx + env(safe-area-inset-top));
  271. width: 70rpx;
  272. height: 70rpx;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. z-index: 10;
  277. background: rgba(255, 255, 255, 0.2);
  278. border-radius: 8rpx;
  279. transition: all 0.2s ease;
  280. &:active {
  281. opacity: 0.8;
  282. }
  283. .back-icon {
  284. font-size: 48rpx;
  285. color: #FFFFFF;
  286. font-weight: bold;
  287. }
  288. }
  289. .crown-icon {
  290. font-size: 120rpx;
  291. margin-bottom: 20rpx;
  292. display: block;
  293. filter: drop-shadow(0 4rpx 8rpx rgba(0, 0, 0, 0.2));
  294. }
  295. .title {
  296. display: block;
  297. font-size: 44rpx;
  298. font-weight: bold;
  299. color: #FFFFFF;
  300. margin-bottom: 15rpx;
  301. letter-spacing: 2rpx;
  302. }
  303. .subtitle {
  304. display: block;
  305. font-size: 26rpx;
  306. color: #FFFFFF;
  307. opacity: 0.95;
  308. }
  309. }
  310. /* 特权列表 - 扁平化金色主题 */
  311. .privileges-section {
  312. margin: -20rpx 30rpx 30rpx;
  313. background-color: #FFFFFF;
  314. border-radius: 16rpx;
  315. padding: 35rpx 30rpx;
  316. border: 2rpx solid #E0E0E0;
  317. .section-title {
  318. font-size: 30rpx;
  319. font-weight: bold;
  320. color: #333333;
  321. margin-bottom: 25rpx;
  322. text-align: center;
  323. }
  324. .privilege-item {
  325. display: flex;
  326. align-items: flex-start;
  327. margin-bottom: 25rpx;
  328. padding: 20rpx;
  329. background: #FFFBF0;
  330. border-radius: 12rpx;
  331. border: 2rpx solid #FFE082;
  332. transition: all 0.2s ease;
  333. &:active {
  334. background: #FFF8E1;
  335. }
  336. &:last-child {
  337. margin-bottom: 0;
  338. }
  339. .privilege-icon {
  340. width: 70rpx;
  341. height: 70rpx;
  342. background: #FFF3E0;
  343. border-radius: 12rpx;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. font-size: 36rpx;
  348. margin-right: 20rpx;
  349. flex-shrink: 0;
  350. border: 2rpx solid #FFD54F;
  351. }
  352. .privilege-content {
  353. flex: 1;
  354. min-width: 0;
  355. overflow: hidden;
  356. .privilege-title {
  357. display: block;
  358. font-size: 28rpx;
  359. font-weight: bold;
  360. color: #333333;
  361. margin-bottom: 8rpx;
  362. word-wrap: break-word;
  363. word-break: break-all;
  364. white-space: normal;
  365. }
  366. .privilege-desc {
  367. display: block;
  368. font-size: 22rpx;
  369. color: #999999;
  370. line-height: 1.4;
  371. word-wrap: break-word;
  372. white-space: normal;
  373. }
  374. }
  375. }
  376. }
  377. /* 套餐列表 - 金色主题 */
  378. .packages-section {
  379. margin: 30rpx;
  380. .section-title {
  381. font-size: 32rpx;
  382. font-weight: bold;
  383. color: #333333;
  384. margin-bottom: 25rpx;
  385. text-align: center;
  386. padding-bottom: 15rpx;
  387. border-bottom: 3rpx solid #FFB300;
  388. }
  389. .packages-list {
  390. display: flex;
  391. flex-direction: column;
  392. gap: 20rpx;
  393. .package-card {
  394. background-color: #FFFFFF;
  395. border-radius: 16rpx;
  396. padding: 35rpx 30rpx;
  397. position: relative;
  398. border: 3rpx solid #E0E0E0;
  399. transition: all 0.2s ease;
  400. &:active {
  401. transform: translateY(-2rpx);
  402. }
  403. .package-name {
  404. font-size: 34rpx;
  405. font-weight: bold;
  406. color: #333333;
  407. margin-bottom: 15rpx;
  408. display: block;
  409. }
  410. .package-price {
  411. display: flex;
  412. align-items: baseline;
  413. margin-bottom: 8rpx;
  414. .price-symbol {
  415. font-size: 30rpx;
  416. color: #FFB300;
  417. font-weight: bold;
  418. }
  419. .price-value {
  420. font-size: 52rpx;
  421. font-weight: bold;
  422. color: #FFB300;
  423. margin: 0 5rpx;
  424. }
  425. .price-unit {
  426. font-size: 26rpx;
  427. color: #999999;
  428. }
  429. }
  430. .package-original {
  431. font-size: 24rpx;
  432. color: #CCCCCC;
  433. text-decoration: line-through;
  434. margin-bottom: 18rpx;
  435. display: block;
  436. }
  437. .package-benefits {
  438. display: flex;
  439. flex-wrap: wrap;
  440. gap: 12rpx;
  441. .benefit-item {
  442. background: #FFF3E0;
  443. padding: 8rpx 20rpx;
  444. border-radius: 8rpx;
  445. font-size: 22rpx;
  446. color: #F57C00;
  447. border: 1rpx solid #FFD54F;
  448. font-weight: 500;
  449. }
  450. }
  451. &.active {
  452. background: linear-gradient(135deg, #FFFBF0 0%, #FFF8E1 100%);
  453. border-color: #FFB300;
  454. border-width: 4rpx;
  455. &::before {
  456. content: '✓ 已选择';
  457. position: absolute;
  458. top: 20rpx;
  459. right: 20rpx;
  460. background: #FFB300;
  461. color: #FFFFFF;
  462. padding: 6rpx 16rpx;
  463. border-radius: 6rpx;
  464. font-size: 22rpx;
  465. font-weight: 600;
  466. }
  467. }
  468. }
  469. }
  470. }
  471. /* 底部购买按钮 - 金色主题 */
  472. .bottom-bar {
  473. position: fixed;
  474. bottom: 0;
  475. left: 0;
  476. right: 0;
  477. background-color: #FFFFFF;
  478. padding: 20rpx 30rpx;
  479. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  480. border-top: 2rpx solid #E0E0E0;
  481. display: flex;
  482. align-items: center;
  483. justify-content: space-between;
  484. z-index: 999;
  485. .total-info {
  486. display: flex;
  487. align-items: baseline;
  488. .total-label {
  489. font-size: 28rpx;
  490. color: #666666;
  491. font-weight: 500;
  492. }
  493. .total-price {
  494. font-size: 48rpx;
  495. font-weight: bold;
  496. color: #FFB300;
  497. margin-left: 10rpx;
  498. }
  499. .total-price-hint {
  500. font-size: 28rpx;
  501. color: #999999;
  502. margin-left: 10rpx;
  503. }
  504. }
  505. .buy-btn {
  506. background: linear-gradient(135deg, #FFB300 0%, #FFA000 100%);
  507. color: #FFFFFF;
  508. padding: 20rpx 60rpx;
  509. border-radius: 50rpx;
  510. font-size: 30rpx;
  511. font-weight: bold;
  512. border: none;
  513. box-shadow: 0 6rpx 16rpx rgba(255, 179, 0, 0.4);
  514. transition: all 0.2s ease;
  515. &:active {
  516. transform: translateY(2rpx);
  517. box-shadow: 0 4rpx 12rpx rgba(255, 179, 0, 0.3);
  518. }
  519. &::after {
  520. border: none;
  521. }
  522. }
  523. }
  524. </style>