2024-07-26 09:21:22 +08:00

233 lines
7.8 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/main/lockDetail/checkingIn/checkingInSetWorkdaySet/checkingInSetWorkdaySet_state.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 'checkingInSetWorkdaySet_logic.dart';
class CheckingInSetWorkdaySet extends StatefulWidget {
const CheckingInSetWorkdaySet({Key? key}) : super(key: key);
@override
State<CheckingInSetWorkdaySet> createState() =>
_CheckingInSetWorkdaySetState();
}
class _CheckingInSetWorkdaySetState extends State<CheckingInSetWorkdaySet> {
final CheckingInSetWorkdaySetLogic logic = Get.put(CheckingInSetWorkdaySetLogic());
final CheckingInSetWorkdaySetState state = Get.find<CheckingInSetWorkdaySetLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle:
'${TranslationLoader.lanKeys!.workday!.tr} ${TranslationLoader.lanKeys!.set!.tr}',
haveBack: true,
backgroundColor: AppColors.mainColor),
body: ListView(
children: <Widget>[
topBtnWidget(),
Obx(() => Visibility(visible: state.isCustom.value, child: bottomCustomSelectBtn())),
Obx(() => Visibility(visible: !state.isCustom.value, child: bottomOddOrEvenDaysOffSelectBtn())),
SizedBox(height: 50.h,),
Container(
margin: EdgeInsets.only(left: 20.w, right: 20.w),
child: SubmitBtn(btnName: '确定'.tr, onClick: () {
if(state.pushType.value == '2'){
logic.editCheckInSetInfoData();
}else{
Get.back(result: <String, Object>{
'attendanceType':state.isCustom.value,
'weekDays':state.weekDays.value,
});
}
}),
),
],
),
);
}
Widget topBtnWidget() {
return Container(
width: 1.sw,
height: 100.h,
// color: Colors.red,
padding: EdgeInsets.all(10.w),
child: Obx(() => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
GestureDetector(
onTap: (){
setState(() {
state.isCustom.value = true;
});
},
child: Container(
width: (1.sw - 5.w * 2) / 2,
height: 100.h,
color: state.isCustom.value ? AppColors.mainColor : AppColors.btnDisableColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(child: Text('自定义'.tr, style: TextStyle(fontSize: 26.sp, color: Colors.white))),
],
),
),
),
// SizedBox(width: 10.w,),
GestureDetector(
onTap: (){
setState(() {
state.isCustom.value = false;
});
},
child: Container(
width: (1.sw - 10 * 3) / 2,
height: 100.h,
color: state.isCustom.value ? AppColors.btnDisableColor : AppColors.mainColor,
padding: EdgeInsets.all(10.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Center(
child: Text(
TranslationLoader.lanKeys!.oddOrEvenDaysOff!.tr,
style: TextStyle(fontSize: 26.sp, color: Colors.white),
textAlign: TextAlign.center,
))),
],
),
),
),
],
)),
);
}
Widget bottomOddOrEvenDaysOffSelectBtn() {
return Container(
padding: EdgeInsets.only(left: 10.w, right: 10.w),
child: Column(
children: <Widget>[
CommonItem(
leftTitel: TranslationLoader.lanKeys!.thisWeek!.tr,
rightTitle: '',
allHeight: 60.h,
isHaveLine: true),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.singleDayWeekend!.tr,
rightTitle: '',
allHeight: 60.h,
isHaveLine: true,
isHaveRightWidget: true,
action: (){
setState(() {
state.isSingledayWeekend.value = 0;
state.weekDays.value = <int>[1, 2 , 3, 4, 5, 6];
});
},
rightWidget: Row(
children: <Widget>[
Image.asset(state.isSingledayWeekend.value == 0 ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w,),
],
)
)),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.twoDaysOff!.tr,
rightTitle: '',
allHeight: 60.h,
isHaveLine: false,
isHaveRightWidget: true,
action: (){
setState(() {
state.isSingledayWeekend.value = 1;
state.weekDays.value = <int>[1, 2 , 3, 4, 5];
});
},
rightWidget: Row(
children: <Widget>[
Image.asset(state.isSingledayWeekend.value == 1 ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w,),
],
)
)),
],
),
);
}
Widget bottomCustomSelectBtn() {
return Container(
padding: EdgeInsets.only(left: 10.w, right: 10.w),
height: 420.h,
child: ListView.builder(
itemCount: 7,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext c, int index) {
index += 1;
String dateStr;
switch (index) {
case 1:
dateStr = '星期一'.tr;
break;
case 2:
dateStr = '星期二'.tr;
break;
case 3:
dateStr = '星期三'.tr;
break;
case 4:
dateStr = '星期四'.tr;
break;
case 5:
dateStr = '星期五'.tr;
break;
case 6:
dateStr = '星期六'.tr;
break;
case 7:
dateStr = '星期日'.tr;
break;
default:
dateStr = '';
break;
}
return Obx(() => CommonItem(
leftTitel: dateStr,
rightTitle: '',
allHeight: 60.h,
isHaveLine: true,
isHaveRightWidget: true,
action: (){
setState(() {
state.isSingledayWeekend.value = 2;
if(state.weekDays.value.contains(index)){
state.weekDays.value.remove(index);
}else{
state.weekDays.value.add(index);
}
state.weekDays.value.sort();
});
},
rightWidget: Row(
children: <Widget>[
Image.asset(state.weekDays.value.contains(index) ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w,),
],
)
));
}
),
);
}
}