import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/checkingIn/checkingInSetWorkTime/checkingInSetWorkTime_state.dart'; import 'package:star_lock/tools/dateTool.dart'; import 'package:star_lock/tools/pickers/pickers.dart'; import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart'; import 'package:star_lock/tools/pickers/time_picker/model/pduration.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/commonItem.dart'; import '../../../../tools/submitBtn.dart'; import '../../../../tools/titleAppBar.dart'; import '../../../../translations/trans_lib.dart'; import 'checkingInSetWorkTime_logic.dart'; class CheckingInSetWorkTimePage extends StatefulWidget { const CheckingInSetWorkTimePage({Key? key}) : super(key: key); @override State createState() => _CheckingInSetWorkTimePageState(); } class _CheckingInSetWorkTimePageState extends State { final CheckingInSetWorkTimeLogic logic = Get.put(CheckingInSetWorkTimeLogic()); final CheckingInSetWorkTimeState state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: '${TranslationLoader.lanKeys!.work!.tr} ${TranslationLoader.lanKeys!.time!.tr} ${TranslationLoader.lanKeys!.set!.tr}', haveBack: true, backgroundColor: AppColors.mainColor), body: buildMainUI(), ); } Widget buildMainUI() { return Column( children: [ Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.officeHours!.tr, rightTitle: state.beginTime.value, isHaveDirection: true, isHaveLine: true, action: () { final PDuration selectDate = PDuration.parse(DateTool().dateToDateTime(state.beginTime.value, 0)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.HM, onConfirm: (PDuration p) { setState(() { state.beginTime.value = DateTool().getYMDHNDateString(p, 3); state.beginTimeTimestamp.value = DateTool() .dateToTimestamp(state.beginTime.value, 0) .toString(); }); }); })), Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.closingTime!.tr, rightTitle: state.endTime.value, isHaveDirection: true, action: () { final PDuration selectDate = PDuration.parse(DateTool().dateToDateTime(state.endTime.value, 0)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.HM, onConfirm: (PDuration p) { setState(() { state.endTime.value = DateTool().getYMDHNDateString(p, 3); state.endTimeTimestamp.value = DateTool() .dateToTimestamp(state.endTime.value, 0) .toString(); }); }); })), SizedBox( height: 30.h, ), SubmitBtn( btnName: '确定'.tr, borderRadius: 20.w, fontSize: 32.sp, margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 20.w), padding: EdgeInsets.only(top: 20.w, bottom: 20.w), onClick: () { if (state.beginTimeTimestamp.value.isEmpty) { logic.showToast('请选择开始时间'); return; } if (state.endTimeTimestamp.value.isEmpty) { logic.showToast('请选择结束时间'); return; } if (int.parse(state.beginTimeTimestamp.value) >= int.parse(state.endTimeTimestamp.value)) { logic.showToast('结束时间必须要比开始时间晚,请重新选择'); return; } if (state.pushType.value == '2') { logic.editCheckInSetInfoData(); } else { Get.back(result: { 'beginTime': state.beginTime.value, 'beginTimeTimestamp': state.beginTimeTimestamp.value, 'endTime': state.endTime.value, 'endTimeTimestamp': state.endTimeTimestamp.value, }); } }), ], ); } String getNowDate() { // 获取当前时间对象 final DateTime today = DateTime.now(); final String dateSlug = "${today.hour.toString().padLeft(2, '0')}:${today.minute.toString().padLeft(2, '0')}"; // //获取当前时间的年 // int year = now.year; // //获取当前时间的月 // int month = now.month; // //获取当前时间的日 // int day = now.day; // //获取当前时间的时 // int hour = now.hour; // //获取当前时间的分 // int minute = now.minute; // //获取当前时间的秒 // int millisecond = now.millisecond; return dateSlug; } }