Files
tuiche/lib/pages/person/select_disease.dart
2026-01-31 14:43:47 +08:00

257 lines
8.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 慢病选择弹窗方法简化版不需要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;
title = title.tr;
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;
}