// // CommonToolVC.m // smartRhino // // Created by niuzhen on 2020/4/28. // Copyright © 2020 tederen. All rights reserved. // #import "CommonToolVC.h" #import "WorkFLowModel.h" #import "WorkFLowCell.h" #import "myApprovalPageVC.h" #import "WorkFlowTabbarController.h" #import "MyWorkWordVC.h" #import "CountDataVC.h" #import "CommonToolMoveVC.h" @interface CommonToolVC () @property (weak, nonatomic) IBOutlet UIButton *setBtn; @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; /// 协同工作 @property (nonatomic, strong) NSMutableArray *cooperativeWorkArray; /// 数据报表 @property (nonatomic, strong) NSMutableArray *dataReportArray; @property (nonatomic, strong) WorkNumberModel *numberDic; @property (nonatomic,assign) NSInteger loadFlag; @end @implementation CommonToolVC +(CommonToolVC *)initCommonToolVC{ CommonToolVC *controller = [StoryboardManager.shared.Common instantiateViewControllerWithIdentifier:@"CommonToolVC"]; return controller; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self.view setBackgroundColor:UIColorHex(0xf7f7f7)]; [self createCollectionView]; WS(weakSelf); [self.setBtn setAction:^{ CommonToolMoveVC * vc = [CommonToolMoveVC initCommonToolMoveVC]; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [self.collectionView reloadData]; } #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 == 3) { 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 == 3) { 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 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return 15; } //- (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.workNumberLab.hidden = YES; cell.titleLabel.text = [NSString stringWithFormat:@"工具%ld",indexPath.row + 1]; cell.iconImageView.image = IMG(@"img_placeHolder"); cell.leftLine.hidden = NO; cell.rightLine.hidden = NO; cell.bottomLine.hidden= NO; cell.topLine.hidden = NO; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [collectionView deselectItemAtIndexPath:indexPath animated:YES]; // 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 { // // MyWorkWordVC *workWordVC = [[MyWorkWordVC alloc]init]; // // workWordVC.title = model.Name; // // workWordVC.pageType = Type_GongWen; // // workWordVC.indexID = model.Id; // // [self.navigationController pushViewController:workWordVC animated:YES]; // // } // // } // if ([model.Name isEqualToString:@"会议"]) { // [self.navigationController pushViewController:[[WorkFlowTabbarController alloc] init] 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 - (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 setCollectionViewLayout: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]; [self.collectionView setShowsVerticalScrollIndicator:NO]; [self.collectionView setShowsHorizontalScrollIndicator:NO]; [self.view addSubview:self.collectionView]; self.collectionView.backgroundColor = UIColorHex(F7F7F7); } @end