index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="member-page">
  3. <LoadingSkeleton v-if="loading" :rows="3" />
  4. <ErrorState v-else-if="error" message="会员信息加载失败" @retry="loadMember" />
  5. <!-- 无会员:两档购买卡 -->
  6. <template v-else>
  7. <view v-if="member.status === 'none'">
  8. <view class="head-banner">
  9. <text class="head-title">年度会员</text>
  10. <text class="head-sub">年度身份 · 沙龙与课程学习权益</text>
  11. </view>
  12. <view class="mcard experience-card">
  13. <view class="mcard-head">
  14. <text class="mcard-name">体验卡</text>
  15. <text class="mcard-price">¥<text class="price-num">365</text><text class="price-year">/年</text></text>
  16. </view>
  17. <view class="mcard-benefit" v-for="(b, idx) in experienceBenefits" :key="idx">
  18. <text class="benefit-dot">·</text>
  19. <text class="benefit-text">{{ b }}</text>
  20. </view>
  21. <text class="mcard-limit">限量 30 张 · 仅 L0 存量学员</text>
  22. <button class="buy-btn" :loading="buying" :disabled="buying" @click="buy('experience')">立即开通</button>
  23. </view>
  24. <view class="mcard companion-card">
  25. <view class="mcard-head">
  26. <text class="mcard-name">爱伴星伙</text>
  27. <text class="mcard-price">¥<text class="price-num">1280</text><text class="price-year">/年</text></text>
  28. </view>
  29. <view class="mcard-benefit" v-for="(b, idx) in companionBenefits" :key="idx">
  30. <text class="benefit-dot">·</text>
  31. <text class="benefit-text">{{ b }}</text>
  32. </view>
  33. <text class="mcard-limit">全年畅享 · 优先报名可携亲友</text>
  34. <button class="buy-btn" :loading="buying" :disabled="buying" @click="buy('companion')">立即开通</button>
  35. </view>
  36. </view>
  37. <!-- 有会员记录:状态卡 -->
  38. <view v-else class="has-member">
  39. <view class="status-card" :class="statusClass">
  40. <view class="status-head">
  41. <text class="status-name">{{ member.cardTypeName || '会员卡' }}</text>
  42. <text class="status-tag">{{ statusText }}</text>
  43. </view>
  44. <view class="status-row">
  45. <text class="status-label">生效时间</text>
  46. <text class="status-value">{{ formatDateTime(member.startDate) }}</text>
  47. </view>
  48. <view class="status-row">
  49. <text class="status-label">有效期至</text>
  50. <text class="status-value">{{ formatDateTime(member.validUntil) }}</text>
  51. </view>
  52. <view v-if="member.status === 'active'" class="status-row">
  53. <text class="status-label">免费沙龙</text>
  54. <text class="status-value">已用 {{ member.salonUsed || 0 }} / {{ member.salonQuota || 0 }} 次</text>
  55. </view>
  56. <view v-if="member.status === 'active' && member.noShowCount > 0" class="status-row">
  57. <text class="status-label">爽约记录</text>
  58. <text class="status-value warn-text">{{ member.noShowCount }} 次</text>
  59. </view>
  60. </view>
  61. <!-- 权益说明 -->
  62. <view class="benefit-card">
  63. <text class="benefit-title">会员权益</text>
  64. <view class="benefit-item" v-for="(b, idx) in member.benefits || []" :key="idx">
  65. <text class="benefit-dot">✓</text>
  66. <text class="benefit-text">{{ b }}</text>
  67. </view>
  68. </view>
  69. <!-- 免费沙龙入口 -->
  70. <button v-if="member.status === 'active' && member.salonRemain > 0" class="salon-btn" @click="goSalonList">
  71. 免费沙龙报名(剩余 {{ member.salonRemain }} 次)
  72. </button>
  73. <button v-else-if="member.status === 'active'" class="salon-btn disabled-btn" disabled>
  74. 免费沙龙次数已用完
  75. </button>
  76. <!-- 续费 / 退卡 -->
  77. <view class="action-row">
  78. <button v-if="member.status !== 'pending'" class="renew-btn" :loading="buying" :disabled="buying" @click="buy(member.cardType)">
  79. {{ member.status === 'active' ? '续费' : '重新购买' }}
  80. </button>
  81. <view v-if="member.refundable" class="refund-link" @click="doRefund">7 日无理由退卡</view>
  82. <text v-if="!member.refundable && member.status === 'active'" class="refund-tip">已过 7 日退卡期</text>
  83. </view>
  84. </view>
  85. </template>
  86. </view>
  87. </template>
  88. <script>
  89. import { getMyMember, createMemberOrder, refundMember } from '@/utils/api.js'
  90. import { formatDateTime } from '@/utils/format.js'
  91. import { guardPage } from '@/utils/guard.js'
  92. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  93. import ErrorState from '@/components/error-state.vue'
  94. export default {
  95. components: { LoadingSkeleton, ErrorState },
  96. data() {
  97. return {
  98. loading: false,
  99. buying: false,
  100. member: { status: 'none' },
  101. error: false,
  102. experienceBenefits: ['年度免费沙龙 4 次', 'L1 课程 95 折', '会员社群 / 资料库'],
  103. companionBenefits: ['年度免费沙龙 12 次', 'L1 课程 9 折', 'L2 课程 95 折', '专家诊室会员价(即将开放)', '会员社群、优先报名']
  104. }
  105. },
  106. computed: {
  107. statusText() {
  108. var map = {
  109. active: this.member.effective ? '生效中' : '已过期',
  110. pending: '待支付',
  111. expired: '已过期',
  112. refunded: '已退卡'
  113. }
  114. return map[this.member.status] || this.member.status || ''
  115. },
  116. statusClass() {
  117. if (this.member.status === 'active') {
  118. return this.member.effective ? 'status-active' : 'status-expired'
  119. }
  120. var cls = { pending: 'status-pending', expired: 'status-expired', refunded: 'status-refunded' }
  121. return cls[this.member.status] || ''
  122. }
  123. },
  124. onLoad() {
  125. if (!guardPage()) return
  126. this.loadMember()
  127. },
  128. methods: {
  129. formatDateTime: formatDateTime,
  130. loadMember() {
  131. var self = this
  132. self.loading = true
  133. self.error = false
  134. getMyMember().then(function(resp) {
  135. self.member = resp.data || { status: 'none' }
  136. }).catch(function(err) {
  137. // 未登录等情况由 guard/全局处理;会员加载失败展示错误态可重试
  138. self.member = { status: 'none' }
  139. self.error = true
  140. console.error('[member] loadMember fail', err)
  141. }).finally(function() {
  142. self.loading = false
  143. })
  144. },
  145. buy(cardType) {
  146. var self = this
  147. if (self.buying) return
  148. var name = cardType === 'experience' ? '体验卡 ¥365/年' : '爱伴星伙卡 ¥1280/年'
  149. var tip = self.member.status === 'active' ? '续费将衔接延长有效期,确认开通 ' + name + ' 吗?' : '确认开通 ' + name + ' 吗?'
  150. uni.showModal({
  151. title: '开通年度会员',
  152. content: tip,
  153. success: function(res) {
  154. if (!res.confirm) return
  155. self.buying = true
  156. uni.showLoading({ title: '下单中…' })
  157. createMemberOrder(cardType).then(function(resp) {
  158. var data = resp.data || {}
  159. uni.hideLoading()
  160. if (data.status === 'paid') {
  161. // test-mode 直付成功即已激活
  162. uni.showToast({ title: '开通成功', icon: 'success' })
  163. self.loadMember()
  164. } else {
  165. uni.showToast({ title: '订单创建成功,等待支付', icon: 'none' })
  166. }
  167. }).catch(function(err) {
  168. uni.hideLoading()
  169. uni.showToast({ title: (err && err.message) || '开通失败', icon: 'none' })
  170. }).finally(function() {
  171. self.buying = false
  172. })
  173. }
  174. })
  175. },
  176. doRefund() {
  177. var self = this
  178. uni.showModal({
  179. title: '退卡确认',
  180. content: '7 日内退卡:退款金额 = 实付 − 已用沙龙次数 × ¥68,确认退卡吗?',
  181. confirmColor: '#C0392B',
  182. success: function(res) {
  183. if (!res.confirm) return
  184. refundMember().then(function(resp) {
  185. uni.showModal({
  186. title: '退卡成功',
  187. content: '退款金额:¥' + (resp.data && resp.data.refundAmount !== undefined ? ((resp.data.refundAmount / 100).toFixed(2)) : '') + ',原路退回',
  188. showCancel: false,
  189. success: function() {
  190. self.loadMember()
  191. }
  192. })
  193. }).catch(function(err) {
  194. uni.showToast({ title: (err && err.message) || '退卡失败', icon: 'none' })
  195. })
  196. }
  197. })
  198. },
  199. goSalonList() {
  200. uni.navigateTo({ url: '/pages/salon/list' })
  201. }
  202. }
  203. }
  204. </script>
  205. <style scoped>
  206. .member-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  207. .empty-tip { font-size: 26rpx; color: #6B7B8C; padding: 64rpx 0; text-align: center; }
  208. .head-banner { background: linear-gradient(135deg, #2E6FA8, #1F4E79); border-radius: 16rpx; padding: 40rpx 32rpx; margin-bottom: 24rpx; }
  209. .head-title { display: block; font-size: 40rpx; font-weight: 700; color: #FFF; margin-bottom: 8rpx; }
  210. .head-sub { display: block; font-size: 26rpx; color: rgba(255,255,255,0.9); }
  211. .mcard { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; border: 2rpx solid #E3ECF4; }
  212. .companion-card { border: 2rpx solid #C3D2DF; }
  213. .mcard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20rpx; }
  214. .mcard-name { font-size: 34rpx; font-weight: 700; color: #1E3A5F; }
  215. .mcard-price { font-size: 26rpx; color: #2E6FA8; }
  216. .price-num { font-size: 56rpx; font-weight: 700; }
  217. .price-year { font-size: 24rpx; color: #6B7B8C; }
  218. .mcard-benefit { display: flex; align-items: center; margin-bottom: 10rpx; }
  219. .benefit-dot { font-size: 26rpx; color: #2E6FA8; margin-right: 10rpx; }
  220. .benefit-text { font-size: 26rpx; color: #3B5A78; }
  221. .mcard-limit { display: block; font-size: 22rpx; color: #6B7B8C; margin-top: 8rpx; }
  222. .buy-btn { width: 100%; height: 84rpx; line-height: 84rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 42rpx; border: none; margin-top: 24rpx; }
  223. .buy-btn:active { opacity: 0.85; }
  224. .status-card { border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  225. .status-active { background: #0E8A4F; }
  226. .status-pending { background: #B9770E; }
  227. .status-expired { background: #6B7B8C; }
  228. .status-refunded { background: #6B7B8C; }
  229. .status-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24rpx; }
  230. .status-name { font-size: 36rpx; font-weight: 700; color: #FFF; }
  231. .status-tag { font-size: 24rpx; color: #FFF; background: rgba(255,255,255,0.25); padding: 6rpx 20rpx; border-radius: 24rpx; }
  232. .status-row { display: flex; align-items: center; margin-bottom: 12rpx; }
  233. .status-label { font-size: 25rpx; color: rgba(255,255,255,0.85); width: 140rpx; flex-shrink: 0; }
  234. .status-value { font-size: 26rpx; color: #FFF; font-weight: 600; }
  235. .warn-text { color: #E8F3FC; }
  236. .benefit-card { background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; }
  237. .benefit-title { display: block; font-size: 30rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 16rpx; }
  238. .benefit-item { display: flex; align-items: center; margin-bottom: 10rpx; }
  239. .benefit-dot { font-size: 26rpx; color: #0E8A4F; margin-right: 10rpx; }
  240. .salon-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-bottom: 24rpx; }
  241. .salon-btn:active { opacity: 0.85; }
  242. .disabled-btn { background: #C3D2DF; }
  243. .action-row { display: flex; flex-direction: column; align-items: center; }
  244. .renew-btn { width: 100%; height: 84rpx; line-height: 84rpx; background: #FFF; color: #2E6FA8; font-size: 30rpx; font-weight: 600; border-radius: 42rpx; border: 2rpx solid #C3D2DF; }
  245. .renew-btn:active { background: #E8F3FC; }
  246. .refund-link { font-size: 26rpx; color: #C0392B; text-decoration: underline; margin-top: 24rpx; padding: 8rpx 16rpx; }
  247. .refund-tip { font-size: 24rpx; color: #6B7B8C; margin-top: 24rpx; }
  248. </style>