feat: 积分商城子页面 + 日常监测 + 统计报表 (Chunk 6)
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

小程序 — 积分商城 (3 新页面):
- mall/exchange: 兑换确认 (余额校验/QR码生成)
- mall/orders: 我的订单 (状态筛选/分页/QR展示)
- mall/detail: 积分明细 (余额卡片/收入支出筛选/流水列表)

小程序 — 上报 Tab 改造:
- health/daily-monitoring: 日常监测表单 (血压/体重/血糖/出入量)
- health/index: 增加快捷操作/打卡状态/近期监测卡片
- consultation: 替换占位为咨询列表 (会话/状态/未读)
- profile: 新增积分余额/打卡天数/我的订单/积分明细入口

小程序 — 新增服务:
- services/consultation.ts: 咨询会话 API
- services/points.ts: 扩展兑换/订单/流水 API
- services/health.ts: 扩展日常监测 API

PC 管理端:
- StatisticsDashboard: 统计报表仪表盘 (患者/咨询/随访/积分卡片 + Top10排行 + 快速链接)
- 侧边栏新增统计报表入口 (健康模块首页)
This commit is contained in:
iven
2026-04-25 19:17:11 +08:00
parent 1507ec6036
commit 280f65658a
23 changed files with 2819 additions and 11 deletions

View File

@@ -0,0 +1,186 @@
import React, { useState, useCallback, useRef } from 'react';
import { View, Text } from '@tarojs/components';
import Taro, { useDidShow, useReachBottom, usePullDownRefresh } from '@tarojs/taro';
import { listMyOrders } from '../../../services/points';
import type { PointsOrder } from '../../../services/points';
import EmptyState from '../../../components/EmptyState';
import Loading from '../../../components/Loading';
import './index.scss';
const STATUS_TABS = [
{ key: '', label: '全部' },
{ key: 'pending', label: '待核销' },
{ key: 'verified', label: '已核销' },
{ key: 'expired', label: '已过期' },
];
const STATUS_CONFIG: Record<string, { label: string; className: string }> = {
pending: { label: '待核销', className: 'status-pending' },
verified: { label: '已核销', className: 'status-verified' },
cancelled: { label: '已取消', className: 'status-cancelled' },
expired: { label: '已过期', className: 'status-expired' },
};
export default function MallOrders() {
const [orders, setOrders] = useState<PointsOrder[]>([]);
const [activeTab, setActiveTab] = useState('');
const [page, setPage] = useState(1);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(false);
const loadingRef = useRef(false);
const fetchOrders = useCallback(
async (pageNum: number, status: string, isRefresh = false) => {
if (loadingRef.current) return;
loadingRef.current = true;
setLoading(true);
try {
const res = await listMyOrders({
page: pageNum,
page_size: 10,
});
let list = res.data || [];
// 前端按状态过滤(后端暂不支持 status 参数)
if (status) {
list = list.filter((o) => o.status === status);
}
if (isRefresh) {
setOrders(list);
} else {
setOrders((prev) => [...prev, ...list]);
}
setTotal(res.total);
setPage(pageNum);
} catch {
Taro.showToast({ title: '加载失败', icon: 'none' });
} finally {
loadingRef.current = false;
setLoading(false);
}
},
[],
);
const loadAll = useCallback(
async (status?: string) => {
const s = status !== undefined ? status : activeTab;
await fetchOrders(1, s, true);
},
[fetchOrders, activeTab],
);
useDidShow(() => {
Taro.setNavigationBarTitle({ title: '我的订单' });
loadAll();
});
usePullDownRefresh(() => {
loadAll().finally(() => {
Taro.stopPullDownRefresh();
});
});
useReachBottom(() => {
if (!loading && orders.length < total) {
fetchOrders(page + 1, activeTab);
}
});
const handleTabChange = (key: string) => {
setActiveTab(key);
fetchOrders(1, key, true);
};
const handleShowQrCode = (qrCode: string) => {
Taro.showModal({
title: '核销码',
content: qrCode,
showCancel: false,
confirmText: '知道了',
});
};
const getStatusConfig = (status: string) => {
return STATUS_CONFIG[status] || { label: status, className: 'status-pending' };
};
const formatDate = (dateStr: string) => {
if (!dateStr) return '';
const d = new Date(dateStr);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
};
return (
<View className='orders-page'>
{/* 状态筛选标签 */}
<View className='status-tabs'>
{STATUS_TABS.map((tab) => (
<View
key={tab.key}
className={`status-tab ${activeTab === tab.key ? 'active' : ''}`}
onClick={() => handleTabChange(tab.key)}
>
<Text
className={`status-tab-text ${activeTab === tab.key ? 'active' : ''}`}
>
{tab.label}
</Text>
</View>
))}
</View>
{/* 订单列表 */}
{orders.length === 0 && !loading ? (
<EmptyState
icon='📋'
text='暂无订单'
hint='去商城兑换心仪商品吧'
actionText='去商城'
onAction={() => Taro.switchTab({ url: '/pages/mall/index' })}
/>
) : (
<View className='order-list'>
{orders.map((order) => {
const statusCfg = getStatusConfig(order.status);
return (
<View className='order-card' key={order.id}>
<View className='order-header'>
<Text className='order-product'> {order.product_id.slice(0, 8)}</Text>
<View className={`order-status ${statusCfg.className}`}>
<Text className='order-status-text'>{statusCfg.label}</Text>
</View>
</View>
<View className='order-body'>
<View className='order-row'>
<Text className='order-row-label'></Text>
<Text className='order-row-value cost'>
🪙 {order.points_cost.toLocaleString()}
</Text>
</View>
<View className='order-row'>
<Text className='order-row-label'></Text>
<Text className='order-row-value'>
{formatDate(order.created_at)}
</Text>
</View>
{order.status === 'pending' && (
<View className='order-qrcode' onClick={() => handleShowQrCode(order.qr_code)}>
<Text className='qrcode-label'>: </Text>
<Text className='qrcode-value'>{order.qr_code}</Text>
<Text className='qrcode-tap'></Text>
</View>
)}
</View>
</View>
);
})}
{loading && <Loading />}
{!loading && orders.length >= total && total > 0 && (
<Loading text='没有更多了' />
)}
</View>
)}
</View>
);
}