更新眠花糖慢病管理
This commit is contained in:
@@ -10,10 +10,12 @@ import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||
import 'package:vbvs_app/controller/mh_controller/people_info_controller.dart';
|
||||
import 'package:vbvs_app/pages/common/selectDialog.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
||||
import 'package:vbvs_app/pages/person/select_city.dart';
|
||||
import 'package:vbvs_app/pages/person/select_disease.dart'; // 导入疾病选择
|
||||
|
||||
//保存人员信息
|
||||
class MHTPeopleInfoPage extends StatefulWidget {
|
||||
@@ -30,9 +32,13 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
final List<TextEditingController> _contactControllers = [];
|
||||
List<Map<String, dynamic>> peopleList = [];
|
||||
List<CityModel> cityModels = []; // 存储每个person的城市数据
|
||||
List<List<String>> diseaseIdsList = []; // 存储每个person的疾病ID列表
|
||||
bool isLoading = true;
|
||||
late Future<List<CityModel>> cityDataFuture;
|
||||
|
||||
// 添加疾病数据(这里需要根据实际情况获取,可以先设为空列表)
|
||||
List diseaseList = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -69,11 +75,29 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
// 初始化城市模型列表
|
||||
cityModels = List.filled(peopleList.length, CityModel());
|
||||
|
||||
// 初始化疾病ID列表
|
||||
diseaseIdsList = List.generate(peopleList.length, (index) => []);
|
||||
|
||||
// 加载疾病数据(这里需要实现获取疾病数据的方法)
|
||||
await _loadDiseaseData();
|
||||
|
||||
// Initialize controllers after data is loaded
|
||||
_initializeControllers();
|
||||
setState(() => isLoading = false);
|
||||
}
|
||||
|
||||
// 加载疾病数据的方法
|
||||
Future<void> _loadDiseaseData() async {
|
||||
try {
|
||||
PeopleInfoController controller = Get.find();
|
||||
await controller.getDiseaseData();
|
||||
diseaseList = controller.diseaseList.value;
|
||||
} catch (e) {
|
||||
print("加载疾病数据失败: $e");
|
||||
diseaseList = [];
|
||||
}
|
||||
}
|
||||
|
||||
void _initializeControllers() {
|
||||
for (var person in peopleList) {
|
||||
_nameControllers.add(TextEditingController(text: person["name"] ?? ""));
|
||||
@@ -112,6 +136,23 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取已选择的慢病名称
|
||||
String getSelectedDiseaseNames(List<String> selectedIds) {
|
||||
if (selectedIds.isEmpty) return "请选择慢病".tr;
|
||||
|
||||
final selectedNames = diseaseList
|
||||
.where((disease) => selectedIds.contains(disease['_id'].toString()))
|
||||
.map((disease) => disease['disease_type_name'].toString())
|
||||
.toList();
|
||||
|
||||
String displayText = selectedNames.join('、');
|
||||
if (displayText.length > 10) {
|
||||
displayText = '${displayText.substring(0, 10)}...';
|
||||
}
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
Future<void> _savePersonData(
|
||||
Map<String, dynamic> personData, BuildContext context) async {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
@@ -133,6 +174,7 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
'id': personData['id'],
|
||||
'UTC': personData['UTC'],
|
||||
'city_id': personData['city_id'],
|
||||
'disease_ids': personData['disease_ids'], // 添加疾病ID字段
|
||||
};
|
||||
await requestWithLog(
|
||||
logTitle: "保存用户信息".tr,
|
||||
@@ -315,14 +357,14 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
}
|
||||
|
||||
// 验证城市选择
|
||||
final cityModel = cityModels[i];
|
||||
if (cityModel.id == null) {
|
||||
TopSlideNotification.show(context,
|
||||
text: "请选择城市".tr,
|
||||
textColor: Color(0xFFFF7159));
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
// final cityModel = cityModels[i];
|
||||
// if (cityModel.id == null) {
|
||||
// TopSlideNotification.show(context,
|
||||
// text: "请选择城市".tr,
|
||||
// textColor: Color(0xFFFF7159));
|
||||
// isValid = false;
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
if (isValid) {
|
||||
@@ -330,10 +372,12 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
for (int i = 0; i < peopleList.length; i++) {
|
||||
final person = peopleList[i];
|
||||
final cityModel = cityModels[i];
|
||||
final diseaseIds = diseaseIdsList[i];
|
||||
|
||||
// 添加城市信息到person数据
|
||||
person['UTC'] = cityModel.UTC;
|
||||
person['city_id'] = cityModel.id;
|
||||
person['disease_ids'] = diseaseIds; // 添加疾病ID
|
||||
|
||||
await _savePersonData(person, context);
|
||||
}
|
||||
@@ -867,6 +911,83 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
),
|
||||
),
|
||||
getLine(),
|
||||
// 慢病管理部分
|
||||
Container(
|
||||
height: 90.rpx,
|
||||
margin: EdgeInsets.only(
|
||||
left: 40.rpx, right: 35.rpx),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
FocusScope.of(context)
|
||||
.requestFocus(FocusNode());
|
||||
Future.delayed(
|
||||
Duration(milliseconds: 250), () {
|
||||
// 获取当前已选择的慢病ID列表
|
||||
final currentDiseaseIds =
|
||||
List<String>.from(
|
||||
diseaseIdsList[index]);
|
||||
|
||||
showDiseaseSelectionDialog(
|
||||
context,
|
||||
selectedIds: currentDiseaseIds,
|
||||
diseaseList: diseaseList,
|
||||
onDiseasesChanged:
|
||||
(List<String> newDiseaseIds) {
|
||||
setState(() {
|
||||
diseaseIdsList[index] =
|
||||
newDiseaseIds;
|
||||
});
|
||||
},
|
||||
title: "选择慢病".tr,
|
||||
colors: DiseaseSelectionColors(
|
||||
pickerBackgroundColor:
|
||||
stringToColor("#003058"),
|
||||
confirmTextColor:
|
||||
stringToColor("#84F5FF"),
|
||||
selectedDiseaseColor:
|
||||
stringToColor("#84F5FF"),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'慢病管理'.tr,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Readex Pro',
|
||||
color: Color(0xFF9EA4B7),
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
getSelectedDiseaseNames(
|
||||
diseaseIdsList[index]),
|
||||
style: TextStyle(
|
||||
color: diseaseIdsList[index]
|
||||
.isNotEmpty
|
||||
? Colors.white
|
||||
: themeController
|
||||
.currentColor.sc4,
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 16.rpx),
|
||||
Icon(Icons.expand_more,
|
||||
color: Colors.white,
|
||||
size: 48.rpx),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
getLine(),
|
||||
],
|
||||
))
|
||||
],
|
||||
@@ -884,4 +1005,3 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
256
lib/pages/person/select_disease.dart
Normal file
256
lib/pages/person/select_disease.dart
Normal file
@@ -0,0 +1,256 @@
|
||||
// 慢病选择弹窗方法(简化版,不需要Future参数)
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
void showDiseaseSelectionDialog(
|
||||
BuildContext context, {
|
||||
required List<String> selectedIds,
|
||||
required List diseaseList,
|
||||
Function(List<String>)? onDiseasesChanged,
|
||||
String title = "选择慢病",
|
||||
DiseaseSelectionColors? colors,
|
||||
}) {
|
||||
ThemeController themeController = Get.find();
|
||||
|
||||
// 使用传入的颜色,如果没传则使用主题颜色
|
||||
final Color pickerBackgroundColor =
|
||||
colors?.pickerBackgroundColor ?? themeController.currentColor.sc17;
|
||||
final Color confirmTextColor =
|
||||
colors?.confirmTextColor ?? themeController.currentColor.sc2;
|
||||
final Color selectedDiseaseColor =
|
||||
colors?.selectedDiseaseColor ?? themeController.currentColor.sc2;
|
||||
|
||||
final RxList<String> selectedDiseaseIds = selectedIds.obs;
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
isScrollControlled: true,
|
||||
enableDrag: false,
|
||||
isDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 半透明遮罩层,点击关闭
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 弹窗内容
|
||||
_buildDiseasePickerContent(
|
||||
context,
|
||||
themeController,
|
||||
title,
|
||||
diseaseList,
|
||||
selectedDiseaseIds,
|
||||
onDiseasesChanged,
|
||||
pickerBackgroundColor: pickerBackgroundColor,
|
||||
confirmTextColor: confirmTextColor,
|
||||
selectedDiseaseColor: selectedDiseaseColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 慢病选择器颜色配置
|
||||
class DiseaseSelectionColors {
|
||||
final Color? pickerBackgroundColor; // 选择器整体背景色
|
||||
final Color? confirmTextColor; // 确定按钮文字颜色
|
||||
final Color? selectedDiseaseColor; // 选中的慢病颜色
|
||||
|
||||
const DiseaseSelectionColors({
|
||||
this.pickerBackgroundColor,
|
||||
this.confirmTextColor,
|
||||
this.selectedDiseaseColor,
|
||||
});
|
||||
}
|
||||
|
||||
// 慢病选择器内容
|
||||
Widget _buildDiseasePickerContent(
|
||||
BuildContext context,
|
||||
ThemeController themeController,
|
||||
String title,
|
||||
List diseaseList,
|
||||
RxList<String> selectedIds,
|
||||
Function(List<String>)? onDiseasesChanged, {
|
||||
required Color pickerBackgroundColor,
|
||||
required Color confirmTextColor,
|
||||
required Color selectedDiseaseColor,
|
||||
}) {
|
||||
final bottomInsets = MediaQuery.of(context).viewInsets.bottom;
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: pickerBackgroundColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20.rpx),
|
||||
topRight: Radius.circular(20.rpx),
|
||||
),
|
||||
),
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.35,
|
||||
),
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsets.fromLTRB(30.rpx, 10.rpx, 30.rpx, bottomInsets + 10.rpx),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
width: 110.rpx,
|
||||
height: 60.rpx,
|
||||
alignment: Alignment.center,
|
||||
child: Text("取消".tr,
|
||||
style: TextStyle(fontSize: 30.rpx, color: Colors.white)),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Readex Pro',
|
||||
color: themeController.currentColor.sc3,
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () {
|
||||
onDiseasesChanged?.call(List.from(selectedIds));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Container(
|
||||
width: 110.rpx,
|
||||
height: 60.rpx,
|
||||
alignment: Alignment.center,
|
||||
child: Text("确定".tr,
|
||||
style: TextStyle(
|
||||
fontSize: 30.rpx,
|
||||
color: confirmTextColor,
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(height: 20.rpx),
|
||||
|
||||
// 慢病标签选择区域
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Obx(() {
|
||||
if (diseaseList.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(top: 100.rpx),
|
||||
child: Text(
|
||||
"暂无慢病数据".tr,
|
||||
style: TextStyle(
|
||||
color: themeController.currentColor.sc4,
|
||||
fontSize: 28.rpx,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(10.rpx, 0, 10.rpx, 0),
|
||||
child: Wrap(
|
||||
spacing: 20.rpx,
|
||||
runSpacing: 20.rpx,
|
||||
children: diseaseList.map<Widget>((disease) {
|
||||
final id = disease['_id'].toString();
|
||||
final name = disease['disease_type_name'].toString();
|
||||
final isSelected = selectedIds.contains(id);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (isSelected) {
|
||||
selectedIds.remove(id);
|
||||
} else {
|
||||
selectedIds.add(id);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 30.rpx,
|
||||
vertical: 15.rpx,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? selectedDiseaseColor
|
||||
: Colors.transparent,
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? selectedDiseaseColor
|
||||
: themeController.currentColor.sc4,
|
||||
width: 1.rpx,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(30.rpx),
|
||||
),
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? pickerBackgroundColor
|
||||
: themeController.currentColor.sc3,
|
||||
fontSize: 28.rpx,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 10.rpx),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 获取已选择的慢病名称
|
||||
String getSelectedDiseaseNames(List diseaseList, List<String> selectedIds) {
|
||||
if (selectedIds.isEmpty) return "请选择慢病".tr;
|
||||
|
||||
final selectedNames = diseaseList
|
||||
.where((disease) => selectedIds.contains(disease['_id'].toString()))
|
||||
.map((disease) => disease['disease_type_name'].toString())
|
||||
.toList();
|
||||
|
||||
String displayText = selectedNames.join('、');
|
||||
if (displayText.length > 10) {
|
||||
displayText = '${displayText.substring(0, 10)}...';
|
||||
}
|
||||
|
||||
return displayText;
|
||||
}
|
||||
Reference in New Issue
Block a user