// // HJClockInStatisticsDetailViewController.m // HappyJob // // Created by 张晓光 on 2020/8/25. // Copyright © 2020 Bob. All rights reserved. // #import "HJClockInStatisticDetailViewController.h" #import "HJClockInStatisticDetailInfoView.h" #import "HJClockInStatisticDetailMonthView.h" #import "HJClockInStatisticDetailWeekView.h" #import "HJGetUserInfoAPIManager.h"//用户信息接口 #import "HJClockInStatisticMonthAPI.h" #import "HJClockInStatisticWeekAPI.h" #import "HJClockInDataBox.h" #import "HJClockInInfoModel.h" #import "HJClockInStatisticDataModel.h" @interface HJClockInStatisticDetailViewController () < HJClockInStatisticDetailTitleViewDelegate, FBScrollLayoutViewDelegate, FBAPIManagerInterceptor, FBAPIManagerDelegate > @property (nonatomic, strong) FBScrollLayoutView *scrollLayoutView; @property (nonatomic, strong) HJClockInStatisticDetailInfoView *infoView; @property (nonatomic, strong) HJClockInStatisticDetailMonthView *monthView; @property (nonatomic, strong) HJClockInStatisticDetailWeekView *weekView; @property (nonatomic, strong) HJClockInStatisticDataModel *dataModel; @property (nonatomic, strong) HJGetUserInfoAPIManager *userInfoAPI; @property (nonatomic, strong) HJClockInStatisticMonthAPI *monthAPI; @property (nonatomic, strong) HJClockInStatisticWeekAPI *weekAPI; @property (nonatomic, strong) HJClockInDataBox *dataBox; @end @implementation HJClockInStatisticDetailViewController #pragma mark - life cycle - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; [self hj_setupNavBar]; self.navigationItem.title = @"统计"; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navi_delete"] style:UIBarButtonItemStyleDone target:self action:@selector(exitClick)]; [self makeConstraintsViews]; [self.userInfoAPI start]; self.monthAPI.month_type = @"1"; [self.monthAPI start]; self.weekAPI.week_type = @"1"; [self.weekAPI start]; } - (void)makeConstraintsViews { self.view.backgroundColor = COLOR_F5F5F5; [self.view addSubview:self.scrollLayoutView]; [self.scrollLayoutView.contentView addSubview:self.infoView]; [self.scrollLayoutView.contentView addSubview:self.monthView]; [self.scrollLayoutView.contentView addSubview:self.weekView]; [self.scrollLayoutView makeConstraints]; } #pragma mark - event - (void)exitClick{ [self.navigationController popToRootViewControllerAnimated:YES]; } #pragma mark - FBScrollLayoutViewDelegate - (void)scrollLayoutViewMakeConstraints:(FBScrollLayoutView *)scrollLayoutView { [scrollLayoutView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.equalTo(self.view).offset(0); }]; } - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView contentView:(UIView *)contentView { [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(contentView).offset(10); make.left.right.equalTo(contentView); }]; [self.monthView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.infoView.mas_bottom).offset(10); make.left.right.equalTo(contentView); }]; [self.weekView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.monthView.mas_bottom).offset(10); make.left.right.equalTo(contentView); }]; [contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.weekView.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.userInfoAPI) { NSDictionary *dataDict = [manager fetchDataWithBox:self.dataBox]; HJClockInInfoModel *userModel = [HJClockInInfoModel yy_modelWithDictionary:dataDict[@"hpUser"]]; HJClockInInfoModel *memberModel = [HJClockInInfoModel yy_modelWithDictionary:dataDict[@"hpMember"]]; [self.infoView.headerIcon sd_setImageWithURL:[NSURL URLWithString:userModel.headImgUrl] placeholderImage:[UIImage imageNamed:@"me_portrait_default"]]; self.infoView.nameLabel.text = memberModel.realName; if (memberModel.authenticationStatus == 1) {//认证中 self.infoView.icon.image = [UIImage imageNamed:@"clockin_anth_audit"]; self.infoView.tagLabel.text = @"认证信息审核中"; self.infoView.tagLabel.textColor = COLOR_999999; } else {//认证成功 self.infoView.icon.image = [UIImage imageNamed:@"clockIn_auth_icon"]; self.infoView.tagLabel.text = @"开心工作认证用户"; self.infoView.tagLabel.textColor = COLOR_0177FF; } } if (manager == self.monthAPI) { NSDictionary *dataDict = [manager fetchDataWithBox:self.dataBox]; HJClockInInfoModel *model = [HJClockInInfoModel yy_modelWithDictionary:dataDict[@"currentSettlement"]]; // self.monthView.monthTotalAdvanceView.contentLabel.text = [NSString stringWithFormat:@"%@元",model.nextMoney ? [NSString stringWithFormat:@"%.2lf",[model.nextMoney floatValue]] : @"0"]; self.monthView.monthTotalWorkeHourView.contentLabel.text = [NSString stringWithFormat:@"%@小时",model.countDuration ? model.countDuration :@"0"]; self.monthView.monthClickInDaysView.contentLabel.text = [NSString stringWithFormat:@"%@次",model.attendance ? model.attendance :@"0"]; self.monthView.monthNoPunchInView.contentLabel.text = [NSString stringWithFormat:@"%@次",model.lackClock ? model.lackClock :@"0"]; if ([self.monthAPI.month_type isEqualToString:@"1"]) { [self.monthView.monthView rightButtonAction]; } else { [self.monthView.monthView leftButtonAction]; } } if (manager == self.weekAPI) { NSDictionary *dataDict = [manager fetchDataWithBox:self.dataBox]; HJClockInInfoModel *model = [HJClockInInfoModel yy_modelWithDictionary:dataDict[@"currentSettlement"]]; // self.weekView.weekTotalAdvanceView.contentLabel.text = [NSString stringWithFormat:@"%@元",model.nextMoney ? [NSString stringWithFormat:@"%.2lf",[model.nextMoney floatValue]] :@"0"]; self.weekView.weekTotalWorkeHourView.contentLabel.text = [NSString stringWithFormat:@"%@小时",model.countDuration ? model.countDuration :@"0"]; self.weekView.weekClockInDaysView.contentLabel.text = [NSString stringWithFormat:@"%@次",model.attendance ? model.attendance : @"0"]; self.weekView.weekNoPunchInView.contentLabel.text = [NSString stringWithFormat:@"%@次",model.lackClock ? model.lackClock :@"0"]; if ([self.weekAPI.week_type isEqualToString:@"1"]) { [self.weekView.weekView rightButtonAction]; } else { [self.weekView.weekView leftButtonAction]; } } } - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager { id fetchData = [manager fetchDataWithBox:self.dataBox]; if ([fetchData isKindOfClass:[NSString class]]) { [self.view fb_showFailureWithStatus:fetchData]; } } #pragma mark - HJClockInStatisticDetailTitleViewDelegate /* 上月,上周 */ - (void)leftButtonActionDelegate:(NSInteger)tag { if (tag == 1) {//上月 self.monthAPI.month_type = @"2"; [self.monthAPI start]; } else {//上周 self.weekAPI.week_type = @"2"; [self.weekAPI start]; } } /* 本月,本周 */ - (void)rightButtonActionDelegate:(NSInteger)tag { if (tag == 2) {//本月 self.monthAPI.month_type = @"1"; [self.monthAPI start]; } else {//本周 self.weekAPI.week_type = @"1"; [self.weekAPI start]; } } #pragma mark - lazy - (HJGetUserInfoAPIManager *)userInfoAPI { if (_userInfoAPI == nil) { _userInfoAPI = [[HJGetUserInfoAPIManager alloc]init]; _userInfoAPI.APIManagerDelegate = self; _userInfoAPI.APIManagerInterceptor = self; } return _userInfoAPI; } - (HJClockInStatisticMonthAPI *)monthAPI { if (_monthAPI == nil) { _monthAPI = [[HJClockInStatisticMonthAPI alloc]init]; _monthAPI.APIManagerDelegate = self; _monthAPI.APIManagerInterceptor = self; } return _monthAPI; } - (HJClockInStatisticWeekAPI *)weekAPI { if (_weekAPI == nil) { _weekAPI = [[HJClockInStatisticWeekAPI alloc]init]; _weekAPI.APIManagerDelegate = self; _weekAPI.APIManagerInterceptor = self; } return _weekAPI; } - (HJClockInDataBox *)dataBox { if (_dataBox == nil) { _dataBox = [[HJClockInDataBox alloc] init]; } return _dataBox; } - (FBScrollLayoutView *)scrollLayoutView { if (_scrollLayoutView == nil) { _scrollLayoutView = [[FBScrollLayoutView alloc] init]; _scrollLayoutView.delegate = self; _scrollLayoutView.backgroundColor = COLOR_F5F5F5; _scrollLayoutView.contentView.backgroundColor = COLOR_F5F5F5; _scrollLayoutView.scrollView.showsVerticalScrollIndicator = NO; } return _scrollLayoutView; } - (HJClockInStatisticDetailInfoView *)infoView { if (_infoView == nil) { _infoView = [[HJClockInStatisticDetailInfoView alloc]init]; } return _infoView; } - (HJClockInStatisticDataModel *)dataModel { if (_dataModel == nil) { _dataModel = [[HJClockInStatisticDataModel alloc] initWithServicerDate:self.servicerDate]; } return _dataModel; } - (HJClockInStatisticDetailMonthView *)monthView { if (_monthView == nil) { _monthView = [[HJClockInStatisticDetailMonthView alloc]init]; _monthView.monthView.contentLabel.text = self.dataModel.yearsArray.lastObject; _monthView.monthView.titleArray = self.dataModel.yearsArray; _monthView.monthView.delegate = self; _monthView.monthView.leftBtn.tag = 1; _monthView.monthView.rightBtn.tag = 2; } return _monthView; } - (HJClockInStatisticDetailWeekView *)weekView { if (_weekView == nil) { _weekView = [[HJClockInStatisticDetailWeekView alloc]init]; _weekView.weekView.contentLabel.text = @"本周"; _weekView.weekView.titleArray = @[@"上周",@"本周"]; _weekView.weekView.delegate = self; _weekView.weekView.leftBtn.tag = 3; _weekView.weekView.rightBtn.tag = 4; } return _weekView; } @end