TDGroupInfoDetailVC.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. //
  2. // TDGroupInfoDetailVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/13.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "TDGroupInfoDetailVC.h"
  9. #import "TDGroupInfoDetailCell.h"
  10. #import "MyTDGroupView.h"
  11. #import "TDGroupInfoListModel.h"
  12. #import "TDGroupQrcodeVC.h"
  13. #import "TDGroupInfoChangeVc.h"
  14. #import "ChatGroupAddVC.h"
  15. #import "MailListDetailVC.h"
  16. #import "TDGroupRoleVC.h"
  17. #import "TDGroupLabelVC.h"
  18. #import "GroupInfoVC.h"
  19. #import "GroupSynopsisUserSearchVC.h"
  20. @interface TDGroupInfoDetailVC ()<UITableViewDelegate,UITableViewDataSource>
  21. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  22. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  23. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  24. @property (strong, nonatomic)NSMutableArray *dataArray;
  25. @property (strong, nonatomic) MyTDGroupView *SearchView;
  26. @property (strong, nonatomic)TDGroupInfoListModel *listModel;
  27. @end
  28. @implementation TDGroupInfoDetailVC
  29. +(TDGroupInfoDetailVC *)initTDGroupInfoDetailVC{
  30. TDGroupInfoDetailVC *controller = [StoryboardManager.shared.TDGroup instantiateViewControllerWithIdentifier:@"TDGroupInfoDetailVC"];
  31. return controller;
  32. }
  33. - (void)viewWillAppear:(BOOL)animated
  34. {
  35. [super viewWillAppear:animated];
  36. [self getData];
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.fd_prefersNavigationBarHidden = YES;
  41. [self.HeadView addSubview:self.SearchView];
  42. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.mas_offset(6);
  44. make.left.right.mas_equalTo(self.HeadView);
  45. make.height.mas_offset(36);
  46. }];
  47. WS(weakSelf);
  48. [self.SearchView.button setAction: ^{
  49. GroupSynopsisUserSearchVC * vc = [[GroupSynopsisUserSearchVC alloc] init];
  50. vc.dataArray = weakSelf.dataArray;
  51. vc.type = 1;
  52. [weakSelf.navigationController pushViewController:vc animated:YES];
  53. }];
  54. self.tableView.delegate = self;
  55. self.tableView.dataSource = self;
  56. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showMessage) name:GROUPADDMESSAGE object:nil];
  57. }
  58. - (MyTDGroupView *)SearchView
  59. {
  60. if (!_SearchView) {
  61. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  62. }
  63. return _SearchView;
  64. }
  65. - (void)getData
  66. {
  67. [self.dataArray removeAllObjects];
  68. WS(weakSelf);
  69. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Detail) parameters:@{@"GroupId":@(self.GroupId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  70. NSLog(@"%@",responseObject);
  71. weakSelf.listModel = [TDGroupInfoListModel modelWithDictionary:responseObject];
  72. weakSelf.dataArray = [NSMutableArray arrayWithArray:weakSelf.listModel.GroupUserListResult];
  73. if (weakSelf.upDateTitleBolck) {
  74. weakSelf.upDateTitleBolck(weakSelf.listModel.Name);
  75. }
  76. dispatch_async(dispatch_get_main_queue(), ^{
  77. [weakSelf.tableView reloadData];
  78. });
  79. } failure:^(NSError * _Nonnull error) {
  80. }];
  81. }
  82. - (NSMutableArray *)dataArray
  83. {
  84. if (!_dataArray) {
  85. _dataArray = [NSMutableArray array];
  86. }
  87. return _dataArray;
  88. }
  89. #pragma mark - UITableViewDelegate
  90. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  91. {
  92. return 2;
  93. }
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  95. {
  96. if (section == 0) {
  97. switch (self.listModel.GroupUserRoleId) {
  98. case 1:
  99. return 6;
  100. break;
  101. case 2:
  102. return 6;
  103. break;
  104. default:
  105. return 4;
  106. break;
  107. }
  108. }else{
  109. return self.dataArray.count;
  110. }
  111. }
  112. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. WS(weakSelf);
  115. if (indexPath.section == 0) {
  116. switch (self.listModel.GroupUserRoleId) {
  117. case 1:
  118. {
  119. switch (indexPath.row) {
  120. case 0:
  121. {
  122. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell0:tableView indexPath:indexPath];
  123. [cell.cell0ImgV sd_setImageWithURL:[NSURL URLWithString:self.listModel.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  124. cell.cell0TitleL.text = self.listModel.Name;
  125. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  126. TDGroupQrcodeVC * vc = [TDGroupQrcodeVC initTDGroupQrcodeVC];
  127. vc.model = weakSelf.listModel;
  128. [weakSelf.navigationController pushViewController:vc animated:YES];
  129. }];
  130. cell.QrcodeV.userInteractionEnabled = YES;
  131. [cell.QrcodeV addGestureRecognizer:tap];
  132. return cell;
  133. }
  134. break;
  135. case 1:
  136. {
  137. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  138. cell.cell1TitleL.text = @"小组信息";
  139. return cell;
  140. }
  141. break;
  142. case 2:
  143. {
  144. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  145. cell.cell1TitleL.text = @"小组标签";
  146. return cell;
  147. }
  148. break;
  149. case 3:
  150. {
  151. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  152. cell.cell1TitleL.text = @"小组权限";
  153. return cell;
  154. }
  155. break;
  156. case 4:
  157. {
  158. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell2:tableView indexPath:indexPath];
  159. cell.cell2TitleL.text = @"保存到通讯录";
  160. [cell.cell2Switch setBlockForControlEvents:UIControlEventValueChanged block:^(id _Nonnull sender) {
  161. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Group_Contacts),weakSelf.GroupId];
  162. [[HttpManager sharedHttpManager] PUTUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  163. weakSelf.listModel.IsContacts = !weakSelf.listModel.IsContacts;
  164. dispatch_async(dispatch_get_main_queue(), ^{
  165. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  166. });
  167. } failure:^(NSError * _Nonnull error) {
  168. SHOWERROR([ZYCTool handerResultData:error]);
  169. }];
  170. }];
  171. [cell.cell2Switch setOn:self.listModel.IsContacts];
  172. return cell;
  173. }
  174. break;
  175. default:
  176. {
  177. ChatGroupAddVC *vc = [[ChatGroupAddVC alloc] init];
  178. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell3:tableView indexPath:indexPath];
  179. cell.cell3TitleL.text = @"添加成员";
  180. [cell.cell3AddBtn setAction:^{
  181. Department *defaltGroupSetion = [[Department alloc]init];
  182. defaltGroupSetion.Name = @"单位通讯录";
  183. defaltGroupSetion.Id = 0;
  184. Department *myGroupSetion = [[Department alloc]init];
  185. myGroupSetion.Name = @"自建通讯录";
  186. defaltGroupSetion.Id = 0;
  187. vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
  188. vc.isDefalutPage = 1;
  189. vc.type = AddGroupUser;
  190. vc.Id = weakSelf.listModel.Id;
  191. NSMutableArray * array = [NSMutableArray array];
  192. for (TDGroupInfoModel * model in self.dataArray) {
  193. SelectModel * smodel = [[SelectModel alloc] init];
  194. smodel.UserId = model.UserId;
  195. smodel.UserName = model.Name;
  196. [array addObject:smodel];
  197. }
  198. vc.grouperArray = array;
  199. [weakSelf.navigationController pushViewController:vc animated:YES];
  200. }];
  201. return cell;
  202. }
  203. break;
  204. }
  205. }
  206. break;
  207. case 2:
  208. {
  209. switch (indexPath.row) {
  210. case 0:
  211. {
  212. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell0:tableView indexPath:indexPath];
  213. [cell.cell0ImgV sd_setImageWithURL:[NSURL URLWithString:self.listModel.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  214. cell.cell0TitleL.text = self.listModel.Name;
  215. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  216. TDGroupQrcodeVC * vc = [TDGroupQrcodeVC initTDGroupQrcodeVC];
  217. vc.model = weakSelf.listModel;
  218. [weakSelf.navigationController pushViewController:vc animated:YES];
  219. }];
  220. cell.QrcodeV.userInteractionEnabled = YES;
  221. [cell.QrcodeV addGestureRecognizer:tap];
  222. return cell;
  223. }
  224. break;
  225. case 1:
  226. {
  227. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  228. cell.cell1TitleL.text = @"小组信息";
  229. return cell;
  230. }
  231. break;
  232. case 2:
  233. {
  234. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  235. cell.cell1TitleL.text = @"小组标签";
  236. return cell;
  237. }
  238. break;
  239. case 3:
  240. {
  241. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  242. cell.cell1TitleL.text = @"小组权限";
  243. return cell;
  244. }
  245. break;
  246. case 4:
  247. {
  248. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell2:tableView indexPath:indexPath];
  249. cell.cell2TitleL.text = @"保存到通讯录";
  250. [cell.cell2Switch setBlockForControlEvents:UIControlEventValueChanged block:^(id _Nonnull sender) {
  251. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Group_Contacts),weakSelf.GroupId];
  252. [[HttpManager sharedHttpManager] PUTUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  253. weakSelf.listModel.IsContacts = !weakSelf.listModel.IsContacts;
  254. dispatch_async(dispatch_get_main_queue(), ^{
  255. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  256. });
  257. } failure:^(NSError * _Nonnull error) {
  258. SHOWERROR([ZYCTool handerResultData:error]);
  259. }];
  260. }];
  261. [cell.cell2Switch setOn:self.listModel.IsContacts];
  262. return cell;
  263. }
  264. break;
  265. default:
  266. {
  267. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell3:tableView indexPath:indexPath];
  268. cell.cell3TitleL.text = @"添加成员";
  269. [cell.cell3AddBtn setAction:^{
  270. Department *defaltGroupSetion = [[Department alloc]init];
  271. defaltGroupSetion.Name = @"单位通讯录";
  272. defaltGroupSetion.Id = 0;
  273. Department *myGroupSetion = [[Department alloc]init];
  274. myGroupSetion.Name = @"自建通讯录";
  275. defaltGroupSetion.Id = 0;
  276. ChatGroupAddVC *vc = [[ChatGroupAddVC alloc] init];
  277. vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
  278. vc.isDefalutPage = 1;
  279. vc.type = AddGroupUser;
  280. vc.Id = weakSelf.listModel.Id;
  281. NSMutableArray * array = [NSMutableArray array];
  282. for (TDGroupInfoModel * model in self.dataArray) {
  283. SelectModel * smodel = [[SelectModel alloc] init];
  284. smodel.UserId = model.UserId;
  285. smodel.UserName = model.Name;
  286. [array addObject:smodel];
  287. }
  288. vc.grouperArray = array;
  289. [weakSelf.navigationController pushViewController:vc animated:YES];
  290. }];
  291. return cell;
  292. }
  293. break;
  294. }
  295. }
  296. break;
  297. default:
  298. {
  299. switch (indexPath.row) {
  300. case 0:
  301. {
  302. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell0:tableView indexPath:indexPath];
  303. [cell.cell0ImgV sd_setImageWithURL:[NSURL URLWithString:self.listModel.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  304. cell.cell0TitleL.text = self.listModel.Name;
  305. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  306. TDGroupQrcodeVC * vc = [TDGroupQrcodeVC initTDGroupQrcodeVC];
  307. vc.model = weakSelf.listModel;
  308. [weakSelf.navigationController pushViewController:vc animated:YES];
  309. }];
  310. cell.QrcodeV.userInteractionEnabled = YES;
  311. [cell.QrcodeV addGestureRecognizer:tap];
  312. return cell;
  313. }
  314. break;
  315. case 1:
  316. {
  317. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  318. cell.cell1TitleL.text = @"小组信息";
  319. return cell;
  320. }
  321. break;
  322. case 2:
  323. {
  324. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath];
  325. cell.cell1TitleL.text = @"小组标签";
  326. return cell;
  327. }
  328. break;
  329. default:
  330. {
  331. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell2:tableView indexPath:indexPath];
  332. cell.cell2TitleL.text = @"保存到通讯录";
  333. [cell.cell2Switch setBlockForControlEvents:UIControlEventValueChanged block:^(id _Nonnull sender) {
  334. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Group_Contacts),weakSelf.GroupId];
  335. [[HttpManager sharedHttpManager] PUTUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  336. weakSelf.listModel.IsContacts = !weakSelf.listModel.IsContacts;
  337. dispatch_async(dispatch_get_main_queue(), ^{
  338. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  339. });
  340. } failure:^(NSError * _Nonnull error) {
  341. SHOWERROR([ZYCTool handerResultData:error]);
  342. }];
  343. }];
  344. [cell.cell2Switch setOn:self.listModel.IsContacts];
  345. return cell;
  346. }
  347. break;
  348. }
  349. }
  350. break;
  351. }
  352. }else{
  353. TDGroupInfoModel * model = [self.dataArray objectAtIndex:indexPath.row];
  354. TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell4:tableView indexPath:indexPath];
  355. [cell.cell4imgV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  356. cell.cell4NameL.text = model.Name;
  357. switch (model.GroupUserRoleId) {
  358. case 1:
  359. {
  360. cell.cell4LevelL.hidden = NO;
  361. cell.cell4LevelL.text = @"创建者";
  362. cell.cell4LevelL.backgroundColor = UIColorHex(#3979D3);
  363. }
  364. break;
  365. case 2:
  366. {
  367. cell.cell4LevelL.hidden = NO;
  368. cell.cell4LevelL.text = @"管理员";
  369. cell.cell4LevelL.backgroundColor = UIColorHex(#FF9503);
  370. }
  371. break;
  372. default:
  373. {
  374. cell.cell4LevelL.hidden = YES;
  375. }
  376. break;
  377. }
  378. cell.cell4subL.text = model.DepartmentName;
  379. cell.cell4TimeL.text = nil;
  380. return cell;
  381. }
  382. }
  383. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  384. {
  385. return 65.f;
  386. }
  387. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  388. {
  389. if (section == 0) {
  390. return 0.01f;
  391. }
  392. return 35.f;
  393. }
  394. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  395. {
  396. return 0.01f;
  397. }
  398. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  399. {
  400. if (section == 0) {
  401. return [UIView new];
  402. }else{
  403. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
  404. view.backgroundColor = UIColorHex(#F0EFF4);
  405. UILabel * label = [UILabel new];
  406. NSString * str = [NSString stringWithFormat:@"成员:%ld人,话题:%ld",(long)self.listModel.GroupUserNumber,(long)self.listModel.GroupTopicNumber];
  407. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 13],NSForegroundColorAttributeName : UIColorHex(#666666)}];
  408. label.attributedText = string;
  409. [view addSubview:label];
  410. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  411. make.left.mas_offset(@15);
  412. make.centerY.mas_equalTo(view);
  413. }];
  414. return view;
  415. }
  416. }
  417. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  418. {
  419. WS(weakSelf);
  420. if (indexPath.section == 0) {
  421. switch (indexPath.row) {
  422. case 0:
  423. {
  424. if (self.listModel.GroupUserRoleId == 1) {
  425. TDGroupInfoChangeVc * vc = [TDGroupInfoChangeVc initTDGroupInfoChangeVc];
  426. vc.model = self.listModel;
  427. [self.navigationController pushViewController:vc animated:YES];
  428. }
  429. }
  430. break;
  431. case 1:
  432. {
  433. GroupInfoVC * vc= [GroupInfoVC initGroupInfoVC];
  434. vc.Id = self.listModel.Id;
  435. vc.GroupName = self.listModel.Name;
  436. vc.IsOwner = self.listModel.GroupUserRoleId == 1 ? YES : NO;
  437. [self.navigationController pushViewController:vc animated:YES];
  438. }
  439. break;
  440. case 2:
  441. {
  442. TDGroupLabelVC * vc= [TDGroupLabelVC initTDGroupLabelVC];
  443. vc.labelName = self.listModel.LabelName;
  444. vc.Id = self.listModel.Id;
  445. vc.refreshBlock = ^{
  446. [weakSelf getData];
  447. };
  448. [self.navigationController pushViewController:vc animated:YES];
  449. }
  450. break;
  451. case 3:
  452. {
  453. TDGroupRoleVC * vc= [TDGroupRoleVC initTDGroupRoleVC];
  454. vc.model = self.listModel;
  455. vc.refreshBlock = ^{
  456. [weakSelf getData];
  457. };
  458. [self.navigationController pushViewController:vc animated:YES];
  459. }
  460. break;
  461. default:
  462. break;
  463. }
  464. }else{
  465. TDGroupInfoModel * model = [self.dataArray objectAtIndex:indexPath.row];
  466. MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
  467. vc.indexId = model.UserId;
  468. [self.navigationController pushViewController:vc animated:YES];
  469. }
  470. }
  471. #pragma mark - UISwitch - event
  472. - (void)NeedAgree
  473. {
  474. WS(weakSelf);
  475. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Group_Set_Admin),(long)self.listModel.Id];
  476. [[HttpManager sharedHttpManager] PUTUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  477. dispatch_async(dispatch_get_main_queue(), ^{
  478. [weakSelf getData];
  479. });
  480. } failure:^(NSError * _Nonnull error) {
  481. }];
  482. }
  483. - (void)AdminTalk
  484. {
  485. WS(weakSelf);
  486. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Group_Set_Words),(long)self.listModel.Id];
  487. [[HttpManager sharedHttpManager] PUTUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  488. dispatch_async(dispatch_get_main_queue(), ^{
  489. [weakSelf getData];
  490. });
  491. } failure:^(NSError * _Nonnull error) {
  492. }];
  493. }
  494. - (void)ChatEnabelChange
  495. {
  496. WS(weakSelf);
  497. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Group_Set_Disturb),(long)self.listModel.Id];
  498. [[HttpManager sharedHttpManager] PUTUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  499. dispatch_async(dispatch_get_main_queue(), ^{
  500. [weakSelf getData];
  501. });
  502. } failure:^(NSError * _Nonnull error) {
  503. }];
  504. }
  505. #pragma Mark 左滑按钮 iOS8以上
  506. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  507. WS(weakSelf);
  508. if (indexPath.section > 0) {
  509. TDGroupInfoModel *model = [self.dataArray objectAtIndex:indexPath.row];
  510. switch (self.listModel.GroupUserRoleId) {
  511. case 1:{
  512. if (model.GroupUserRoleId != 1) {
  513. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  514. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  515. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  516. [weakSelf deleteFind:model];
  517. }];
  518. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  519. }];
  520. [alert addAction:sureAction];
  521. [alert addAction:cancelAction];
  522. [weakSelf presentViewController:alert animated:YES completion:^{
  523. }];
  524. }];
  525. action1.backgroundColor = UIColorHex(#F64A33);
  526. NSString * isAdmin = model.GroupUserRoleId == 2 ? @"取消管理员" : @"设为管理员";
  527. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:isAdmin handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  528. [weakSelf setRoleLevel:model];
  529. }];
  530. action2.backgroundColor = UIColorHex(#FF9503);
  531. UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"转让小组" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  532. [weakSelf ReturnToOther:model];
  533. }];
  534. action3.backgroundColor = UIColorHex(#589AF1);
  535. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2,action3]];
  536. actions.performsFirstActionWithFullSwipe = NO;
  537. return actions;
  538. }
  539. }break;
  540. case 2:{
  541. if (model.GroupUserRoleId == 3) {
  542. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  543. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  544. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  545. [weakSelf deleteFind:@[model].mutableCopy];
  546. }];
  547. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  548. }];
  549. [alert addAction:sureAction];
  550. [alert addAction:cancelAction];
  551. [weakSelf presentViewController:alert animated:YES completion:^{
  552. }];
  553. }];
  554. action1.backgroundColor = UIColorHex(#F64A33);
  555. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1]];
  556. actions.performsFirstActionWithFullSwipe = NO;
  557. return actions;
  558. }
  559. }break;
  560. default:{
  561. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
  562. actions.performsFirstActionWithFullSwipe = NO;
  563. return actions;
  564. }
  565. }
  566. }
  567. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
  568. actions.performsFirstActionWithFullSwipe = NO;
  569. return actions;
  570. }
  571. - (void)deleteFind:(TDGroupInfoModel *)model
  572. {
  573. WS(weakSelf);
  574. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_DELETE_User) parameters:@{@"GroupUserIds":@[@(model.UserId)],@"GroupId":@(self.listModel.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  575. SHOWSUCCESS(@"删除成功")
  576. dispatch_async(dispatch_get_main_queue(), ^{
  577. [weakSelf getData];
  578. });
  579. } failure:^(NSError * _Nonnull error) {
  580. }];
  581. }
  582. - (void)setRoleLevel:(TDGroupInfoModel *)model
  583. {
  584. NSInteger level = model.GroupUserRoleId == 2 ? 3 : 2;
  585. WS(weakSelf);
  586. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update_User) parameters:@{@"RoleId":@(level),@"Id":@(model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  587. SHOWSUCCESS(@"设置成功")
  588. [weakSelf getData];
  589. } failure:^(NSError * _Nonnull error) {
  590. }];
  591. }
  592. - (void)ReturnToOther:(TDGroupInfoModel *)model
  593. {
  594. WS(weakSelf);
  595. [[HttpManager sharedHttpManager] PUTUrl:Host(API_APP_Group_Transfer) parameters:@{@"GroupId":@(self.GroupId),@"TransferUserId":@(model.UserId)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  596. SHOWSUCCESS(@"转让成功")
  597. [weakSelf getData];
  598. } failure:^(NSError * _Nonnull error) {
  599. SHOWERROR([ZYCTool handerResultData:error]);
  600. }];
  601. }
  602. /// 退出小组
  603. - (IBAction)qiutGroupAction:(id)sender {
  604. SHOWLOADING
  605. WEAKSELF
  606. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(SaoYiSao3_Post),(long)self.GroupId];
  607. [[HttpManager sharedHttpManager] DeleteUrl:url parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  608. REMOVESHOW
  609. for (UIViewController * vc in weakSelf.navigationController.viewControllers) {
  610. if ([vc isKindOfClass:NSClassFromString(@"MyTDGroupViewController")]
  611. ||[vc isKindOfClass:NSClassFromString(@"SourceGroupVC")]){
  612. [weakSelf.navigationController popToViewController:vc animated:YES];
  613. return;
  614. }
  615. }
  616. } failure:^(NSError * _Nonnull error) {
  617. REMOVESHOW
  618. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[ZYCTool handerResultData:error] preferredStyle:(UIAlertControllerStyleAlert)];
  619. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  620. }];
  621. [alert addAction:sureAction];
  622. [self presentViewController:alert animated:YES completion:^{
  623. }];
  624. }];
  625. }
  626. - (IBAction)backAction:(id)sender {
  627. [super backAction:sender];
  628. }
  629. - (void)dealloc
  630. {
  631. [[NSNotificationCenter defaultCenter] removeObserver:self];
  632. }
  633. - (void)viewWillDisappear:(BOOL)animated
  634. {
  635. [super viewWillDisappear:animated];
  636. WKWebsiteDataStore *dateStore = [WKWebsiteDataStore defaultDataStore];
  637. [dateStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes]
  638. completionHandler:^(NSArray * __nonnull records) {
  639. for (WKWebsiteDataRecord *record in records)
  640. {
  641. [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:record.dataTypes
  642. forDataRecords:@[record]
  643. completionHandler:^{
  644. NSLog(@"Cookies for %@ deleted successfully",record.displayName);
  645. }];
  646. }
  647. }];
  648. }
  649. - (void)showMessage
  650. {
  651. UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"需等待对方验证同意加入本小组" message:nil preferredStyle:UIAlertControllerStyleAlert];
  652. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  653. }]];
  654. [self presentViewController:alertController animated:YES completion:nil];
  655. }
  656. @end