| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- //
- // HJClockInStatisticsViewController.m
- // HappyJob
- //
- // Created by 张晓光 on 2020/8/25.
- // Copyright © 2020 Bob. All rights reserved.
- //
- #import "HJClockInStatisticViewController.h"
- #import "HJClockInNaviView.h"
- #import "HJClockInStatisticCollectView.h"
- #import "HJClockInStatisticCalendarView.h"
- #import "HJClockInStatisticDayView.h"
- #import "HJClockInStatisticDetailViewController.h"
- #import "HJClockInStatisticCurrentMonthAPI.h"
- #import "HJClockInStatisticCollectAPI.h"
- #import "HJClockInStatisticDayAPI.h"
- #import "HJClockInDataBox.h"
- #import "HJClockInInfoModel.h"
- #import "HJClockInStatisticDataModel.h"
- @interface HJClockInStatisticViewController ()
- <
- HJClockInStatisticDetailTitleViewDelegate,
- FBScrollLayoutViewDelegate,
- FBAPIManagerInterceptor,
- FBAPIManagerDelegate,
- UIGestureRecognizerDelegate
- >
- @property (nonatomic, strong) FBScrollLayoutView *scrollLayoutView;
- @property (nonatomic, strong) HJClockInNaviView *naviView;
- @property (nonatomic, strong) HJClockInStatisticCollectView *collectView;//UICollectionView
- @property (nonatomic, strong) HJClockInStatisticCalendarView *calendarView;
- @property (nonatomic, strong) HJClockInStatisticDayView *dayWorkView;
- @property (nonatomic, strong) HJClockInStatisticDataModel *dataModel;
- @property (nonatomic, strong) HJClockInStatisticCurrentMonthAPI *currentMonthAPI;
- @property (nonatomic, strong) HJClockInStatisticCollectAPI *collectAPI;
- @property (nonatomic, strong) HJClockInStatisticDayAPI *dayAPI;
- @property (nonatomic, strong) HJClockInDataBox *dataBox;
- @property (nonatomic, strong) HJClockInInfoModel *model;
- @end
- @implementation HJClockInStatisticViewController
- #pragma mark - life cycle
- - (void)viewWillAppear:(BOOL)animated {
-
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- self.navigationController.interactivePopGestureRecognizer.delegate = self;
- }
-
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.view.backgroundColor = COLOR_F5F5F5;
- [self makeConstraintsNaviViews];
- [self.currentMonthAPI start];
- }
- - (void)makeConstraintsNaviViews {
-
- [self.view addSubview:self.naviView];
- [self.naviView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.top.right.equalTo(self.view).offset(0);
- }];
- }
- - (void)makeConstraintsViews {
-
- [self.view addSubview:self.scrollLayoutView];
- [self.scrollLayoutView.contentView addSubview:self.collectView];
- [self.scrollLayoutView.contentView addSubview:self.calendarView];
- [self.scrollLayoutView.contentView addSubview:self.dayWorkView];
- [self.scrollLayoutView makeConstraints];
-
- __weak typeof(self) weakSelf = self;
- self.calendarView.selectDayDateBlock = ^(NSString * _Nonnull day) {
-
- weakSelf.dayAPI.search_date = day;
- [weakSelf.dayAPI start];
- };
- }
- #pragma mark - FBScrollLayoutViewDelegate
- - (void)scrollLayoutViewMakeConstraints:(FBScrollLayoutView *)scrollLayoutView {
-
- [scrollLayoutView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(self.naviView.mas_bottom).offset(0);
- make.left.right.bottom.equalTo(self.view).offset(0);
- }];
- }
- - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView contentView:(UIView *)contentView {
- [self.collectView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(contentView);
- }];
-
- [self.calendarView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(self.collectView.mas_bottom).offset(0);
- make.left.right.equalTo(contentView);
- }];
- [self.dayWorkView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.calendarView.mas_bottom).offset(0);
- make.left.right.equalTo(contentView);
- }];
-
- [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.dayWorkView.mas_bottom).offset(0);
- }];
- }
- #pragma mark - FBAPIManagerInterceptor
- - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
-
- [self.view fb_showLoading];
- return YES;
- }
- - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
-
- [self.view fb_dismiss];
- }
- #pragma mark - FBAPIManagerDelegate
- - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
-
- if (manager == self.currentMonthAPI)
- {
- NSDictionary *dataDict = [manager fetchDataWithBox:self.dataBox];
- self.model = [HJClockInInfoModel yy_modelWithDictionary:dataDict[@"currentSettlement"]];
-
- //集合
- self.collectAPI.month_type = @"1";
- [self.collectAPI start];
-
- //当天的
- self.dayAPI.search_date = self.model.date;
- [self.dayAPI start];
-
- self.collectView.monthLabel.text = [NSString stringWithFormat:@"%ld月汇总",(long)[self.collectView month:self.model.date]];
- self.collectView.moneyLabel.text = self.model.nextMoney ? [NSString stringWithFormat:@"%.2lf",[self.model.nextMoney floatValue]] : @"0";
- self.collectView.workeHourLabel.text = self.model.countDuration ? self.model.countDuration : @"0";
- self.collectView.numberLabel.text = self.model.lackClock ? self.model.lackClock : @"0";
-
- [self makeConstraintsViews];
- }
-
- if (manager == self.collectAPI)
- {
- self.calendarView.calendarView.viewModel.collectArray = [manager fetchDataWithBox:self.dataBox][@"wsPunchClockList"];
- if ([self.collectAPI.month_type isEqualToString: @"2"])
- {
- [self.calendarView.monthView leftButtonAction];
- }
- else
- {
- [self.calendarView.monthView rightButtonAction];
- }
- [self.calendarView.calendarView.collectionView reloadData];
- }
-
- if (manager == self.dayAPI)
- {
- [self.dayWorkView configurationData:[manager fetchDataWithBox:self.dataBox]];
- }
- }
- - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
-
- if (manager == self.currentMonthAPI)
- {
- [self showErrorView];
- }
- id fetchData = [manager fetchDataWithBox:self.dataBox];
- if ([fetchData isKindOfClass:[NSString class]])
- {
- [self.view fb_showFailureWithStatus:fetchData];
- }
- }
- /* 显示错误View */
- - (void)showErrorView {
-
- [self.view showErrorView];
- [self.view.errorView.refreshButton addTarget:self action:@selector(refreshButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.view.errorView mas_remakeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(self.naviView.mas_bottom).offset(0);
- make.left.bottom.right.equalTo(self.view).offset(0);
- }];
- }
- #pragma mark - HJClockInStatisticDetailTitleViewDelegate
- - (void)leftButtonActionDelegate:(NSInteger)tag {
-
- [self.calendarView lastMonth];
- self.collectAPI.month_type = @"2";
- [self.collectAPI start];
- }
- - (void)rightButtonActionDelegate:(NSInteger)tag {
-
- [self.calendarView nextMonth];
- self.collectAPI.month_type = @"1";
- [self.collectAPI start];
- }
- #pragma mark - event
- - (void)deleteBtnClick:(UIButton *)btn {
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)detailClick:(UITapGestureRecognizer *)tap {
-
- HJClockInStatisticDetailViewController *detailVC = [[HJClockInStatisticDetailViewController alloc] init];
- detailVC.servicerDate = self.model.date;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- /* 错误刷新 */
- - (void)refreshButtonAction:(UIButton *)btn {
-
- [self.view dismissErrorView];
- [self.currentMonthAPI start];
- }
- #pragma mark - lazy
- - (HJClockInDataBox *)dataBox {
-
- if (_dataBox == nil)
- {
- _dataBox = [[HJClockInDataBox alloc] init];
- }
- return _dataBox;
- }
- - (HJClockInStatisticCurrentMonthAPI *)currentMonthAPI {
-
- if (_currentMonthAPI == nil)
- {
- _currentMonthAPI = [[HJClockInStatisticCurrentMonthAPI alloc]init];
- _currentMonthAPI.APIManagerDelegate = self;
- _currentMonthAPI.APIManagerInterceptor = self;
- }
- return _currentMonthAPI;
- }
- - (HJClockInStatisticCollectAPI *)collectAPI {
-
- if (_collectAPI == nil)
- {
- _collectAPI = [[HJClockInStatisticCollectAPI alloc]init];
- _collectAPI.APIManagerDelegate = self;
- _collectAPI.APIManagerInterceptor = self;
- }
- return _collectAPI;
- }
- - (HJClockInStatisticDayAPI *)dayAPI {
-
- if (_dayAPI == nil)
- {
- _dayAPI = [[HJClockInStatisticDayAPI alloc]init];
- _dayAPI.APIManagerDelegate = self;
- _dayAPI.APIManagerInterceptor = self;
- }
- return _dayAPI;
- }
- - (FBScrollLayoutView *)scrollLayoutView {
-
- if (_scrollLayoutView == nil)
- {
- _scrollLayoutView = [[FBScrollLayoutView alloc] init];
- _scrollLayoutView.delegate = self;
- _scrollLayoutView.backgroundColor = COLOR_F5F5F5;
- _scrollLayoutView.contentView.backgroundColor = COLOR_F5F5F5;
- }
- return _scrollLayoutView;
- }
- - (HJClockInNaviView *)naviView {
-
- if (_naviView == nil)
- {
- _naviView = [[HJClockInNaviView alloc] init];
- [_naviView.deleteBtn addTarget:self action:@selector(deleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _naviView;
- }
- - (HJClockInStatisticCollectView *)collectView {
-
- if (_collectView == nil)
- {
- _collectView = [[HJClockInStatisticCollectView alloc] init];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(detailClick:)];
- [_collectView addGestureRecognizer:tap];
- }
- return _collectView;
- }
- - (HJClockInStatisticDataModel *)dataModel {
-
- if (_dataModel == nil)
- {
- _dataModel = [[HJClockInStatisticDataModel alloc] initWithServicerDate:self.model.date];
- }
- return _dataModel;
- }
- - (HJClockInStatisticCalendarView *)calendarView {
-
- if (_calendarView == nil)
- {
- _calendarView = [[HJClockInStatisticCalendarView alloc] initWithFrame:CGRectZero withServicerDate:self.model.date];
- _calendarView.monthView.delegate = self;
- _calendarView.monthView.contentLabel.text = self.dataModel.monthArray.lastObject;
- _calendarView.monthView.titleArray = self.dataModel.monthArray;
- }
- return _calendarView;
- }
- - (HJClockInStatisticDayView *)dayWorkView {
-
- if (_dayWorkView == nil)
- {
- _dayWorkView = [[HJClockInStatisticDayView alloc] init];
- }
- return _dayWorkView;
- }
- @end
|