upgrade.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <scroll-view class="page" scroll-y>
  3. <!-- 当前会员状态卡片 -->
  4. <view class="status-card">
  5. <view class="status-badge" :class="isFree ? 'badge-free' : 'badge-family'">
  6. <text class="badge-icon">{{ isFree ? '○' : '●' }}</text>
  7. <text class="badge-text">{{ currentLevelName }}</text>
  8. </view>
  9. <view class="status-body" v-if="membership && membership.levelCode !== 'FREE'">
  10. <view class="expiry-row">
  11. <text class="expiry-label">到期时间</text>
  12. <text class="expiry-value">{{ formatDate(membership.endDate) }}</text>
  13. </view>
  14. <view class="days-remaining" v-if="membership.isActive">
  15. <text class="days-num">{{ membership.daysRemaining || 0 }}</text>
  16. <text class="days-unit">天剩余</text>
  17. </view>
  18. <view class="expired-msg" v-else>
  19. <text class="expired-text">会员已过期,续费恢复权益</text>
  20. </view>
  21. </view>
  22. <view class="status-body" v-else>
  23. <text class="free-hint">当前为免费版,开通家庭会员解锁全部特权</text>
  24. </view>
  25. </view>
  26. <!-- 家庭会员开通卡片 -->
  27. <view class="upgrade-card" v-if="isFree">
  28. <view class="upgrade-header">
  29. <text class="upgrade-title">家庭会员</text>
  30. <text class="upgrade-subtitle">FAMILY</text>
  31. </view>
  32. <view class="upgrade-price">
  33. <text class="price-symbol">¥</text>
  34. <text class="price-amount">365</text>
  35. <text class="price-unit">/年</text>
  36. </view>
  37. <view class="feature-list">
  38. <view class="feature-item" v-for="(feature, idx) in features" :key="idx">
  39. <text class="feature-check">✓</text>
  40. <text class="feature-text">{{ feature }}</text>
  41. </view>
  42. </view>
  43. <button class="btn-upgrade" @click="handleUpgrade">立即开通</button>
  44. </view>
  45. <!-- 续费卡片 -->
  46. <view class="upgrade-card" v-else>
  47. <view class="upgrade-header">
  48. <text class="upgrade-title">续费会员</text>
  49. <text class="upgrade-subtitle">保持权益不中断</text>
  50. </view>
  51. <view class="upgrade-price">
  52. <text class="price-symbol">¥</text>
  53. <text class="price-amount">365</text>
  54. <text class="price-unit">/年</text>
  55. </view>
  56. <button class="btn-upgrade btn-renew" @click="handleRenew">立即续费</button>
  57. </view>
  58. <!-- 权益对比表 -->
  59. <view class="compare-section">
  60. <text class="section-title">权益对比</text>
  61. <view class="compare-table">
  62. <view class="compare-row header-row">
  63. <text class="compare-cell cell-feature">权益项</text>
  64. <text class="compare-cell cell-free">免费</text>
  65. <text class="compare-cell cell-family active">家庭会员</text>
  66. </view>
  67. <view class="compare-row" v-for="(item, idx) in compareData" :key="idx">
  68. <text class="compare-cell cell-feature">{{ item.name }}</text>
  69. <text class="compare-cell cell-free">{{ item.free }}</text>
  70. <text class="compare-cell cell-family active">{{ item.family }}</text>
  71. </view>
  72. </view>
  73. </view>
  74. <!-- 升级记录 -->
  75. <view class="records-section" v-if="records.length > 0">
  76. <text class="section-title">升级记录</text>
  77. <view class="record-item" v-for="record in records" :key="record.id">
  78. <view class="record-left">
  79. <text class="record-level">{{ record.levelName }}</text>
  80. <text class="record-time">{{ formatDate(record.createdAt) }}</text>
  81. </view>
  82. <text class="record-amount">¥{{ record.amount || '0.00' }}</text>
  83. </view>
  84. </view>
  85. </scroll-view>
  86. </template>
  87. <script>
  88. import { getMyMembership, getMembershipLevels, getUpgradeRecords, upgradeMember, createOrder } from '../../utils/api.js'
  89. export default {
  90. data() {
  91. return {
  92. membership: null,
  93. levels: [],
  94. records: [],
  95. features: ['折扣购物', '家庭管理', '推荐佣金', '专属活动', '任务特权', '成长报告'],
  96. isFree: true,
  97. currentLevelName: '免费用户',
  98. compareData: [
  99. { name: '商品折扣', free: '普通价格', family: '会员专享价' },
  100. { name: '家庭管理', free: '基础功能', family: '全部功能' },
  101. { name: '推荐佣金', free: '不可参与', family: '最高15%' },
  102. { name: '专属活动', free: '部分参与', family: '全部参与' },
  103. { name: '成长报告', free: '月度', family: '每周+深度' },
  104. { name: '任务配额', free: '每日5个', family: '不限量' }
  105. ]
  106. }
  107. },
  108. onLoad() {
  109. this.loadData()
  110. },
  111. methods: {
  112. async loadData() {
  113. try {
  114. const membershipRes = await getMyMembership()
  115. this.membership = membershipRes.data
  116. if (this.membership && this.membership.levelCode && this.membership.levelCode !== 'FREE') {
  117. this.isFree = false
  118. this.currentLevelName = this.membership.levelName || '家庭会员'
  119. } else {
  120. this.isFree = true
  121. this.currentLevelName = '免费用户'
  122. }
  123. } catch (e) {
  124. console.error('加载会员信息失败', e)
  125. }
  126. try {
  127. const levelsRes = await getMembershipLevels()
  128. this.levels = levelsRes.data || []
  129. } catch (e) {
  130. console.error('加载会员等级失败', e)
  131. }
  132. try {
  133. const recordsRes = await getUpgradeRecords()
  134. if (recordsRes.data && recordsRes.data.records) {
  135. this.records = recordsRes.data.records
  136. }
  137. } catch (e) {
  138. console.error('加载升级记录失败', e)
  139. }
  140. },
  141. handleUpgrade() {
  142. uni.showModal({
  143. title: '确认开通',
  144. content: '确认开通家庭会员(¥365/年)?',
  145. success: async (res) => {
  146. if (!res.confirm) return
  147. try {
  148. await upgradeMember('FAMILY')
  149. uni.showToast({ title: '开通成功', icon: 'success' })
  150. this.loadData()
  151. } catch (e) {
  152. uni.showToast({ title: e.message || '开通失败', icon: 'none' })
  153. }
  154. }
  155. })
  156. },
  157. handleRenew() {
  158. uni.showModal({
  159. title: '确认续费',
  160. content: '确认续费家庭会员(¥365/年)?',
  161. success: async (res) => {
  162. if (!res.confirm) return
  163. try {
  164. await upgradeMember('FAMILY')
  165. uni.showToast({ title: '续费成功', icon: 'success' })
  166. this.loadData()
  167. } catch (e) {
  168. uni.showToast({ title: e.message || '续费失败', icon: 'none' })
  169. }
  170. }
  171. })
  172. },
  173. formatDate(date) {
  174. if (!date) return ''
  175. var d = new Date(date)
  176. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped>
  182. .page {
  183. min-height: 100vh;
  184. background: #FFF7ED;
  185. padding: 30rpx;
  186. box-sizing: border-box;
  187. }
  188. /* ===== 状态卡片 ===== */
  189. .status-card {
  190. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  191. border-radius: 20rpx;
  192. padding: 40rpx;
  193. margin-bottom: 30rpx;
  194. }
  195. .status-badge {
  196. display: inline-flex;
  197. align-items: center;
  198. padding: 10rpx 24rpx;
  199. border-radius: 9999rpx;
  200. font-size: 24rpx;
  201. }
  202. .badge-free {
  203. background: rgba(255,255,255,0.2);
  204. color: #fff;
  205. }
  206. .badge-family {
  207. background: rgba(255,255,255,0.3);
  208. color: #fff;
  209. }
  210. .badge-icon {
  211. font-size: 20rpx;
  212. margin-right: 8rpx;
  213. }
  214. .badge-text {
  215. font-weight: 600;
  216. }
  217. .status-body {
  218. margin-top: 24rpx;
  219. }
  220. .expiry-row {
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. }
  225. .expiry-label {
  226. font-size: 26rpx;
  227. color: rgba(255,255,255,0.8);
  228. }
  229. .expiry-value {
  230. font-size: 28rpx;
  231. color: #fff;
  232. font-weight: 500;
  233. }
  234. .days-remaining {
  235. display: flex;
  236. align-items: baseline;
  237. justify-content: center;
  238. margin-top: 20rpx;
  239. }
  240. .days-num {
  241. font-size: 56rpx;
  242. font-weight: bold;
  243. color: #FEF3C7;
  244. }
  245. .days-unit {
  246. font-size: 26rpx;
  247. color: rgba(255,255,255,0.7);
  248. margin-left: 8rpx;
  249. }
  250. .expired-msg {
  251. text-align: center;
  252. margin-top: 16rpx;
  253. }
  254. .expired-text {
  255. font-size: 26rpx;
  256. color: #FEF3C7;
  257. }
  258. .free-hint {
  259. font-size: 26rpx;
  260. color: rgba(255,255,255,0.85);
  261. text-align: center;
  262. display: block;
  263. }
  264. /* ===== 升级/续费卡片 ===== */
  265. .upgrade-card {
  266. background: #FFFFFF;
  267. border-radius: 20rpx;
  268. padding: 40rpx;
  269. margin-bottom: 30rpx;
  270. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  271. }
  272. .upgrade-header {
  273. text-align: center;
  274. margin-bottom: 20rpx;
  275. }
  276. .upgrade-title {
  277. font-size: 36rpx;
  278. font-weight: bold;
  279. color: #1E293B;
  280. display: block;
  281. }
  282. .upgrade-subtitle {
  283. font-size: 24rpx;
  284. color: #94A3B8;
  285. margin-top: 6rpx;
  286. display: block;
  287. }
  288. .upgrade-price {
  289. text-align: center;
  290. margin: 24rpx 0;
  291. }
  292. .price-symbol {
  293. font-size: 28rpx;
  294. color: #F97316;
  295. vertical-align: top;
  296. }
  297. .price-amount {
  298. font-size: 64rpx;
  299. font-weight: bold;
  300. color: #F97316;
  301. line-height: 1;
  302. }
  303. .price-unit {
  304. font-size: 26rpx;
  305. color: #94A3B8;
  306. margin-left: 6rpx;
  307. }
  308. .feature-list {
  309. margin: 24rpx 0;
  310. }
  311. .feature-item {
  312. display: flex;
  313. align-items: center;
  314. padding: 12rpx 0;
  315. }
  316. .feature-check {
  317. width: 40rpx;
  318. height: 40rpx;
  319. line-height: 40rpx;
  320. text-align: center;
  321. background: #F97316;
  322. color: #fff;
  323. border-radius: 50%;
  324. font-size: 22rpx;
  325. margin-right: 16rpx;
  326. flex-shrink: 0;
  327. }
  328. .feature-text {
  329. font-size: 28rpx;
  330. color: #1E293B;
  331. }
  332. .btn-upgrade {
  333. width: 100%;
  334. height: 88rpx;
  335. line-height: 88rpx;
  336. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  337. color: #fff;
  338. font-size: 32rpx;
  339. font-weight: 600;
  340. border-radius: 44rpx;
  341. margin-top: 20rpx;
  342. border: none;
  343. }
  344. .btn-upgrade::after {
  345. border: none;
  346. }
  347. .btn-upgrade:active {
  348. opacity: 0.9;
  349. }
  350. .btn-renew {
  351. background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
  352. }
  353. /* ===== 权益对比 ===== */
  354. .compare-section {
  355. background: #FFFFFF;
  356. border-radius: 20rpx;
  357. padding: 30rpx;
  358. margin-bottom: 30rpx;
  359. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  360. }
  361. .section-title {
  362. font-size: 32rpx;
  363. font-weight: bold;
  364. color: #1E293B;
  365. display: block;
  366. margin-bottom: 24rpx;
  367. }
  368. .compare-table {
  369. border-radius: 16rpx;
  370. overflow: hidden;
  371. border: 1rpx solid #FED7AA;
  372. }
  373. .compare-row {
  374. display: flex;
  375. border-bottom: 1rpx solid #FED7AA;
  376. }
  377. .compare-row:last-child {
  378. border-bottom: none;
  379. }
  380. .header-row {
  381. background: #FFF7ED;
  382. }
  383. .compare-cell {
  384. flex: 1;
  385. padding: 20rpx 16rpx;
  386. font-size: 26rpx;
  387. text-align: center;
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. }
  392. .cell-feature {
  393. flex: 1.5;
  394. color: #1E293B;
  395. font-weight: 500;
  396. justify-content: flex-start;
  397. }
  398. .cell-free {
  399. color: #94A3B8;
  400. }
  401. .cell-family.active {
  402. color: #F97316;
  403. font-weight: 600;
  404. }
  405. .header-row .compare-cell {
  406. font-size: 24rpx;
  407. font-weight: 600;
  408. color: #64748B;
  409. }
  410. .header-row .cell-family.active {
  411. color: #F97316;
  412. }
  413. /* ===== 升级记录 ===== */
  414. .records-section {
  415. background: #FFFFFF;
  416. border-radius: 20rpx;
  417. padding: 30rpx;
  418. margin-bottom: 30rpx;
  419. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  420. }
  421. .record-item {
  422. display: flex;
  423. justify-content: space-between;
  424. align-items: center;
  425. padding: 20rpx 0;
  426. border-bottom: 1rpx solid #FED7AA;
  427. }
  428. .record-item:last-child {
  429. border-bottom: none;
  430. }
  431. .record-left {
  432. flex: 1;
  433. }
  434. .record-level {
  435. font-size: 28rpx;
  436. color: #1E293B;
  437. display: block;
  438. }
  439. .record-time {
  440. font-size: 22rpx;
  441. color: #94A3B8;
  442. margin-top: 4rpx;
  443. display: block;
  444. }
  445. .record-amount {
  446. font-size: 30rpx;
  447. font-weight: bold;
  448. color: #F97316;
  449. }
  450. </style>