2024-05-18 09:37:50 +08:00

139 lines
5.0 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.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<CheckingInSetWorkTimePage> createState() =>
_CheckingInSetWorkTimePageState();
}
class _CheckingInSetWorkTimePageState extends State<CheckingInSetWorkTimePage> {
final logic = Get.put(CheckingInSetWorkTimeLogic());
final state = Get.find<CheckingInSetWorkTimeLogic>().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: () {
PDuration selectDate = PDuration.parse(DateTool().dateToDateTime(state.beginTime.value, 0));
Pickers.showDatePicker(context,
selectDate: selectDate, mode: DateMode.HM, onConfirm: (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: () {
PDuration selectDate = PDuration.parse(DateTool().dateToDateTime(state.endTime.value, 0));
Pickers.showDatePicker(context,
selectDate: selectDate, mode: DateMode.HM, onConfirm: (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: TranslationLoader.lanKeys!.sure!.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() {
// 获取当前时间对象
DateTime today = DateTime.now();
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;
}
}