一级睡眠报告
This commit is contained in:
@@ -2,12 +2,26 @@ import 'dart:ui';
|
||||
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||
import 'package:vbvs_app/controller/date/CalendarController.dart';
|
||||
import 'package:vbvs_app/controller/sleep/sleep_report_controller.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/language/AppLanguage.dart';
|
||||
import 'package:vbvs_app/pages/common/selectDialog.dart';
|
||||
import 'package:vbvs_app/pages/main_bottom/component/main_page_b_bottom_change.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/component/SleepScoreWidget.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/component/SleepView.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/component/Vital_signs.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/component/new_sleep_view.dart';
|
||||
import 'package:vbvs_app/pages/sleep_report/new_sleep_report_page.dart';
|
||||
|
||||
class MhtSleepReportPage extends StatefulWidget {
|
||||
@@ -17,11 +31,14 @@ class MhtSleepReportPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
SleepReportController sleepReportController = Get.find();
|
||||
CalendarController calendarController = Get.find();
|
||||
UserInfoController userInfoController = Get.find();
|
||||
MHTHomeController deviceController = Get.find();
|
||||
MHTHomeController homeController = Get.find();
|
||||
double borderRadius = 16.rpx;
|
||||
|
||||
late DateTime selectedDate;
|
||||
final RxBool isRightLimit = false.obs;
|
||||
var formFieldController = FormFieldController<String>(null);
|
||||
var personInfo = {}.obs;
|
||||
|
||||
@@ -32,6 +49,15 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
//查询人员信息列表
|
||||
deviceController.getPersonList();
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final selected = DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch);
|
||||
|
||||
calendarController.selectedDate.value = selected;
|
||||
sleepReportController.selectedDate.value = selected;
|
||||
sleepReportController.model.type = 1;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -215,11 +241,11 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
final list = deviceController.personnelList.value;
|
||||
if (list.isNotEmpty) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
formFieldController.value = list[0]["mac".tr];
|
||||
formFieldController.value = list[0]["mac"];
|
||||
personInfo.value = list[0];
|
||||
homeController.selectPerson.value = list[0];
|
||||
homeController.selectDevcie.value =
|
||||
list[0]["mac".tr];
|
||||
list[0]["mac"];
|
||||
deviceController
|
||||
.getSleeps(formFieldController.value);
|
||||
homeController.updateAll();
|
||||
@@ -227,7 +253,7 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
0.rpx, 40.rpx, 30.rpx, 10.rpx),
|
||||
0.rpx, 40.rpx, 30.rpx, 40.rpx),
|
||||
child: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
constraints: BoxConstraints(
|
||||
@@ -239,7 +265,7 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
30.rpx, 16.rpx, 16.rpx, 25.rpx),
|
||||
30.rpx, 16.rpx, 0.rpx, 25.rpx),
|
||||
child: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
child: Row(
|
||||
@@ -247,16 +273,16 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'健康报告'.tr,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Readex Pro',
|
||||
color:
|
||||
themeController.currentColor.sc3,
|
||||
letterSpacing: 0,
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
),
|
||||
// Text(
|
||||
// '健康报告'.tr,
|
||||
// style: TextStyle(
|
||||
// fontFamily: 'Readex Pro',
|
||||
// color:
|
||||
// themeController.currentColor.sc3,
|
||||
// letterSpacing: 0,
|
||||
// fontSize: 30.rpx,
|
||||
// ),
|
||||
// ),
|
||||
ScrollbarTheme(
|
||||
data: ScrollbarThemeData(
|
||||
thumbColor: MaterialStateProperty.all(
|
||||
@@ -313,7 +339,7 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
final selectedPerson =
|
||||
list.firstWhere(
|
||||
(element) =>
|
||||
element['mac'.tr] ==
|
||||
element['mac'] ==
|
||||
val,
|
||||
orElse: () => null,
|
||||
);
|
||||
@@ -386,6 +412,52 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
),
|
||||
))),
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor:
|
||||
themeController.currentColor.sc3,
|
||||
padding: EdgeInsets.zero,
|
||||
borderRadius: 8,
|
||||
onTap: () {
|
||||
showSleepCalendarBottomSheet(
|
||||
type: sleepReportController
|
||||
.model.type,
|
||||
timestamp: selectedDate
|
||||
.millisecondsSinceEpoch,
|
||||
context: context,
|
||||
mac: homeController
|
||||
.selectDevcie.value,
|
||||
onDateSelected: (newDate) {
|
||||
sleepReportController
|
||||
.selectedDate
|
||||
.value = newDate;
|
||||
calendarController.selectedDate
|
||||
.value = newDate;
|
||||
String data =
|
||||
MyUtils.formatDate(
|
||||
calendarController
|
||||
.selectedDate
|
||||
.value!);
|
||||
loadSleepReport(data);
|
||||
sleepReportController
|
||||
.updateAll();
|
||||
calendarController.updateAll();
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10.rpx),
|
||||
child: Container(
|
||||
width: 36.rpx,
|
||||
height: 36.rpx,
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/calendar.svg',
|
||||
fit: BoxFit.cover,
|
||||
color: themeController
|
||||
.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -399,22 +471,42 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
Obx(() {
|
||||
if (homeController.selectDevcie.value != null &&
|
||||
homeController.selectDevcie.value!.isNotEmpty &&
|
||||
deviceController.personnelList.value.isNotEmpty)
|
||||
deviceController.personnelList.value.isNotEmpty &&
|
||||
sleepReportController.sleepReport.value != null) {
|
||||
return Expanded(
|
||||
child: NewSleepReportPage(
|
||||
data: {
|
||||
"tag": "123",
|
||||
'date': DateTime.now().millisecondsSinceEpoch,
|
||||
'mac'.tr: homeController.selectDevcie.value,
|
||||
'person': homeController.selectPerson.value,
|
||||
'backgroundImg':
|
||||
'assets/images/new_background.png',
|
||||
'arrow': false,
|
||||
'noBackImg': true,
|
||||
'person_show': false,
|
||||
},
|
||||
),
|
||||
);
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
getTimeWidget(),
|
||||
SleepScoreWidget(
|
||||
sleepReport:
|
||||
sleepReportController.sleepReport.value,
|
||||
showLabelWrap: false,
|
||||
),
|
||||
NewSleepViewWidget(
|
||||
sleepReport:
|
||||
sleepReportController.sleepReport.value),
|
||||
SizedBox(height: 25.rpx),
|
||||
VitalSignsWidget(
|
||||
sleepReport:
|
||||
sleepReportController.sleepReport.value)
|
||||
],
|
||||
|
||||
// child: NewSleepReportPage(
|
||||
// data: {
|
||||
// "tag": "123",
|
||||
// 'date': DateTime.now().millisecondsSinceEpoch,
|
||||
// 'mac'.tr: homeController.selectDevcie.value,
|
||||
// 'person': homeController.selectPerson.value,
|
||||
// 'backgroundImg':
|
||||
// 'assets/images/new_background.png',
|
||||
// 'arrow': false,
|
||||
// 'noBackImg': true,
|
||||
// 'person_show': false,
|
||||
// },
|
||||
// ),
|
||||
)));
|
||||
}
|
||||
return Container();
|
||||
}),
|
||||
],
|
||||
@@ -427,4 +519,164 @@ class _MhtSleepReportPageState extends State<MhtSleepReportPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getTimeWidget() {
|
||||
selectedDate = sleepReportController.selectedDate.value!;
|
||||
final type = sleepReportController.model.type;
|
||||
bool isChinese = AppLanguage().isChinese();
|
||||
String displayText = '';
|
||||
if (isChinese) {
|
||||
// 日报
|
||||
displayText =
|
||||
MyUtils.getFormatChineseTime(selectedDate.millisecondsSinceEpoch);
|
||||
} else {
|
||||
// Daily Report
|
||||
displayText =
|
||||
MyUtils.getFormatEnglishDate(selectedDate.millisecondsSinceEpoch);
|
||||
}
|
||||
|
||||
void onLeftArrowTap() {
|
||||
isRightLimit.value = false;
|
||||
sleepReportController.selectedDate.value =
|
||||
selectedDate.subtract(const Duration(days: 1));
|
||||
calendarController.selectedDate.value =
|
||||
sleepReportController.selectedDate.value;
|
||||
// String date = MyUtils.formatToDate(widget.data['date']);
|
||||
String data = MyUtils.formatDate(calendarController.selectedDate.value!);
|
||||
loadSleepReport(data);
|
||||
sleepReportController.updateAll();
|
||||
calendarController.updateAll();
|
||||
}
|
||||
|
||||
void onRightArrowTap() {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day, 23, 59, 59, 999);
|
||||
DateTime targetDate = selectedDate;
|
||||
final nextDate = selectedDate.add(const Duration(days: 1));
|
||||
if (!nextDate.isAfter(today)) {
|
||||
targetDate = nextDate;
|
||||
} else {
|
||||
isRightLimit.value = true;
|
||||
return;
|
||||
}
|
||||
// 👉 更新数据并请求
|
||||
sleepReportController.selectedDate.value = targetDate;
|
||||
calendarController.selectedDate.value = targetDate;
|
||||
|
||||
String data = MyUtils.formatDate(targetDate);
|
||||
loadSleepReport(data);
|
||||
|
||||
sleepReportController.updateAll();
|
||||
calendarController.updateAll();
|
||||
}
|
||||
|
||||
void onChangeArrowTap() {
|
||||
sleepReportController.selectedDate.value =
|
||||
selectedDate.subtract(const Duration(days: 1));
|
||||
|
||||
calendarController.selectedDate.value =
|
||||
sleepReportController.selectedDate.value;
|
||||
// String date = MyUtils.formatToDate(widget.data['date']);
|
||||
String data = MyUtils.formatDate(calendarController.selectedDate.value!);
|
||||
loadSleepReport(data);
|
||||
|
||||
sleepReportController.updateAll();
|
||||
calendarController.updateAll();
|
||||
}
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
padding: EdgeInsets.all(10.rpx),
|
||||
borderRadius: 8.rpx,
|
||||
onTap: onLeftArrowTap,
|
||||
child: Container(
|
||||
width: 30.rpx,
|
||||
height: 30.rpx,
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/arrow_left1.svg',
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20.rpx),
|
||||
child: Text(
|
||||
displayText,
|
||||
style: TextStyle(
|
||||
fontSize: AppConstants().normal_text_fontSize,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() => ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
padding: EdgeInsets.all(10.rpx),
|
||||
borderRadius: 8.rpx,
|
||||
onTap: isRightLimit.value ? () {} : onRightArrowTap,
|
||||
child: Container(
|
||||
width: 30.rpx,
|
||||
height: 30.rpx,
|
||||
child: SvgPicture.asset('assets/img/icon/arrow_right1.svg',
|
||||
color: isRightLimit.value
|
||||
? Color(0xFF929699)
|
||||
: Color(0xFFFFFFFF)),
|
||||
),
|
||||
))
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void loadSleepReport(String data) {
|
||||
requestWithLog(
|
||||
logTitle: "查询睡眠报告",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl:
|
||||
"https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${homeController.selectDevcie.value}&time=${data}&type=${sleepReportController.model.type}",
|
||||
onSuccess: (res) {
|
||||
print(res);
|
||||
sleepReportController.sleepReport.value = res.data;
|
||||
sleepReportController.updateAll();
|
||||
},
|
||||
onFailure: (res) {
|
||||
if (MainPageBBottomChange.getCurrentIndex() != null) {
|
||||
if (MainPageBBottomChange.getCurrentIndex() == 1) {
|
||||
TopSlideNotification.show(context,
|
||||
text: res.msg!, textColor: themeController.currentColor.sc9);
|
||||
}
|
||||
} else {
|
||||
TopSlideNotification.show(context,
|
||||
text: res.msg!, textColor: themeController.currentColor.sc9);
|
||||
}
|
||||
sleepReportController.sleepReport.value = {};
|
||||
sleepReportController.updateAll();
|
||||
print(res);
|
||||
});
|
||||
}
|
||||
|
||||
static String _getEnglishMonthName(int month) {
|
||||
const monthNames = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December'
|
||||
];
|
||||
return monthNames[month - 1];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user