index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <scroll-view class="container" scroll-y>
  3. <!-- 当前会员状态 -->
  4. <view class="membership-card">
  5. <view class="card-header">
  6. <view class="card-header-left">
  7. <text class="card-title">我的会员</text>
  8. <text class="card-subtitle">Membership</text>
  9. </view>
  10. <text class="card-level-badge" :class="currentLevel.levelCode === 'FAMILY' ? 'badge-family' : 'badge-free'">
  11. {{ currentLevel.levelName || '免费用户' }}
  12. </text>
  13. </view>
  14. <view class="card-body" v-if="membership">
  15. <view class="expiry-info">
  16. <text class="label">到期时间</text>
  17. <text class="value">{{ formatDate(membership.endDate) }}</text>
  18. </view>
  19. <view class="days-info" v-if="membership.isActive">
  20. <text class="remaining">{{ membership.daysRemaining }}天</text>
  21. <text class="tip">剩余天数</text>
  22. </view>
  23. <view class="expired-tip" v-else>
  24. <text class="tip">会员已过期,请续费</text>
  25. </view>
  26. </view>
  27. <view class="card-body" v-else>
  28. <text class="free-tip">您当前为免费版,升级享受更多服务</text>
  29. </view>
  30. <button class="btn-upgrade" @click="goToUpgrade">
  31. {{ currentLevel.levelCode === 'FAMILY' ? '续费升级' : '立即升级' }}
  32. </button>
  33. </view>
  34. <!-- 会员权益亮点 -->
  35. <view class="highlights-section">
  36. <text class="section-title">会员特权</text>
  37. <view class="highlights-grid">
  38. <view class="highlight-item" v-for="(item, idx) in highlights" :key="idx">
  39. <view class="highlight-icon" :style="'background:' + item.bg">
  40. <text class="highlight-emoji">{{ item.icon }}</text>
  41. </view>
  42. <text class="highlight-name">{{ item.name }}</text>
  43. <text class="highlight-desc">{{ item.desc }}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 开通CTA -->
  48. <view class="cta-section" v-if="!membership || !membership.isActive">
  49. <text class="cta-title">开通家庭会员,享受全部特权</text>
  50. <text class="cta-price">¥365/年</text>
  51. <button class="cta-btn" @click="goToUpgrade">立即开通</button>
  52. </view>
  53. <!-- 会员权益 -->
  54. <view class="benefits-section">
  55. <text class="section-title">会员等级</text>
  56. <view class="benefits-grid">
  57. <view class="benefit-item" v-for="level in levels" :key="level.levelCode">
  58. <view class="benefit-header">
  59. <text class="level-name">{{ level.levelName }}</text>
  60. <text class="level-price" v-if="level.priceMonthly > 0">¥{{ level.priceMonthly }}/月</text>
  61. <text class="level-price free" v-else>免费</text>
  62. </view>
  63. <view class="benefit-features">
  64. <text class="feature-tag" v-for="(feature, idx) in parseFeatures(level.features)" :key="idx">
  65. {{ feature }}
  66. </text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 老师咨询授权 -->
  72. <view class="auth-section">
  73. <text class="section-title">老师咨询授权</text>
  74. <view class="auth-item" v-for="auth in authorizations" :key="auth.id">
  75. <view class="auth-info">
  76. <text class="teacher-name">{{ auth.teacherName }}</text>
  77. <text class="auth-status" :class="auth.status">{{ auth.statusText }}</text>
  78. </view>
  79. <view class="auth-actions">
  80. <button class="btn-revoke" v-if="auth.status === 'active'" @click="revokeAuth(auth.id)">撤销</button>
  81. </view>
  82. </view>
  83. <view class="no-auth" v-if="authorizations.length === 0">
  84. <text class="tip">暂无老师授权</text>
  85. <text class="desc">联系老师获取授权后,可查看孩子任务执行情况</text>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. </template>
  90. <script>
  91. import { getMembershipLevels, getMyMembership, getAuthorizations } from '../../utils/api.js'
  92. export default {
  93. data() {
  94. return {
  95. levels: [],
  96. membership: null,
  97. currentLevel: {},
  98. authorizations: [],
  99. highlights: [
  100. { icon: '🛒', name: '折扣购物', desc: '商品会员专享价', bg: '#FEF3C7' },
  101. { icon: '👨‍👩‍👧‍👦', name: '家庭管理', desc: '多成员统一管理', bg: '#DBEAFE' },
  102. { icon: '💰', name: '推荐佣金', desc: '分享赚取佣金', bg: '#D1FAE5' },
  103. { icon: '🎪', name: '专属活动', desc: '会员优先参与', bg: '#FCE7F3' }
  104. ]
  105. }
  106. },
  107. onShow() {
  108. this.loadData()
  109. },
  110. methods: {
  111. async loadData() {
  112. try {
  113. // 获取会员等级
  114. const levelsRes = await getMembershipLevels()
  115. this.levels = levelsRes.data || []
  116. // 获取我的会员信息
  117. const membershipRes = await getMyMembership()
  118. this.membership = membershipRes.data
  119. // 确定当前等级
  120. if (this.membership && this.membership.levelCode) {
  121. this.currentLevel = this.levels.find(function(l) { return l.levelCode === this.membership.levelCode }.bind(this)) || {}
  122. } else {
  123. this.currentLevel = this.levels.find(function(l) { return l.levelCode === 'FREE' }) || {}
  124. }
  125. // 获取授权列表
  126. const authRes = await getAuthorizations()
  127. const authData = authRes.data || []
  128. this.authorizations = authData.map(function(a) {
  129. return Object.assign({}, a, {
  130. statusText: a.status === 'active' ? '已授权' : '已撤销'
  131. })
  132. })
  133. } catch (e) {
  134. console.error('加载数据失败', e)
  135. }
  136. },
  137. formatDate(date) {
  138. if (!date) return ''
  139. const d = new Date(date)
  140. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  141. },
  142. parseFeatures(features) {
  143. if (!features) return []
  144. try {
  145. return JSON.parse(features)
  146. } catch (e) {
  147. return []
  148. }
  149. },
  150. goToUpgrade() {
  151. uni.navigateTo({
  152. url: '/pages/membership/upgrade'
  153. })
  154. },
  155. revokeAuth(authId) {
  156. uni.showModal({
  157. title: '撤销授权',
  158. content: '确定要撤销该老师的查看权限吗?',
  159. success: function(res) {
  160. if (res.confirm) {
  161. uni.showToast({ title: '已撤销', icon: 'success' })
  162. this.loadData()
  163. }
  164. }.bind(this)
  165. })
  166. }
  167. }
  168. }
  169. </script>
  170. <style scoped>
  171. .container {
  172. padding: 30rpx;
  173. }
  174. .membership-card {
  175. background: linear-gradient(135deg, #5B9BD5 0%, #3A7CC4 100%);
  176. border-radius: 20rpx;
  177. padding: 40rpx;
  178. margin-bottom: 30rpx;
  179. }
  180. .card-header {
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: center;
  184. }
  185. .card-header-left {
  186. display: flex;
  187. flex-direction: column;
  188. }
  189. .card-title {
  190. font-size: 32rpx;
  191. color: #fff;
  192. font-weight: bold;
  193. }
  194. .card-subtitle {
  195. font-size: 20rpx;
  196. color: rgba(255,255,255,0.6);
  197. margin-top: 4rpx;
  198. }
  199. .card-level-badge {
  200. font-size: 22rpx;
  201. padding: 8rpx 20rpx;
  202. border-radius: 9999rpx;
  203. font-weight: 600;
  204. }
  205. .badge-free {
  206. background: rgba(255,255,255,0.2);
  207. color: #fff;
  208. }
  209. .badge-family {
  210. background: #FEF3C7;
  211. color: #D97706;
  212. }
  213. .card-body {
  214. margin-top: 30rpx;
  215. }
  216. .expiry-info {
  217. display: flex;
  218. justify-content: space-between;
  219. }
  220. .expiry-info .label {
  221. font-size: 26rpx;
  222. color: rgba(255,255,255,0.8);
  223. }
  224. .expiry-info .value {
  225. font-size: 26rpx;
  226. color: #fff;
  227. }
  228. .days-info {
  229. text-align: center;
  230. margin-top: 20rpx;
  231. }
  232. .remaining {
  233. font-size: 48rpx;
  234. font-weight: bold;
  235. color: #FFD700;
  236. }
  237. .days-info .tip {
  238. font-size: 24rpx;
  239. color: rgba(255,255,255,0.7);
  240. display: block;
  241. }
  242. .expired-tip {
  243. text-align: center;
  244. margin-top: 20rpx;
  245. }
  246. .expired-tip .tip {
  247. color: #FFD700;
  248. font-size: 26rpx;
  249. }
  250. .free-tip {
  251. font-size: 26rpx;
  252. color: rgba(255,255,255,0.8);
  253. text-align: center;
  254. }
  255. .btn-upgrade {
  256. margin-top: 30rpx;
  257. background: #FFD700;
  258. color: #333;
  259. border-radius: 40rpx;
  260. font-size: 28rpx;
  261. }
  262. .benefits-section {
  263. background: #fff;
  264. border-radius: 20rpx;
  265. padding: 30rpx;
  266. margin-bottom: 30rpx;
  267. }
  268. .section-title {
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #333;
  272. display: block;
  273. margin-bottom: 20rpx;
  274. }
  275. .benefits-grid {
  276. display: flex;
  277. flex-direction: column;
  278. gap: 20rpx;
  279. }
  280. .benefit-item {
  281. border: 1rpx solid #eee;
  282. border-radius: 10rpx;
  283. padding: 20rpx;
  284. }
  285. .benefit-header {
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. }
  290. .level-name {
  291. font-size: 28rpx;
  292. font-weight: bold;
  293. color: #333;
  294. }
  295. .level-price {
  296. font-size: 26rpx;
  297. color: #5B9BD5;
  298. }
  299. .level-price.free {
  300. color: #52C41A;
  301. }
  302. .benefit-features {
  303. display: flex;
  304. flex-wrap: wrap;
  305. gap: 10rpx;
  306. margin-top: 15rpx;
  307. }
  308. .feature-tag {
  309. font-size: 22rpx;
  310. padding: 6rpx 16rpx;
  311. background: #f5f5f5;
  312. border-radius: 20rpx;
  313. color: #666;
  314. }
  315. .auth-section {
  316. background: #fff;
  317. border-radius: 20rpx;
  318. padding: 30rpx;
  319. }
  320. .auth-item {
  321. display: flex;
  322. justify-content: space-between;
  323. align-items: center;
  324. padding: 20rpx 0;
  325. border-bottom: 1rpx solid #f0f0f0;
  326. }
  327. .auth-item:last-child {
  328. border-bottom: none;
  329. }
  330. .auth-info {
  331. flex: 1;
  332. }
  333. .teacher-name {
  334. font-size: 28rpx;
  335. color: #333;
  336. display: block;
  337. }
  338. .auth-status {
  339. font-size: 24rpx;
  340. color: #999;
  341. margin-top: 8rpx;
  342. }
  343. .auth-status.active {
  344. color: #52C41A;
  345. }
  346. .btn-revoke {
  347. font-size: 24rpx;
  348. padding: 10rpx 20rpx;
  349. background: #FF4D4F;
  350. color: #fff;
  351. border-radius: 10rpx;
  352. }
  353. .no-auth {
  354. text-align: center;
  355. padding: 40rpx;
  356. }
  357. .no-auth .tip {
  358. font-size: 28rpx;
  359. color: #999;
  360. display: block;
  361. }
  362. .no-auth .desc {
  363. font-size: 24rpx;
  364. color: #ccc;
  365. margin-top: 10rpx;
  366. display: block;
  367. }
  368. /* ===== 权益亮点 ===== */
  369. .highlights-section {
  370. background: #fff;
  371. border-radius: 20rpx;
  372. padding: 30rpx;
  373. margin-bottom: 30rpx;
  374. }
  375. .highlights-grid {
  376. display: flex;
  377. flex-wrap: wrap;
  378. gap: 20rpx;
  379. }
  380. .highlight-item {
  381. width: calc(50% - 10rpx);
  382. display: flex;
  383. flex-direction: column;
  384. align-items: center;
  385. padding: 24rpx 16rpx;
  386. background: #FFF7ED;
  387. border-radius: 16rpx;
  388. box-sizing: border-box;
  389. }
  390. .highlight-icon {
  391. width: 72rpx;
  392. height: 72rpx;
  393. border-radius: 50%;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. margin-bottom: 12rpx;
  398. }
  399. .highlight-emoji {
  400. font-size: 36rpx;
  401. }
  402. .highlight-name {
  403. font-size: 28rpx;
  404. font-weight: 600;
  405. color: #1E293B;
  406. margin-bottom: 4rpx;
  407. }
  408. .highlight-desc {
  409. font-size: 22rpx;
  410. color: #94A3B8;
  411. }
  412. /* ===== CTA开通 ===== */
  413. .cta-section {
  414. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  415. border-radius: 20rpx;
  416. padding: 40rpx;
  417. text-align: center;
  418. margin-bottom: 30rpx;
  419. }
  420. .cta-title {
  421. font-size: 30rpx;
  422. color: #fff;
  423. font-weight: 600;
  424. display: block;
  425. }
  426. .cta-price {
  427. font-size: 44rpx;
  428. color: #FEF3C7;
  429. font-weight: bold;
  430. margin: 16rpx 0 24rpx;
  431. display: block;
  432. }
  433. .cta-btn {
  434. width: 280rpx;
  435. height: 72rpx;
  436. line-height: 72rpx;
  437. background: #fff;
  438. color: #F97316;
  439. font-size: 28rpx;
  440. font-weight: 600;
  441. border-radius: 36rpx;
  442. border: none;
  443. }
  444. .cta-btn::after {
  445. border: none;
  446. }
  447. </style>