// // WorkFlowController.m // smartRhino // // Created by tederen on 2019/10/21. // Copyright © 2019 tederen. All rights reserved. // #import "WorkFlowController.h" #import "WorkFLowModel.h" #import "MyChanelCollectionReusableViewTop.h" #import "FootCollectionReusableView.h" #import "WorkFLowCell.h" #import "MyApprovalPageVC.h" #import "MyWorkWordVC.h" #import "VersionDataVC.h" #import "WorkFlowTabbarController.h" #import "FecordJoinWorkFlowListController.h" #import "MyWorkCarVC.h" #import "CountDataVC.h" @interface WorkFlowController () @property (nonatomic, strong) UILabel *titleLabel; @property (strong, nonatomic) UICollectionView *collectionView; /// 协同工作 @property (nonatomic, strong) NSMutableArray *cooperativeWorkArray; /// 数据报表 @property (nonatomic, strong) NSMutableArray *dataReportArray; @property (nonatomic, strong) WorkNumberModel *numberDic; @property (nonatomic,assign) NSInteger loadFlag; @end @implementation WorkFlowController - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self getData]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.fd_prefersNavigationBarHidden = YES; [self loadStatusBarColor:[UIColor whiteColor]]; self.view.backgroundColor = UIColorHex(F7F7F7); [self.view addSubview:self.titleLabel]; [self createCollectionView]; [self layoutSubviews]; SHOWLOADING self.loadFlag = 1; } - (BOOL)hidesBottomBarWhenPushed { return NO; } #pragma mark - 数据加载 - (void)getData{ [self.cooperativeWorkArray removeAllObjects]; [self.dataReportArray removeAllObjects]; [self testData]; self.loadFlag = 1; [[HttpManager sharedHttpManager] GETUrl: [NSString stringWithFormat:@"%@%@",BaseUrl,WorkFlowHomeData_Post]parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSArray *array = responseObject; NSMutableArray *arr = [NSMutableArray array]; for (NSDictionary *dic in array) { WorkFLowModel *mode = [[WorkFLowModel alloc] initWithDictionary:dic error:nil]; [self.cooperativeWorkArray addObject:mode]; } [self.cooperativeWorkArray addObjectsFromArray:arr]; self.loadFlag += 1; if (self.loadFlag == 4) { REMOVESHOW [self.collectionView reloadData]; } } failure:^(NSError * _Nonnull error) { }]; //获取我审批和我发起以及抄送我的未读数 [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/user/user-uread-count"] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSDictionary *dic = responseObject; self.numberDic = [[WorkNumberModel alloc] initWithDictionary:dic error:nil]; self.navigationController.tabBarItem.badgeValue = [self.numberDic allNumber]; /// 我的审批未读数 self.cooperativeWorkArray.firstObject.workNumber = [dic[@"FlowAuditUReadCount"] integerValue]; for (WorkFLowModel *model in self.cooperativeWorkArray) { if ([model.Name isEqualToString:@"我发起的"]) { model.workNumber = [dic[@"FlowSendUReadCount"] integerValue]; } if ([model.Name isEqualToString:@"抄送我的"]) { model.workNumber = [dic[@"FlowCcUReadCount"] integerValue]; } } self.loadFlag += 1; if (self.loadFlag == 4) { REMOVESHOW [self.collectionView reloadData]; } } failure:^(NSError * _Nonnull error) { }]; [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,WorkFlowHomeData2_Post] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSArray *array = responseObject; NSLog(@"%@",responseObject); for (NSDictionary *dic in array) { WorkFLowModel *mode = [[WorkFLowModel alloc]initWithDictionary:dic error:nil]; [self.dataReportArray addObject:mode]; } self.loadFlag += 1; if (self.loadFlag == 4) { REMOVESHOW [self.collectionView reloadData]; } } failure:^(NSError * _Nonnull error) { }]; } - (void)testData{ WorkFLowModel *mode1 = [[WorkFLowModel alloc] init]; mode1.Name = @"我的审批"; mode1.iconImage = IMG(@"work_flow_approvalme"); mode1.workNumber = 0; [self.cooperativeWorkArray addObject:mode1]; WorkFLowModel *mode2 = [[WorkFLowModel alloc] init]; mode2.Name = @"我发起的"; mode2.iconImage = IMG(@"work_flow_fromme"); mode2.workNumber = 0; [self.cooperativeWorkArray addObject:mode2]; WorkFLowModel *mode3 = [[WorkFLowModel alloc] init]; mode3.Name = @"抄送我的"; mode3.iconImage = IMG(@"work_flow_forme"); mode3.workNumber = 0; [self.cooperativeWorkArray addObject:mode3]; // // WorkFLowModel *mode13 = [[WorkFLowModel alloc] init]; // mode13.Name = @"财务数据"; // mode13.iconImage = IMG(@"work_flow_money_data"); // mode13.workNumber = 0; // [self.dataReportArray addObject:mode13]; // // WorkFLowModel *mode14 = [[WorkFLowModel alloc] init]; // mode14.Name = @"出版数据"; // mode14.iconImage = IMG(@"work_flow_version_data"); // mode14.workNumber = 0; // [self.dataReportArray addObject:mode14]; // // WorkFLowModel *mode15 = [[WorkFLowModel alloc] init]; // mode15.Name = @"人事数据"; // mode15.iconImage = IMG(@"work_flow_hr_data"); // mode15.workNumber = 0; // [self.dataReportArray addObject:mode15]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 2; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (section == 0) { return self.cooperativeWorkArray.count; }else{ return self.dataReportArray.count; } } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if (kind == UICollectionElementKindSectionFooter){ FootCollectionReusableView *footerView = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FootCollectionReusableView" forIndexPath:indexPath]; return footerView; }else{ MyChanelCollectionReusableViewTop *headerView = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyChanelCollectionReusableViewTop" forIndexPath:indexPath]; headerView.bottomLineView.hidden = NO; if (indexPath.section == 0) { headerView.labelTitle.text = @"协同办公"; headerView.left.constant = 15.f; headerView.labelTitle.font = [UIFont systemFontOfSize:15.f]; headerView.labelDetail.text = @""; }else{ headerView.labelTitle.text = @"数据报表"; headerView.left.constant = 15.f; headerView.labelTitle.font = [UIFont systemFontOfSize:15.f]; headerView.labelDetail.text = @""; } return headerView; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(kGXScreenWidth-14, 39); } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ return CGSizeMake(kGXScreenWidth-14, 20); } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake((kGXScreenWidth -14)/3 ,(kGXScreenWidth -14)/3); } -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0, 0, 0, 0); } //func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { // return UIEdgeInsetsZero //} // // func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { // return 1 //} // //func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { // return 5 //} - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { WorkFLowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WorkFLowCellID" forIndexPath:indexPath]; WorkFLowModel *model = (indexPath.section == 0) ? self.cooperativeWorkArray[indexPath.item]:self.dataReportArray[indexPath.item]; if (model.workNumber > 0) { NSString * count = [NSString stringWithFormat:@"%ld",(long)model.workNumber]; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; cell.workNumberLab.layer.cornerRadius = 8; cell.workNumberLab.layer.masksToBounds = YES; if ((width + 5) < 16) { cell.width.constant = 16; }else{ cell.width.constant = width + 8; } cell.workNumberLab.text = count; } if (model.workNumber == 0 ) { cell.workNumberLab.hidden = YES; cell.workNumberLab.layer.cornerRadius = 10; cell.workNumberLab.layer.masksToBounds = YES; }else{ cell.workNumberLab.hidden = NO; } cell.titleLabel.text = model.Name; if (indexPath.item == 0 || indexPath.item == 1 || indexPath.item == 2) { cell.iconImageView.image = model.iconImage; }else{ [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.IconUrl] placeholder:IMG(@"work_flow_approvalme")]; } cell.leftLine.hidden = NO; cell.rightLine.hidden = NO; cell.bottomLine.hidden= NO; cell.topLine.hidden = NO; if (indexPath.section == 1) { cell.titleLabel.text = model.Title; [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.IocUrl] placeholder:IMG(@"work_flow_approvalme")]; } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ WorkFLowModel *model = (indexPath.section == 0) ? self.cooperativeWorkArray[indexPath.item]:self.dataReportArray[indexPath.item]; if (indexPath.section == 0) { if (indexPath.item == 0 || indexPath.item == 1 || indexPath.item == 2) { MyApprovalPageVC *myApprovalPageVC = [[MyApprovalPageVC alloc]init]; myApprovalPageVC.title = model.Name; if (indexPath.item == 0) { myApprovalPageVC.pageType = Type_ONEA; } if (indexPath.item == 1) { myApprovalPageVC.pageType = Type_ONEB; } if (indexPath.item == 2) { myApprovalPageVC.pageType = Type_ONEC; } myApprovalPageVC.numberDic = self.numberDic; [self.navigationController pushViewController:myApprovalPageVC animated:YES]; }else{ if ([model.Name isEqualToString:@"会议"]) { [self.navigationController pushViewController:[[WorkFlowTabbarController alloc] init] animated:YES]; // }else if ([model.Name isEqualToString:@"车辆"]){ // MyWorkCarVC *vc = [[MyWorkCarVC alloc]init]; // vc.title = model.Name; // vc.indexID = model.Id; // [self.navigationController pushViewController:vc animated:YES]; } else { MyWorkWordVC *workWordVC = [[MyWorkWordVC alloc]init]; workWordVC.title = model.Name; workWordVC.pageType = Type_GongWen; workWordVC.indexID = model.Id; [self.navigationController pushViewController:workWordVC animated:YES]; } } } if (indexPath.section == 1) { WorkFLowCell *cell = (WorkFLowCell *)[collectionView cellForItemAtIndexPath:indexPath]; if ([cell.titleLabel.text isEqualToString:@"财务统计"]) { CountDataVC *vc = [CountDataVC initCountDataVC]; vc.index = 0; vc.titleStr = @"财务统计"; [self.navigationController pushViewController:vc animated:YES]; } if ([cell.titleLabel.text isEqualToString:@"人事统计"]) { CountDataVC *vc = [CountDataVC initCountDataVC]; vc.index = 1; vc.titleStr = @"人事统计"; [self.navigationController pushViewController:vc animated:YES]; } if ([cell.titleLabel.text isEqualToString:@"出版统计"]) { CountDataVC *vc = [CountDataVC initCountDataVC]; vc.index = 2; vc.titleStr = @"出版统计"; [self.navigationController pushViewController:vc animated:YES]; } // WorkFLowCell *cell = (WorkFLowCell *)[collectionView cellForItemAtIndexPath:indexPath]; // if ([cell.titleLabel.text isEqualToString:@"财务统计"]) { // VersionDataVC *vc = [VersionDataVC initVersionDataVC]; // vc.pageType = 1; // [self.navigationController pushViewController:vc animated:YES]; // } // if ([cell.titleLabel.text isEqualToString:@"人事统计"]) { // VersionDataVC *vc = [VersionDataVC initVersionData3VC]; // vc.pageType = 3; // [self.navigationController pushViewController:vc animated:YES]; // } // if ([cell.titleLabel.text isEqualToString:@"出版统计"]) { // VersionDataVC *vc = [VersionDataVC initVersionData2VC]; // vc.pageType = 2; // [self.navigationController pushViewController:vc animated:YES]; // } } } #pragma mark - Setter - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [UILabel new]; _titleLabel.backgroundColor = [UIColor whiteColor]; _titleLabel.text = @"工作应用"; _titleLabel.font = [UIFont systemFontOfSize:16.f]; _titleLabel.textColor = UIColorHex(1A1A1A); _titleLabel.textAlignment = NSTextAlignmentCenter; } return _titleLabel; } - (NSMutableArray *)cooperativeWorkArray{ if (!_cooperativeWorkArray) { _cooperativeWorkArray = [NSMutableArray new]; } return _cooperativeWorkArray; } - (NSMutableArray *)dataReportArray{ if (!_dataReportArray) { _dataReportArray = [NSMutableArray new]; } return _dataReportArray; } - (void)createCollectionView { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 0; layout.minimumInteritemSpacing = 0; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; self.collectionView.dataSource = self; self.collectionView.delegate = self; self.collectionView.layer.cornerRadius = 2; self.collectionView.layer.masksToBounds = YES; self.collectionView.backgroundColor = UIColorHex(F7F7F7); [self.collectionView registerNib:[UINib nibWithNibName:@"WorkFLowCell" bundle:nil] forCellWithReuseIdentifier:@"WorkFLowCellID"]; [self.collectionView registerNib:[UINib nibWithNibName:@"MyChanelCollectionReusableViewTop" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyChanelCollectionReusableViewTop"]; [self.collectionView registerNib:[UINib nibWithNibName:@"FootCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FootCollectionReusableView"]; self.collectionView.backgroundColor = [UIColor whiteColor]; // UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]; // [self.collectionView addGestureRecognizer:longPressGesture]; [self.collectionView setShowsVerticalScrollIndicator:NO]; [self.collectionView setShowsHorizontalScrollIndicator:NO]; [self.view addSubview:self.collectionView]; self.collectionView.backgroundColor = UIColorHex(F7F7F7); } #pragma mark - 布局 -(void)layoutSubviews{ [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.statusBar.mas_bottom); make.left.right.equalTo(self.view); make.height.equalTo(@44); }]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_offset(7); make.right.mas_offset(-7); make.top.mas_equalTo(self.titleLabel.mas_bottom); if (@available(iOS 11.0, *)) { make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom); } else { make.bottom.equalTo(self.view.mas_bottom); } }]; } @end