index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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/inf',
  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. fail: (err) => {
  159. console.error('获取VIP信息失败:', err)
  160. uni.showToast({
  161. title: '加载VIP信息失败',
  162. icon: 'none'
  163. })
  164. }
  165. })
  166. },
  167. goBack() {
  168. uni.navigateBack({
  169. delta: 1
  170. })
  171. },
  172. selectPackage(index) {
  173. this.selectedPackage = index
  174. },
  175. handlePurchase() {
  176. // 检查是否选择了套餐
  177. if (this.selectedPackage === null || this.selectedPackage === undefined) {
  178. uni.showToast({
  179. title: '请先选择一个套餐',
  180. icon: 'none'
  181. })
  182. return
  183. }
  184. const pkg = this.packages[this.selectedPackage]
  185. if (!pkg) {
  186. uni.showToast({
  187. title: '请选择套餐',
  188. icon: 'none'
  189. })
  190. return
  191. }
  192. // 获取用户ID
  193. const userId = this.currentUserId || 1
  194. uni.showModal({
  195. title: '确认开通',
  196. content: `确认开通${pkg.name}(¥${pkg.price})?`,
  197. success: (res) => {
  198. if (res.confirm) {
  199. this.requestPay(userId, pkg)
  200. }
  201. }
  202. })
  203. },
  204. /**
  205. * 请求支付参数并调起微信支付
  206. */
  207. requestPay(userId, pkg) {
  208. uni.showLoading({
  209. title: '处理中...'
  210. })
  211. uni.request({
  212. url: this.gatewayURL + '/api/vip/purchase',
  213. method: 'POST',
  214. data: {
  215. userId: userId,
  216. packageId: pkg.packageId
  217. },
  218. header: {
  219. 'content-type': 'application/json',
  220. 'token': uni.getStorageSync('token') // 携带登录态
  221. },
  222. success: (res) => {
  223. uni.hideLoading()
  224. if (res.data && res.data.code === 200) {
  225. const payParams = res.data.ext // 后端返回的支付参数
  226. this.callWxPay(payParams, pkg) // 调起微信支付
  227. } else {
  228. uni.showToast({
  229. title: res.data?.message || '获取支付参数失败',
  230. icon: 'none'
  231. })
  232. }
  233. },
  234. fail: (err) => {
  235. uni.hideLoading()
  236. console.error('请求支付参数失败:', err)
  237. uni.showToast({
  238. title: '网络请求失败',
  239. icon: 'none'
  240. })
  241. }
  242. })
  243. },
  244. /**
  245. * 调起微信支付组件
  246. */
  247. callWxPay(payParams, pkg) {
  248. uni.requestPayment({
  249. provider: 'wxpay',
  250. timeStamp: payParams.timeStamp,
  251. nonceStr: payParams.nonceStr,
  252. package: payParams.package,
  253. signType: payParams.signType,
  254. paySign: payParams.paySign,
  255. total_fee: payParams.totalFee,
  256. success: (payResult) => {
  257. if (payResult.errMsg === 'requestPayment:ok') {
  258. uni.showToast({
  259. title: '支付成功!VIP已开通',
  260. icon: 'success',
  261. duration: 2000
  262. })
  263. // 延迟返回上一页,并触发页面刷新
  264. setTimeout(() => {
  265. // 通过事件通知个人页面刷新数据
  266. uni.$emit('vipPurchased')
  267. // 返回上一页
  268. uni.navigateBack({
  269. success: () => {
  270. console.log('✅ 返回个人页面')
  271. }
  272. })
  273. }, 2000)
  274. }
  275. },
  276. fail: (payError) => {
  277. console.error('支付失败:', payError)
  278. if (payError.errMsg.includes('cancel')) {
  279. uni.showToast({
  280. title: '已取消支付',
  281. icon: 'none'
  282. })
  283. } else {
  284. uni.showToast({
  285. title: `支付失败:${payError.errMsg}`,
  286. icon: 'none'
  287. })
  288. }
  289. }
  290. })
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. /* 原有样式保持不变 */
  297. .vip-page {
  298. height: 100vh;
  299. background: #F5F5F5;
  300. }
  301. .bottom-placeholder {
  302. height: 180rpx;
  303. }
  304. .header-bg {
  305. background: linear-gradient(135deg, #FFB300 0%, #FFA000 100%);
  306. padding: 60rpx 60rpx 120rpx;
  307. padding-top: calc(60rpx + env(safe-area-inset-top));
  308. text-align: center;
  309. position: relative;
  310. border-bottom: 4rpx solid #FF8F00;
  311. .back-btn {
  312. position: absolute;
  313. left: 30rpx;
  314. top: calc(60rpx + env(safe-area-inset-top));
  315. width: 70rpx;
  316. height: 70rpx;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. z-index: 10;
  321. background: rgba(255, 255, 255, 0.2);
  322. border-radius: 8rpx;
  323. transition: all 0.2s ease;
  324. &:active {
  325. opacity: 0.8;
  326. }
  327. .back-icon {
  328. font-size: 48rpx;
  329. color: #FFFFFF;
  330. font-weight: bold;
  331. }
  332. }
  333. .crown-icon {
  334. font-size: 120rpx;
  335. margin-bottom: 20rpx;
  336. display: block;
  337. filter: drop-shadow(0 4rpx 8rpx rgba(0, 0, 0, 0.2));
  338. }
  339. .title {
  340. display: block;
  341. font-size: 44rpx;
  342. font-weight: bold;
  343. color: #FFFFFF;
  344. margin-bottom: 15rpx;
  345. letter-spacing: 2rpx;
  346. }
  347. .subtitle {
  348. display: block;
  349. font-size: 26rpx;
  350. color: #FFFFFF;
  351. opacity: 0.95;
  352. }
  353. }
  354. .privileges-section {
  355. margin: -20rpx 30rpx 30rpx;
  356. background-color: #FFFFFF;
  357. border-radius: 16rpx;
  358. padding: 35rpx 30rpx;
  359. border: 2rpx solid #E0E0E0;
  360. .section-title {
  361. font-size: 30rpx;
  362. font-weight: bold;
  363. color: #333333;
  364. margin-bottom: 25rpx;
  365. text-align: center;
  366. }
  367. .privilege-item {
  368. display: flex;
  369. align-items: flex-start;
  370. margin-bottom: 25rpx;
  371. padding: 20rpx;
  372. background: #FFFBF0;
  373. border-radius: 12rpx;
  374. border: 2rpx solid #FFE082;
  375. transition: all 0.2s ease;
  376. &:active {
  377. background: #FFF8E1;
  378. }
  379. &:last-child {
  380. margin-bottom: 0;
  381. }
  382. .privilege-icon {
  383. width: 70rpx;
  384. height: 70rpx;
  385. background: #FFF3E0;
  386. border-radius: 12rpx;
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. font-size: 36rpx;
  391. margin-right: 20rpx;
  392. flex-shrink: 0;
  393. border: 2rpx solid #FFD54F;
  394. }
  395. .privilege-content {
  396. flex: 1;
  397. min-width: 0;
  398. overflow: hidden;
  399. .privilege-title {
  400. display: block;
  401. font-size: 28rpx;
  402. font-weight: bold;
  403. color: #333333;
  404. margin-bottom: 8rpx;
  405. word-wrap: break-word;
  406. word-break: break-all;
  407. white-space: normal;
  408. }
  409. .privilege-desc {
  410. display: block;
  411. font-size: 22rpx;
  412. color: #999999;
  413. line-height: 1.4;
  414. word-wrap: break-word;
  415. white-space: normal;
  416. }
  417. }
  418. }
  419. }
  420. .packages-section {
  421. margin: 30rpx;
  422. .section-title {
  423. font-size: 32rpx;
  424. font-weight: bold;
  425. color: #333333;
  426. margin-bottom: 25rpx;
  427. text-align: center;
  428. padding-bottom: 15rpx;
  429. border-bottom: 3rpx solid #FFB300;
  430. }
  431. .packages-list {
  432. display: flex;
  433. flex-direction: column;
  434. gap: 20rpx;
  435. .package-card {
  436. background-color: #FFFFFF;
  437. border-radius: 16rpx;
  438. padding: 35rpx 30rpx;
  439. position: relative;
  440. border: 3rpx solid #E0E0E0;
  441. transition: all 0.2s ease;
  442. &:active {
  443. transform: translateY(-2rpx);
  444. }
  445. .package-name {
  446. font-size: 34rpx;
  447. font-weight: bold;
  448. color: #333333;
  449. margin-bottom: 15rpx;
  450. display: block;
  451. }
  452. .package-price {
  453. display: flex;
  454. align-items: baseline;
  455. margin-bottom: 8rpx;
  456. .price-symbol {
  457. font-size: 30rpx;
  458. color: #FFB300;
  459. font-weight: bold;
  460. }
  461. .price-value {
  462. font-size: 52rpx;
  463. font-weight: bold;
  464. color: #FFB300;
  465. margin: 0 5rpx;
  466. }
  467. .price-unit {
  468. font-size: 26rpx;
  469. color: #999999;
  470. }
  471. }
  472. .package-original {
  473. font-size: 24rpx;
  474. color: #CCCCCC;
  475. text-decoration: line-through;
  476. margin-bottom: 18rpx;
  477. display: block;
  478. }
  479. .package-benefits {
  480. display: flex;
  481. flex-wrap: wrap;
  482. gap: 12rpx;
  483. .benefit-item {
  484. background: #FFF3E0;
  485. padding: 8rpx 20rpx;
  486. border-radius: 8rpx;
  487. font-size: 22rpx;
  488. color: #F57C00;
  489. border: 1rpx solid #FFD54F;
  490. font-weight: 500;
  491. }
  492. }
  493. &.active {
  494. background: linear-gradient(135deg, #FFFBF0 0%, #FFF8E1 100%);
  495. border-color: #FFB300;
  496. border-width: 4rpx;
  497. &::before {
  498. content: '✓ 已选择';
  499. position: absolute;
  500. top: 20rpx;
  501. right: 20rpx;
  502. background: #FFB300;
  503. color: #FFFFFF;
  504. padding: 6rpx 16rpx;
  505. border-radius: 6rpx;
  506. font-size: 22rpx;
  507. font-weight: 600;
  508. }
  509. }
  510. }
  511. }
  512. }
  513. .bottom-bar {
  514. position: fixed;
  515. bottom: 0;
  516. left: 0;
  517. right: 0;
  518. background-color: #FFFFFF;
  519. padding: 20rpx 30rpx;
  520. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  521. border-top: 2rpx solid #E0E0E0;
  522. display: flex;
  523. align-items: center;
  524. justify-content: space-between;
  525. z-index: 999;
  526. .total-info {
  527. display: flex;
  528. align-items: baseline;
  529. .total-label {
  530. font-size: 28rpx;
  531. color: #666666;
  532. font-weight: 500;
  533. }
  534. .total-price {
  535. font-size: 48rpx;
  536. font-weight: bold;
  537. color: #FFB300;
  538. margin-left: 10rpx;
  539. }
  540. .total-price-hint {
  541. font-size: 28rpx;
  542. color: #999999;
  543. margin-left: 10rpx;
  544. }
  545. }
  546. .buy-btn {
  547. background: linear-gradient(135deg, #FFB300 0%, #FFA000 100%);
  548. color: #FFFFFF;
  549. padding: 20rpx 60rpx;
  550. border-radius: 50rpx;
  551. font-size: 30rpx;
  552. font-weight: bold;
  553. border: none;
  554. box-shadow: 0 6rpx 16rpx rgba(255, 179, 0, 0.4);
  555. transition: all 0.2s ease;
  556. &:active {
  557. transform: translateY(2rpx);
  558. box-shadow: 0 4rpx 12rpx rgba(255, 179, 0, 0.3);
  559. }
  560. &::after {
  561. border: none;
  562. }
  563. }
  564. }
  565. </style>