更新眠花糖慢病管理
This commit is contained in:
@@ -1,15 +1,19 @@
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||||
import 'package:ef/ef.dart';
|
import 'package:ef/ef.dart';
|
||||||
import 'package:flutter/src/widgets/framework.dart';
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||||
import 'package:json_annotation/json_annotation.dart';
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||||
|
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||||
|
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||||
import 'package:vbvs_app/common/pojo/city.dart';
|
import 'package:vbvs_app/common/pojo/city.dart';
|
||||||
|
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||||
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
import 'package:vbvs_app/enum/APPPackageType.dart';
|
||||||
import 'package:vbvs_app/model/api_response.dart';
|
import 'package:vbvs_app/model/api_response.dart';
|
||||||
|
|
||||||
part 'people_info_controller.g.dart'; // 由json_serializable自动生成的部分
|
part 'people_info_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||||
@@ -25,6 +29,7 @@ class PeopleInfoModel {
|
|||||||
String? contact;
|
String? contact;
|
||||||
List peopleList = [];
|
List peopleList = [];
|
||||||
List<CityModel> cityModels = [];
|
List<CityModel> cityModels = [];
|
||||||
|
List selectedDiseaseIds = [];
|
||||||
PeopleInfoModel();
|
PeopleInfoModel();
|
||||||
|
|
||||||
factory PeopleInfoModel.fromJson(Map<String, dynamic> json) {
|
factory PeopleInfoModel.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -46,6 +51,8 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final CityModelController cityController = Get.find<CityModelController>();
|
final CityModelController cityController = Get.find<CityModelController>();
|
||||||
|
RxList diseaseList = [].obs;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onInit() async {
|
Future<void> onInit() async {
|
||||||
@@ -127,15 +134,18 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
|||||||
ef.log("开始查找city_id: $cityId");
|
ef.log("开始查找city_id: $cityId");
|
||||||
|
|
||||||
// 使用cityController查找完整的城市数据
|
// 使用cityController查找完整的城市数据
|
||||||
final CityModel? completeCityData = cityController.findCityById(cityId);
|
final CityModel? completeCityData =
|
||||||
|
cityController.findCityById(cityId);
|
||||||
|
|
||||||
if (completeCityData != null) {
|
if (completeCityData != null) {
|
||||||
// 将找到的城市数据添加到cityModels列表中
|
// 将找到的城市数据添加到cityModels列表中
|
||||||
model.cityModels.add(completeCityData);
|
model.cityModels.add(completeCityData);
|
||||||
ef.log("成功添加城市数据: ${completeCityData.displayName} for person: ${person['name'] ?? 'Unknown'}");
|
ef.log(
|
||||||
|
"成功添加城市数据: ${completeCityData.displayName} for person: ${person['name'] ?? 'Unknown'}");
|
||||||
} else {
|
} else {
|
||||||
// 如果找不到对应的城市数据,添加一个空的CityModel,但保留city_id
|
// 如果找不到对应的城市数据,添加一个空的CityModel,但保留city_id
|
||||||
final CityModel emptyCityModel = CityModel(id: int.tryParse(cityId));
|
final CityModel emptyCityModel =
|
||||||
|
CityModel(id: int.tryParse(cityId));
|
||||||
model.cityModels.add(emptyCityModel);
|
model.cityModels.add(emptyCityModel);
|
||||||
ef.log("未找到对应城市数据,创建默认CityModel for city_id: $cityId");
|
ef.log("未找到对应城市数据,创建默认CityModel for city_id: $cityId");
|
||||||
}
|
}
|
||||||
@@ -155,7 +165,8 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
|||||||
// 更新UI
|
// 更新UI
|
||||||
updateAll();
|
updateAll();
|
||||||
|
|
||||||
ef.log("初始化城市数据完成,peopleList长度: ${model.peopleList.length}, cityModels长度: ${model.cityModels.length}");
|
ef.log(
|
||||||
|
"初始化城市数据完成,peopleList长度: ${model.peopleList.length}, cityModels长度: ${model.cityModels.length}");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ef.log("初始化城市数据失败: $e");
|
ef.log("初始化城市数据失败: $e");
|
||||||
}
|
}
|
||||||
@@ -176,4 +187,52 @@ class PeopleInfoController extends GetControllerEx<PeopleInfoModel> {
|
|||||||
updateAll();
|
updateAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<ApiResponse> getDiseaseData() async {
|
||||||
|
try {
|
||||||
|
ApiResponse apiResponse = ApiResponse(code: -1, msg: "请求失败".tr);
|
||||||
|
String serviceAddress = ServiceConstant.service_address;
|
||||||
|
String serviceName = ServiceConstant.server_service;
|
||||||
|
String serviceApi = ServiceConstant.disease_list;
|
||||||
|
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||||
|
String? language = "";
|
||||||
|
if (AppConstants().ent_type == APPPackageType.MHT.code) {
|
||||||
|
if (mhLanguageController.selectLanguage != null) {
|
||||||
|
language = mhLanguageController.selectLanguage.value!.language_code;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (languageController.selectLanguage != null) {
|
||||||
|
language = languageController.selectLanguage.value!.language_code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (language != null && language.isNotEmpty) {
|
||||||
|
if (queryUrl.contains("?")) {
|
||||||
|
queryUrl += "&lang=$language";
|
||||||
|
} else {
|
||||||
|
queryUrl += "?lang=$language";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var response = await EasyDartModule.dio.get(queryUrl);
|
||||||
|
if (response != null) {
|
||||||
|
var responseData =
|
||||||
|
response.data is String ? jsonDecode(response.data) : response.data;
|
||||||
|
ApiResponse res =
|
||||||
|
ApiResponse.fromJson(responseData, (object) => object);
|
||||||
|
MyUtils.formatResponse(res, "请求成功".tr, "请求失败".tr);
|
||||||
|
if (res.code == HttpStatusCodes.ok) {
|
||||||
|
// bindDeviceNum.value = res.total!;
|
||||||
|
diseaseList.value = res.data!;
|
||||||
|
updateAll();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ApiResponse(code: -1, msg: "失败".tr);
|
||||||
|
}
|
||||||
|
return apiResponse;
|
||||||
|
} catch (e) {
|
||||||
|
EasyDartModule.logger.info("疾病请求列表: $e");
|
||||||
|
DailyLogUtils.writeLog("疾病请求列表: $e");
|
||||||
|
}
|
||||||
|
return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,12 @@ import 'package:vbvs_app/common/util/MyUtils.dart';
|
|||||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||||
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
||||||
import 'package:vbvs_app/component/tool/TopSlideNotification.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/common/selectDialog.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.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/mh_page/homepage/controller/mht_home_controller.dart';
|
||||||
import 'package:vbvs_app/pages/person/select_city.dart';
|
import 'package:vbvs_app/pages/person/select_city.dart';
|
||||||
|
import 'package:vbvs_app/pages/person/select_disease.dart'; // 导入疾病选择
|
||||||
|
|
||||||
//保存人员信息
|
//保存人员信息
|
||||||
class MHTPeopleInfoPage extends StatefulWidget {
|
class MHTPeopleInfoPage extends StatefulWidget {
|
||||||
@@ -30,9 +32,13 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
|||||||
final List<TextEditingController> _contactControllers = [];
|
final List<TextEditingController> _contactControllers = [];
|
||||||
List<Map<String, dynamic>> peopleList = [];
|
List<Map<String, dynamic>> peopleList = [];
|
||||||
List<CityModel> cityModels = []; // 存储每个person的城市数据
|
List<CityModel> cityModels = []; // 存储每个person的城市数据
|
||||||
|
List<List<String>> diseaseIdsList = []; // 存储每个person的疾病ID列表
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
late Future<List<CityModel>> cityDataFuture;
|
late Future<List<CityModel>> cityDataFuture;
|
||||||
|
|
||||||
|
// 添加疾病数据(这里需要根据实际情况获取,可以先设为空列表)
|
||||||
|
List diseaseList = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -69,11 +75,29 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
|||||||
// 初始化城市模型列表
|
// 初始化城市模型列表
|
||||||
cityModels = List.filled(peopleList.length, CityModel());
|
cityModels = List.filled(peopleList.length, CityModel());
|
||||||
|
|
||||||
|
// 初始化疾病ID列表
|
||||||
|
diseaseIdsList = List.generate(peopleList.length, (index) => []);
|
||||||
|
|
||||||
|
// 加载疾病数据(这里需要实现获取疾病数据的方法)
|
||||||
|
await _loadDiseaseData();
|
||||||
|
|
||||||
// Initialize controllers after data is loaded
|
// Initialize controllers after data is loaded
|
||||||
_initializeControllers();
|
_initializeControllers();
|
||||||
setState(() => isLoading = false);
|
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() {
|
void _initializeControllers() {
|
||||||
for (var person in peopleList) {
|
for (var person in peopleList) {
|
||||||
_nameControllers.add(TextEditingController(text: person["name"] ?? ""));
|
_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(
|
Future<void> _savePersonData(
|
||||||
Map<String, dynamic> personData, BuildContext context) async {
|
Map<String, dynamic> personData, BuildContext context) async {
|
||||||
String serviceAddress = ServiceConstant.service_address;
|
String serviceAddress = ServiceConstant.service_address;
|
||||||
@@ -133,6 +174,7 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
|||||||
'id': personData['id'],
|
'id': personData['id'],
|
||||||
'UTC': personData['UTC'],
|
'UTC': personData['UTC'],
|
||||||
'city_id': personData['city_id'],
|
'city_id': personData['city_id'],
|
||||||
|
'disease_ids': personData['disease_ids'], // 添加疾病ID字段
|
||||||
};
|
};
|
||||||
await requestWithLog(
|
await requestWithLog(
|
||||||
logTitle: "保存用户信息".tr,
|
logTitle: "保存用户信息".tr,
|
||||||
@@ -315,14 +357,14 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 验证城市选择
|
// 验证城市选择
|
||||||
final cityModel = cityModels[i];
|
// final cityModel = cityModels[i];
|
||||||
if (cityModel.id == null) {
|
// if (cityModel.id == null) {
|
||||||
TopSlideNotification.show(context,
|
// TopSlideNotification.show(context,
|
||||||
text: "请选择城市".tr,
|
// text: "请选择城市".tr,
|
||||||
textColor: Color(0xFFFF7159));
|
// textColor: Color(0xFFFF7159));
|
||||||
isValid = false;
|
// isValid = false;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
@@ -330,10 +372,12 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
|||||||
for (int i = 0; i < peopleList.length; i++) {
|
for (int i = 0; i < peopleList.length; i++) {
|
||||||
final person = peopleList[i];
|
final person = peopleList[i];
|
||||||
final cityModel = cityModels[i];
|
final cityModel = cityModels[i];
|
||||||
|
final diseaseIds = diseaseIdsList[i];
|
||||||
|
|
||||||
// 添加城市信息到person数据
|
// 添加城市信息到person数据
|
||||||
person['UTC'] = cityModel.UTC;
|
person['UTC'] = cityModel.UTC;
|
||||||
person['city_id'] = cityModel.id;
|
person['city_id'] = cityModel.id;
|
||||||
|
person['disease_ids'] = diseaseIds; // 添加疾病ID
|
||||||
|
|
||||||
await _savePersonData(person, context);
|
await _savePersonData(person, context);
|
||||||
}
|
}
|
||||||
@@ -867,6 +911,83 @@ class _MHTPeopleInfoPageState extends State<MHTPeopleInfoPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
getLine(),
|
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