ChatHomeVC.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // ChatHomeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/10/14.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "ChatHomeVC.h"
  9. #import "GHRefreshCollectionView.h"
  10. #import "MyTDGroupView.h"
  11. #import "WorkNumberModel.h"
  12. #import "ChatMsgCollectionCell.h"
  13. #import "YCMenuView.h"
  14. #import "ShowNewGroupAlert.h"
  15. #import "ChatMsgListVC.h"
  16. #import "SWQRCodeViewController.h"
  17. #import "ChatNewGroupVC.h"
  18. #import "MailListDetailVC.h"
  19. #import "ChatJoinGroupVC.h"
  20. #import "TDGroupInfoListVC.h"
  21. #import "TDQrJoinVC.h"
  22. #import "LoginPCVC.h"
  23. #import "ChatMsgTopSearchVC.h"
  24. #import "TDInterLeterHomeViewController.h"
  25. #import "ReplayMeVC.h"
  26. #import "ChatTestingVC.h"
  27. #import "MailListVC.h"
  28. #import "ChatMsgEditVC.h"
  29. @interface ChatHomeVC ()<UICollectionViewDelegate,UICollectionViewDataSource,SWQRCodeViewControllerDelegate>
  30. @property (nonatomic, strong) UILabel *titleL;
  31. @property (nonatomic, strong) UIButton *addBtn;
  32. @property (nonatomic, strong) UIView *headView;
  33. @property (nonatomic, strong) GHRefreshCollectionView *collectionView;
  34. @property (assign, nonatomic) NSInteger unReadCount;
  35. @property (strong, nonatomic) MyTDGroupView *SearchView;
  36. @property (strong, nonatomic) WorkNumberModel *numModel;
  37. @property (strong, nonatomic) NSMutableArray *collectionDataSource;
  38. @property (strong, nonatomic) NSMutableArray *ImArray;
  39. @property (strong, nonatomic) NSMutableArray *taskActionArray;
  40. @property (strong, nonatomic) ChatMsgListVC *chatVC;
  41. @end
  42. @implementation ChatHomeVC
  43. - (void)viewWillAppear:(BOOL)animated
  44. {
  45. [super viewWillAppear:animated];
  46. [self getUnreadCount];
  47. }
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. self.fd_prefersNavigationBarHidden = YES;
  51. [self loadStatusBarColor:[UIColor whiteColor]];
  52. [self.view addSubview:self.titleL];
  53. [self.view addSubview:self.addBtn];
  54. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.equalTo(self.statusBar.mas_bottom);
  56. make.left.right.equalTo(self.view);
  57. make.height.equalTo(@44);
  58. }];
  59. [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.mas_equalTo(self.statusBar.mas_bottom);
  61. make.right.mas_offset(-10);
  62. make.size.mas_offset(CGSizeMake(44, 44));
  63. }];
  64. WS(weakSelf);
  65. [self.addBtn setAction:^{
  66. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
  67. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
  68. view.menuColor = RGB(255, 255, 255);
  69. view.separatorColor = RGB(234, 234, 234);
  70. view.textColor = RGB(102, 102, 102);
  71. view.textFont = [UIFont systemFontOfSize:16.0];
  72. view.menuCellHeight = 43.5;
  73. view.maxDisplayCount = 10;
  74. view.offset = - 6;
  75. [view show];
  76. }];
  77. [self addHeadView];
  78. [self setCusPageVC];
  79. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moveAction) name:CHATMOVESUCCESS object:nil];
  80. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PushSettingVC:) name:DRAWERPUSHVC object:nil];
  81. }
  82. - (void)PushSettingVC:(NSNotification *)notification
  83. {
  84. NSInteger index = [[notification.userInfo objectForKey:VCINDEX] integerValue];
  85. if (index == 0) {
  86. TDInterLeterHomeViewController *vc = [TDInterLeterHomeViewController initChatMsgNoticeVC];
  87. vc.hidesBottomBarWhenPushed = YES;
  88. vc.interLeterFolderId = 0;
  89. vc.isHome = YES;
  90. [self.navigationController pushViewController:vc animated:NO];
  91. }
  92. }
  93. - (BOOL)hidesBottomBarWhenPushed
  94. {
  95. [self.tabBarController.tabBar setHidden:NO];
  96. return NO;
  97. }
  98. - (void)moveAction
  99. {
  100. [self.chatVC headRefresh];
  101. }
  102. - (void)dealloc
  103. {
  104. [[NSNotificationCenter defaultCenter] removeObserver:self];
  105. }
  106. - (void)addHeadView
  107. {
  108. UIView * lineV = [UIView new];
  109. lineV.backgroundColor = UIColorHex(0xEAEAEA);
  110. [self.headView addSubview:lineV];
  111. [self.headView addSubview:self.SearchView];
  112. [self.headView addSubview:self.collectionView];
  113. [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.left.right.bottom.mas_equalTo(self.headView);
  115. make.height.mas_offset(0.5);
  116. }];
  117. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.right.mas_equalTo(self.headView);
  119. make.bottom.mas_equalTo(lineV.mas_top);
  120. make.height.mas_offset(69);
  121. }];
  122. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.top.mas_offset(5);
  124. make.left.right.mas_equalTo(self.headView);
  125. make.bottom.mas_equalTo(self.collectionView.mas_top);
  126. }];
  127. WS(weakSelf);
  128. [self.SearchView.button setAction:^{
  129. ChatMsgTopSearchVC *vc = [[ChatMsgTopSearchVC alloc] init];
  130. vc.hidesBottomBarWhenPushed = YES;
  131. [weakSelf.navigationController pushViewController:vc animated:YES];
  132. }];
  133. }
  134. -(NSMutableArray *)collectionDataSource{
  135. if(!_collectionDataSource){
  136. _collectionDataSource = [[NSMutableArray alloc] init];
  137. }
  138. return _collectionDataSource;
  139. }
  140. -(NSMutableArray *)ImArray{
  141. if(!_ImArray){
  142. _ImArray = [[NSMutableArray alloc] init];
  143. }
  144. return _ImArray;
  145. }
  146. -(NSMutableArray *)taskActionArray{
  147. if(!_taskActionArray){
  148. _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"建文件夹",@"批量编辑",@"新建群聊",@"扫一扫", nil];
  149. }
  150. return _taskActionArray;
  151. }
  152. - (UILabel *)titleL
  153. {
  154. if (!_titleL) {
  155. _titleL = [UILabel new];
  156. _titleL.text = @"消息";
  157. _titleL.font = [UIFont systemFontOfSize:16.f];
  158. _titleL.textColor = UIColorHex(1A1A1A);
  159. _titleL.textAlignment = NSTextAlignmentCenter;
  160. }
  161. return _titleL;
  162. }
  163. - (UIButton *)addBtn
  164. {
  165. if (!_addBtn) {
  166. _addBtn = [UIButton new];
  167. [_addBtn setImage:IMG(@"chatmsg_right_add_icon") forState:UIControlStateNormal];
  168. }
  169. return _addBtn;
  170. }
  171. - (UIView *)headView
  172. {
  173. if (!_headView) {
  174. _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115.5)];
  175. _headView.backgroundColor = [UIColor whiteColor];
  176. }
  177. return _headView;
  178. }
  179. - (MyTDGroupView *)SearchView
  180. {
  181. if (!_SearchView) {
  182. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  183. }
  184. return _SearchView;
  185. }
  186. - (void)setCusPageVC
  187. {
  188. CGFloat height = SCREEN_HEIGHT - NAVH - self.tabBarController.tabBar.frame.size.height;
  189. WS(weakSelf);
  190. NSMutableArray * data = [NSMutableArray array];
  191. NSMutableArray * vcArr = [NSMutableArray array];
  192. self.chatVC = [[ChatMsgListVC alloc] init];
  193. [data addObject:@""];
  194. [vcArr addObject:self.chatVC];
  195. WMZPageParam *param = PageParam()
  196. .wTitleArrSet(data)
  197. .wControllersSet(vcArr)
  198. //固定在所有子控制器底部 需要放在第一个控制器里 例如此例子
  199. .wFixFirstSet(YES)
  200. //悬浮开启
  201. .wTopSuspensionSet(YES)
  202. //等分
  203. .wTopOffsetSet(NAVH)
  204. .wFromNaviSet(YES)
  205. .wMenuAnimalSet(PageTitleMenuNone)
  206. .wMenuTitleFontSet(15.f)
  207. .wMenuTitleSelectColorSet(UIColorHex(0x3979D3))
  208. .wMenuIndicatorYSet(0.f)
  209. .wMenuIndicatorColorSet(UIColorHex(0x3979D3))
  210. .wMenuTitleColorSet(UIColorHex(0x666666))
  211. .wMenuTitleSelectFontSet(15.f)
  212. .wMenuFixShadowSet(NO)
  213. .wMenuFixRightDataSet(@" ")
  214. .wMenuFixWidthSet(0)
  215. .wNoMenuSet(YES)
  216. .wScrollCanTransferSet(NO)
  217. //头部
  218. .wMenuHeadViewSet(^UIView *{
  219. return self.headView;
  220. });
  221. self.param = param;
  222. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  223. dispatch_async(dispatch_get_main_queue(), ^{
  224. for (UIView * view in weakSelf.view.subviews) {
  225. if ([view isKindOfClass:[WMZPageScroller class]]) {
  226. [view setFrame:CGRectMake(0, NAVH, SCREEN_WIDTH, height)];
  227. }
  228. if ([view isKindOfClass:[UIScrollView class]]) {
  229. UIScrollView * sView = (UIScrollView *)view;
  230. sView.showsVerticalScrollIndicator = NO;
  231. }
  232. }
  233. });
  234. });
  235. }
  236. -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{
  237. NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
  238. for(int i=0;i<titleArray.count;i++){
  239. NSString *titleStr = [titleArray objectAtIndex:i];
  240. WS(weakSelf);
  241. YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
  242. if([@"建文件夹" isEqualToString:action.title]){
  243. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"建文件夹" placeholder:@"请输入文件夹名称" confirm:^(NSString * _Nonnull groupName) {
  244. NSLog(@"%@",groupName);
  245. NSDictionary * paraDict = @{@"FolderName":groupName,
  246. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  247. @"ParentId":@(0),
  248. @"TypeId":@(10)
  249. };
  250. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Middle_Add_Folder) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  251. [weakSelf.chatVC headRefresh];
  252. } failure:^(NSError * _Nonnull error) {
  253. NSLog(@"%@",error);
  254. SHOWERROR([ZYCTool handerResultData:error])
  255. }];
  256. } cancle:^{
  257. }] show];
  258. }
  259. else if ([@"批量编辑" isEqualToString:action.title]){
  260. [weakSelf.chatVC pushEditVC];
  261. }
  262. else if ([@"新建群聊" isEqualToString:action.title]){
  263. ChatNewGroupVC *vc = [ChatNewGroupVC initChatNewGroupVC];
  264. vc.upDataBlock = ^{
  265. [weakSelf.chatVC headRefresh];
  266. };
  267. vc.hidesBottomBarWhenPushed = YES;
  268. [weakSelf.navigationController pushViewController:vc animated:YES];
  269. }else if ([@"扫一扫" isEqualToString:action.title]){
  270. [weakSelf scanAction];
  271. }
  272. }];
  273. [menuDataSourceArray addObject:actionMenu];
  274. }
  275. return menuDataSourceArray;
  276. }
  277. - (GHRefreshCollectionView *)collectionView {
  278. if (!_collectionView) {
  279. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  280. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  281. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  282. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  283. _collectionView.delegate = self;
  284. _collectionView.dataSource = self;
  285. _collectionView.showsHorizontalScrollIndicator = NO;
  286. [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"];
  287. _collectionView.backgroundColor = [UIColor whiteColor];
  288. }
  289. return _collectionView;
  290. }
  291. - (void)getUnreadCount
  292. {
  293. WS(weakSelf);
  294. [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_User_User_Uread_Count) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  295. NSDictionary *dic = responseObject;
  296. weakSelf.numModel = [[WorkNumberModel alloc] initWithDictionary:dic error:nil];
  297. dispatch_async(dispatch_get_main_queue(), ^{
  298. weakSelf.numModel.UReadChatCount = weakSelf.numModel.UReadChatCount + weakSelf.unReadCount;
  299. NSInteger count = weakSelf.numModel.allNumber + weakSelf.numModel.UReadChatCount;
  300. // weakSelf.tabBarController.tabBar.items[2].badgeValue = count > 0 ? [NSString stringWithFormat:@"%ld",(long)count] : nil;
  301. [weakSelf initCollectionData:weakSelf.numModel];
  302. });
  303. } failure:^(NSError * _Nonnull error) {
  304. }];
  305. }
  306. -(void)initCollectionData:(WorkNumberModel *)numModel{
  307. [self.collectionDataSource removeAllObjects];
  308. NSMutableArray * array = [NSMutableArray array];
  309. for (int i= 0;i < 4; i++) {
  310. MoreAppInfoModel *model = [[MoreAppInfoModel alloc] init];
  311. switch (i) {
  312. case 0:{
  313. model.title = @"收件箱";
  314. model.imgName = @"chat_shou_icon";
  315. model.notImgName = @"chat_shou_icon";
  316. model.type = ChatMenuZhanXinType;
  317. model.readNum = numModel.FlowAuditUReadCount + numModel.FlowSendUReadCount + numModel.FlowCcUReadCount + numModel.noticeCount + numModel.missiveCount;
  318. model.showEditFlag = YES;
  319. }break;
  320. case 1:{
  321. model.title = @"回复我的";
  322. model.imgName = @"chat_replay_icon";
  323. model.notImgName = @"chat_replay_icon";
  324. model.type = ChatMenuReplayType;
  325. model.readNum = 0;
  326. model.showEditFlag = YES;
  327. }break;
  328. case 2:{
  329. model.title = @"验证消息";
  330. model.imgName = @"chat_verify_icon";
  331. model.notImgName = @"chat_verify_icon";
  332. model.type = ChatMenuVerifyType;
  333. model.readNum = 0;
  334. model.showEditFlag = YES;
  335. }break;
  336. default:{
  337. model.title = @"通讯录";
  338. model.imgName = @"chat_maillist_icon";
  339. model.notImgName = @"chat_maillist_icon";
  340. model.type = ChatMenuTeleListType;
  341. model.readNum = 0;
  342. model.showEditFlag = YES;
  343. }break;
  344. }
  345. [array addObject:model];
  346. }
  347. self.collectionDataSource = array;
  348. [self.collectionView reloadData];
  349. }
  350. #pragma mark -UICollectionViewDataSource
  351. /**********************************************************************/
  352. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  353. return self.collectionDataSource.count;
  354. }
  355. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  356. {
  357. MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item];
  358. ChatMsgCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath];
  359. cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName];
  360. cell.cell0TitleLabel.text = bean.title;
  361. cell.imagH.constant = 25.f;
  362. cell.imagW.constant = 25.f;
  363. switch (bean.type) {
  364. case ChatMenuNoticeType:
  365. {
  366. NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum];
  367. cell.cell0ReadNumLabel.text = count;
  368. cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES;
  369. UILabel * label = [UILabel new];
  370. label.font = [UIFont systemFontOfSize:12];
  371. label.text = count;
  372. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  373. if ((width + 5) < 16) {
  374. cell.constant.constant = 16;
  375. }else{
  376. cell.constant.constant = width + 8;
  377. }
  378. }
  379. break;
  380. case ChatMenuZhanXinType:
  381. {
  382. NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum];
  383. cell.cell0ReadNumLabel.text = count;
  384. cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES;
  385. UILabel * label = [UILabel new];
  386. label.font = [UIFont systemFontOfSize:12];
  387. label.text = count;
  388. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  389. if ((width + 5) < 16) {
  390. cell.constant.constant = 16;
  391. }else{
  392. cell.constant.constant = width + 8;
  393. }
  394. }
  395. break;
  396. case ChatMenuWaitType:
  397. {
  398. NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum];
  399. cell.cell0ReadNumLabel.text = count;
  400. cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES;
  401. UILabel * label = [UILabel new];
  402. label.font = [UIFont systemFontOfSize:12];
  403. label.text = count;
  404. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  405. if ((width + 5) < 16) {
  406. cell.constant.constant = 16;
  407. }else{
  408. cell.constant.constant = width + 8;
  409. }
  410. }
  411. break;
  412. default:
  413. {
  414. NSString * count = [NSString stringWithFormat:@"%ld",bean.readNum];
  415. cell.cell0ReadNumLabel.text = count;
  416. cell.cell0ReadNumLabel.hidden = bean.readNum > 0 ? NO : YES;
  417. }
  418. break;
  419. }
  420. cell.cell0MengCengView.hidden = YES;
  421. return cell;
  422. }
  423. /****************************************************/
  424. #pragma mark --UICollectionViewDelegateFlowLayout
  425. /****************************************************/
  426. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  427. {
  428. CGFloat width = (SCREEN_WIDTH - 20) / self.collectionDataSource.count;
  429. CGFloat height = 69;
  430. return CGSizeMake(width, height);
  431. }
  432. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  433. {
  434. CGFloat W = 10;
  435. return UIEdgeInsetsMake(0,W,0,W);
  436. }
  437. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  438. return 0;
  439. }
  440. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  441. return 0;
  442. }
  443. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  444. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  445. MoreAppInfoModel * model = [self.collectionDataSource objectAtIndex:indexPath.item];
  446. switch (model.type) {
  447. case ChatMenuZhanXinType:{
  448. TDInterLeterHomeViewController *vc = [TDInterLeterHomeViewController initChatMsgNoticeVC];
  449. vc.hidesBottomBarWhenPushed = YES;
  450. vc.interLeterFolderId = 0;
  451. vc.isHome = YES;
  452. [self.navigationController pushViewController:vc animated:YES];
  453. }break;
  454. case ChatMenuReplayType:{
  455. ReplayMeVC *vc = [ReplayMeVC initReplayMeVC];
  456. vc.hidesBottomBarWhenPushed = YES;
  457. [self.navigationController pushViewController:vc animated:YES];
  458. }break;
  459. case ChatMenuVerifyType:{
  460. ChatTestingVC *vc = [ChatTestingVC initChatTestingVC];
  461. vc.hidesBottomBarWhenPushed = YES;
  462. [self.navigationController pushViewController:vc animated:YES];
  463. }break;
  464. case ChatMenuTeleListType:{
  465. MailListVC * vc = [MailListVC initMailListVC];
  466. vc.hidesBottomBarWhenPushed = YES;
  467. [self.navigationController pushViewController:vc animated:YES];
  468. }break;
  469. default:
  470. break;
  471. }
  472. }
  473. #pragma mark - buttonAction
  474. - (void)scanAction{
  475. SWQRCodeConfig *config = [[SWQRCodeConfig alloc]init];
  476. config.scannerType = SWScannerTypeBoth;
  477. SWQRCodeViewController *qrcodeVC = [[SWQRCodeViewController alloc]init];
  478. qrcodeVC.codeConfig = config;
  479. qrcodeVC.delegate = self;
  480. qrcodeVC.hidesBottomBarWhenPushed = YES;
  481. [self.navigationController pushViewController:qrcodeVC animated:YES];
  482. }
  483. #pragma mark - 扫一扫结果
  484. - (void)scanResult:(NSString *)scanStr{
  485. ScanResultModel *model = [[ScanResultModel alloc]initWithString:scanStr error:nil];
  486. NSLog(@"%@",model);
  487. WEAKSELF
  488. switch (model.key) {
  489. case 1:// 用户
  490. {
  491. [self scanNetWork:model.value urlStrong:SaoYiSao_Post ScanKey:@"Guid" success:^(id responseObject) {
  492. NSDictionary *dic = responseObject;
  493. AddressUserModel *model = [[AddressUserModel alloc] initWithDictionary:dic error:nil];
  494. dispatch_async(dispatch_get_main_queue(), ^{
  495. MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
  496. vc.indexId = model.Id;
  497. vc.isAdd = YES;
  498. vc.hidesBottomBarWhenPushed = YES;
  499. [weakSelf.navigationController pushViewController:vc animated:YES];
  500. });
  501. } failure:^(NSError *error) {
  502. SHOWERROR([ZYCTool handerResultData:error]);
  503. }];
  504. }
  505. break;
  506. case 2:// 群聊
  507. {
  508. [self scanToNetWork:model.value urlStrong:SaoYiSao2_Post success:^(id responseObject) {
  509. ChatJoinGroupVC * vc = [ChatJoinGroupVC initChatJoinGroupVC];
  510. vc.dict = responseObject;
  511. vc.hidesBottomBarWhenPushed = YES;
  512. [weakSelf.navigationController pushViewController:vc animated:YES];
  513. } failure:^(NSError *error) {
  514. SHOWERROR([ZYCTool handerResultData:error]);
  515. }];
  516. }
  517. break;
  518. case 3://小组
  519. {
  520. [self scanToNetWork:model.value urlStrong:SaoYiSao3_Post success:^(id responseObject) {
  521. if ([responseObject[@"IsUser"] boolValue]) {
  522. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  523. vc.GroupId = [responseObject[@"Id"] integerValue];
  524. vc.titleStr = responseObject[@"Name"];
  525. vc.hidesBottomBarWhenPushed = YES;
  526. [weakSelf.navigationController pushViewController:vc animated:YES];
  527. }else{
  528. dispatch_async(dispatch_get_main_queue(), ^{
  529. TDQrJoinVC * vc = [TDQrJoinVC initTDQrJoinVC];
  530. vc.dict = responseObject;
  531. vc.hidesBottomBarWhenPushed = YES;
  532. [weakSelf.navigationController pushViewController:vc animated:YES];
  533. });
  534. }
  535. } failure:^(NSError *error) {
  536. SHOWERROR([ZYCTool handerResultData:error]);
  537. }];
  538. }
  539. break;
  540. case 4://扫码登录
  541. {
  542. LoginPCVC * vc = [LoginPCVC initLoginPCVC];
  543. vc.key = model.value;
  544. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  545. [self presentViewController:vc animated:YES completion:^{
  546. }];
  547. }
  548. break;
  549. default:
  550. break;
  551. }
  552. }
  553. - (void)scanNetWork:(NSString *)scanStr urlStrong:(NSString *)urlstring ScanKey:(NSString*)key success:(void (^) (id responseObject))successful failure:(void (^) (NSError *error))failure{
  554. SHOWLOADING
  555. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,urlstring] parameters:@{key:scanStr} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  556. successful(responseObject);
  557. REMOVESHOW
  558. } failure:^(NSError * _Nonnull error) {
  559. REMOVESHOW
  560. failure(error);
  561. }];
  562. }
  563. - (void)scanToNetWork:(NSString *)scanStr urlStrong:(NSString *)urlstring success:(void (^) (id responseObject))successful failure:(void (^) (NSError *error))failure{
  564. SHOWLOADING
  565. NSString * url = [NSString stringWithFormat:@"%@%@",Host(urlstring),scanStr];
  566. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} success:^(id _Nonnull responseObject) {
  567. REMOVESHOW
  568. successful(responseObject);
  569. } failure:^(NSError * _Nonnull error) {
  570. REMOVESHOW
  571. }];
  572. }
  573. @end