diff --git a/lib/const/api.dart b/lib/const/api.dart index 0cb226c..6f3c0d9 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -9,6 +9,7 @@ class API { static String get resource => '$host/static'; static String image(String path) => '$resource$path'; + static String file(String path) => '$resource$path'; static const int networkTimeOut = 10000; static _Auth auth = _Auth(); @@ -230,6 +231,21 @@ class _Manage { ///管家app设施设备检查:提交报告 String get submitFacilitiesCheckInfo => '/user/facilitiesCheck/submitCheck'; + + ///管家app 考勤管理:查询当前用户今日打卡记录 + String get todayClockRecord => '/user/attendance/todayClockRecord'; + + ///管家app 考勤管理:上下班打卡 + String get clockInOut => '/user/attendance/clock'; + + ///管家app 考勤管理:打卡记录 + String get clockRecord => '/user/attendance/clockRecord'; + + ///管家app 考勤管理:加班/请假申请记录 + String get clockApplyRecord => '/user/attendance/applyRecord'; + + ///管家app 考勤管理:填写加班/请假申请 + String get clockApply => '/user/attendance/apply'; } class _Upload { diff --git a/lib/models/manager/clock_in_out/clock_apply_record_list_model.dart b/lib/models/manager/clock_in_out/clock_apply_record_list_model.dart new file mode 100644 index 0000000..162e501 --- /dev/null +++ b/lib/models/manager/clock_in_out/clock_apply_record_list_model.dart @@ -0,0 +1,104 @@ +import 'package:aku_community_manager/style/app_style.dart'; +import 'package:common_utils/common_utils.dart'; +import 'package:flutter/material.dart'; + +class ClockApplyRecordListModel { + int id; + String reason; + int status; + int type; + String startDate; + String endDate; + String createName; + String createTel; + String createDate; + String reviewerName; + String reviewerDate; + + ClockApplyRecordListModel( + {this.id, + this.reason, + this.status, + this.type, + this.startDate, + this.endDate, + this.createName, + this.createTel, + this.createDate, + this.reviewerName, + this.reviewerDate}); + + ClockApplyRecordListModel.fromJson(Map json) { + id = json['id']; + reason = json['reason']; + status = json['status']; + type = json['type']; + startDate = json['startDate']; + endDate = json['endDate']; + createName = json['createName']; + createTel = json['createTel']; + createDate = json['createDate']; + reviewerName = json['reviewerName']; + reviewerDate = json['reviewerDate']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['reason'] = this.reason; + data['status'] = this.status; + data['type'] = this.type; + data['startDate'] = this.startDate; + data['endDate'] = this.endDate; + data['createName'] = this.createName; + data['createTel'] = this.createTel; + data['createDate'] = this.createDate; + data['reviewerName'] = this.reviewerName; + data['reviewerDate'] = this.reviewerDate; + return data; + } + + String get typeString { + switch (this.type) { + case 1: + return '请假'; + case 2: + return '加班'; + default: + return '未知'; + } + } + + String get statusString { + switch (this.status) { + case 1: + return '待审核'; + case 2: + return '审核通过'; + case 3: + return '审核驳回'; + default: + return '未知'; + } + } + + Color get statusColor { + switch (this.status) { + case 1: + return kPrimaryColor; + case 2: + return Colors.green; + case 3: + return Colors.red; + default: + return Colors.black; + } + } + + String get startTimeString => + DateUtil.formatDateStr(this.startDate, format: 'yyyy-MM-dd HH:mm'); + String get endTimeString => + DateUtil.formatDateStr(this.endDate, format: 'yyyy-MM-dd HH:mm'); + String get applyTimeString => + DateUtil.formatDateStr(this.createDate, format: 'yyyy-MM-dd HH:mm:ss'); +} diff --git a/lib/models/manager/clock_in_out/clock_record_list_model.dart b/lib/models/manager/clock_in_out/clock_record_list_model.dart new file mode 100644 index 0000000..45dbfe7 --- /dev/null +++ b/lib/models/manager/clock_in_out/clock_record_list_model.dart @@ -0,0 +1,58 @@ +import 'package:aku_community_manager/utils/weekdays_to_chinese.dart'; +import 'package:common_utils/common_utils.dart'; + +class ClockRecordListModel { + int id; + String startClockDate; + String endClockDate; + String cardReplacementDate; + String operatorName; + String clockName; + String clockTel; + String createDate; + + ClockRecordListModel( + {this.id, + this.startClockDate, + this.endClockDate, + this.cardReplacementDate, + this.operatorName, + this.clockName, + this.clockTel, + this.createDate}); + + ClockRecordListModel.fromJson(Map json) { + id = json['id']; + startClockDate = json['startClockDate']; + endClockDate = json['endClockDate']; + cardReplacementDate = json['cardReplacementDate']; + operatorName = json['operatorName']; + clockName = json['clockName']; + clockTel = json['clockTel']; + createDate = json['createDate']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['startClockDate'] = this.startClockDate; + data['endClockDate'] = this.endClockDate; + data['cardReplacementDate'] = this.cardReplacementDate; + data['operatorName'] = this.operatorName; + data['clockName'] = this.clockName; + data['clockTel'] = this.clockTel; + data['createDate'] = this.createDate; + return data; + } + + String get startClockString => + DateUtil.formatDateStr(this.startClockDate, format: 'HH:mm:ss'); + + String get endClockString => + DateUtil.formatDateStr(this.endClockDate, format: 'HH:mm:ss'); + + String get clockDateString => + DateUtil.formatDateStr(this.startClockDate, format: 'yyyy.MM.dd'); + String get weekDay => WeekDaysToChinese.fromInt( + DateUtil.getDateTime(this.startClockDate).weekday); +} diff --git a/lib/models/manager/clock_in_out/today_clock_record_model.dart b/lib/models/manager/clock_in_out/today_clock_record_model.dart new file mode 100644 index 0000000..887cf14 --- /dev/null +++ b/lib/models/manager/clock_in_out/today_clock_record_model.dart @@ -0,0 +1,49 @@ +import 'package:common_utils/common_utils.dart'; + +class TodayClockRecordModel { + int id; + String startClockDate; + String endClockDate; + String cardReplacementDate; + String operatorName; + String clockName; + String clockTel; + String createDate; + + TodayClockRecordModel( + {this.id, + this.startClockDate, + this.endClockDate, + this.cardReplacementDate, + this.operatorName, + this.clockName, + this.clockTel, + this.createDate}); + + TodayClockRecordModel.fromJson(Map json) { + id = json['id']; + startClockDate = json['startClockDate']; + endClockDate = json['endClockDate']; + cardReplacementDate = json['cardReplacementDate']; + operatorName = json['operatorName']; + clockName = json['clockName']; + clockTel = json['clockTel']; + createDate = json['createDate']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['startClockDate'] = this.startClockDate; + data['endClockDate'] = this.endClockDate; + data['cardReplacementDate'] = this.cardReplacementDate; + data['operatorName'] = this.operatorName; + data['clockName'] = this.clockName; + data['clockTel'] = this.clockTel; + data['createDate'] = this.createDate; + return data; + } + + DateTime get clockInTime => DateUtil.getDateTime(this.startClockDate); + DateTime get clockOutTime => DateUtil.getDateTime(this.endClockDate); +} diff --git a/lib/models/manager/rules_manage/rules_manage_list_model.dart b/lib/models/manager/rules_manage/rules_manage_list_model.dart index 9bb6a58..3560577 100644 --- a/lib/models/manager/rules_manage/rules_manage_list_model.dart +++ b/lib/models/manager/rules_manage/rules_manage_list_model.dart @@ -4,14 +4,24 @@ class RulesManageListModel { int id; String title; String content; + String fileDocUrl; + String fileDocName; String releaseDate; - RulesManageListModel({this.id, this.title, this.content, this.releaseDate}); + RulesManageListModel( + {this.id, + this.title, + this.content, + this.fileDocUrl, + this.fileDocName, + this.releaseDate}); RulesManageListModel.fromJson(Map json) { id = json['id']; title = json['title']; content = json['content']; + fileDocUrl = json['fileDocUrl']; + fileDocName = json['fileDocName']; releaseDate = json['releaseDate']; } @@ -20,6 +30,8 @@ class RulesManageListModel { data['id'] = this.id; data['title'] = this.title; data['content'] = this.content; + data['fileDocUrl'] = this.fileDocUrl; + data['fileDocName'] = this.fileDocName; data['releaseDate'] = this.releaseDate; return data; } diff --git a/lib/ui/manage_pages/clock_in_out/clock_func.dart b/lib/ui/manage_pages/clock_in_out/clock_func.dart new file mode 100644 index 0000000..6a8af04 --- /dev/null +++ b/lib/ui/manage_pages/clock_in_out/clock_func.dart @@ -0,0 +1,53 @@ +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/manager/clock_in_out/today_clock_record_model.dart'; +import 'package:aku_community_manager/utils/network/base_model.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:common_utils/common_utils.dart'; + +class ClockFunc { + static Future initClockInfo() async { + BaseModel baseModel = await NetUtil().get(API.manage.todayClockRecord); + if (baseModel.status && baseModel.data != null) { + return TodayClockRecordModel.fromJson(baseModel.data); + } else { + BotToast.showText(text: baseModel.message); + } + } + + static Future clockIn(int id, DateTime dateTime) async { + BaseModel baseModel = await NetUtil().post( + API.manage.clockInOut, + params: { + "id": id, + "startClockDate": + DateUtil.formatDate(dateTime, format: 'yyyy-MM-dd HH:mm:ss'), + }, + showMessage: true, + ); + } + + static Future clockOut(int id, DateTime dateTime) async { + BaseModel baseModel = await NetUtil().post(API.manage.clockInOut, + params: { + "id": id, + "endClockDate": + DateUtil.formatDate(dateTime, format: 'yyyy-MM-dd HH:mm:ss'), + }, + showMessage: true); + } + + static Future clockApply( + String reason, int type, DateTime start, DateTime end) async { + BaseModel baseModel = await NetUtil().post(API.manage.clockApply, + params: { + "reason": reason, + 'type': type, + "startDate": + DateUtil.formatDate(start, format: 'yyyy-MM-dd HH:mm:ss'), + "endDate": DateUtil.formatDate(end, format: 'yyyy-MM-dd HH:mm:ss') + }, + showMessage: true); + return baseModel.status; + } +} diff --git a/lib/ui/manage_pages/clock_in_out/clock_in_out_apply_card.dart b/lib/ui/manage_pages/clock_in_out/clock_in_out_apply_card.dart index 7215cc8..09291a7 100644 --- a/lib/ui/manage_pages/clock_in_out/clock_in_out_apply_card.dart +++ b/lib/ui/manage_pages/clock_in_out/clock_in_out_apply_card.dart @@ -1,3 +1,4 @@ +import 'package:aku_community_manager/models/manager/clock_in_out/clock_apply_record_list_model.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/aku_divider.dart'; import 'package:flutter/material.dart'; @@ -6,7 +7,8 @@ import 'package:velocity_x/velocity_x.dart'; import 'package:aku_community_manager/tools/extensions/list_extension_tool.dart'; class ClockInOutApplyCard extends StatefulWidget { - ClockInOutApplyCard({Key key}) : super(key: key); + final ClockApplyRecordListModel model; + ClockInOutApplyCard({Key key, this.model}) : super(key: key); @override _ClockInOutApplyCardState createState() => _ClockInOutApplyCardState(); @@ -25,9 +27,17 @@ class _ClockInOutApplyCardState extends State { children: [ Row( children: [ - 'Name'.text.size(32.sp).color(kTextPrimaryColor).bold.make(), + widget.model.typeString.text + .size(32.sp) + .color(kTextPrimaryColor) + .bold + .make(), Spacer(), - '待审核'.text.size(28.sp).bold.color(kPrimaryColor).make() + widget.model.statusString.text + .size(28.sp) + .bold + .color(widget.model.statusColor) + .make() ], ), 16.w.heightBox, @@ -35,18 +45,16 @@ class _ClockInOutApplyCardState extends State { 24.w.heightBox, ...[ _rowTile( - R.ASSETS_MANAGE_IC_RENWU_PNG, + R.ASSETS_MANAGE_IC_TIME_PNG, '开始时间', - '2021-05-19 10:00:00' - .text + widget.model.startTimeString.text .size(24.sp) .color(kTextSubColor) .make()), _rowTile( - R.ASSETS_MANAGE_LOCK_PNG, + R.ASSETS_MANAGE_IC_TIME_PNG, '结束时间', - '2021-05-19 10:00:00' - .text + widget.model.endTimeString.text .size(24.sp) .color(kTextSubColor) .make()), @@ -67,23 +75,22 @@ class _ClockInOutApplyCardState extends State { 160.w.widthBox, Row( children: [ - '弟弟结婚,需要回趟家帮忙张罗婚礼的筹备' - .text + widget.model.reason.text .size(24.sp) .maxLines(2) .overflow(TextOverflow.ellipsis) .align(TextAlign.end) .color(kTextSubColor) - .make().expand() + .make() + .expand() ], ).expand() ], ), _rowTile( - R.ASSETS_MANAGE_LOCK_PNG, + R.ASSETS_MANAGE_IC_TIME_PNG, '申请时间', - '2021-05-19 10:00:00' - .text + widget.model.applyTimeString.text .size(24.sp) .color(kTextSubColor) .make()), diff --git a/lib/ui/manage_pages/clock_in_out/clock_in_out_main_page.dart b/lib/ui/manage_pages/clock_in_out/clock_in_out_main_page.dart index 68a82c9..d7e182f 100644 --- a/lib/ui/manage_pages/clock_in_out/clock_in_out_main_page.dart +++ b/lib/ui/manage_pages/clock_in_out/clock_in_out_main_page.dart @@ -1,8 +1,10 @@ import 'dart:async'; +import 'package:aku_community_manager/models/manager/clock_in_out/today_clock_record_model.dart'; import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/user_tool.dart'; +import 'package:aku_community_manager/ui/manage_pages/clock_in_out/clock_func.dart'; import 'package:aku_community_manager/utils/weekdays_to_chinese.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; @@ -19,10 +21,11 @@ class ClockInOutMainPage extends StatefulWidget { _ClockInOutMainPageState createState() => _ClockInOutMainPageState(); } -class _ClockInOutMainPageState extends State { +class _ClockInOutMainPageState extends State with AutomaticKeepAliveClientMixin { EasyRefreshController _refreshController; Timer _clockSetState; DateTime _lastPressed; + TodayClockRecordModel _model; bool get canTap { if (_lastPressed == null || DateTime.now().difference(_lastPressed) > Duration(seconds: 15)) { @@ -42,7 +45,6 @@ class _ClockInOutMainPageState extends State { _clockSetState = Timer.periodic(Duration(seconds: 1), (_timer) { setState(() {}); }); - UserTool.appProvider.initClock(); } @override @@ -59,7 +61,24 @@ class _ClockInOutMainPageState extends State { firstRefresh: true, header: MaterialHeader(), controller: _refreshController, - onRefresh: () async {}, + onRefresh: () async { + UserTool.appProvider.initClock(); + _model = await ClockFunc.initClockInfo(); + if (_model != null) { + UserTool.appProvider.resetClock(); //若成功获取今日打卡信息,则先重置打卡状态 + if (_model.startClockDate != null) { + //若有上班打卡信息 则将打卡状态转换为已上班打卡 + UserTool.appProvider.setClockInTime(_model.clockInTime); + } + + if (_model.endClockDate != null) { + //若有下班打卡信息,则将打卡状态转换为已下班打卡 + UserTool.appProvider.setClockOutTime(_model.clockOutTime); + } + } + + setState(() {}); + }, child: Container( margin: EdgeInsets.all(32.w), padding: EdgeInsets.all(32.w), @@ -96,14 +115,18 @@ class _ClockInOutMainPageState extends State { ); } + ///打卡函数 根据WORKCLOCK当前状态判断是上班打卡还是下班打卡 clockInOut() { + DateTime _currentTime = DateTime.now(); switch (UserTool.appProvider.clockStatus) { case WORKCLOCK.NOTIN: - UserTool.appProvider.setClockInTime(DateTime.now()); + ClockFunc.clockIn(_model.id, _currentTime); + UserTool.appProvider.setClockInTime(_currentTime); BotToast.showText(text: '上班打卡成功'); break; case WORKCLOCK.IN: - UserTool.appProvider.setClockOutTime(DateTime.now()); + ClockFunc.clockOut(_model.id, _currentTime); + UserTool.appProvider.setClockOutTime(_currentTime); BotToast.showText(text: '下班打卡成功'); break; case WORKCLOCK.OUT: @@ -227,4 +250,7 @@ class _ClockInOutMainPageState extends State { } return '$_hour小时$_min分钟'; } + + @override + bool get wantKeepAlive => true; } diff --git a/lib/ui/manage_pages/clock_in_out/clock_in_out_record_card.dart b/lib/ui/manage_pages/clock_in_out/clock_in_out_record_card.dart index 753b47d..8c4ddc6 100644 --- a/lib/ui/manage_pages/clock_in_out/clock_in_out_record_card.dart +++ b/lib/ui/manage_pages/clock_in_out/clock_in_out_record_card.dart @@ -1,11 +1,12 @@ +import 'package:aku_community_manager/models/manager/clock_in_out/clock_record_list_model.dart'; import 'package:aku_community_manager/style/app_style.dart'; -import 'package:common_utils/common_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:velocity_x/velocity_x.dart'; class ClockInOutRecordCard extends StatefulWidget { - ClockInOutRecordCard({Key key}) : super(key: key); + final ClockRecordListModel model; + ClockInOutRecordCard({Key key, this.model}) : super(key: key); @override _ClockInOutRecordCardState createState() => _ClockInOutRecordCardState(); @@ -24,15 +25,18 @@ class _ClockInOutRecordCardState extends State { children: [ Row( children: [ - '2021.05.19' - .text + widget.model.clockDateString.text .size(28.sp) .bold .color(kTextPrimaryColor) .bold .make(), Spacer(), - '周三'.text.size(32.sp).bold.color(kTextPrimaryColor).make(), + widget.model.weekDay.text + .size(32.sp) + .bold + .color(kTextPrimaryColor) + .make(), ], ), 40.w.heightBox, @@ -48,12 +52,14 @@ class _ClockInOutRecordCardState extends State { width: 16.w, height: 16.w, decoration: BoxDecoration( - color: Color(0xFF3F8FFE), + color: widget.model.startClockDate == null + ? Color(0xFFE60E0E) + : Color(0xFF3F8FFE), borderRadius: BorderRadius.circular(8.w), ), ), 8.w.widthBox, - '上班打卡时间' + (widget.model.startClockDate == null ? '上班未打卡' : '上班打卡时间') .text .size(28.sp) .color(kTextPrimaryColor) @@ -61,19 +67,22 @@ class _ClockInOutRecordCardState extends State { .make(), ], ), - 16.w.heightBox, - Row( - children: [ - 24.w.widthBox, - (DateUtil.formatDateStr('2020-10-11 08:24:30', - format: 'HH:mm:ss')) - .text - .size(32.sp) - .color(kTextPrimaryColor) - .bold - .make(), - ], - ), + ...widget.model.startClockDate == null + ? [] + : [ + 16.w.heightBox, + Row( + children: [ + 24.w.widthBox, + (widget.model.startClockString) + .text + .size(32.sp) + .color(kTextPrimaryColor) + .bold + .make(), + ], + ), + ] ], ), 130.w.widthBox, @@ -86,12 +95,14 @@ class _ClockInOutRecordCardState extends State { width: 16.w, height: 16.w, decoration: BoxDecoration( - color: Color(0xFF3F8FFE), + color: widget.model.startClockDate == null + ? Color(0xFFE60E0E) + : Color(0xFF3F8FFE), borderRadius: BorderRadius.circular(8.w), ), ), 8.w.widthBox, - '下班打卡时间' + (widget.model.startClockDate == null ? '下班未打卡' : '下班打卡时间') .text .size(28.sp) .color(kTextPrimaryColor) @@ -99,18 +110,21 @@ class _ClockInOutRecordCardState extends State { .make(), ], ), - 16.w.heightBox, - Row( - children: [ - 24.w.widthBox, - DateUtil.formatDateStr('08:24:09', format: 'HH:mm:ss') - .text - .size(32.sp) - .color(kTextPrimaryColor) - .bold - .make(), - ], - ), + ...widget.model.startClockDate == null + ? [] + : [ + 16.w.heightBox, + Row( + children: [ + 24.w.widthBox, + widget.model.endClockString.text + .size(32.sp) + .color(kTextPrimaryColor) + .bold + .make(), + ], + ), + ] ], ), ], diff --git a/lib/ui/manage_pages/clock_in_out/clock_in_out_view.dart b/lib/ui/manage_pages/clock_in_out/clock_in_out_view.dart index bf7df67..ed09ffb 100644 --- a/lib/ui/manage_pages/clock_in_out/clock_in_out_view.dart +++ b/lib/ui/manage_pages/clock_in_out/clock_in_out_view.dart @@ -1,7 +1,13 @@ +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/manager/clock_in_out/clock_apply_record_list_model.dart'; +import 'package:aku_community_manager/models/manager/clock_in_out/clock_record_list_model.dart'; import 'package:aku_community_manager/ui/manage_pages/clock_in_out/clock_in_out_apply_card.dart'; import 'package:aku_community_manager/ui/manage_pages/clock_in_out/clock_in_out_record_card.dart'; +import 'package:aku_community_manager/ui/widgets/common/bee_list_view.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:velocity_x/velocity_x.dart'; class ClockInOutView extends StatefulWidget { final int index; @@ -12,20 +18,71 @@ class ClockInOutView extends StatefulWidget { } class _ClockInOutViewState extends State { + EasyRefreshController _refreshController; + @override + void initState() { + super.initState(); + _refreshController = EasyRefreshController(); + } + + @override + void dispose() { + _refreshController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { - return widget.index == 1 - ? ListView( - padding: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), - children: [ - ClockInOutRecordCard(), - ], - ) - : ListView( - padding: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), - children: [ - ClockInOutApplyCard(), - ], - ); + return _getView(); + } + + _getView() { + switch (widget.index) { + case 1: + return BeeListView( + path: API.manage.clockRecord, + controller: _refreshController, + convert: (models) { + return models.tableList + .map((e) => ClockRecordListModel.fromJson(e)) + .toList(); + }, + builder: (items) { + return ListView.separated( + padding: EdgeInsets.all(32.w), + itemBuilder: (context, index) { + return ClockInOutRecordCard( + model: items[index], + ); + }, + separatorBuilder: (_, __) { + return 24.w.heightBox; + }, + itemCount: items.length); + }); + case 2: + return BeeListView( + path: API.manage.clockApplyRecord, + controller: _refreshController, + convert: (models) { + return models.tableList + .map((e) => ClockApplyRecordListModel.fromJson(e)) + .toList(); + }, + builder: (items) { + return ListView.separated( + padding: EdgeInsets.all(32.w), + itemBuilder: (context, index) { + return ClockInOutApplyCard( + model: items[index], + ); + }, + separatorBuilder: (_, __) { + return 24.w.heightBox; + }, + itemCount: items.length); + }); + default: + } } } diff --git a/lib/ui/manage_pages/clock_in_out/work_apply_page.dart b/lib/ui/manage_pages/clock_in_out/work_apply_page.dart index 9067543..f19514d 100644 --- a/lib/ui/manage_pages/clock_in_out/work_apply_page.dart +++ b/lib/ui/manage_pages/clock_in_out/work_apply_page.dart @@ -1,5 +1,6 @@ import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/aku_divider.dart'; +import 'package:aku_community_manager/ui/manage_pages/clock_in_out/clock_func.dart'; import 'package:aku_community_manager/ui/widgets/app_widgets/aku_single_check_button.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/bee_date_picker.dart'; @@ -9,6 +10,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; import 'package:velocity_x/velocity_x.dart'; class WorkApplyPage extends StatefulWidget { @@ -21,25 +23,25 @@ class WorkApplyPage extends StatefulWidget { class _WorkApplyPageState extends State { int _type = 1; //请假为1 加班为2 - TextEditingController _nameController; - TextEditingController _positionController; - TextEditingController _phoneController; - DateTime _beginTime ; - DateTime _endTime ; + // TextEditingController _nameController; + // TextEditingController _positionController; + TextEditingController _reasonController; + DateTime _beginTime; + DateTime _endTime; @override void initState() { super.initState(); - _nameController = TextEditingController(); - _positionController = TextEditingController(); - _phoneController = TextEditingController(); + // _nameController = TextEditingController(); + // _positionController = TextEditingController(); + _reasonController = TextEditingController(); } @override void dispose() { - _nameController?.dispose(); - _positionController?.dispose(); - _phoneController?.dispose(); + // _nameController?.dispose(); + // _positionController?.dispose(); + _reasonController?.dispose(); super.dispose(); } @@ -52,15 +54,19 @@ class _WorkApplyPageState extends State { padding: EdgeInsets.all(32.w), children: [ _headType(), - _inputRowTile('姓名', _nameController), - _inputRowTile('职位', _positionController), - _inputRowTile('联系方式', _phoneController), + _inputRowTile('理由', _reasonController), _timePick(), ], ), bottom: AkuBottomButton( title: '确认提交', - onTap: () {}, + onTap: () async { + bool _result = await ClockFunc.clockApply( + _reasonController.text, _type, _beginTime, _endTime); + if (_result) { + Get.back(); + } + }, ), ); } @@ -151,7 +157,7 @@ class _WorkApplyPageState extends State { : _beginTime, max: _beginTime == null ? DateTime.now().add(Duration(days: 1)) - : (_beginTime).add(Duration(days: 1)), + : (_beginTime).add(Duration(days: 7)), mode: CupertinoDatePickerMode.dateAndTime, ); if (date != null) { diff --git a/lib/ui/manage_pages/rules_manage/rules_manage_detail_page.dart b/lib/ui/manage_pages/rules_manage/rules_manage_detail_page.dart index 02520cd..f97723d 100644 --- a/lib/ui/manage_pages/rules_manage/rules_manage_detail_page.dart +++ b/lib/ui/manage_pages/rules_manage/rules_manage_detail_page.dart @@ -1,10 +1,15 @@ import 'package:aku_community_manager/models/manager/rules_manage/rules_manage_list_model.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:aku_community_manager/ui/widgets/common/bee_download_view.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:open_file/open_file.dart'; import 'package:velocity_x/velocity_x.dart'; +import 'package:aku_community_manager/const/resource.dart'; class RulesManageDetailPage extends StatefulWidget { final RulesManageListModel model; @@ -21,57 +26,105 @@ class _RulesManageDetailPageState extends State { return AkuScaffold( backgroundColor: Colors.white, title: '规程管理', - body: ListView( - padding: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), - children: [ - _detailModel.title.text - .size(32.sp) - .color(kTextPrimaryColor) - .bold - .align(TextAlign.center) - .make(), - 24.w.heightBox, - SizedBox( - width: double.infinity, - child: _detailModel.content.text - .size(28.sp) + body: Stack( + children:[ ListView( + padding: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), + children: [ + _detailModel.title.text + .size(32.sp) .color(kTextPrimaryColor) + .bold + .align(TextAlign.center) .make(), - // child: RichText( - // text: TextSpan( - // children: List.generate(_parasedText.length, (index) { - // if (index.isEven) { - // return TextSpan( - // text: _parasedText[index], - // style: TextStyle(fontSize: 28.sp, color: ktextPrimary), - // ); - // } else { - // return TextSpan( - // text: _parasedText[index], - // style: TextStyle( - // fontSize: 28.sp, - // color: Colors.lightBlue, - // ), - // recognizer: _tapLinkUrlLancher - // ..onTap = () { - // launch(_parasedText[index]); - // }); - // } - // })), - // ), - ), - 40.w.heightBox, - Row( - children: [ - Spacer(), - '发布于 ${DateUtil.formatDateStr(_detailModel.releaseDate, format: 'MM-dd HH:mm')}' - .text - .size(24.sp) - .color(kTextSubColor) + 24.w.heightBox, + SizedBox( + width: double.infinity, + child: _detailModel.content.text + .size(28.sp) + .color(kTextPrimaryColor) .make(), - ], - ) - ], + // child: RichText( + // text: TextSpan( + // children: List.generate(_parasedText.length, (index) { + // if (index.isEven) { + // return TextSpan( + // text: _parasedText[index], + // style: TextStyle(fontSize: 28.sp, color: ktextPrimary), + // ); + // } else { + // return TextSpan( + // text: _parasedText[index], + // style: TextStyle( + // fontSize: 28.sp, + // color: Colors.lightBlue, + // ), + // recognizer: _tapLinkUrlLancher + // ..onTap = () { + // launch(_parasedText[index]); + // }); + // } + // })), + // ), + ), + 40.w.heightBox, + Row( + children: [ + Spacer(), + '发布于 ${DateUtil.formatDateStr(_detailModel.releaseDate, format: 'MM-dd HH:mm')}' + .text + .size(24.sp) + .color(kTextSubColor) + .make(), + ], + ), + // docView( + // widget.model?.fileDocName ?? '', widget.model?.fileDocUrl ?? '') + ], + ), + Positioned( + bottom: MediaQuery.of(context).padding.bottom+88.w, + left: 32.w, + right: 32.w, + child: docView( + widget.model?.fileDocName ?? '', widget.model?.fileDocUrl ?? '') ), + ] + + ), + ); + } + + Widget docView(String title, String path) { + // if (title?.isEmpty ?? true) return SizedBox(); + return Container( + // margin: EdgeInsets.only(right: 113.w), + alignment: Alignment.centerLeft, + child: MaterialButton( + minWidth: 606.w, + height: 154.w, + padding: EdgeInsets.symmetric(horizontal: 32.w), + child: Row( + children: [ + title.text.size(32.sp).make().expand(), + Image.asset( + R.ASSETS_MANAGE_IC_RENWU_PNG, + height: 52.w, + width: 52.w, + ), + ], + ), + onPressed: path.isEmptyOrNull + ? () { + BotToast.showText(text: '文件为空!'); + } + : () async { + String result = await Get.dialog(BeeDownloadView(file: path)); + if (result != null) OpenFile.open(result); + }, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.w), + side: BorderSide(color: Color(0xFFD4CFBE)), + ), + color: Colors.white, ), ); } diff --git a/lib/ui/widgets/common/bee_download_view.dart b/lib/ui/widgets/common/bee_download_view.dart new file mode 100644 index 0000000..ecb41a2 --- /dev/null +++ b/lib/ui/widgets/common/bee_download_view.dart @@ -0,0 +1,63 @@ +import 'dart:io'; + +import 'package:aku_community_manager/const/api.dart'; +import 'package:flutter/material.dart'; + +import 'package:dio/dio.dart'; +import 'package:get/get.dart'; +import 'package:path_provider/path_provider.dart'; + + +class BeeDownloadView extends StatefulWidget { + final String file; + BeeDownloadView({Key key, this.file}) : super(key: key); + + @override + _BeeDownloadViewState createState() => _BeeDownloadViewState(); +} + +class _BeeDownloadViewState extends State { + Dio dio = Dio(); + double progress; + Future download() async { + Directory dir = await getApplicationDocumentsDirectory(); + Directory docPath = Directory('${dir.path}/docs'); + if (!await (docPath.exists())) { + await docPath.create(); + } + await Future.delayed(Duration(milliseconds: 500)); + await dio.download( + API.file(widget.file), + '${docPath.path}/${widget.file.split('/').last}', + onReceiveProgress: (start, all) { + setState(() { + progress = start / all; + }); + print('$start,$all'); + }, + ); + Get.back(result: '${docPath.path}/${widget.file.split('/').last}'); + } + + @override + void initState() { + super.initState(); + download(); + } + + @override + Widget build(BuildContext context) { + return Center( + child: Container( + width: 100, + height: 100, + alignment: Alignment.center, + child: CircularProgressIndicator(value: progress), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + ), + ); + } +} diff --git a/lib/utils/weekdays_to_chinese.dart b/lib/utils/weekdays_to_chinese.dart index 55339e4..c612b0c 100644 --- a/lib/utils/weekdays_to_chinese.dart +++ b/lib/utils/weekdays_to_chinese.dart @@ -19,4 +19,25 @@ class WeekDaysToChinese { return '未知'; } } + + static String fromInt(int weekday) { + switch (weekday) { + case 1: + return '周一'; + case 2: + return '周二'; + case 3: + return '周三'; + case 4: + return '周四'; + case 5: + return '周五'; + case 6: + return '周六'; + case 7: + return '周日'; + default: + return '未知'; + } + } } diff --git a/pubspec.lock b/pubspec.lock index 7a7e38f..fe11134 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -655,6 +655,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" + open_file: + dependency: "direct main" + description: + name: open_file + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.2.1" package_config: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 87474a8..e6487f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -71,6 +71,8 @@ dependencies: shimmer: ^2.0.0-nullsafety.0 badges: ^2.0.0-nullsafety.1 equatable: ^2.0.0 + #打开文件 + open_file: ^3.2.1 dev_dependencies: flutter_test: