upgrade.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. <template>
  2. <view class="upgrade-page-wrapper">
  3. <scroll-view class="page" scroll-y>
  4. <!-- 当前会员状态卡片 -->
  5. <view class="status-card">
  6. <view class="status-badge" :class="isFree ? 'badge-free' : 'badge-family'">
  7. <text class="badge-icon">{{ isFree ? '○' : '●' }}</text>
  8. <text class="badge-text">{{ currentLevelName }}</text>
  9. </view>
  10. <view class="status-body" v-if="membership && membership.levelCode !== 'FREE'">
  11. <view class="expiry-row">
  12. <text class="expiry-label">到期时间</text>
  13. <text class="expiry-value">{{ formatDate(membership.endDate) }}</text>
  14. </view>
  15. <view class="days-remaining" v-if="membership.isActive">
  16. <text class="days-num">{{ membership.daysRemaining || 0 }}</text>
  17. <text class="days-unit">天剩余</text>
  18. </view>
  19. <view class="expired-msg" v-else>
  20. <text class="expired-text">会员已过期,续费恢复权益</text>
  21. </view>
  22. </view>
  23. <view class="status-body" v-else>
  24. <text class="free-hint">当前为免费版,开通家庭会员解锁全部特权</text>
  25. </view>
  26. </view>
  27. <!-- 家庭会员开通卡片 -->
  28. <view class="upgrade-card" v-if="isFree">
  29. <view class="upgrade-header">
  30. <text class="upgrade-title">家庭会员</text>
  31. <text class="upgrade-subtitle">FAMILY</text>
  32. </view>
  33. <view class="upgrade-price">
  34. <text class="price-symbol">¥</text>
  35. <text class="price-amount">365</text>
  36. <text class="price-unit">/年</text>
  37. </view>
  38. <view class="feature-list">
  39. <view class="feature-item" v-for="(feature, idx) in features" :key="idx">
  40. <text class="feature-check">✓</text>
  41. <text class="feature-text">{{ feature }}</text>
  42. </view>
  43. </view>
  44. <!-- Coupon section -->
  45. <view class="coupon-row" @click="openCouponPicker">
  46. <text class="coupon-row-label">优惠券</text>
  47. <text v-if="selectedCoupon" class="coupon-row-discount">-{{ formatPriceWithSymbol(selectedCoupon.value) }} {{ selectedCoupon.name }}</text>
  48. <text v-else class="coupon-row-placeholder">选择优惠券</text>
  49. <text class="coupon-row-arrow">›</text>
  50. </view>
  51. <button class="btn-upgrade" @click="handleUpgrade">立即开通</button>
  52. </view>
  53. <!-- 续费卡片 -->
  54. <view class="upgrade-card" v-else>
  55. <view class="upgrade-header">
  56. <text class="upgrade-title">续费会员</text>
  57. <text class="upgrade-subtitle">保持权益不中断</text>
  58. </view>
  59. <view class="upgrade-price">
  60. <text class="price-symbol">¥</text>
  61. <text class="price-amount">365</text>
  62. <text class="price-unit">/年</text>
  63. </view>
  64. <!-- Coupon section -->
  65. <view class="coupon-row" @click="openCouponPicker">
  66. <text class="coupon-row-label">优惠券</text>
  67. <text v-if="selectedCoupon" class="coupon-row-discount">-{{ formatPriceWithSymbol(selectedCoupon.value) }} {{ selectedCoupon.name }}</text>
  68. <text v-else class="coupon-row-placeholder">选择优惠券</text>
  69. <text class="coupon-row-arrow">›</text>
  70. </view>
  71. <button class="btn-upgrade btn-renew" @click="handleRenew">立即续费</button>
  72. </view>
  73. <!-- 权益对比表 -->
  74. <view class="compare-section">
  75. <text class="section-title">权益对比</text>
  76. <view class="compare-table">
  77. <view class="compare-row header-row">
  78. <text class="compare-cell cell-feature">权益项</text>
  79. <text class="compare-cell cell-free">免费</text>
  80. <text class="compare-cell cell-family active">家庭会员</text>
  81. </view>
  82. <view class="compare-row" v-for="(item, idx) in compareData" :key="idx">
  83. <text class="compare-cell cell-feature">{{ item.name }}</text>
  84. <text class="compare-cell cell-free">{{ item.free }}</text>
  85. <text class="compare-cell cell-family active">{{ item.family }}</text>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 升级记录 -->
  90. <view class="records-section" v-if="records.length > 0">
  91. <text class="section-title">升级记录</text>
  92. <view class="record-item" v-for="record in records" :key="record.id">
  93. <view class="record-left">
  94. <text class="record-level">{{ record.levelName }}</text>
  95. <text class="record-time">{{ formatDate(record.createdAt) }}</text>
  96. </view>
  97. <text class="record-amount">{{ formatPriceWithSymbol(record.amount) }}</text>
  98. </view>
  99. </view>
  100. </scroll-view>
  101. <!-- Coupon Picker Bottom Sheet -->
  102. <view class="modal-mask" v-if="showCouponPicker" @click="showCouponPicker = false">
  103. <view class="coupon-picker" @click.stop>
  104. <view class="picker-header">
  105. <text class="picker-title">选择优惠券</text>
  106. <text class="picker-close" @click="showCouponPicker = false">关闭</text>
  107. </view>
  108. <scroll-view scroll-y class="picker-list">
  109. <view
  110. v-for="coupon in availableCoupons"
  111. :key="coupon.id"
  112. class="picker-item"
  113. :class="selectedCoupon && selectedCoupon.id === coupon.id ? 'picker-item-active' : ''"
  114. @click="selectCoupon(coupon)"
  115. >
  116. <view class="picker-item-left">
  117. <text class="picker-item-value">{{ formatPriceWithSymbol(coupon.value) }}</text>
  118. </view>
  119. <view class="picker-item-right">
  120. <text class="picker-item-name">{{ coupon.name }}</text>
  121. <text class="picker-item-condition">{{ getCouponCondition(coupon.minSpend) }}</text>
  122. </view>
  123. <view class="picker-item-check" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
  124. <text>✓</text>
  125. </view>
  126. </view>
  127. <view class="picker-empty" v-if="availableCoupons.length === 0">
  128. <text>暂无可用优惠券</text>
  129. </view>
  130. </scroll-view>
  131. <view class="picker-footer" v-if="selectedCoupon">
  132. <button class="picker-btn-remove" @click="removeCoupon">不使用优惠券</button>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </template>
  138. <script>
  139. import { getMyMembership, getMembershipLevels, getUpgradeRecords, upgradeMember, createOrder, getCouponList } from '../../utils/api.js'
  140. export default {
  141. data() {
  142. return {
  143. membership: null,
  144. levels: [],
  145. records: [],
  146. features: ['折扣购物', '家庭管理', '推荐佣金', '专属活动', '任务特权', '成长报告'],
  147. isFree: true,
  148. currentLevelName: '免费用户',
  149. compareData: [
  150. { name: '商品折扣', free: '普通价格', family: '会员专享价' },
  151. { name: '家庭管理', free: '基础功能', family: '全部功能' },
  152. { name: '推荐佣金', free: '不可参与', family: '最高15%' },
  153. { name: '专属活动', free: '部分参与', family: '全部参与' },
  154. { name: '成长报告', free: '月度', family: '每周+深度' },
  155. { name: '任务配额', free: '每日5个', family: '不限量' }
  156. ],
  157. coupons: [],
  158. selectedCoupon: null,
  159. showCouponPicker: false
  160. }
  161. },
  162. computed: {
  163. availableCoupons() {
  164. var self = this
  165. return this.coupons.filter(function(c) {
  166. if (c.status && c.status !== 'AVAILABLE') return false
  167. if (c.applicableTo && c.applicableTo !== 'ALL' && c.applicableTo !== 'MEMBERSHIP') return false
  168. return true
  169. })
  170. }
  171. },
  172. onLoad() {
  173. this.loadData()
  174. },
  175. methods: {
  176. async loadData() {
  177. try {
  178. const membershipRes = await getMyMembership()
  179. this.membership = membershipRes.data
  180. if (this.membership && this.membership.levelCode && this.membership.levelCode !== 'FREE') {
  181. this.isFree = false
  182. this.currentLevelName = this.membership.levelName || '家庭会员'
  183. } else {
  184. this.isFree = true
  185. this.currentLevelName = '免费用户'
  186. }
  187. } catch (e) {
  188. console.error('加载会员信息失败', e)
  189. }
  190. try {
  191. const levelsRes = await getMembershipLevels()
  192. this.levels = levelsRes.data || []
  193. } catch (e) {
  194. console.error('加载会员等级失败', e)
  195. }
  196. try {
  197. const recordsRes = await getUpgradeRecords()
  198. if (recordsRes.data && recordsRes.data.records) {
  199. this.records = recordsRes.data.records
  200. }
  201. } catch (e) {
  202. console.error('加载升级记录失败', e)
  203. }
  204. try {
  205. const couponsRes = await getCouponList()
  206. this.coupons = couponsRes.data || []
  207. } catch (e) {
  208. console.error('加载优惠券失败', e)
  209. }
  210. },
  211. openCouponPicker() {
  212. if (this.availableCoupons.length === 0 && !this.selectedCoupon) {
  213. uni.showToast({ title: '暂无可用优惠券', icon: 'none' })
  214. return
  215. }
  216. this.showCouponPicker = true
  217. },
  218. selectCoupon(coupon) {
  219. this.selectedCoupon = coupon
  220. this.showCouponPicker = false
  221. },
  222. removeCoupon() {
  223. this.selectedCoupon = null
  224. this.showCouponPicker = false
  225. },
  226. getCouponCondition(minSpend) {
  227. if (!minSpend || minSpend <= 0) return '无门槛'
  228. return '满' + (minSpend / 100).toFixed(2) + '元可用'
  229. },
  230. handleUpgrade() {
  231. uni.showModal({
  232. title: '确认开通',
  233. content: '确认开通家庭会员(¥365.00/年)?',
  234. success: async (res) => {
  235. if (!res.confirm) return
  236. try {
  237. await upgradeMember('FAMILY')
  238. uni.showToast({ title: '开通成功', icon: 'success' })
  239. this.loadData()
  240. } catch (e) {
  241. uni.showToast({ title: e.message || '开通失败', icon: 'none' })
  242. }
  243. }
  244. })
  245. },
  246. handleRenew() {
  247. uni.showModal({
  248. title: '确认续费',
  249. content: '确认续费家庭会员(¥365.00/年)?',
  250. success: async (res) => {
  251. if (!res.confirm) return
  252. try {
  253. await upgradeMember('FAMILY')
  254. uni.showToast({ title: '续费成功', icon: 'success' })
  255. this.loadData()
  256. } catch (e) {
  257. uni.showToast({ title: e.message || '续费失败', icon: 'none' })
  258. }
  259. }
  260. })
  261. },
  262. formatDate(date) {
  263. if (!date) return ''
  264. var d = new Date(date)
  265. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  266. }
  267. }
  268. }
  269. </script>
  270. <style scoped>
  271. .page {
  272. min-height: 100vh;
  273. background: #FFF7ED;
  274. padding: 30rpx;
  275. box-sizing: border-box;
  276. }
  277. /* ===== 状态卡片 ===== */
  278. .status-card {
  279. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  280. border-radius: 20rpx;
  281. padding: 40rpx;
  282. margin-bottom: 30rpx;
  283. }
  284. .status-badge {
  285. display: inline-flex;
  286. align-items: center;
  287. padding: 10rpx 24rpx;
  288. border-radius: 9999rpx;
  289. font-size: 24rpx;
  290. }
  291. .badge-free {
  292. background: rgba(255,255,255,0.2);
  293. color: #fff;
  294. }
  295. .badge-family {
  296. background: rgba(255,255,255,0.3);
  297. color: #fff;
  298. }
  299. .badge-icon {
  300. font-size: 20rpx;
  301. margin-right: 8rpx;
  302. }
  303. .badge-text {
  304. font-weight: 600;
  305. }
  306. .status-body {
  307. margin-top: 24rpx;
  308. }
  309. .expiry-row {
  310. display: flex;
  311. justify-content: space-between;
  312. align-items: center;
  313. }
  314. .expiry-label {
  315. font-size: 26rpx;
  316. color: rgba(255,255,255,0.8);
  317. }
  318. .expiry-value {
  319. font-size: 28rpx;
  320. color: #fff;
  321. font-weight: 500;
  322. }
  323. .days-remaining {
  324. display: flex;
  325. align-items: baseline;
  326. justify-content: center;
  327. margin-top: 20rpx;
  328. }
  329. .days-num {
  330. font-size: 56rpx;
  331. font-weight: bold;
  332. color: #FEF3C7;
  333. }
  334. .days-unit {
  335. font-size: 26rpx;
  336. color: rgba(255,255,255,0.7);
  337. margin-left: 8rpx;
  338. }
  339. .expired-msg {
  340. text-align: center;
  341. margin-top: 16rpx;
  342. }
  343. .expired-text {
  344. font-size: 26rpx;
  345. color: #FEF3C7;
  346. }
  347. .free-hint {
  348. font-size: 26rpx;
  349. color: rgba(255,255,255,0.85);
  350. text-align: center;
  351. display: block;
  352. }
  353. /* ===== 升级/续费卡片 ===== */
  354. .upgrade-card {
  355. background: #FFFFFF;
  356. border-radius: 20rpx;
  357. padding: 40rpx;
  358. margin-bottom: 30rpx;
  359. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  360. }
  361. .upgrade-header {
  362. text-align: center;
  363. margin-bottom: 20rpx;
  364. }
  365. .upgrade-title {
  366. font-size: 36rpx;
  367. font-weight: bold;
  368. color: #1E293B;
  369. display: block;
  370. }
  371. .upgrade-subtitle {
  372. font-size: 24rpx;
  373. color: #94A3B8;
  374. margin-top: 6rpx;
  375. display: block;
  376. }
  377. .upgrade-price {
  378. text-align: center;
  379. margin: 24rpx 0;
  380. }
  381. .price-symbol {
  382. font-size: 28rpx;
  383. color: #F97316;
  384. vertical-align: top;
  385. }
  386. .price-amount {
  387. font-size: 64rpx;
  388. font-weight: bold;
  389. color: #F97316;
  390. line-height: 1;
  391. }
  392. .price-unit {
  393. font-size: 26rpx;
  394. color: #94A3B8;
  395. margin-left: 6rpx;
  396. }
  397. .feature-list {
  398. margin: 24rpx 0;
  399. }
  400. .feature-item {
  401. display: flex;
  402. align-items: center;
  403. padding: 12rpx 0;
  404. }
  405. .feature-check {
  406. width: 40rpx;
  407. height: 40rpx;
  408. line-height: 40rpx;
  409. text-align: center;
  410. background: #F97316;
  411. color: #fff;
  412. border-radius: 50%;
  413. font-size: 22rpx;
  414. margin-right: 16rpx;
  415. flex-shrink: 0;
  416. }
  417. .feature-text {
  418. font-size: 28rpx;
  419. color: #1E293B;
  420. }
  421. .btn-upgrade {
  422. width: 100%;
  423. height: 88rpx;
  424. line-height: 88rpx;
  425. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  426. color: #fff;
  427. font-size: 32rpx;
  428. font-weight: 600;
  429. border-radius: 44rpx;
  430. margin-top: 20rpx;
  431. border: none;
  432. }
  433. .btn-upgrade::after {
  434. border: none;
  435. }
  436. .btn-upgrade:active {
  437. opacity: 0.9;
  438. }
  439. .btn-renew {
  440. background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
  441. }
  442. /* ===== 权益对比 ===== */
  443. .compare-section {
  444. background: #FFFFFF;
  445. border-radius: 20rpx;
  446. padding: 30rpx;
  447. margin-bottom: 30rpx;
  448. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  449. }
  450. .section-title {
  451. font-size: 32rpx;
  452. font-weight: bold;
  453. color: #1E293B;
  454. display: block;
  455. margin-bottom: 24rpx;
  456. }
  457. .compare-table {
  458. border-radius: 16rpx;
  459. overflow: hidden;
  460. border: 1rpx solid #FED7AA;
  461. }
  462. .compare-row {
  463. display: flex;
  464. border-bottom: 1rpx solid #FED7AA;
  465. }
  466. .compare-row:last-child {
  467. border-bottom: none;
  468. }
  469. .header-row {
  470. background: #FFF7ED;
  471. }
  472. .compare-cell {
  473. flex: 1;
  474. padding: 20rpx 16rpx;
  475. font-size: 26rpx;
  476. text-align: center;
  477. display: flex;
  478. align-items: center;
  479. justify-content: center;
  480. }
  481. .cell-feature {
  482. flex: 1.5;
  483. color: #1E293B;
  484. font-weight: 500;
  485. justify-content: flex-start;
  486. }
  487. .cell-free {
  488. color: #94A3B8;
  489. }
  490. .cell-family.active {
  491. color: #F97316;
  492. font-weight: 600;
  493. }
  494. .header-row .compare-cell {
  495. font-size: 24rpx;
  496. font-weight: 600;
  497. color: #64748B;
  498. }
  499. .header-row .cell-family.active {
  500. color: #F97316;
  501. }
  502. /* ===== 升级记录 ===== */
  503. .records-section {
  504. background: #FFFFFF;
  505. border-radius: 20rpx;
  506. padding: 30rpx;
  507. margin-bottom: 30rpx;
  508. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  509. }
  510. .record-item {
  511. display: flex;
  512. justify-content: space-between;
  513. align-items: center;
  514. padding: 20rpx 0;
  515. border-bottom: 1rpx solid #FED7AA;
  516. }
  517. .record-item:last-child {
  518. border-bottom: none;
  519. }
  520. .record-left {
  521. flex: 1;
  522. }
  523. .record-level {
  524. font-size: 28rpx;
  525. color: #1E293B;
  526. display: block;
  527. }
  528. .record-time {
  529. font-size: 22rpx;
  530. color: #94A3B8;
  531. margin-top: 4rpx;
  532. display: block;
  533. }
  534. .record-amount {
  535. font-size: 30rpx;
  536. font-weight: bold;
  537. color: #F97316;
  538. }
  539. /* ===== Coupon Row ===== */
  540. .coupon-row {
  541. display: flex;
  542. align-items: center;
  543. padding: 24rpx 0;
  544. border-top: 1rpx solid #f5f5f5;
  545. margin-top: 16rpx;
  546. }
  547. .coupon-row:active {
  548. opacity: 0.7;
  549. }
  550. .coupon-row-label {
  551. font-size: 26rpx;
  552. color: #666;
  553. margin-right: 16rpx;
  554. }
  555. .coupon-row-discount {
  556. flex: 1;
  557. font-size: 26rpx;
  558. color: #F97316;
  559. font-weight: 600;
  560. text-align: right;
  561. }
  562. .coupon-row-placeholder {
  563. flex: 1;
  564. font-size: 26rpx;
  565. color: #ccc;
  566. text-align: right;
  567. }
  568. .coupon-row-arrow {
  569. font-size: 32rpx;
  570. color: #ccc;
  571. margin-left: 8rpx;
  572. }
  573. /* ===== Coupon Picker Modal ===== */
  574. .modal-mask {
  575. position: fixed;
  576. top: 0;
  577. left: 0;
  578. right: 0;
  579. bottom: 0;
  580. background: rgba(0,0,0,0.5);
  581. z-index: 999;
  582. display: flex;
  583. align-items: flex-end;
  584. }
  585. .coupon-picker {
  586. background: #fff;
  587. border-radius: 24rpx 24rpx 0 0;
  588. width: 100%;
  589. max-height: 70vh;
  590. display: flex;
  591. flex-direction: column;
  592. }
  593. .picker-header {
  594. display: flex;
  595. justify-content: space-between;
  596. align-items: center;
  597. padding: 30rpx;
  598. border-bottom: 1rpx solid #eee;
  599. }
  600. .picker-title {
  601. font-size: 30rpx;
  602. font-weight: 600;
  603. color: #333;
  604. }
  605. .picker-close {
  606. font-size: 26rpx;
  607. color: #999;
  608. }
  609. .picker-list {
  610. max-height: 50vh;
  611. padding: 0 20rpx;
  612. }
  613. .picker-item {
  614. display: flex;
  615. align-items: center;
  616. padding: 24rpx 16rpx;
  617. border-bottom: 1rpx solid #f5f5f5;
  618. }
  619. .picker-item:active {
  620. background: #fafafa;
  621. }
  622. .picker-item-active {
  623. background: #FFF7ED;
  624. }
  625. .picker-item-left {
  626. width: 120rpx;
  627. text-align: center;
  628. flex-shrink: 0;
  629. }
  630. .picker-item-value {
  631. font-size: 32rpx;
  632. font-weight: bold;
  633. color: #F97316;
  634. }
  635. .picker-item-right {
  636. flex: 1;
  637. margin: 0 16rpx;
  638. }
  639. .picker-item-name {
  640. font-size: 26rpx;
  641. color: #333;
  642. display: block;
  643. margin-bottom: 4rpx;
  644. }
  645. .picker-item-condition {
  646. font-size: 22rpx;
  647. color: #999;
  648. }
  649. .picker-item-check {
  650. width: 40rpx;
  651. height: 40rpx;
  652. background: #F97316;
  653. border-radius: 50%;
  654. display: flex;
  655. align-items: center;
  656. justify-content: center;
  657. flex-shrink: 0;
  658. color: #fff;
  659. font-size: 24rpx;
  660. font-weight: bold;
  661. }
  662. .picker-empty {
  663. text-align: center;
  664. padding: 60rpx 0;
  665. font-size: 26rpx;
  666. color: #999;
  667. }
  668. .picker-footer {
  669. padding: 20rpx;
  670. border-top: 1rpx solid #eee;
  671. }
  672. .picker-btn-remove {
  673. background: #f5f5f5;
  674. color: #666;
  675. font-size: 26rpx;
  676. border-radius: 12rpx;
  677. border: none;
  678. }
  679. .picker-btn-remove::after {
  680. border: none;
  681. }
  682. </style>