更新眠花糖慢病管理

This commit is contained in:
wyf
2025-12-17 14:55:51 +08:00
parent 18c3b86e8a
commit 0ad6a1e326
3 changed files with 458 additions and 23 deletions

View 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;
}