Files
tuiche/lib/pages/device/component/health_experience_tool.dart
2026-04-02 16:02:25 +08:00

64 lines
1.7 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.
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:vbvs_app/controller/device/device_type_controller.dart';
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
DeviceTypeController deviceTypeController = Get.find();
String getGenderText(dynamic gender) {
var genderMap = {
'1': ''.tr,
'2': ''.tr,
};
String genderStr = gender.toString().trim();
return genderMap[genderStr] ?? '-'.tr;
}
// 显示解绑确认对话框
void showCancelConfirmDialog(BuildContext context, personInfo) {
showConfirmDialog(
context,
Container(),
"是否确认结束?".tr,
onConfirm: () async {
bool opRes = await deviceTypeController.qcCheckControl(personInfo, 2);
if (!opRes) {
return;
}
deviceTypeController.experience_status.value = 404;
deviceTypeController.updateAll();
},
onCancel: () {},
);
}
String calculateAge(String birthdayStr) {
try {
// 解析生日字符串 (格式: yyyy/MM/dd)
List<String> parts = birthdayStr.trim().split('/');
if (parts.length != 3) return '-'.tr;
int year = int.parse(parts[0]);
int month = int.parse(parts[1]);
int day = int.parse(parts[2]);
DateTime birthDate = DateTime(year, month, day);
DateTime today = DateTime.now();
// 计算年龄
int age = today.year - birthDate.year;
// 如果今年还没过生日年龄减1
if (today.month < birthDate.month ||
(today.month == birthDate.month && today.day < birthDate.day)) {
age--;
}
return age.toString();
} catch (e) {
return '-'.tr;
}
}