139 lines
5.1 KiB
Dart
Raw Normal View History

2023-07-11 18:37:25 +08:00
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';
2023-07-11 18:37:25 +08:00
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';
2023-07-11 18:37:25 +08:00
class CheckingInSetWorkTimePage extends StatefulWidget {
2023-07-15 15:11:28 +08:00
const CheckingInSetWorkTimePage({Key? key}) : super(key: key);
2023-07-11 18:37:25 +08:00
@override
State<CheckingInSetWorkTimePage> createState() =>
_CheckingInSetWorkTimePageState();
2023-07-11 18:37:25 +08:00
}
class _CheckingInSetWorkTimePageState extends State<CheckingInSetWorkTimePage> {
final CheckingInSetWorkTimeLogic logic = Get.put(CheckingInSetWorkTimeLogic());
final CheckingInSetWorkTimeState state = Get.find<CheckingInSetWorkTimeLogic>().state;
2023-07-11 18:37:25 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
2024-07-26 14:12:26 +08:00
barTitle: '工作时间设置'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
2023-07-11 18:37:25 +08:00
body: buildMainUI(),
);
}
Widget buildMainUI() {
2023-07-11 18:37:25 +08:00
return Column(
children: <Widget>[
Obx(() => CommonItem(
2024-07-29 19:30:29 +08:00
leftTitel: '上班时间'.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(
2024-07-29 19:30:29 +08:00
leftTitel: '下班时间'.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(
2024-07-26 09:21:22 +08:00
btnName: '确定'.tr,
2023-07-11 18:37:25 +08:00
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: <String, String>{
'beginTime': state.beginTime.value,
'beginTimeTimestamp': state.beginTimeTimestamp.value,
'endTime': state.endTime.value,
'endTimeTimestamp': state.endTimeTimestamp.value,
});
}
}),
2023-07-11 18:37:25 +08:00
],
);
}
String getNowDate() {
2023-07-11 18:37:25 +08:00
// 获取当前时间对象
final DateTime today = DateTime.now();
final String dateSlug =
"${today.hour.toString().padLeft(2, '0')}:${today.minute.toString().padLeft(2, '0')}";
2023-07-11 18:37:25 +08:00
// //获取当前时间的年
// 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;
}
}