diff --git a/src/app.config.ts b/src/app.config.ts index 010eb78..ad6049d 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -9,6 +9,7 @@ export default { 'pages/device/add', 'pages/device/config', 'pages/family/index', + 'pages/family/detail', 'pages/event/index' ], window: { diff --git a/src/pages/family/detail.module.scss b/src/pages/family/detail.module.scss new file mode 100644 index 0000000..eab13b5 --- /dev/null +++ b/src/pages/family/detail.module.scss @@ -0,0 +1,54 @@ +.page { + min-height: 100vh; + background: $color-bg; + padding-bottom: 40px; +} + +.stateWrap { + margin-top: 80px; + display: flex; + flex-direction: column; + align-items: center; +} + +.body { + padding: 24px; +} + +// 添加关爱对象虚线卡:与列表页底部加号卡同款式 +.addCared { + margin-top: 24px; + padding: 48px 32px; + background: $color-bg-white; + border: 1px dashed $color-primary-light-border; + border-radius: $radius-lg; + display: flex; + flex-direction: column; + align-items: center; +} + +.addCaredIcon { + width: 96px; + height: 96px; + border-radius: $radius-circle; + background: $color-primary; + display: flex; + align-items: center; + justify-content: center; + margin-bottom: 16px; +} + +.addCaredIconText { + font-size: 48px; + font-weight: 300; + color: #ffffff; +} + +.addCaredText { + font-size: 26px; + color: $color-text-secondary; +} + +.section { + margin-top: 24px; +} diff --git a/src/pages/family/detail.tsx b/src/pages/family/detail.tsx new file mode 100644 index 0000000..87bbd84 --- /dev/null +++ b/src/pages/family/detail.tsx @@ -0,0 +1,117 @@ +import { useState } from 'react' +import { useRouter, useDidShow } from '@tarojs/taro' +import { View, Text } from '@tarojs/components' +import { Navbar } from '@/components/navbar' +import { Loading } from '@/components/loading' +import { StateView } from '@/components/state-view' +import { FamilyCard } from '@/components/family-card' +import { ListRow, ListRowGroup } from '@/components/list-row' +import { + getFamilyDetail, + canAddCared, + type FamilyDetailData +} from '@/api/family' +import { MAX_CARED_PER_FAMILY } from '@/constants/family' +import { ROUTES } from '@/constants/routes' +import { navigateBack, navigateTo } from '@/utils/navigation' +import { showToast } from '@/utils/toast' +import styles from './detail.module.scss' + +export default function FamilyDetail() { + const router = useRouter() + const familyId = router.params.id ?? '' + + const [loading, setLoading] = useState(true) + const [detail, setDetail] = useState(null) + + const load = async () => { + setLoading(true) + try { + setDetail(await getFamilyDetail(familyId)) + } catch { + setDetail(null) + } finally { + setLoading(false) + } + } + + // 从添加表单返回时刷新(caredCount 变化) + useDidShow(() => { + load() + }) + + const addCared = async () => { + if (!(await canAddCared(familyId))) { + showToast('已达上限') + return + } + navigateTo(`${ROUTES.FAMILY_CONTACT_ADD}?familyId=${familyId}`) + } + + if (loading) { + return ( + + + + + ) + } + + if (!detail) { + return ( + + + navigateBack()} + /> + + ) + } + + const canAdd = detail.family.caredCount < MAX_CARED_PER_FAMILY + const stub = (tip: string) => () => showToast(tip) + + return ( + + + + + + + {/* 添加关爱对象卡:达上限后静态 */} + + + + + + + {canAdd ? `+ 最多可添加 ${MAX_CARED_PER_FAMILY} 人` : '已达上限'} + + + + + + {detail.members.map((m) => ( + + ))} + + + + + + + + + + + + + + ) +}