// // ChatHomeVC.m // smartRhino // // Created by niuzhen on 2020/10/14. // Copyright © 2020 tederen. All rights reserved. // #import "ChatHomeVC.h" #import "GHRefreshCollectionView.h" #import "MyTDGroupView.h" #import "WorkNumberModel.h" #import "ChatMsgCollectionCell.h" #import "YCMenuView.h" #import "ShowNewGroupAlert.h" #import "ChatMsgListVC.h" #import "SWQRCodeViewController.h" #import "ChatNewGroupVC.h" #import "MailListDetailVC.h" #import "ChatJoinGroupVC.h" #import "TDGroupInfoListVC.h" #import "TDQrJoinVC.h" #import "LoginPCVC.h" #import "ChatMsgTopSearchVC.h" #import "TDInterLeterHomeViewController.h" #import "ReplayMeVC.h" #import "ChatTestingVC.h" #import "MailListVC.h" #import "ChatMsgEditVC.h" @interface ChatHomeVC () @property (nonatomic, strong) UILabel *titleL; @property (nonatomic, strong) UIButton *addBtn; @property (nonatomic, strong) UIView *headView; @property (nonatomic, strong) GHRefreshCollectionView *collectionView; @property (assign, nonatomic) NSInteger unReadCount; @property (strong, nonatomic) MyTDGroupView *SearchView; @property (strong, nonatomic) WorkNumberModel *numModel; @property (strong, nonatomic) NSMutableArray *collectionDataSource; @property (strong, nonatomic) NSMutableArray *ImArray; @property (strong, nonatomic) NSMutableArray *taskActionArray; @property (strong, nonatomic) ChatMsgListVC *chatVC; @end @implementation ChatHomeVC - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self getUnreadCount]; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self loadStatusBarColor:[UIColor whiteColor]]; [self.view addSubview:self.titleL]; [self.view addSubview:self.addBtn]; [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.statusBar.mas_bottom); make.left.right.equalTo(self.view); make.height.equalTo(@44); }]; [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.statusBar.mas_bottom); make.right.mas_offset(-10); make.size.mas_offset(CGSizeMake(44, 44)); }]; WS(weakSelf); [self.addBtn setAction:^{ NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray]; YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn]; view.menuColor = RGB(255, 255, 255); view.separatorColor = RGB(234, 234, 234); view.textColor = RGB(102, 102, 102); view.textFont = [UIFont systemFontOfSize:16.0]; view.menuCellHeight = 43.5; view.maxDisplayCount = 10; view.offset = - 6; [view show]; }]; [self addHeadView]; [self setCusPageVC]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moveAction) name:CHATMOVESUCCESS object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PushSettingVC:) name:DRAWERPUSHVC object:nil]; } - (void)PushSettingVC:(NSNotification *)notification { NSInteger index = [[notification.userInfo objectForKey:VCINDEX] integerValue]; if (index == 0) { TDInterLeterHomeViewController *vc = [TDInterLeterHomeViewController initChatMsgNoticeVC]; vc.hidesBottomBarWhenPushed = YES; vc.interLeterFolderId = 0; vc.isHome = YES; [self.navigationController pushViewController:vc animated:NO]; } } - (BOOL)hidesBottomBarWhenPushed { [self.tabBarController.tabBar setHidden:NO]; return NO; } - (void)moveAction { [self.chatVC headRefresh]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)addHeadView { UIView * lineV = [UIView new]; lineV.backgroundColor = UIColorHex(0xEAEAEA); [self.headView addSubview:lineV]; [self.headView addSubview:self.SearchView]; [self.headView addSubview:self.collectionView]; [lineV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(self.headView); make.height.mas_offset(0.5); }]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.bottom.mas_equalTo(lineV.mas_top); make.height.mas_offset(69); }]; [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(5); make.left.right.mas_equalTo(self.headView); make.bottom.mas_equalTo(self.collectionView.mas_top); }]; WS(weakSelf); [self.SearchView.button setAction:^{ ChatMsgTopSearchVC *vc = [[ChatMsgTopSearchVC alloc] init]; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; } -(NSMutableArray *)collectionDataSource{ if(!_collectionDataSource){ _collectionDataSource = [[NSMutableArray alloc] init]; } return _collectionDataSource; } -(NSMutableArray *)ImArray{ if(!_ImArray){ _ImArray = [[NSMutableArray alloc] init]; } return _ImArray; } -(NSMutableArray *)taskActionArray{ if(!_taskActionArray){ _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"建文件夹",@"批量编辑",@"新建群聊",@"扫一扫", nil]; } return _taskActionArray; } - (UILabel *)titleL { if (!_titleL) { _titleL = [UILabel new]; _titleL.text = @"消息"; _titleL.font = [UIFont systemFontOfSize:16.f]; _titleL.textColor = UIColorHex(1A1A1A); _titleL.textAlignment = NSTextAlignmentCenter; } return _titleL; } - (UIButton *)addBtn { if (!_addBtn) { _addBtn = [UIButton new]; [_addBtn setImage:IMG(@"chatmsg_right_add_icon") forState:UIControlStateNormal]; } return _addBtn; } - (UIView *)headView { if (!_headView) { _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115.5)]; _headView.backgroundColor = [UIColor whiteColor]; } return _headView; } - (MyTDGroupView *)SearchView { if (!_SearchView) { _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)]; } return _SearchView; } - (void)setCusPageVC { CGFloat height = SCREEN_HEIGHT - NAVH - self.tabBarController.tabBar.frame.size.height; WS(weakSelf); NSMutableArray * data = [NSMutableArray array]; NSMutableArray * vcArr = [NSMutableArray array]; self.chatVC = [[ChatMsgListVC alloc] init]; [data addObject:@""]; [vcArr addObject:self.chatVC]; WMZPageParam *param = PageParam() .wTitleArrSet(data) .wControllersSet(vcArr) //固定在所有子控制器底部 需要放在第一个控制器里 例如此例子 .wFixFirstSet(YES) //悬浮开启 .wTopSuspensionSet(YES) //等分 .wTopOffsetSet(NAVH) .wFromNaviSet(YES) .wMenuAnimalSet(PageTitleMenuNone) .wMenuTitleFontSet(15.f) .wMenuTitleSelectColorSet(UIColorHex(0x3979D3)) .wMenuIndicatorYSet(0.f) .wMenuIndicatorColorSet(UIColorHex(0x3979D3)) .wMenuTitleColorSet(UIColorHex(0x666666)) .wMenuTitleSelectFontSet(15.f) .wMenuFixShadowSet(NO) .wMenuFixRightDataSet(@" ") .wMenuFixWidthSet(0) .wNoMenuSet(YES) .wScrollCanTransferSet(NO) //头部 .wMenuHeadViewSet(^UIView *{ return self.headView; }); self.param = param; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{ for (UIView * view in weakSelf.view.subviews) { if ([view isKindOfClass:[WMZPageScroller class]]) { [view setFrame:CGRectMake(0, NAVH, SCREEN_WIDTH, height)]; } if ([view isKindOfClass:[UIScrollView class]]) { UIScrollView * sView = (UIScrollView *)view; sView.showsVerticalScrollIndicator = NO; } } }); }); } -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{ NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init]; for(int i=0;i 0 ? [NSString stringWithFormat:@"%ld",(long)count] : nil; [weakSelf initCollectionData:weakSelf.numModel]; }); } failure:^(NSError * _Nonnull error) { }]; } -(void)initCollectionData:(WorkNumberModel *)numModel{ [self.collectionDataSource removeAllObjects]; NSMutableArray * array = [NSMutableArray array]; for (int i= 0;i < 4; i++) { MoreAppInfoModel *model = [[MoreAppInfoModel alloc] init]; switch (i) { case 0:{ model.title = @"收件箱"; model.imgName = @"chat_shou_icon"; model.notImgName = @"chat_shou_icon"; model.type = ChatMenuZhanXinType; model.readNum = numModel.FlowAuditUReadCount + numModel.FlowSendUReadCount + numModel.FlowCcUReadCount + numModel.noticeCount + numModel.missiveCount; model.showEditFlag = YES; }break; case 1:{ model.title = @"回复我的"; model.imgName = @"chat_replay_icon"; model.notImgName = @"chat_replay_icon"; model.type = ChatMenuReplayType; model.readNum = 0; model.showEditFlag = YES; }break; case 2:{ model.title = @"验证消息"; model.imgName = @"chat_verify_icon"; model.notImgName = @"chat_verify_icon"; model.type = ChatMenuVerifyType; model.readNum = 0; model.showEditFlag = YES; }break; default:{ model.title = @"通讯录"; model.imgName = @"chat_maillist_icon"; model.notImgName = @"chat_maillist_icon"; model.type = ChatMenuTeleListType; model.readNum = 0; model.showEditFlag = YES; }break; } [array addObject:model]; } self.collectionDataSource = array; [self.collectionView reloadData]; } #pragma mark -UICollectionViewDataSource /**********************************************************************/ - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.collectionDataSource.count; } - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item]; ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath]; cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName]; cell.cell0TitleLabel.text = bean.title; cell.imagH.constant = 25.f; cell.imagW.constant = 25.f; switch (bean.type) { case ChatMenuNoticeType: { NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum]; cell.cell0ReadNumLabel.text = count; cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; case ChatMenuZhanXinType: { NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum]; cell.cell0ReadNumLabel.text = count; cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; case ChatMenuWaitType: { NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum]; cell.cell0ReadNumLabel.text = count; cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES; UILabel * label = [UILabel new]; label.font = [UIFont systemFontOfSize:12]; label.text = count; CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width; if ((width + 5) < 16) { cell.constant.constant = 16; }else{ cell.constant.constant = width + 8; } } break; default: { NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum]; cell.cell0ReadNumLabel.text = count; cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES; } break; } cell.cell0MengCengView.hidden = YES; return cell; } /****************************************************/ #pragma mark --UICollectionViewDelegateFlowLayout /****************************************************/ - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count; CGFloat height = 69; return CGSizeMake(width, height); } -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { CGFloat W = 10; return UIEdgeInsetsMake(0,W,0,W); } - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ return 0; } - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{ return 0; } - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [collectionView deselectItemAtIndexPath:indexPath animated:YES]; MoreAppInfoModel * model = [self.collectionDataSource objectAtIndex:indexPath.item]; switch (model.type) { case ChatMenuZhanXinType:{ TDInterLeterHomeViewController *vc = [TDInterLeterHomeViewController initChatMsgNoticeVC]; vc.hidesBottomBarWhenPushed = YES; vc.interLeterFolderId = 0; vc.isHome = YES; [self.navigationController pushViewController:vc animated:YES]; }break; case ChatMenuReplayType:{ ReplayMeVC *vc = [ReplayMeVC initReplayMeVC]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }break; case ChatMenuVerifyType:{ ChatTestingVC *vc = [ChatTestingVC initChatTestingVC]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }break; case ChatMenuTeleListType:{ MailListVC * vc = [MailListVC initMailListVC]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }break; default: break; } } #pragma mark - buttonAction - (void)scanAction{ SWQRCodeConfig *config = [[SWQRCodeConfig alloc]init]; config.scannerType = SWScannerTypeBoth; SWQRCodeViewController *qrcodeVC = [[SWQRCodeViewController alloc]init]; qrcodeVC.codeConfig = config; qrcodeVC.delegate = self; qrcodeVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:qrcodeVC animated:YES]; } #pragma mark - 扫一扫结果 - (void)scanResult:(NSString *)scanStr{ ScanResultModel *model = [[ScanResultModel alloc]initWithString:scanStr error:nil]; NSLog(@"%@",model); WEAKSELF switch (model.key) { case 1:// 用户 { [self scanNetWork:model.value urlStrong:SaoYiSao_Post ScanKey:@"Guid" success:^(id responseObject) { NSDictionary *dic = responseObject; AddressUserModel *model = [[AddressUserModel alloc] initWithDictionary:dic error:nil]; dispatch_async(dispatch_get_main_queue(), ^{ MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC]; vc.indexId = model.Id; vc.isAdd = YES; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; }); } failure:^(NSError *error) { SHOWERROR([ZYCTool handerResultData:error]); }]; } break; case 2:// 群聊 { [self scanToNetWork:model.value urlStrong:SaoYiSao2_Post success:^(id responseObject) { ChatJoinGroupVC * vc = [ChatJoinGroupVC initChatJoinGroupVC]; vc.dict = responseObject; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; } failure:^(NSError *error) { SHOWERROR([ZYCTool handerResultData:error]); }]; } break; case 3://小组 { [self scanToNetWork:model.value urlStrong:SaoYiSao3_Post success:^(id responseObject) { if ([responseObject[@"IsUser"] boolValue]) { TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.GroupId = [responseObject[@"Id"] integerValue]; vc.titleStr = responseObject[@"Name"]; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; }else{ dispatch_async(dispatch_get_main_queue(), ^{ TDQrJoinVC * vc = [TDQrJoinVC initTDQrJoinVC]; vc.dict = responseObject; vc.hidesBottomBarWhenPushed = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; }); } } failure:^(NSError *error) { SHOWERROR([ZYCTool handerResultData:error]); }]; } break; case 4://扫码登录 { LoginPCVC * vc = [LoginPCVC initLoginPCVC]; vc.key = model.value; vc.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:vc animated:YES completion:^{ }]; } break; default: break; } } - (void)scanNetWork:(NSString *)scanStr urlStrong:(NSString *)urlstring ScanKey:(NSString*)key success:(void (^) (id responseObject))successful failure:(void (^) (NSError *error))failure{ SHOWLOADING [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,urlstring] parameters:@{key:scanStr} responseStyle:JOSN success:^(id _Nonnull responseObject) { successful(responseObject); REMOVESHOW } failure:^(NSError * _Nonnull error) { REMOVESHOW failure(error); }]; } - (void)scanToNetWork:(NSString *)scanStr urlStrong:(NSString *)urlstring success:(void (^) (id responseObject))successful failure:(void (^) (NSError *error))failure{ SHOWLOADING NSString * url = [NSString stringWithFormat:@"%@%@",Host(urlstring),scanStr]; [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} success:^(id _Nonnull responseObject) { REMOVESHOW successful(responseObject); } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; } @end