index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="page-payment">
  3. <view class="plan-card">
  4. <view class="plan-header">
  5. <text class="plan-name">VIP 会员</text>
  6. <text class="plan-price">¥398</text>
  7. <text class="plan-period">/ 年</text>
  8. </view>
  9. <view class="plan-features">
  10. <text class="feature">✓ 无限次数字能量分析</text>
  11. <text class="feature">✓ AI 深度解读报告</text>
  12. <text class="feature">✓ 号码标注与标签管理</text>
  13. <text class="feature">✓ 历史记录永久保存</text>
  14. <text class="feature">✓ 推广赚取佣金</text>
  15. </view>
  16. </view>
  17. <view class="order-summary">
  18. <text class="summary-title">订单摘要</text>
  19. <view class="summary-row">
  20. <text>VIP 会员年费</text>
  21. <text>¥398</text>
  22. </view>
  23. <view class="summary-row total">
  24. <text>合计</text>
  25. <text>¥398</text>
  26. </view>
  27. </view>
  28. <button class="pay-btn" @click="handlePay" :disabled="paying">
  29. {{ paying ? '支付中...' : '立即支付 ¥398' }}
  30. </button>
  31. </view>
  32. </template>
  33. <script setup>
  34. import { ref } from 'vue'
  35. import { payApi } from '@/utils/api'
  36. const paying = ref(false)
  37. async function handlePay() {
  38. paying.value = true
  39. try {
  40. const order = await payApi.create({ totalFee: 39800, payType: 'wxpay' })
  41. // Dev mode — WxPay returns mock prepay params directly
  42. if (order.mock) {
  43. // In dev/mock mode, simulate payment success
  44. uni.showToast({ title: '支付成功!', icon: 'success' })
  45. setTimeout(() => uni.navigateBack(), 1500)
  46. } else if (order.prepayId) {
  47. // Real WeChat Pay — invoke payment SDK
  48. uni.requestPayment({
  49. provider: 'wxpay',
  50. timeStamp: order.timeStamp,
  51. nonceStr: order.nonceStr,
  52. package: order.package,
  53. signType: order.signType || 'MD5',
  54. paySign: order.paySign,
  55. success: () => {
  56. uni.showToast({ title: '支付成功!', icon: 'success' })
  57. setTimeout(() => uni.navigateBack(), 1500)
  58. },
  59. fail: () => {
  60. uni.showToast({ title: '支付取消', icon: 'none' })
  61. }
  62. })
  63. }
  64. } catch (e) {
  65. uni.showToast({ title: '支付失败: ' + (e.message || ''), icon: 'none' })
  66. } finally {
  67. paying.value = false
  68. }
  69. }
  70. </script>
  71. <style scoped lang="scss">
  72. .page-payment { padding: 16px; }
  73. .plan-card {
  74. background: #fff; border-radius: 16px; padding: 24px;
  75. text-align: center; margin-bottom: 16px;
  76. }
  77. .plan-header { margin-bottom: 20px; }
  78. .plan-name { font-size: 20px; font-weight: 700; color: #1F2937; display: block; }
  79. .plan-price {
  80. font-size: 36px; font-weight: 800; color: #3B82F6; display: inline; margin-top: 8px;
  81. }
  82. .plan-period { font-size: 14px; color: #6B7280; }
  83. .plan-features { text-align: left; }
  84. .feature {
  85. display: block; padding: 6px 0; color: #4B5563; font-size: 14px;
  86. }
  87. .order-summary {
  88. background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 24px;
  89. }
  90. .summary-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; display: block; }
  91. .summary-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14px; }
  92. .summary-row.total { border-top: 1px solid #E5E7EB; margin-top: 8px; padding-top: 12px; font-weight: 700; }
  93. .pay-btn {
  94. width: 100%; height: 48px; background: #3B82F6; color: #fff;
  95. border: none; border-radius: 12px; font-size: 18px; line-height: 48px;
  96. }
  97. .pay-btn[disabled] { opacity: 0.6; }
  98. </style>