TeacherFamilies.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <div class="teacher-families admin-page">
  3. <!-- 页面标题区 -->
  4. <div class="page-header">
  5. <div class="header-left">
  6. <h2 class="page-title">我的家庭</h2>
  7. <span class="page-desc">管理您服务家庭的信息和任务</span>
  8. </div>
  9. <div class="header-actions">
  10. </div>
  11. </div>
  12. <!-- 统计卡片 -->
  13. <el-row :gutter="24" class="stats-row">
  14. <el-col :span="6">
  15. <div class="stat-card">
  16. <div class="stat-icon blue">
  17. <i class="el-icon-user-solid"></i>
  18. </div>
  19. <div class="stat-info">
  20. <div class="stat-value">{{ stats.total }}</div>
  21. <div class="stat-label">总家庭数</div>
  22. </div>
  23. </div>
  24. </el-col>
  25. <el-col :span="6">
  26. <div class="stat-card">
  27. <div class="stat-icon green">
  28. <i class="el-icon-circle-check"></i>
  29. </div>
  30. <div class="stat-info">
  31. <div class="stat-value">{{ stats.active }}</div>
  32. <div class="stat-label">服务中</div>
  33. </div>
  34. </div>
  35. </el-col>
  36. <el-col :span="6">
  37. <div class="stat-card">
  38. <div class="stat-icon orange">
  39. <i class="el-icon-user"></i>
  40. </div>
  41. <div class="stat-info">
  42. <div class="stat-value">{{ stats.children }}</div>
  43. <div class="stat-label">孩子总数</div>
  44. </div>
  45. </div>
  46. </el-col>
  47. <el-col :span="6">
  48. <div class="stat-card">
  49. <div class="stat-icon purple">
  50. <i class="el-icon-s-data"></i>
  51. </div>
  52. <div class="stat-info">
  53. <div class="stat-value">{{ stats.avgCompletion }}%</div>
  54. <div class="stat-label">平均完成率</div>
  55. </div>
  56. </div>
  57. </el-col>
  58. </el-row>
  59. <!-- 搜索筛选 -->
  60. <el-card class="filter-card">
  61. <el-row :gutter="16">
  62. <el-col :span="8">
  63. <el-input placeholder="搜索家庭名称或ID" v-model="searchKeyword" prefix-icon="el-icon-search" clearable>
  64. </el-input>
  65. </el-col>
  66. <el-col :span="6">
  67. <el-select placeholder="服务状态" v-model="filterStatus" clearable>
  68. <el-option label="服务中" value="active"></el-option>
  69. <el-option label="已暂停" value="inactive"></el-option>
  70. </el-select>
  71. </el-col>
  72. <el-col :span="6">
  73. <el-select placeholder="服务类型" v-model="filterServiceType" clearable>
  74. <el-option label="基础服务" value="basic"></el-option>
  75. <el-option label="高级服务" value="premium"></el-option>
  76. </el-select>
  77. </el-col>
  78. </el-row>
  79. </el-card>
  80. <!-- 家庭列表 -->
  81. <el-card class="table-card">
  82. <el-table :data="filteredFamilies" stripe style="width: 100%;" v-loading="loading" :max-height="tableHeight">
  83. <el-table-column label="家庭信息" min-width="200">
  84. <template slot-scope="scope">
  85. <div class="family-cell">
  86. <div class="family-avatar">
  87. <i class="el-icon-house"></i>
  88. </div>
  89. <div class="family-detail">
  90. <div class="family-name">{{ scope.row.familyName || '家庭' + scope.row.familyId }}</div>
  91. <div class="family-id">ID: {{ scope.row.familyId }}</div>
  92. </div>
  93. </div>
  94. </template>
  95. </el-table-column>
  96. <el-table-column prop="serviceType" label="服务类型" width="120">
  97. <template slot-scope="scope">
  98. <el-tag size="small" :type="scope.row.serviceType === 'premium' ? 'warning' : ''" effect="plain">
  99. {{ scope.row.serviceType === 'premium' ? '高级服务' : '基础服务' }}
  100. </el-tag>
  101. </template>
  102. </el-table-column>
  103. <el-table-column prop="servicePrice" label="服务价格" width="120">
  104. <template slot-scope="scope">
  105. <span class="price">{{ formatPriceWithSymbol(scope.row.servicePrice) }}</span>
  106. </template>
  107. </el-table-column>
  108. <el-table-column prop="childrenCount" label="孩子数" width="80">
  109. <template slot-scope="scope">
  110. <span class="children-count">{{ scope.row.childrenCount || 0 }}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column prop="taskCompletionRate" label="任务完成率" width="150">
  114. <template slot-scope="scope">
  115. <div class="completion-cell">
  116. <el-progress :percentage="scope.row.taskCompletionRate || 0" :color="getCompletionColor(scope.row.taskCompletionRate || 0)" :show-text="false" style="width: 80px"></el-progress>
  117. <span class="completion-text">{{ scope.row.taskCompletionRate || 0 }}%</span>
  118. </div>
  119. </template>
  120. </el-table-column>
  121. <el-table-column prop="status" label="状态" width="100">
  122. <template slot-scope="scope">
  123. <el-tag :type="scope.row.status === 'active' ? 'success' : 'info'" effect="dark" size="small">
  124. {{ scope.row.status === 'active' ? '服务中' : '已暂停' }}
  125. </el-tag>
  126. </template>
  127. </el-table-column>
  128. <el-table-column prop="boundAt" label="绑定时间" width="160"></el-table-column>
  129. <el-table-column label="操作" width="200" fixed="right">
  130. <template slot-scope="{ row }">
  131. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  132. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  133. <el-button size="mini">
  134. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  135. </el-button>
  136. <el-dropdown-menu slot="dropdown">
  137. <el-dropdown-item command="view" icon="el-icon-view">查看详情</el-dropdown-item>
  138. <el-dropdown-item command="message" icon="el-icon-chat-dot-round">发消息</el-dropdown-item>
  139. <el-dropdown-item command="delete" icon="el-icon-delete">删除</el-dropdown-item>
  140. </el-dropdown-menu>
  141. </el-dropdown>
  142. </template>
  143. </el-table-column>
  144. </el-table>
  145. </el-card>
  146. <!-- 家庭详情抽屉 -->
  147. <el-drawer :visible.sync="drawerVisible" :title="(currentFamily && currentFamily.familyName) || '家庭详情'" size="500px" direction="rtl">
  148. <div class="drawer-content" v-if="currentFamily">
  149. <el-divider content-position="left">基本信息</el-divider>
  150. <div class="detail-row">
  151. <span class="detail-label">家庭ID</span>
  152. <span class="detail-value">{{ currentFamily.familyId }}</span>
  153. </div>
  154. <div class="detail-row">
  155. <span class="detail-label">家庭名称</span>
  156. <span class="detail-value">{{ currentFamily.familyName || '-' }}</span>
  157. </div>
  158. <div class="detail-row">
  159. <span class="detail-label">服务类型</span>
  160. <span class="detail-value">{{ currentFamily.serviceType === 'premium' ? '高级服务' : '基础服务' }}</span>
  161. </div>
  162. <div class="detail-row">
  163. <span class="detail-label">服务价格</span>
  164. <span class="detail-value price">{{ formatPriceWithSymbol(currentFamily.servicePrice) }}</span>
  165. </div>
  166. <div class="detail-row">
  167. <span class="detail-label">绑定时间</span>
  168. <span class="detail-value">{{ currentFamily.boundAt }}</span>
  169. </div>
  170. <el-divider content-position="left">成员信息</el-divider>
  171. <div class="member-list">
  172. <div class="member-item" v-for="child in currentFamily.children || []" :key="child.id">
  173. <div class="member-avatar">
  174. <i class="el-icon-user"></i>
  175. </div>
  176. <div class="member-info">
  177. <div class="member-name">{{ child.nickname || '孩子' + child.id }}</div>
  178. <div class="member-meta">
  179. <span>{{ child.age || 0 }}岁</span>
  180. </div>
  181. </div>
  182. <div class="member-stats">
  183. <span class="points">{{ child.totalPoints || 0 }}积分</span>
  184. </div>
  185. </div>
  186. <div v-if="!currentFamily.children || currentFamily.children.length === 0" class="no-members">
  187. 暂无成员信息
  188. </div>
  189. </div>
  190. <el-divider content-position="left">任务概况</el-divider>
  191. <el-row :gutter="12" class="task-stats">
  192. <el-col :span="8">
  193. <div class="task-stat-item">
  194. <div class="task-stat-value" style="color: #3B82F6">{{ currentFamily.todayTasks || 0 }}</div>
  195. <div class="task-stat-label">今日任务</div>
  196. </div>
  197. </el-col>
  198. <el-col :span="8">
  199. <div class="task-stat-item">
  200. <div class="task-stat-value" style="color: #10B981">{{ currentFamily.completedTasks || 0 }}</div>
  201. <div class="task-stat-label">已完成</div>
  202. </div>
  203. </el-col>
  204. <el-col :span="8">
  205. <div class="task-stat-item">
  206. <div class="task-stat-value" style="color: #F59E0B">{{ currentFamily.pendingTasks || 0 }}</div>
  207. <div class="task-stat-label">待完成</div>
  208. </div>
  209. </el-col>
  210. </el-row>
  211. </div>
  212. </el-drawer>
  213. </div>
  214. </template>
  215. <script>
  216. import { getBoundFamilies } from '@/api/guide'
  217. export default {
  218. name: 'TeacherFamilies',
  219. data() {
  220. return {
  221. families: [],
  222. searchKeyword: '',
  223. filterStatus: '',
  224. filterServiceType: '',
  225. drawerVisible: false,
  226. currentFamily: null,
  227. loading: false
  228. }
  229. },
  230. computed: {
  231. tableHeight() {
  232. return window.innerHeight - 300
  233. },
  234. stats() {
  235. return {
  236. total: this.families.length,
  237. active: this.families.filter(f => f.status === 'active').length,
  238. children: this.families.reduce((sum, f) => sum + (f.childrenCount || 0), 0),
  239. avgCompletion: this.families.length > 0
  240. ? Math.round(this.families.reduce((sum, f) => sum + (f.taskCompletionRate || 0), 0) / this.families.length)
  241. : 0
  242. }
  243. },
  244. filteredFamilies() {
  245. return this.families.filter(f => {
  246. if (this.searchKeyword) {
  247. const kw = this.searchKeyword.toLowerCase()
  248. const matchName = (f.familyName || '').toLowerCase().includes(kw)
  249. const matchId = String(f.familyId).includes(kw)
  250. if (!matchName && !matchId) return false
  251. }
  252. if (this.filterStatus && f.status !== this.filterStatus) return false
  253. if (this.filterServiceType && f.serviceType !== this.filterServiceType) return false
  254. return true
  255. })
  256. }
  257. },
  258. created() {
  259. this.loadFamilies()
  260. },
  261. methods: {
  262. async loadFamilies() {
  263. this.loading = true
  264. try {
  265. const res = await getBoundFamilies()
  266. if (res.data) {
  267. this.families = res.data
  268. }
  269. } catch (e) {
  270. console.error(e)
  271. } finally {
  272. this.loading = false
  273. }
  274. },
  275. handleView(row) {
  276. this.currentFamily = row
  277. this.drawerVisible = true
  278. },
  279. handleMessage(row) {
  280. this.$router.push({ path: '/teacher-messages', query: { familyId: row.familyId } })
  281. },
  282. handleEdit(row) {
  283. this.handleView(row)
  284. },
  285. handleActionCmd(row, cmd) {
  286. switch (cmd) {
  287. case 'view': this.handleView(row); break
  288. case 'edit': this.handleEdit(row); break
  289. case 'message': this.handleMessage(row); break
  290. case 'delete': this.$confirm('确认删除该家庭吗?', '提示', { type: 'warning' }).then(() => {}).catch(() => {}); break
  291. }
  292. },
  293. getCompletionColor(rate) {
  294. if (rate >= 80) return '#10B981'
  295. if (rate >= 50) return '#F59E0B'
  296. return '#EF4444'
  297. }
  298. }
  299. }
  300. </script>
  301. <style scoped>
  302. .teacher-families {
  303. padding: 24px;
  304. background: #F0F7FF;
  305. min-height: calc(100vh - 120px);
  306. }
  307. /* 页面标题 */
  308. .page-header {
  309. display: flex;
  310. justify-content: space-between;
  311. align-items: flex-start;
  312. margin-bottom: 24px;
  313. }
  314. .page-title {
  315. font-size: 24px;
  316. font-weight: 700;
  317. color: #1E293B;
  318. margin: 0 0 4px 0;
  319. }
  320. .page-desc {
  321. font-size: 14px;
  322. color: #64748B;
  323. }
  324. .primary-btn {
  325. background: linear-gradient(135deg, #3B82F6 0%, #60A5FA 100%);
  326. border: none;
  327. padding: 12px 24px;
  328. border-radius: 10px;
  329. font-weight: 500;
  330. }
  331. .primary-btn:hover {
  332. background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
  333. }
  334. /* 统计卡片 */
  335. .stats-row {
  336. margin-bottom: 24px;
  337. }
  338. .stat-card {
  339. display: flex;
  340. align-items: center;
  341. padding: 20px 24px;
  342. background: #FFFFFF;
  343. border-radius: 16px;
  344. box-shadow: 0 2px 12px rgba(59, 130, 246, 0.08);
  345. }
  346. .stat-icon {
  347. width: 52px;
  348. height: 52px;
  349. border-radius: 14px;
  350. display: flex;
  351. align-items: center;
  352. justify-content: center;
  353. margin-right: 16px;
  354. font-size: 22px;
  355. color: #FFFFFF;
  356. }
  357. .stat-icon.blue {
  358. background: linear-gradient(135deg, #3B82F6 0%, #60A5FA 100%);
  359. }
  360. .stat-icon.green {
  361. background: linear-gradient(135deg, #10B981 0%, #34D399 100%);
  362. }
  363. .stat-icon.orange {
  364. background: linear-gradient(135deg, #F59E0B 0%, #FBBF24 100%);
  365. }
  366. .stat-icon.purple {
  367. background: linear-gradient(135deg, #8B5CF6 0%, #A78BFA 100%);
  368. }
  369. .stat-value {
  370. font-size: 28px;
  371. font-weight: 700;
  372. color: #1E293B;
  373. }
  374. .stat-label {
  375. font-size: 14px;
  376. color: #64748B;
  377. margin-top: 2px;
  378. }
  379. /* 筛选卡片 */
  380. .filter-card {
  381. border-radius: 16px;
  382. margin-bottom: 24px;
  383. border: none;
  384. box-shadow: 0 2px 12px rgba(59, 130, 246, 0.06);
  385. }
  386. /* 表格卡片 */
  387. .table-card {
  388. border-radius: 16px;
  389. border: none;
  390. box-shadow: 0 2px 12px rgba(59, 130, 246, 0.06);
  391. }
  392. .family-cell {
  393. display: flex;
  394. align-items: center;
  395. }
  396. .family-avatar {
  397. width: 40px;
  398. height: 40px;
  399. background: linear-gradient(135deg, #3B82F6 0%, #60A5FA 100%);
  400. border-radius: 10px;
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. color: #FFFFFF;
  405. margin-right: 12px;
  406. font-size: 16px;
  407. }
  408. .family-name {
  409. font-weight: 600;
  410. font-size: 15px;
  411. color: #1E293B;
  412. }
  413. .family-id {
  414. font-size: 12px;
  415. color: #94A3B8;
  416. margin-top: 2px;
  417. }
  418. .price {
  419. font-weight: 600;
  420. color: #F59E0B;
  421. }
  422. .children-count {
  423. font-weight: 600;
  424. color: #3B82F6;
  425. }
  426. .completion-cell {
  427. display: flex;
  428. align-items: center;
  429. gap: 8px;
  430. }
  431. .completion-text {
  432. font-size: 13px;
  433. font-weight: 600;
  434. color: #64748B;
  435. width: 35px;
  436. }
  437. /* 抽屉样式 */
  438. .drawer-content {
  439. padding: 0 24px;
  440. }
  441. .detail-row {
  442. display: flex;
  443. justify-content: space-between;
  444. padding: 10px 0;
  445. border-bottom: 1px solid #F1F5F9;
  446. }
  447. .detail-label {
  448. color: #64748B;
  449. font-size: 14px;
  450. }
  451. .detail-value {
  452. color: #1E293B;
  453. font-size: 14px;
  454. font-weight: 500;
  455. }
  456. .member-list {
  457. margin-top: 12px;
  458. }
  459. .member-item {
  460. display: flex;
  461. align-items: center;
  462. padding: 12px 0;
  463. border-bottom: 1px solid #F1F5F9;
  464. }
  465. .member-avatar {
  466. width: 40px;
  467. height: 40px;
  468. background: linear-gradient(135deg, #FF6B9D 0%, #FF8C6B 100%);
  469. border-radius: 50%;
  470. display: flex;
  471. align-items: center;
  472. justify-content: center;
  473. color: #FFFFFF;
  474. margin-right: 12px;
  475. }
  476. .member-name {
  477. font-weight: 600;
  478. color: #1E293B;
  479. }
  480. .member-meta {
  481. display: flex;
  482. align-items: center;
  483. gap: 8px;
  484. margin-top: 4px;
  485. font-size: 13px;
  486. color: #64748B;
  487. }
  488. .member-stats {
  489. margin-left: auto;
  490. }
  491. .points {
  492. font-weight: 600;
  493. color: #F59E0B;
  494. }
  495. .no-members {
  496. text-align: center;
  497. padding: 24px;
  498. color: #94A3B8;
  499. }
  500. .task-stats {
  501. margin-top: 12px;
  502. }
  503. .task-stat-item {
  504. text-align: center;
  505. padding: 16px;
  506. background: #F8FAFC;
  507. border-radius: 12px;
  508. }
  509. .task-stat-value {
  510. font-size: 24px;
  511. font-weight: 700;
  512. }
  513. .task-stat-label {
  514. font-size: 12px;
  515. color: #64748B;
  516. margin-top: 4px;
  517. }
  518. </style>