2023-07-13 14:13:44 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
2024-06-07 10:53:24 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/checkingIn/checkingInDetail/checkingInDetail_state.dart';
|
2023-07-13 14:13:44 +08:00
|
|
|
|
|
|
|
|
|
|
import '../../../../app_settings/app_colors.dart';
|
|
|
|
|
|
import '../../../../tools/titleAppBar.dart';
|
2023-09-15 16:04:11 +08:00
|
|
|
|
import 'checkingInDetail_logic.dart';
|
2023-07-13 14:13:44 +08:00
|
|
|
|
|
|
|
|
|
|
class CheckingInDetailPage extends StatefulWidget {
|
2023-07-15 15:11:28 +08:00
|
|
|
|
const CheckingInDetailPage({Key? key}) : super(key: key);
|
2023-07-13 14:13:44 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
_CheckingInDetailPageState createState() => _CheckingInDetailPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _CheckingInDetailPageState extends State<CheckingInDetailPage> {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final CheckingInDetailLogic logic = Get.put(CheckingInDetailLogic());
|
|
|
|
|
|
final CheckingInDetailState state = Get.find<CheckingInDetailLogic>().state;
|
2023-09-15 16:04:11 +08:00
|
|
|
|
|
2023-07-13 14:13:44 +08:00
|
|
|
|
int _year = DateTime.now().year;
|
|
|
|
|
|
int _month = DateTime.now().month;
|
|
|
|
|
|
int _day = DateTime.now().day;
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final List<CalendarModel> _datas = <CalendarModel>[];
|
|
|
|
|
|
final List<CalendarModel> _listDatas = <CalendarModel>[];
|
2023-07-13 14:13:44 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
super.initState();
|
|
|
|
|
|
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//设置默认当前月日期
|
|
|
|
|
|
_setDatas(year: _year, month: _month);
|
|
|
|
|
|
|
2023-09-15 16:04:11 +08:00
|
|
|
|
logic.getCheckInDetailData((){
|
|
|
|
|
|
//设置模拟数据,日历月事件,可根据接口返回的结果
|
2024-06-07 10:53:24 +08:00
|
|
|
|
_loadAttendanceMonthRecord('$_year-$_month');
|
2023-09-15 16:04:11 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//设置模拟数据,日历月事件,可根据接口返回的结果
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// _loadAttendanceMonthRecord("$_year-$_month");
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//日历日事件
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// _loadAttendanceDayRecord("$_year-$_month-$_day");
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//加载月历事件,请求接口
|
|
|
|
|
|
_loadAttendanceMonthRecord(String dateTime) async {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 显示的上个月的天数
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int placeholderDays = _getPlaceholderDays(year: _year, month: _month);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 当月多少天
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int currentMonthDays = _getCurrentMonthDays(year: _year, month: _month);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
|
2023-07-13 14:13:44 +08:00
|
|
|
|
setState(() {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 因为_datas这个月上个月都包含的都有 遍历把本月的赋值
|
2023-07-13 14:13:44 +08:00
|
|
|
|
for (int i = 0; i < _datas.length; i++) {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 因为i从0开始 所以i>=上个月的天数 且小于上个月跟本月天数之和
|
|
|
|
|
|
if((i >= placeholderDays) && (i < (placeholderDays + currentMonthDays))){
|
|
|
|
|
|
_datas[i].workType = state.monthListData[i-placeholderDays].colorType.toString();
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//加载日事件,请求接口
|
2023-07-29 17:04:03 +08:00
|
|
|
|
_loadAttendanceDayRecord(String dateTime) async {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//可根据接口返回的内容在日历下面打卡信息或者其余内容
|
2023-09-15 16:04:11 +08:00
|
|
|
|
state.checkDate.value = DateTime.parse(dateTime).millisecondsSinceEpoch;
|
|
|
|
|
|
logic.getCheckInDetailData((){
|
|
|
|
|
|
//设置模拟数据,日历月事件,可根据接口返回的结果
|
2024-06-07 10:53:24 +08:00
|
|
|
|
_loadAttendanceMonthRecord('$_year-$_month');
|
2023-09-15 16:04:11 +08:00
|
|
|
|
});
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
2023-07-29 17:04:03 +08:00
|
|
|
|
|
2023-07-13 14:13:44 +08:00
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Scaffold(
|
2023-07-29 17:04:03 +08:00
|
|
|
|
appBar: TitleAppBar(
|
2024-04-07 14:03:59 +08:00
|
|
|
|
barTitle: state.staffName.value,
|
2023-07-29 17:04:03 +08:00
|
|
|
|
haveBack: true,
|
|
|
|
|
|
backgroundColor: AppColors.mainColor),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
|
child: Column(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-29 17:04:03 +08:00
|
|
|
|
Container(
|
|
|
|
|
|
// margin: EdgeInsets.all(20.sp),
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
//设置颜色
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(12.r)),
|
|
|
|
|
|
//设置四周边框
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Column(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-29 17:04:03 +08:00
|
|
|
|
_yearHeader(),
|
|
|
|
|
|
SizedBox(height: 10.h),
|
|
|
|
|
|
_weekHeader(),
|
|
|
|
|
|
_everyDay(),
|
|
|
|
|
|
_bottomStatisticsWidget()
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
|
2023-07-29 17:04:03 +08:00
|
|
|
|
//下面可以添加日事件中的信息,例如打卡信息
|
|
|
|
|
|
Container(),
|
|
|
|
|
|
],
|
|
|
|
|
|
)));
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//头部年
|
|
|
|
|
|
Widget _yearHeader() {
|
|
|
|
|
|
return Container(
|
|
|
|
|
|
height: 30,
|
|
|
|
|
|
margin: const EdgeInsets.only(top: 10),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-13 14:13:44 +08:00
|
|
|
|
GestureDetector(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
onTap: _lastMonth,
|
|
|
|
|
|
child: Image(width: 50.w, height: 30.w, image: const AssetImage('images/icon_left_black.png'),),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
),
|
2023-09-15 16:04:11 +08:00
|
|
|
|
SizedBox(width: 60.w,),
|
2024-06-07 10:53:24 +08:00
|
|
|
|
Text('$_year-$_month', style: TextStyle(fontSize: 28.sp, color: Colors.black, fontWeight: FontWeight.w500)),
|
2023-09-15 16:04:11 +08:00
|
|
|
|
SizedBox(width: 60.w),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
GestureDetector(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
onTap: _nextMonth,
|
|
|
|
|
|
child: Image(width: 50.w, height: 30.w, image: const AssetImage('images/icon_right_black.png')),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//中部周
|
|
|
|
|
|
Widget _weekHeader() {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final List<String> array = <String>[
|
2024-07-26 09:21:22 +08:00
|
|
|
|
'简写周一'.tr,
|
|
|
|
|
|
'简写周二'.tr,
|
|
|
|
|
|
'简写周三'.tr,
|
|
|
|
|
|
'简写周四'.tr,
|
|
|
|
|
|
'简写周五'.tr,
|
|
|
|
|
|
'简写周六'.tr,
|
|
|
|
|
|
'简写周日'.tr
|
2023-07-29 17:04:03 +08:00
|
|
|
|
];
|
2024-06-07 10:53:24 +08:00
|
|
|
|
return SizedBox(
|
2023-07-13 14:13:44 +08:00
|
|
|
|
height: 50.h,
|
|
|
|
|
|
child: GridView.builder(
|
|
|
|
|
|
padding: const EdgeInsets.only(left: 10, right: 10),
|
|
|
|
|
|
itemCount: array.length,
|
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
2023-07-29 17:04:03 +08:00
|
|
|
|
//横轴元素个数
|
2023-07-13 14:13:44 +08:00
|
|
|
|
crossAxisCount: 7,
|
|
|
|
|
|
//纵轴间距
|
|
|
|
|
|
// mainAxisSpacing: ScreenUtil().setHeight(10),
|
|
|
|
|
|
// 横轴间距
|
|
|
|
|
|
// crossAxisSpacing: ScreenUtil().setWidth(15),
|
|
|
|
|
|
//子组件宽高长度比例
|
|
|
|
|
|
childAspectRatio: 2),
|
2024-06-07 10:53:24 +08:00
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
return Container(
|
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
array[index],
|
|
|
|
|
|
style: TextStyle(
|
2024-04-03 09:51:26 +08:00
|
|
|
|
color:
|
|
|
|
|
|
// index == 5 || index == 6
|
|
|
|
|
|
// ? const Color(0xFFC4C8D0) :
|
|
|
|
|
|
const Color(0xFF3C3E43),
|
2023-08-07 10:32:24 +08:00
|
|
|
|
fontSize: 26.sp),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
));
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//底部日
|
|
|
|
|
|
Widget _everyDay() {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
return GridView.builder(
|
|
|
|
|
|
padding: EdgeInsets.only(left: 10.sp, top: 10.sp, right: 10.sp),
|
|
|
|
|
|
itemCount: _getRowsForMonthYear(year: _year, month: _month) * 7,
|
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
|
|
//横轴元素个数
|
|
|
|
|
|
crossAxisCount: 7,
|
|
|
|
|
|
// //纵轴间距
|
|
|
|
|
|
// mainAxisSpacing: ScreenUtil().setHeight(10),
|
|
|
|
|
|
// // 横轴间距
|
|
|
|
|
|
// crossAxisSpacing: ScreenUtil().setWidth(10),
|
|
|
|
|
|
//子组件宽高长度比例
|
|
|
|
|
|
childAspectRatio: 1),
|
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
|
Color backColor = Colors.white;
|
|
|
|
|
|
// Color textColor = const Color(0xFFFFFFFF);
|
|
|
|
|
|
if(_datas[index].workType == '1'){
|
|
|
|
|
|
// 迟到
|
|
|
|
|
|
backColor = const Color(0xFFE83523);
|
|
|
|
|
|
}else if( _datas[index].workType == '2'){
|
|
|
|
|
|
// 早退
|
|
|
|
|
|
backColor = const Color(0xFFEDB459);
|
|
|
|
|
|
}else if( _datas[index].workType == '3'){
|
|
|
|
|
|
// 未打卡
|
|
|
|
|
|
backColor = const Color(0xFF666666);
|
|
|
|
|
|
}
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
// setState(() {
|
|
|
|
|
|
// if (_datas[index].month == _month) {
|
|
|
|
|
|
// //判断点击的是否是当月日期,只对当前月点击的日期做处理
|
|
|
|
|
|
// for (int i = 0; i < _datas.length; i++) {
|
|
|
|
|
|
// if (i == index) {
|
|
|
|
|
|
// //切换至选中的日期
|
|
|
|
|
|
// _day = _datas[i].day!;
|
|
|
|
|
|
// _datas[i].isSelect = true;
|
|
|
|
|
|
//
|
|
|
|
|
|
// //加载选中的日期事件
|
|
|
|
|
|
// _loadAttendanceDayRecord(
|
|
|
|
|
|
// "${_datas[i].year}-${_datas[i].month}-${_datas[i].day}");
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// _datas[i].isSelect = false;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// //不是当月的不做处理
|
|
|
|
|
|
// // _datas[index].is_select=false;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
},
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
|
Container(
|
|
|
|
|
|
width: 40.w,
|
|
|
|
|
|
height: 40.w,
|
|
|
|
|
|
//设置底部背景
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: backColor,
|
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Center(
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
//不是当前月不显示值
|
|
|
|
|
|
_datas[index].month == _month
|
|
|
|
|
|
? _datas[index].day.toString()
|
|
|
|
|
|
: '',
|
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
|
//设置选中字体颜色 休息的颜色都是黑色 其余的都是白色因为有背景色
|
|
|
|
|
|
style: (int.parse(_datas[index].workType!) > 0)
|
|
|
|
|
|
? TextStyle(
|
|
|
|
|
|
fontSize: 24.sp, color: const Color(0xFFFFFFFF))
|
|
|
|
|
|
: TextStyle(
|
|
|
|
|
|
fontSize: 24.sp,
|
|
|
|
|
|
color: Colors.black),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
),
|
2024-06-07 10:53:24 +08:00
|
|
|
|
),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
),
|
2024-06-07 10:53:24 +08:00
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
|
|
//设置底部小圆点,非当前月的不显示,设置为透明,其余的根据状态判断显示
|
|
|
|
|
|
// _datas[index].month == _month &&
|
|
|
|
|
|
// _datas[index].workType != "" &&
|
|
|
|
|
|
// _datas[index].workType != "0"
|
|
|
|
|
|
// ? Container(
|
|
|
|
|
|
// height: 6.0,
|
|
|
|
|
|
// width: 6.0,
|
|
|
|
|
|
// decoration: BoxDecoration(
|
|
|
|
|
|
// shape: BoxShape.circle,
|
|
|
|
|
|
// color: _datas[index].workType == "1"
|
|
|
|
|
|
// ? const Color(0xFFF48835)
|
|
|
|
|
|
// : const Color(0xFF2C91F6)),
|
|
|
|
|
|
// )
|
|
|
|
|
|
// : Container(),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
2023-07-13 14:13:44 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-29 17:04:03 +08:00
|
|
|
|
Widget _bottomStatisticsWidget() {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
return Column(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-13 14:13:44 +08:00
|
|
|
|
Row(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-13 14:13:44 +08:00
|
|
|
|
Container(
|
|
|
|
|
|
width: 1.sw,
|
|
|
|
|
|
// height: 40.h,
|
2023-07-29 17:04:03 +08:00
|
|
|
|
padding: EdgeInsets.only(left: 50.w, top: 5.h, bottom: 5.h),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
color: Colors.grey,
|
2023-07-29 17:04:03 +08:00
|
|
|
|
child: Text(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
'月统计'.tr,
|
2023-07-29 17:04:03 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
color: Colors.white,
|
2023-08-07 10:32:24 +08:00
|
|
|
|
fontSize: 26.sp,
|
2023-07-29 17:04:03 +08:00
|
|
|
|
fontWeight: FontWeight.w500),
|
|
|
|
|
|
),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2024-06-07 10:53:24 +08:00
|
|
|
|
_bottomStatisticsItemWidget(const Color(0xFFE83523), '迟到'.tr, state.lateTimes.value),
|
|
|
|
|
|
_bottomStatisticsItemWidget(const Color(0xFFEDB459), '早退'.tr, state.earlyTimes.value),
|
|
|
|
|
|
_bottomStatisticsItemWidget(const Color(0xFF666666), '未打卡'.tr, state.noPunchTimes.value),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-29 17:04:03 +08:00
|
|
|
|
Widget _bottomStatisticsItemWidget(
|
|
|
|
|
|
Color color,
|
|
|
|
|
|
String leftTitel,
|
|
|
|
|
|
String rightTitle,
|
|
|
|
|
|
) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
return Column(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-13 14:13:44 +08:00
|
|
|
|
Container(
|
2024-04-03 09:51:26 +08:00
|
|
|
|
// height: 70.h,
|
2023-07-29 17:04:03 +08:00
|
|
|
|
padding:
|
|
|
|
|
|
EdgeInsets.only(left: 20.w, right: 10.w, top: 20.w, bottom: 20.w),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
child: Row(
|
2024-06-07 10:53:24 +08:00
|
|
|
|
children: <Widget>[
|
2023-07-29 17:04:03 +08:00
|
|
|
|
SizedBox(width: 20.w),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
Container(
|
2023-08-07 10:32:24 +08:00
|
|
|
|
width: 30.w,
|
|
|
|
|
|
height: 30.w,
|
2023-07-13 14:13:44 +08:00
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: color,
|
2023-08-07 10:32:24 +08:00
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(30.h))),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
),
|
2023-07-29 17:04:03 +08:00
|
|
|
|
SizedBox(width: 20.w),
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: Text(leftTitel,
|
|
|
|
|
|
style: TextStyle(
|
2023-08-07 10:32:24 +08:00
|
|
|
|
fontSize: 24.sp, fontWeight: FontWeight.w500))),
|
2023-07-29 17:04:03 +08:00
|
|
|
|
SizedBox(width: 20.w),
|
|
|
|
|
|
Text(rightTitle,
|
|
|
|
|
|
textAlign: TextAlign.end,
|
|
|
|
|
|
style:
|
2023-08-07 10:32:24 +08:00
|
|
|
|
TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w500)),
|
2023-07-29 17:04:03 +08:00
|
|
|
|
SizedBox(width: 10.w),
|
2023-07-13 14:13:44 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2023-07-29 17:04:03 +08:00
|
|
|
|
Container(
|
|
|
|
|
|
height: 0.5.h,
|
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
|
)
|
2023-07-13 14:13:44 +08:00
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取行数
|
2023-07-15 15:11:28 +08:00
|
|
|
|
int _getRowsForMonthYear({int? year, int? month}) {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 当前月天数
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int currentMonthDays = _getCurrentMonthDays(year: year, month: month);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 这个月1号前面有几天
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int placeholderDays = _getPlaceholderDays(year: year, month: month);
|
2023-07-13 14:13:44 +08:00
|
|
|
|
|
|
|
|
|
|
int rows = (currentMonthDays + placeholderDays) ~/ 7;
|
|
|
|
|
|
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int remainder = (currentMonthDays + placeholderDays) % 7;
|
2023-07-13 14:13:44 +08:00
|
|
|
|
if (remainder > 0) {
|
|
|
|
|
|
rows = rows + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return rows;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 得到这个月的第一天是星期几
|
2023-07-15 15:11:28 +08:00
|
|
|
|
int _getPlaceholderDays({int? year, int? month}) {
|
|
|
|
|
|
return DateTime(year!, month!).weekday - 1 % 7;
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前月份天数
|
2023-07-15 15:11:28 +08:00
|
|
|
|
int _getCurrentMonthDays({int? year, int? month}) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
if (month == 2) {
|
|
|
|
|
|
//判断2月份是闰年月还是平年
|
2023-07-15 15:11:28 +08:00
|
|
|
|
if (((year! % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
return 29;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 28;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (month == 1 ||
|
|
|
|
|
|
month == 3 ||
|
|
|
|
|
|
month == 5 ||
|
|
|
|
|
|
month == 7 ||
|
|
|
|
|
|
month == 8 ||
|
|
|
|
|
|
month == 10 ||
|
|
|
|
|
|
month == 12) {
|
|
|
|
|
|
return 31;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 30;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 获取展示信息
|
2023-07-15 15:11:28 +08:00
|
|
|
|
_setDatas({int? year, int? month}) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
/// 上个月占位
|
2024-06-07 10:53:24 +08:00
|
|
|
|
int? lastYear = year;
|
|
|
|
|
|
int lastMonth = month! - 1;
|
2023-07-13 14:13:44 +08:00
|
|
|
|
if (month == 1) {
|
2023-07-15 15:11:28 +08:00
|
|
|
|
lastYear = (year! - 1)!;
|
2023-07-13 14:13:44 +08:00
|
|
|
|
lastMonth = 12;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int placeholderDays = _getPlaceholderDays(year: year, month: month);
|
|
|
|
|
|
final int lastMonthDays = _getCurrentMonthDays(year: lastYear, month: lastMonth);
|
|
|
|
|
|
final int firstDay = lastMonthDays - placeholderDays;
|
|
|
|
|
|
for (int i = 0; i < placeholderDays; i++) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
_datas.add(CalendarModel(
|
|
|
|
|
|
year: lastYear,
|
|
|
|
|
|
month: lastMonth,
|
|
|
|
|
|
day: firstDay + i + 1,
|
|
|
|
|
|
isSelect: false,
|
2024-06-07 10:53:24 +08:00
|
|
|
|
workType: '0'));
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 本月显示
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int currentMonthDays = _getCurrentMonthDays(year: year, month: month);
|
|
|
|
|
|
for (int i = 0; i < currentMonthDays; i++) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
if (i == _day - 1) {
|
|
|
|
|
|
_datas.add(CalendarModel(
|
|
|
|
|
|
year: year,
|
|
|
|
|
|
month: month,
|
|
|
|
|
|
day: i + 1,
|
|
|
|
|
|
isSelect: true,
|
2024-06-07 10:53:24 +08:00
|
|
|
|
workType: '0'));
|
2023-07-13 14:13:44 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
_datas.add(CalendarModel(
|
|
|
|
|
|
year: year,
|
|
|
|
|
|
month: month,
|
|
|
|
|
|
day: i + 1,
|
|
|
|
|
|
isSelect: false,
|
2024-06-07 10:53:24 +08:00
|
|
|
|
workType: '0'));
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 下个月占位
|
2024-06-07 10:53:24 +08:00
|
|
|
|
int? nextYear = year;
|
|
|
|
|
|
int nextMonth = month + 1;
|
2023-07-13 14:13:44 +08:00
|
|
|
|
if (month == 12) {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
nextYear = year! + 1;
|
2023-07-13 14:13:44 +08:00
|
|
|
|
nextMonth = 1;
|
|
|
|
|
|
}
|
2024-06-07 10:53:24 +08:00
|
|
|
|
final int nextPlaceholderDays =
|
2023-07-29 17:04:03 +08:00
|
|
|
|
_getPlaceholderDays(year: nextYear, month: nextMonth);
|
2024-06-07 10:53:24 +08:00
|
|
|
|
for (int i = 0; i < 7 - nextPlaceholderDays; i++) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
_datas.add(CalendarModel(
|
|
|
|
|
|
year: nextYear,
|
|
|
|
|
|
month: nextMonth,
|
|
|
|
|
|
day: i + 1,
|
|
|
|
|
|
isSelect: false,
|
2024-06-07 10:53:24 +08:00
|
|
|
|
workType: '0'));
|
2023-07-13 14:13:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 上月
|
|
|
|
|
|
_lastMonth() {
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
if (_month == 1) {
|
|
|
|
|
|
_year = _year - 1;
|
|
|
|
|
|
_month = 12;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
_month = _month - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
_day = 1; //查看上一个月时,默认选中的为第一天
|
|
|
|
|
|
_datas.clear();
|
|
|
|
|
|
_setDatas(year: _year, month: _month);
|
|
|
|
|
|
//更新月历事件
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// _loadAttendanceMonthRecord("$_year-$_month");
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//更新日事件
|
2023-09-15 16:04:11 +08:00
|
|
|
|
_loadAttendanceDayRecord("$_year-${_month.toString().padLeft(2,'0')}-${_day.toString().padLeft(2,'0')}");
|
2023-07-13 14:13:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 下月
|
|
|
|
|
|
_nextMonth() {
|
2023-07-29 17:04:03 +08:00
|
|
|
|
if (_month == 12) {
|
|
|
|
|
|
//当前月是12月,下一个月就是下一年
|
|
|
|
|
|
if (DateTime.now().year >= _year + 1) {
|
|
|
|
|
|
//判断下一年是否大于当前年
|
2023-07-13 14:13:44 +08:00
|
|
|
|
_setNextMonthData();
|
|
|
|
|
|
}
|
2023-07-29 17:04:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
//当前月不是12月,还处于当前年
|
|
|
|
|
|
if (DateTime.now().month >= _month + 1) {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//判断下一个月是否超过当前月,超过当前月不做操作
|
|
|
|
|
|
_setNextMonthData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//设置下个月的数据
|
2023-07-29 17:04:03 +08:00
|
|
|
|
_setNextMonthData() {
|
2023-07-13 14:13:44 +08:00
|
|
|
|
setState(() {
|
|
|
|
|
|
if (_month == 12) {
|
|
|
|
|
|
_year = _year + 1;
|
|
|
|
|
|
_month = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
_month = _month + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_month == DateTime.now().month) {
|
|
|
|
|
|
//如果下个月时当前月,默认选中当天
|
|
|
|
|
|
_day = DateTime.now().day;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//如果不是当前月,默认选中第一天
|
|
|
|
|
|
_day = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
_datas.clear();
|
|
|
|
|
|
_setDatas(year: _year, month: _month);
|
|
|
|
|
|
//更新月历事件
|
2024-06-07 10:53:24 +08:00
|
|
|
|
_loadAttendanceMonthRecord('$_year-$_month');
|
2023-07-13 14:13:44 +08:00
|
|
|
|
//更新日事件
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// _loadAttendanceDayRecord("$_year-$_month-$_day");
|
|
|
|
|
|
_loadAttendanceDayRecord("$_year-${_month.toString().padLeft(2,'0')}-${_day.toString().padLeft(2,'0')}");
|
2023-07-13 14:13:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//日历bean
|
|
|
|
|
|
class CalendarModel {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
|
|
|
|
|
|
CalendarModel(
|
|
|
|
|
|
{this.year, this.month, this.day, this.isSelect, this.workType});
|
2023-07-15 15:11:28 +08:00
|
|
|
|
int? year;
|
|
|
|
|
|
int? month;
|
|
|
|
|
|
int? day;
|
2024-06-07 10:53:24 +08:00
|
|
|
|
String? workType = ''; //日期事件,0休息,1迟到,2早退,3未打卡
|
2023-07-15 15:11:28 +08:00
|
|
|
|
bool? isSelect = false;
|
2023-07-29 17:04:03 +08:00
|
|
|
|
}
|