select.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="select-page" :style="{ '--font-scale': fontScale }">
  3. <!-- 顶部状态区 -->
  4. <view class="status-card" v-if="pageState === 'bound'">
  5. <view class="current-label">我的管家</view>
  6. <view class="current-row">
  7. <image class="current-avatar" :src="myButler.avatar || '/static/logo.png'" mode="aspectFill" />
  8. <view class="current-info">
  9. <text class="current-name">{{ myButler.nickname }}</text>
  10. <text class="current-date">{{ formatDate(myButler.assignedAt) }} 绑定</text>
  11. </view>
  12. </view>
  13. <view class="current-desc">{{ myButler.description }}</view>
  14. <button class="btn-change" @click="scrollToList">更换管家</button>
  15. </view>
  16. <view class="upgrade-banner" v-if="pageState === 'locked'" @click="goUpgrade">
  17. <text class="upgrade-text">久久一生(L2)会员专享,升级后可选择专属管家</text>
  18. <text class="upgrade-arrow">›</text>
  19. </view>
  20. <!-- 管家列表 -->
  21. <view class="list-section" id="butlerList">
  22. <view class="section-title">可选管家</view>
  23. <view class="butler-card" v-for="(item, idx) in butlers" :key="idx"
  24. :class="{ active: myButler && myButler.butlerUserId === item.butlerUserId }">
  25. <image class="card-avatar" :src="item.avatar || '/static/logo.png'" mode="aspectFill" />
  26. <view class="card-body">
  27. <view class="card-top">
  28. <text class="card-name">{{ item.nickname }}</text>
  29. <text class="card-slots">剩余名额 {{ item.remainingSlots }}</text>
  30. </view>
  31. <text class="card-desc">{{ item.description || '专业家庭健康管家' }}</text>
  32. </view>
  33. <button class="btn-select"
  34. :disabled="pageState === 'locked' || item.remainingSlots <= 0"
  35. @click="onSelect(item)">
  36. {{ myButler && myButler.butlerUserId === item.butlerUserId ? '当前' : '选择' }}
  37. </button>
  38. </view>
  39. <view class="empty-tip" v-if="butlers.length === 0 && !loading">暂无可选管家</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { getAvailableButlers, getMyButler, selectButler } from '@/utils/api.js'
  45. import fontScaleMixin from '@/mixins/font-scale.js'
  46. export default {
  47. mixins: [fontScaleMixin],
  48. data() {
  49. return {
  50. loading: false,
  51. pageState: 'browse', // browse=可浏览未绑定 / bound=已绑定 / locked=非L2
  52. lockReason: '',
  53. myButler: null,
  54. butlers: [],
  55. keySeq: 0
  56. }
  57. },
  58. onLoad() {
  59. this.initPage()
  60. },
  61. onShow() {
  62. if (this.myButler || this.pageState === 'bound') {
  63. this.refreshMyButler()
  64. }
  65. },
  66. methods: {
  67. formatDate(iso) {
  68. if (!iso) return ''
  69. return iso.substring(0, 19).replace('T', ' ').substring(0, 16)
  70. },
  71. initPage() {
  72. var that = this
  73. that.loading = true
  74. Promise.all([getAvailableButlers(), getMyButler()])
  75. .then(function (resArr) {
  76. var listRes = resArr[0]
  77. var myRes = resArr[1]
  78. if (listRes && listRes.code === 200) {
  79. that.butlers = listRes.data || []
  80. }
  81. if (myRes && myRes.code === 200 && myRes.data) {
  82. that.myButler = myRes.data
  83. that.pageState = 'bound'
  84. }
  85. })
  86. .catch(function () {
  87. uni.showToast({ title: '加载失败', icon: 'none' })
  88. })
  89. .then(function () { that.loading = false })
  90. },
  91. refreshMyButler() {
  92. var that = this
  93. getMyButler().then(function (res) {
  94. if (res && res.code === 200) {
  95. that.myButler = res.data
  96. that.pageState = res.data ? 'bound' : 'browse'
  97. }
  98. })
  99. },
  100. markLocked(msg) {
  101. this.pageState = 'locked'
  102. this.lockReason = msg || ''
  103. },
  104. onSelect(item) {
  105. var that = this
  106. if (that.myButler && that.myButler.butlerUserId === item.butlerUserId) return
  107. uni.showModal({
  108. title: '确认选择',
  109. content: '确定选择「' + item.nickname + '」作为您的专属管家?',
  110. success: function (mr) {
  111. if (!mr.confirm) return
  112. selectButler(item.butlerUserId).then(function (res) {
  113. if (res && res.code === 200) {
  114. uni.showToast({ title: '绑定成功', icon: 'success' })
  115. that.initPage()
  116. } else if (res && res.message && res.message.indexOf('久久一生') !== -1) {
  117. that.markLocked(res.message)
  118. uni.showModal({
  119. title: '会员权益',
  120. content: res.message,
  121. showCancel: false,
  122. success: function () { that.goUpgrade() }
  123. })
  124. } else {
  125. uni.showToast({ title: (res && res.message) || '绑定失败', icon: 'none' })
  126. }
  127. })
  128. }
  129. })
  130. },
  131. scrollToList() {
  132. uni.pageScrollTo({ selector: '#butlerList', duration: 300 })
  133. },
  134. goUpgrade() {
  135. uni.navigateTo({ url: '/pages/membership/upgrade' })
  136. }
  137. }
  138. }
  139. </script>
  140. <style scoped lang="scss">
  141. .select-page { min-height: 100vh; background: $facade-fill-blue-ghost; padding: 24rpx; box-sizing: border-box; display: flex; flex-direction: column; }
  142. .status-card { background: $app-surface; border-radius: 24rpx; padding: 32rpx; margin-bottom: 24rpx; }
  143. .current-label { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-bottom: 16rpx; }
  144. .current-row { display: flex; align-items: center; }
  145. .current-avatar { width: 96rpx; height: 96rpx; border-radius: 50%; margin-right: 20rpx; }
  146. .current-info { display: flex; flex-direction: column; }
  147. .current-name { font-size: calc(34rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; }
  148. .current-date { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-top: 6rpx; }
  149. .current-desc { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-body; margin-top: 20rpx; line-height: 1.6; }
  150. .btn-change { margin-top: 24rpx; background: $brand-primary; color: $app-surface; font-size: calc(28rpx * var(--font-scale, 1)); border-radius: 24rpx; }
  151. .upgrade-banner { display: flex; justify-content: space-between; align-items: center; background: $uni-primary-pale; border: 1rpx solid #ffb56b; border-radius: 16rpx; padding: 24rpx; margin-bottom: 24rpx; }
  152. .upgrade-text { font-size: calc(26rpx * var(--font-scale, 1)); color: #d4770a; flex: 1; }
  153. .upgrade-arrow { font-size: calc(36rpx * var(--font-scale, 1)); color: #d4770a; margin-left: 12rpx; }
  154. .section-title { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; margin: 8rpx 0 20rpx; }
  155. .butler-card { display: flex; align-items: center; background: $app-surface; border-radius: 24rpx; padding: 28rpx; margin-bottom: 20rpx; }
  156. .butler-card.active { border: 2rpx solid $brand-primary; }
  157. .card-avatar { width: 88rpx; height: 88rpx; border-radius: 50%; margin-right: 20rpx; flex-shrink: 0; }
  158. .card-body { flex: 1; min-width: 0; }
  159. .card-top { display: flex; align-items: center; justify-content: space-between; }
  160. .card-name { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; }
  161. .card-slots { font-size: calc(22rpx * var(--font-scale, 1)); color: $status-success; }
  162. .card-desc { display: block; font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-faint; margin-top: 8rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  163. .btn-select { width: 120rpx; height: 60rpx; line-height: 60rpx; padding: 0; font-size: calc(26rpx * var(--font-scale, 1)); background: $brand-primary; color: $app-surface; border-radius: 24rpx; flex-shrink: 0; margin-left: 16rpx; }
  164. .btn-select[disabled] { background: $facade-text-ghost; color: $app-surface; }
  165. .empty-tip { text-align: center; color: $facade-text-muted; font-size: calc(26rpx * var(--font-scale, 1)); padding: 60rpx 0; }
  166. </style>