index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <text class="title">我的下级成长规划师</text>
  5. <text class="subtitle">查看和管理下级成长规划师</text>
  6. </view>
  7. <!-- 下级成长规划师列表 -->
  8. <view class="section">
  9. <view class="section-title">直接下级</view>
  10. <view class="guide-list" v-if="childGuides.length > 0">
  11. <view
  12. class="guide-item"
  13. v-for="guide in childGuides"
  14. :key="guide.id"
  15. @click="viewGuideDetail(guide)"
  16. >
  17. <image class="guide-avatar" :src="guide.avatar || '/static/default-avatar.png'" />
  18. <view class="guide-info">
  19. <text class="guide-name">{{ guide.nickname || '未命名' }}</text>
  20. <text class="guide-stats">服务家庭: {{ guide.familyCount || 0 }}</text>
  21. <text class="guide-stats">测评次数: {{ guide.assessmentCount || 0 }}</text>
  22. </view>
  23. <view class="guide-actions">
  24. <text class="action-btn" @click.stop="viewReports(guide)">查看报告</text>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="empty-state" v-else>
  29. <text class="empty-icon">👥</text>
  30. <text class="empty-text">还没有下级成长规划师</text>
  31. <text class="empty-hint">分享邀请码邀请其他成长规划师加入</text>
  32. </view>
  33. </view>
  34. <!-- 所有下级成长规划师 -->
  35. <view class="section" v-if="allChildGuides.length > 0">
  36. <view class="section-title">所有下级(含间接)</view>
  37. <view class="guide-list">
  38. <view
  39. class="guide-item"
  40. v-for="guide in allChildGuides"
  41. :key="guide.id"
  42. @click="viewGuideDetail(guide)"
  43. >
  44. <image class="guide-avatar" :src="guide.avatar || '/static/default-avatar.png'" />
  45. <view class="guide-info">
  46. <text class="guide-name">{{ guide.nickname || '未命名' }}</text>
  47. <text class="guide-stats">服务家庭: {{ guide.familyCount || 0 }}</text>
  48. <text class="guide-stats">测评次数: {{ guide.assessmentCount || 0 }}</text>
  49. </view>
  50. <view class="guide-actions">
  51. <text class="action-btn" @click.stop="viewReports(guide)">查看报告</text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 上级成长规划师 -->
  57. <view class="section" v-if="parentGuide">
  58. <view class="section-title">我的上级成长规划师</view>
  59. <view class="parent-guide-card">
  60. <image class="guide-avatar" :src="parentGuide.avatar || '/static/default-avatar.png'" />
  61. <view class="guide-info">
  62. <text class="guide-name">{{ parentGuide.nickname || '未命名' }}</text>
  63. <text class="guide-desc">我的上级成长规划师</text>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 邀请码分享 -->
  68. <view class="section">
  69. <view class="section-title">邀请下级成长规划师</view>
  70. <button class="btn-share" @click="goToShare">
  71. <text class="btn-icon">📤</text>
  72. <text class="btn-text">分享邀请码</text>
  73. </button>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import { getChildGuides, getAllChildGuides, getParentGuide } from '../../../utils/api.js'
  79. export default {
  80. data() {
  81. return {
  82. childGuides: [],
  83. allChildGuides: [],
  84. parentGuide: null
  85. }
  86. },
  87. onLoad() {
  88. this.loadData()
  89. this._onLoadFired = true
  90. },
  91. onShow() {
  92. // 首次进入:onLoad 已加载,跳过避免双发;切 Tab 返回时刷新
  93. if (this._onLoadFired) {
  94. this._onLoadFired = false
  95. } else {
  96. this.loadData()
  97. }
  98. },
  99. methods: {
  100. async loadData() {
  101. try {
  102. const userId = uni.getStorageSync('userId')
  103. // 并行获取数据
  104. const [childRes, allChildRes, parentRes] = await Promise.all([
  105. getChildGuides(userId),
  106. getAllChildGuides(userId),
  107. getParentGuide(userId)
  108. ])
  109. if (childRes.code === 200) {
  110. this.childGuides = childRes.data || []
  111. }
  112. if (allChildRes.code === 200) {
  113. this.allChildGuides = allChildRes.data || []
  114. }
  115. if (parentRes.code === 200) {
  116. this.parentGuide = parentRes.data
  117. }
  118. } catch (e) {
  119. console.error('加载数据失败', e)
  120. }
  121. },
  122. viewGuideDetail(guide) {
  123. uni.showModal({
  124. title: '成长规划师详情',
  125. content: `姓名: ${guide.nickname || '未命名'}\n服务家庭: ${guide.familyCount || 0}\n测评次数: ${guide.assessmentCount || 0}`,
  126. showCancel: false
  127. })
  128. },
  129. viewReports(guide) {
  130. uni.navigateTo({
  131. url: `/pages/assessment/results?guideId=${guide.id}`
  132. })
  133. },
  134. goToShare() {
  135. uni.navigateTo({
  136. url: '/pages/guide/invite/share'
  137. })
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped>
  143. .container {
  144. padding: 30rpx;
  145. background: #F8F8F8;
  146. min-height: 100vh;
  147. }
  148. .header {
  149. text-align: center;
  150. padding: 60rpx 0 40rpx;
  151. }
  152. .title {
  153. font-size: 48rpx;
  154. font-weight: bold;
  155. color: #333;
  156. display: block;
  157. margin-bottom: 20rpx;
  158. }
  159. .subtitle {
  160. font-size: 28rpx;
  161. color: #666;
  162. }
  163. .section {
  164. background: #fff;
  165. border-radius: 20rpx;
  166. padding: 30rpx;
  167. margin-bottom: 30rpx;
  168. }
  169. .section-title {
  170. font-size: 32rpx;
  171. font-weight: bold;
  172. color: #333;
  173. margin-bottom: 20rpx;
  174. }
  175. .guide-list {
  176. display: flex;
  177. flex-direction: column;
  178. gap: 20rpx;
  179. }
  180. .guide-item {
  181. display: flex;
  182. align-items: center;
  183. background: #F8F8F8;
  184. border-radius: 10rpx;
  185. padding: 20rpx;
  186. }
  187. .guide-avatar {
  188. width: 80rpx;
  189. height: 80rpx;
  190. border-radius: 50%;
  191. object-fit: cover;
  192. margin-right: 20rpx;
  193. }
  194. .guide-info {
  195. flex: 1;
  196. }
  197. .guide-name {
  198. font-size: 30rpx;
  199. font-weight: bold;
  200. color: #333;
  201. display: block;
  202. margin-bottom: 8rpx;
  203. }
  204. .guide-stats {
  205. font-size: 24rpx;
  206. color: #999;
  207. display: block;
  208. margin-bottom: 4rpx;
  209. }
  210. .guide-actions {
  211. display: flex;
  212. gap: 10rpx;
  213. }
  214. .action-btn {
  215. font-size: 24rpx;
  216. color: #667eea;
  217. padding: 8rpx 16rpx;
  218. background: #F0F4FF;
  219. border-radius: 20rpx;
  220. }
  221. .empty-state {
  222. text-align: center;
  223. padding: 60rpx 0;
  224. }
  225. .empty-icon {
  226. font-size: 80rpx;
  227. display: block;
  228. margin-bottom: 20rpx;
  229. }
  230. .empty-text {
  231. font-size: 28rpx;
  232. color: #999;
  233. display: block;
  234. margin-bottom: 10rpx;
  235. }
  236. .empty-hint {
  237. font-size: 24rpx;
  238. color: #CCC;
  239. }
  240. .parent-guide-card {
  241. display: flex;
  242. align-items: center;
  243. background: #F0F4FF;
  244. border-radius: 10rpx;
  245. padding: 20rpx;
  246. }
  247. .btn-share {
  248. width: 100%;
  249. height: 80rpx;
  250. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  251. color: #fff;
  252. border-radius: 40rpx;
  253. font-size: 28rpx;
  254. font-weight: bold;
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. gap: 10rpx;
  259. }
  260. .btn-icon {
  261. font-size: 32rpx;
  262. }
  263. .btn-text {
  264. font-size: 28rpx;
  265. }
  266. </style>