index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="container">
  3. <!-- 当前会员状态 -->
  4. <view class="membership-card">
  5. <view class="card-header">
  6. <text class="card-title">我的会员</text>
  7. <text class="card-status" :class="currentLevel.levelCode">{{ currentLevel.levelName }}</text>
  8. </view>
  9. <view class="card-body" v-if="membership">
  10. <view class="expiry-info">
  11. <text class="label">到期时间</text>
  12. <text class="value">{{ formatDate(membership.endDate) }}</text>
  13. </view>
  14. <view class="days-info" v-if="membership.isActive">
  15. <text class="remaining">{{ membership.daysRemaining }}天</text>
  16. <text class="tip">剩余天数</text>
  17. </view>
  18. <view class="expired-tip" v-else>
  19. <text class="tip">会员已过期,请续费</text>
  20. </view>
  21. </view>
  22. <view class="card-body" v-else>
  23. <text class="free-tip">您当前为免费版,升级享受更多服务</text>
  24. </view>
  25. <button class="btn-upgrade" @click="goToUpgrade">立即升级</button>
  26. </view>
  27. <!-- 会员权益 -->
  28. <view class="benefits-section">
  29. <text class="section-title">会员权益</text>
  30. <view class="benefits-grid">
  31. <view class="benefit-item" v-for="level in levels" :key="level.levelCode">
  32. <view class="benefit-header">
  33. <text class="level-name">{{ level.levelName }}</text>
  34. <text class="level-price" v-if="level.priceMonthly > 0">¥{{ level.priceMonthly }}/月</text>
  35. <text class="level-price free" v-else>免费</text>
  36. </view>
  37. <view class="benefit-features">
  38. <text class="feature-tag" v-for="(feature, idx) in parseFeatures(level.features)" :key="idx">
  39. {{ feature }}
  40. </text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 老师咨询授权 -->
  46. <view class="auth-section">
  47. <text class="section-title">老师咨询授权</text>
  48. <view class="auth-item" v-for="auth in authorizations" :key="auth.id">
  49. <view class="auth-info">
  50. <text class="teacher-name">{{ auth.teacherName }}</text>
  51. <text class="auth-status" :class="auth.status">{{ auth.statusText }}</text>
  52. </view>
  53. <view class="auth-actions">
  54. <button class="btn-revoke" v-if="auth.status === 'active'" @click="revokeAuth(auth.id)">撤销</button>
  55. </view>
  56. </view>
  57. <view class="no-auth" v-if="authorizations.length === 0">
  58. <text class="tip">暂无老师授权</text>
  59. <text class="desc">联系老师获取授权后,可查看孩子任务执行情况</text>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import { getMembershipLevels, getMyMembership, getAuthorizations } from '../../utils/api.js'
  66. export default {
  67. data() {
  68. return {
  69. levels: [],
  70. membership: null,
  71. currentLevel: {},
  72. authorizations: []
  73. }
  74. },
  75. onShow() {
  76. this.loadData()
  77. },
  78. methods: {
  79. async loadData() {
  80. try {
  81. // 获取会员等级
  82. const levelsRes = await getMembershipLevels()
  83. this.levels = levelsRes.data || []
  84. // 获取我的会员信息
  85. const membershipRes = await getMyMembership()
  86. this.membership = membershipRes.data
  87. // 确定当前等级
  88. if (this.membership && this.membership.levelCode) {
  89. this.currentLevel = this.levels.find(l => l.levelCode === this.membership.levelCode) || {}
  90. } else {
  91. this.currentLevel = this.levels.find(l => l.levelCode === 'FREE') || {}
  92. }
  93. // 获取授权列表
  94. const authRes = await getAuthorizations()
  95. this.authorizations = (authRes.data || []).map(a => ({
  96. ...a,
  97. statusText: a.status === 'active' ? '已授权' : '已撤销'
  98. }))
  99. } catch (e) {
  100. console.error('加载数据失败', e)
  101. }
  102. },
  103. formatDate(date) {
  104. if (!date) return ''
  105. const d = new Date(date)
  106. return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`
  107. },
  108. parseFeatures(features) {
  109. if (!features) return []
  110. try {
  111. return JSON.parse(features)
  112. } catch {
  113. return []
  114. }
  115. },
  116. goToUpgrade() {
  117. uni.navigateTo({
  118. url: '/pages/membership/upgrade'
  119. })
  120. },
  121. revokeAuth(authId) {
  122. uni.showModal({
  123. title: '撤销授权',
  124. content: '确定要撤销该老师的查看权限吗?',
  125. success: (res) => {
  126. if (res.confirm) {
  127. // TODO: 调用撤销API
  128. uni.showToast({ title: '已撤销', icon: 'success' })
  129. this.loadData()
  130. }
  131. }
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. .container {
  139. padding: 30rpx;
  140. }
  141. .membership-card {
  142. background: linear-gradient(135deg, #5B9BD5 0%, #3A7CC4 100%);
  143. border-radius: 20rpx;
  144. padding: 40rpx;
  145. margin-bottom: 30rpx;
  146. }
  147. .card-header {
  148. display: flex;
  149. justify-content: space-between;
  150. align-items: center;
  151. }
  152. .card-title {
  153. font-size: 32rpx;
  154. color: #fff;
  155. font-weight: bold;
  156. }
  157. .card-status {
  158. font-size: 24rpx;
  159. padding: 8rpx 20rpx;
  160. border-radius: 20rpx;
  161. background: rgba(255,255,255,0.2);
  162. color: #fff;
  163. }
  164. .card-body {
  165. margin-top: 30rpx;
  166. }
  167. .expiry-info {
  168. display: flex;
  169. justify-content: space-between;
  170. }
  171. .expiry-info .label {
  172. font-size: 26rpx;
  173. color: rgba(255,255,255,0.8);
  174. }
  175. .expiry-info .value {
  176. font-size: 26rpx;
  177. color: #fff;
  178. }
  179. .days-info {
  180. text-align: center;
  181. margin-top: 20rpx;
  182. }
  183. .remaining {
  184. font-size: 48rpx;
  185. font-weight: bold;
  186. color: #FFD700;
  187. }
  188. .days-info .tip {
  189. font-size: 24rpx;
  190. color: rgba(255,255,255,0.7);
  191. display: block;
  192. }
  193. .expired-tip {
  194. text-align: center;
  195. margin-top: 20rpx;
  196. }
  197. .expired-tip .tip {
  198. color: #FFD700;
  199. font-size: 26rpx;
  200. }
  201. .free-tip {
  202. font-size: 26rpx;
  203. color: rgba(255,255,255,0.8);
  204. text-align: center;
  205. }
  206. .btn-upgrade {
  207. margin-top: 30rpx;
  208. background: #FFD700;
  209. color: #333;
  210. border-radius: 40rpx;
  211. font-size: 28rpx;
  212. }
  213. .benefits-section {
  214. background: #fff;
  215. border-radius: 20rpx;
  216. padding: 30rpx;
  217. margin-bottom: 30rpx;
  218. }
  219. .section-title {
  220. font-size: 32rpx;
  221. font-weight: bold;
  222. color: #333;
  223. display: block;
  224. margin-bottom: 20rpx;
  225. }
  226. .benefits-grid {
  227. display: flex;
  228. flex-direction: column;
  229. gap: 20rpx;
  230. }
  231. .benefit-item {
  232. border: 1rpx solid #eee;
  233. border-radius: 10rpx;
  234. padding: 20rpx;
  235. }
  236. .benefit-header {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. }
  241. .level-name {
  242. font-size: 28rpx;
  243. font-weight: bold;
  244. color: #333;
  245. }
  246. .level-price {
  247. font-size: 26rpx;
  248. color: #5B9BD5;
  249. }
  250. .level-price.free {
  251. color: #52C41A;
  252. }
  253. .benefit-features {
  254. display: flex;
  255. flex-wrap: wrap;
  256. gap: 10rpx;
  257. margin-top: 15rpx;
  258. }
  259. .feature-tag {
  260. font-size: 22rpx;
  261. padding: 6rpx 16rpx;
  262. background: #f5f5f5;
  263. border-radius: 20rpx;
  264. color: #666;
  265. }
  266. .auth-section {
  267. background: #fff;
  268. border-radius: 20rpx;
  269. padding: 30rpx;
  270. }
  271. .auth-item {
  272. display: flex;
  273. justify-content: space-between;
  274. align-items: center;
  275. padding: 20rpx 0;
  276. border-bottom: 1rpx solid #f0f0f0;
  277. }
  278. .auth-item:last-child {
  279. border-bottom: none;
  280. }
  281. .auth-info {
  282. flex: 1;
  283. }
  284. .teacher-name {
  285. font-size: 28rpx;
  286. color: #333;
  287. display: block;
  288. }
  289. .auth-status {
  290. font-size: 24rpx;
  291. color: #999;
  292. margin-top: 8rpx;
  293. }
  294. .auth-status.active {
  295. color: #52C41A;
  296. }
  297. .btn-revoke {
  298. font-size: 24rpx;
  299. padding: 10rpx 20rpx;
  300. background: #FF4D4F;
  301. color: #fff;
  302. border-radius: 10rpx;
  303. }
  304. .no-auth {
  305. text-align: center;
  306. padding: 40rpx;
  307. }
  308. .no-auth .tip {
  309. font-size: 28rpx;
  310. color: #999;
  311. display: block;
  312. }
  313. .no-auth .desc {
  314. font-size: 24rpx;
  315. color: #ccc;
  316. margin-top: 10rpx;
  317. display: block;
  318. }
  319. </style>