HJClockInStatisticViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //
  2. // HJClockInStatisticsViewController.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2020/8/25.
  6. // Copyright © 2020 Bob. All rights reserved.
  7. //
  8. #import "HJClockInStatisticViewController.h"
  9. #import "HJClockInNaviView.h"
  10. #import "HJClockInStatisticCollectView.h"
  11. #import "HJClockInStatisticCalendarView.h"
  12. #import "HJClockInStatisticDayView.h"
  13. #import "HJClockInStatisticDetailViewController.h"
  14. #import "HJClockInStatisticCurrentMonthAPI.h"
  15. #import "HJClockInStatisticCollectAPI.h"
  16. #import "HJClockInStatisticDayAPI.h"
  17. #import "HJClockInDataBox.h"
  18. #import "HJClockInInfoModel.h"
  19. #import "HJClockInStatisticDataModel.h"
  20. @interface HJClockInStatisticViewController ()
  21. <
  22. HJClockInStatisticDetailTitleViewDelegate,
  23. FBScrollLayoutViewDelegate,
  24. FBAPIManagerInterceptor,
  25. FBAPIManagerDelegate,
  26. UIGestureRecognizerDelegate
  27. >
  28. @property (nonatomic, strong) FBScrollLayoutView *scrollLayoutView;
  29. @property (nonatomic, strong) HJClockInNaviView *naviView;
  30. @property (nonatomic, strong) HJClockInStatisticCollectView *collectView;//UICollectionView
  31. @property (nonatomic, strong) HJClockInStatisticCalendarView *calendarView;
  32. @property (nonatomic, strong) HJClockInStatisticDayView *dayWorkView;
  33. @property (nonatomic, strong) HJClockInStatisticDataModel *dataModel;
  34. @property (nonatomic, strong) HJClockInStatisticCurrentMonthAPI *currentMonthAPI;
  35. @property (nonatomic, strong) HJClockInStatisticCollectAPI *collectAPI;
  36. @property (nonatomic, strong) HJClockInStatisticDayAPI *dayAPI;
  37. @property (nonatomic, strong) HJClockInDataBox *dataBox;
  38. @property (nonatomic, strong) HJClockInInfoModel *model;
  39. @end
  40. @implementation HJClockInStatisticViewController
  41. #pragma mark - life cycle
  42. - (void)viewWillAppear:(BOOL)animated {
  43. [super viewWillAppear:animated];
  44. [self.navigationController setNavigationBarHidden:YES animated:animated];
  45. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. self.view.backgroundColor = COLOR_F5F5F5;
  50. [self makeConstraintsNaviViews];
  51. [self.currentMonthAPI start];
  52. }
  53. - (void)makeConstraintsNaviViews {
  54. [self.view addSubview:self.naviView];
  55. [self.naviView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.top.right.equalTo(self.view).offset(0);
  57. }];
  58. }
  59. - (void)makeConstraintsViews {
  60. [self.view addSubview:self.scrollLayoutView];
  61. [self.scrollLayoutView.contentView addSubview:self.collectView];
  62. [self.scrollLayoutView.contentView addSubview:self.calendarView];
  63. [self.scrollLayoutView.contentView addSubview:self.dayWorkView];
  64. [self.scrollLayoutView makeConstraints];
  65. __weak typeof(self) weakSelf = self;
  66. self.calendarView.selectDayDateBlock = ^(NSString * _Nonnull day) {
  67. weakSelf.dayAPI.search_date = day;
  68. [weakSelf.dayAPI start];
  69. };
  70. }
  71. #pragma mark - FBScrollLayoutViewDelegate
  72. - (void)scrollLayoutViewMakeConstraints:(FBScrollLayoutView *)scrollLayoutView {
  73. [scrollLayoutView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(self.naviView.mas_bottom).offset(0);
  75. make.left.right.bottom.equalTo(self.view).offset(0);
  76. }];
  77. }
  78. - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView contentView:(UIView *)contentView {
  79. [self.collectView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.left.right.equalTo(contentView);
  81. }];
  82. [self.calendarView mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.top.equalTo(self.collectView.mas_bottom).offset(0);
  84. make.left.right.equalTo(contentView);
  85. }];
  86. [self.dayWorkView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.top.equalTo(self.calendarView.mas_bottom).offset(0);
  88. make.left.right.equalTo(contentView);
  89. }];
  90. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.bottom.equalTo(self.dayWorkView.mas_bottom).offset(0);
  92. }];
  93. }
  94. #pragma mark - FBAPIManagerInterceptor
  95. - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
  96. [self.view fb_showLoading];
  97. return YES;
  98. }
  99. - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
  100. [self.view fb_dismiss];
  101. }
  102. #pragma mark - FBAPIManagerDelegate
  103. - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
  104. if (manager == self.currentMonthAPI)
  105. {
  106. NSDictionary *dataDict = [manager fetchDataWithBox:self.dataBox];
  107. self.model = [HJClockInInfoModel yy_modelWithDictionary:dataDict[@"currentSettlement"]];
  108. //集合
  109. self.collectAPI.month_type = @"1";
  110. [self.collectAPI start];
  111. //当天的
  112. self.dayAPI.search_date = self.model.date;
  113. [self.dayAPI start];
  114. self.collectView.monthLabel.text = [NSString stringWithFormat:@"%ld月汇总",(long)[self.collectView month:self.model.date]];
  115. self.collectView.moneyLabel.text = self.model.nextMoney ? [NSString stringWithFormat:@"%.2lf",[self.model.nextMoney floatValue]] : @"0";
  116. self.collectView.workeHourLabel.text = self.model.countDuration ? self.model.countDuration : @"0";
  117. self.collectView.numberLabel.text = self.model.lackClock ? self.model.lackClock : @"0";
  118. [self makeConstraintsViews];
  119. }
  120. if (manager == self.collectAPI)
  121. {
  122. self.calendarView.calendarView.viewModel.collectArray = [manager fetchDataWithBox:self.dataBox][@"wsPunchClockList"];
  123. if ([self.collectAPI.month_type isEqualToString: @"2"])
  124. {
  125. [self.calendarView.monthView leftButtonAction];
  126. }
  127. else
  128. {
  129. [self.calendarView.monthView rightButtonAction];
  130. }
  131. [self.calendarView.calendarView.collectionView reloadData];
  132. }
  133. if (manager == self.dayAPI)
  134. {
  135. [self.dayWorkView configurationData:[manager fetchDataWithBox:self.dataBox]];
  136. }
  137. }
  138. - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
  139. if (manager == self.currentMonthAPI)
  140. {
  141. [self showErrorView];
  142. }
  143. id fetchData = [manager fetchDataWithBox:self.dataBox];
  144. if ([fetchData isKindOfClass:[NSString class]])
  145. {
  146. [self.view fb_showFailureWithStatus:fetchData];
  147. }
  148. }
  149. /* 显示错误View */
  150. - (void)showErrorView {
  151. [self.view showErrorView];
  152. [self.view.errorView.refreshButton addTarget:self action:@selector(refreshButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  153. [self.view.errorView mas_remakeConstraints:^(MASConstraintMaker *make) {
  154. make.top.equalTo(self.naviView.mas_bottom).offset(0);
  155. make.left.bottom.right.equalTo(self.view).offset(0);
  156. }];
  157. }
  158. #pragma mark - HJClockInStatisticDetailTitleViewDelegate
  159. - (void)leftButtonActionDelegate:(NSInteger)tag {
  160. [self.calendarView lastMonth];
  161. self.collectAPI.month_type = @"2";
  162. [self.collectAPI start];
  163. }
  164. - (void)rightButtonActionDelegate:(NSInteger)tag {
  165. [self.calendarView nextMonth];
  166. self.collectAPI.month_type = @"1";
  167. [self.collectAPI start];
  168. }
  169. #pragma mark - event
  170. - (void)deleteBtnClick:(UIButton *)btn {
  171. [self.navigationController popViewControllerAnimated:YES];
  172. }
  173. - (void)detailClick:(UITapGestureRecognizer *)tap {
  174. HJClockInStatisticDetailViewController *detailVC = [[HJClockInStatisticDetailViewController alloc] init];
  175. detailVC.servicerDate = self.model.date;
  176. [self.navigationController pushViewController:detailVC animated:YES];
  177. }
  178. /* 错误刷新 */
  179. - (void)refreshButtonAction:(UIButton *)btn {
  180. [self.view dismissErrorView];
  181. [self.currentMonthAPI start];
  182. }
  183. #pragma mark - lazy
  184. - (HJClockInDataBox *)dataBox {
  185. if (_dataBox == nil)
  186. {
  187. _dataBox = [[HJClockInDataBox alloc] init];
  188. }
  189. return _dataBox;
  190. }
  191. - (HJClockInStatisticCurrentMonthAPI *)currentMonthAPI {
  192. if (_currentMonthAPI == nil)
  193. {
  194. _currentMonthAPI = [[HJClockInStatisticCurrentMonthAPI alloc]init];
  195. _currentMonthAPI.APIManagerDelegate = self;
  196. _currentMonthAPI.APIManagerInterceptor = self;
  197. }
  198. return _currentMonthAPI;
  199. }
  200. - (HJClockInStatisticCollectAPI *)collectAPI {
  201. if (_collectAPI == nil)
  202. {
  203. _collectAPI = [[HJClockInStatisticCollectAPI alloc]init];
  204. _collectAPI.APIManagerDelegate = self;
  205. _collectAPI.APIManagerInterceptor = self;
  206. }
  207. return _collectAPI;
  208. }
  209. - (HJClockInStatisticDayAPI *)dayAPI {
  210. if (_dayAPI == nil)
  211. {
  212. _dayAPI = [[HJClockInStatisticDayAPI alloc]init];
  213. _dayAPI.APIManagerDelegate = self;
  214. _dayAPI.APIManagerInterceptor = self;
  215. }
  216. return _dayAPI;
  217. }
  218. - (FBScrollLayoutView *)scrollLayoutView {
  219. if (_scrollLayoutView == nil)
  220. {
  221. _scrollLayoutView = [[FBScrollLayoutView alloc] init];
  222. _scrollLayoutView.delegate = self;
  223. _scrollLayoutView.backgroundColor = COLOR_F5F5F5;
  224. _scrollLayoutView.contentView.backgroundColor = COLOR_F5F5F5;
  225. }
  226. return _scrollLayoutView;
  227. }
  228. - (HJClockInNaviView *)naviView {
  229. if (_naviView == nil)
  230. {
  231. _naviView = [[HJClockInNaviView alloc] init];
  232. [_naviView.deleteBtn addTarget:self action:@selector(deleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  233. }
  234. return _naviView;
  235. }
  236. - (HJClockInStatisticCollectView *)collectView {
  237. if (_collectView == nil)
  238. {
  239. _collectView = [[HJClockInStatisticCollectView alloc] init];
  240. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(detailClick:)];
  241. [_collectView addGestureRecognizer:tap];
  242. }
  243. return _collectView;
  244. }
  245. - (HJClockInStatisticDataModel *)dataModel {
  246. if (_dataModel == nil)
  247. {
  248. _dataModel = [[HJClockInStatisticDataModel alloc] initWithServicerDate:self.model.date];
  249. }
  250. return _dataModel;
  251. }
  252. - (HJClockInStatisticCalendarView *)calendarView {
  253. if (_calendarView == nil)
  254. {
  255. _calendarView = [[HJClockInStatisticCalendarView alloc] initWithFrame:CGRectZero withServicerDate:self.model.date];
  256. _calendarView.monthView.delegate = self;
  257. _calendarView.monthView.contentLabel.text = self.dataModel.monthArray.lastObject;
  258. _calendarView.monthView.titleArray = self.dataModel.monthArray;
  259. }
  260. return _calendarView;
  261. }
  262. - (HJClockInStatisticDayView *)dayWorkView {
  263. if (_dayWorkView == nil)
  264. {
  265. _dayWorkView = [[HJClockInStatisticDayView alloc] init];
  266. }
  267. return _dayWorkView;
  268. }
  269. @end