index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <view class="page-payment">
  3. <view class="header">
  4. <text class="header-title">{{ pageTitle }}</text>
  5. <text class="header-desc">{{ pageDesc }}</text>
  6. </view>
  7. <template v-if="loading">
  8. <view class="loading-state"><text class="loading-text">加载中...</text></view>
  9. </template>
  10. <template v-else-if="product === 'annual'">
  11. <!-- C端年费 ¥131 -->
  12. <view class="plan-card selected">
  13. <view class="plan-badge popular">推荐</view>
  14. <view class="plan-top">
  15. <text class="plan-name">C端会员</text>
  16. <view class="plan-price-row">
  17. <text class="price-symbol">¥</text>
  18. <text class="price">{{ formatYuan(pricing.annualFee) }}</text>
  19. <text class="per">/年</text>
  20. </view>
  21. <text class="price-daily">每天仅 ¥{{ (pricing.annualFee / 100 / 365).toFixed(2) }}</text>
  22. </view>
  23. <view class="plan-features">
  24. <text class="feature">✦ AI 互动问答 — 无限次</text>
  25. <text class="feature">✦ 获得推广权限,赚取佣金</text>
  26. <text class="feature">✦ 一级 40% + 二级 5% 佣金比例</text>
  27. <text class="feature">✦ VIP 标识</text>
  28. </view>
  29. </view>
  30. <button class="pay-btn" @click="onPay" :disabled="paying">
  31. {{ paying ? '处理中...' : `立即开通 · C端会员 ¥${formatYuan(pricing.annualFee)}/年` }}
  32. </button>
  33. </template>
  34. <template v-else-if="product === 'practitioner'">
  35. <!-- 能量师 种子价/标准价 -->
  36. <view class="plan-card plan-pro selected">
  37. <view class="plan-badge pro">专业</view>
  38. <view class="plan-top">
  39. <text class="plan-name">能量师</text>
  40. <view class="plan-price-row">
  41. <text class="price-symbol">¥</text>
  42. <text class="price">{{ formatYuan(currentPrice) }}</text>
  43. <text class="per">/年</text>
  44. </view>
  45. <view v-if="pricing.isSeedPrice" class="seed-badge">
  46. 种子价 · 仅剩 {{ pricing.remainingSeats }}/{{ pricing.seedLimit }} 个名额
  47. </view>
  48. <text v-else class="standard-label">标准定价</text>
  49. <!-- US-4.4 Upgrade breakdown -->
  50. <view v-if="isUpgrade" class="upgrade-info">
  51. <view class="upgrade-row">
  52. <text class="upgrade-label">原年费金额</text>
  53. <text class="upgrade-value">¥{{ formatYuan(pricing.originalPaidAmount) }}</text>
  54. </view>
  55. <view class="upgrade-row">
  56. <text class="upgrade-label">年费剩余价值</text>
  57. <text class="upgrade-value minus">-¥{{ formatYuan(pricing.remainingValue) }}</text>
  58. </view>
  59. <view class="upgrade-row total">
  60. <text class="upgrade-label">应付差价</text>
  61. <text class="upgrade-value highlight">¥{{ formatYuan(pricing.upgradePrice) }}</text>
  62. </view>
  63. </view>
  64. <text class="price-daily">每天仅 ¥{{ (currentPrice / 100 / 365).toFixed(2) }}</text>
  65. </view>
  66. <view class="plan-features">
  67. <text class="feature">✦ 包含 C 端全部权益</text>
  68. <text class="feature">✦ 无限能量盘生成</text>
  69. <text class="feature">✦ AI 五区完整解读,随问随答</text>
  70. <text class="feature">✦ 全部历史记录永久保存</text>
  71. <text class="feature">✦ 推广佣金 — 固定 ¥500/人 + 二级 ¥100/人</text>
  72. </view>
  73. </view>
  74. <button class="pay-btn pro-btn" @click="onPay" :disabled="paying">
  75. {{ paying ? '处理中...' : `立即开通 · 能量师 ${priceLabel} ¥${formatYuan(currentPrice)}/年` }}
  76. </button>
  77. </template>
  78. <text class="note">支付即表示同意《订阅协议》</text>
  79. </view>
  80. </template>
  81. <script setup>
  82. import { ref, computed, onMounted } from 'vue'
  83. import { useUserStore } from '@/stores/user'
  84. import { payApi, pricingApi } from '@/utils/api'
  85. const userStore = useUserStore()
  86. const paying = ref(false)
  87. const loading = ref(true)
  88. const product = ref('annual')
  89. const isUpgrade = ref(false)
  90. const pricing = ref({
  91. seedPrice: 131400,
  92. standardPrice: 198600,
  93. annualFee: 13100,
  94. isSeedPrice: true,
  95. remainingSeats: 300,
  96. seedLimit: 300
  97. })
  98. const pageTitle = computed(() => {
  99. return product.value === 'annual' ? 'C端会员' : '能量师专业版'
  100. })
  101. const pageDesc = computed(() => {
  102. return product.value === 'annual' ? '解锁无限AI解读,获取推广佣金' : '获取完整能量盘分析、AI解读与分销推广权限'
  103. })
  104. const currentPrice = computed(() => {
  105. if (product.value === 'annual') return pricing.value.annualFee
  106. if (isUpgrade.value) return pricing.value.upgradePrice
  107. return pricing.value.isSeedPrice ? pricing.value.seedPrice : pricing.value.standardPrice
  108. })
  109. const priceLabel = computed(() => {
  110. if (isUpgrade.value) return '升级价'
  111. return pricing.value.isSeedPrice ? '种子价' : '标准价'
  112. })
  113. function formatYuan(cents) {
  114. if (cents == null) return '0'
  115. return (cents / 100).toLocaleString()
  116. }
  117. onMounted(async () => {
  118. // Ensure user profile is loaded (vipType, etc.)
  119. try {
  120. await userStore.fetchProfile()
  121. } catch (e) {
  122. // ignore, use cached
  123. }
  124. // Read product param from URL
  125. const pages = getCurrentPages()
  126. const page = pages[pages.length - 1]
  127. const params = page?.options || {}
  128. product.value = params.product || 'annual'
  129. // Determine upgrade scenario: annual member upgrading to practitioner
  130. if (product.value === 'practitioner' && userStore.vipType === 'annual') {
  131. isUpgrade.value = true
  132. }
  133. // Always get base pricing first (isSeedPrice + correct practitioner price)
  134. try {
  135. const res = await pricingApi.current()
  136. if (res) pricing.value = res
  137. } catch (e) {
  138. // Use defaults if API fails
  139. }
  140. // If upgrade, overlay upgrade-specific fields (upgradePrice, remainingValue, etc.)
  141. if (isUpgrade.value) {
  142. try {
  143. const upgradeRes = await pricingApi.upgrade()
  144. if (upgradeRes) {
  145. pricing.value = {
  146. ...pricing.value, // base: isSeedPrice, seedPrice, standardPrice, annualFee
  147. ...upgradeRes // overlay: upgradePrice, remainingValue, originalPaidAmount, usedDays
  148. }
  149. }
  150. } catch (e) {
  151. // Fallback: treat as non-upgrade
  152. isUpgrade.value = false
  153. }
  154. }
  155. loading.value = false
  156. })
  157. async function onPay() {
  158. paying.value = true
  159. try {
  160. const totalFee = currentPrice.value
  161. const productType = product.value
  162. await payApi.create({
  163. totalFee,
  164. payType: 'wxpay',
  165. productType,
  166. isUpgrade: isUpgrade.value
  167. })
  168. // Refresh user profile to reflect VIP status change
  169. await userStore.fetchProfile()
  170. uni.showToast({ title: '开通成功!', icon: 'success' })
  171. setTimeout(() => uni.navigateBack(), 1500)
  172. } catch (e) {
  173. uni.showToast({ title: '支付失败,请重试', icon: 'none' })
  174. }
  175. paying.value = false
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .page-payment {
  180. padding: 20px;
  181. min-height: 100vh;
  182. background: linear-gradient(180deg, #0c0a1a 0%, #120d28 60%, #0f0c1e 100%);
  183. }
  184. .header {
  185. text-align: center;
  186. margin-bottom: 20px;
  187. }
  188. .header-title {
  189. font-size: 22px;
  190. font-weight: 700;
  191. color: rgba(255,255,255,0.9);
  192. display: block;
  193. }
  194. .header-desc {
  195. font-size: 13px;
  196. color: rgba(255,255,255,0.4);
  197. margin-top: 6px;
  198. display: block;
  199. }
  200. .loading-state {
  201. padding: 60px 0;
  202. text-align: center;
  203. }
  204. .loading-text {
  205. font-size: 14px;
  206. color: rgba(255,255,255,0.3);
  207. }
  208. /* Plan Cards */
  209. .plan-card {
  210. position: relative;
  211. background: rgba(255,255,255,0.03);
  212. border: 1px solid rgba(255,255,255,0.08);
  213. border-radius: 16px;
  214. padding: 22px 18px 18px;
  215. margin-bottom: 12px;
  216. }
  217. .plan-card.selected {
  218. border-color: #fbbf24;
  219. background: rgba(251,191,36,0.06);
  220. }
  221. .plan-card.plan-pro.selected {
  222. border-color: #a78bfa;
  223. background: rgba(167,139,250,0.06);
  224. }
  225. .plan-badge {
  226. position: absolute;
  227. top: -1px;
  228. right: 20px;
  229. font-size: 11px;
  230. font-weight: 600;
  231. padding: 3px 14px;
  232. border-radius: 0 0 8px 8px;
  233. }
  234. .plan-badge.popular {
  235. background: #f59e0b;
  236. color: #fff;
  237. }
  238. .plan-badge.pro {
  239. background: #7c3aed;
  240. color: #fff;
  241. }
  242. .plan-top { text-align: center; }
  243. .plan-name {
  244. font-size: 17px;
  245. font-weight: 600;
  246. color: rgba(255,255,255,0.85);
  247. display: block;
  248. margin-bottom: 10px;
  249. }
  250. .plan-price-row {
  251. display: flex;
  252. align-items: baseline;
  253. justify-content: center;
  254. }
  255. .price-symbol {
  256. font-size: 20px;
  257. color: #fbbf24;
  258. font-weight: 600;
  259. }
  260. .price {
  261. font-size: 38px;
  262. font-weight: 700;
  263. color: #fbbf24;
  264. margin: 0 2px;
  265. }
  266. .plan-pro .price-symbol,
  267. .plan-pro .price {
  268. color: #a78bfa;
  269. }
  270. .per {
  271. font-size: 14px;
  272. color: rgba(255,255,255,0.4);
  273. }
  274. .price-daily {
  275. display: block;
  276. font-size: 12px;
  277. color: rgba(255,255,255,0.3);
  278. margin-top: 4px;
  279. }
  280. .seed-badge {
  281. display: inline-block;
  282. margin-top: 6px;
  283. font-size: 11px;
  284. color: #fbbf24;
  285. background: rgba(251,191,36,0.12);
  286. padding: 2px 12px;
  287. border-radius: 4px;
  288. }
  289. .standard-label {
  290. display: inline-block;
  291. margin-top: 6px;
  292. font-size: 11px;
  293. color: rgba(255,255,255,0.35);
  294. padding: 2px 12px;
  295. border-radius: 4px;
  296. border: 1px solid rgba(255,255,255,0.1);
  297. }
  298. /* US-4.4 Upgrade breakdown */
  299. .upgrade-info {
  300. margin-top: 12px;
  301. padding: 10px 12px;
  302. background: rgba(255,255,255,0.04);
  303. border-radius: 8px;
  304. border: 1px dashed rgba(255,255,255,0.15);
  305. }
  306. .upgrade-row {
  307. display: flex;
  308. justify-content: space-between;
  309. align-items: center;
  310. font-size: 13px;
  311. margin-bottom: 6px;
  312. }
  313. .upgrade-row:last-child {
  314. margin-bottom: 0;
  315. }
  316. .upgrade-row.total {
  317. margin-top: 6px;
  318. padding-top: 6px;
  319. border-top: 1px solid rgba(255,255,255,0.1);
  320. }
  321. .upgrade-label {
  322. color: rgba(255,255,255,0.5);
  323. }
  324. .upgrade-value {
  325. color: rgba(255,255,255,0.9);
  326. font-weight: 500;
  327. }
  328. .upgrade-value.minus {
  329. color: #fbbf24;
  330. }
  331. .upgrade-value.highlight {
  332. color: #a78bfa;
  333. font-weight: 600;
  334. }
  335. .plan-features {
  336. margin-top: 16px;
  337. }
  338. .feature {
  339. display: block;
  340. padding: 5px 0;
  341. font-size: 13px;
  342. color: rgba(255,255,255,0.6);
  343. line-height: 1.5;
  344. }
  345. .plan-card.selected .feature {
  346. color: rgba(255,255,255,0.8);
  347. }
  348. .pay-btn {
  349. width: 100%;
  350. padding: 16px;
  351. background: linear-gradient(135deg, #f59e0b, #d97706);
  352. color: #fff;
  353. border: none;
  354. border-radius: 14px;
  355. font-size: 17px;
  356. font-weight: 600;
  357. letter-spacing: 2px;
  358. margin-bottom: 8px;
  359. }
  360. .pay-btn.pro-btn {
  361. background: linear-gradient(135deg, #7c3aed, #6d28d9);
  362. }
  363. .pay-btn[disabled] { opacity: 0.4; }
  364. .note {
  365. display: block;
  366. text-align: center;
  367. font-size: 12px;
  368. color: rgba(255,255,255,0.25);
  369. }
  370. </style>