SendInfoGroupVC.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. //
  2. // SendInfoGroupVC.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/4.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "SendInfoGroupVC.h"
  9. #import "SendInfoGroupModel.h"
  10. #import "SendInfoGroupSubModel.h"
  11. #import "SendInfoGroupSubTwoModel.h"
  12. #import "SendInfoGroupCell.h"
  13. #import "SendGroupBCell.h"
  14. #import "AddressBookGroupModel.h"
  15. #import "SearchBarDisplayCenter.h"
  16. #import "WZSendInfoCell.h"
  17. @interface SendInfoGroupVC ()<UITableViewDelegate,UITableViewDataSource>
  18. @property (nonatomic, strong) IBOutlet UIButton *allSelectButton;
  19. @property (weak, nonatomic) IBOutlet UILabel *pageTitleLabel;
  20. @property (nonatomic, strong) IBOutlet UIButton *rightButton;
  21. @property (nonatomic, strong) IBOutlet UITableView *myTableView;
  22. @property (nonatomic, strong) NSMutableArray <NSMutableArray<WZContactModel *> *>*groupArray;
  23. @property (nonatomic, strong) TDButton *serachButton;
  24. @property (nonatomic, strong) AddressBookGroupModel *addressBookModel;
  25. @property (nonatomic, strong) NSMutableSet *userIdsSet;
  26. @property (nonatomic, strong) NSMutableSet *departmentIdsSet;
  27. @property (nonatomic, strong) NSMutableSet *addressBookGroupIdsSet;
  28. @property (strong,nonatomic) SearchBarDisplayCenter *searchBar;
  29. @property (nonatomic, strong) NSMutableArray *userIdsArr;
  30. @property (nonatomic, strong) NSMutableArray *departmentIdsArr;
  31. @property (nonatomic, strong) NSMutableArray *addressBookGroupIdsArr;
  32. @property (nonatomic,assign) BOOL isShowEditor;
  33. @end
  34. @implementation SendInfoGroupVC
  35. +(SendInfoGroupVC *)initSendInfoGroupVC{
  36. SendInfoGroupVC *controller = [StoryboardManager.shared.mailList instantiateViewControllerWithIdentifier:@"SendInfoGroupVC"];
  37. return controller;
  38. }
  39. -(void)getSearchKeyWord:(NSString *)searchWord{
  40. NSLog(@"%@",searchWord);
  41. WS(weakSelf);
  42. if(searchWord.length > 0){
  43. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  44. [dict setObject:searchWord forKey:@"Key"];
  45. [[HttpManager sharedHttpManager] POSTWithUrl:AddressBookGroup_Search_Post parameters:dict success:^(id _Nonnull responseObject) {
  46. NSArray *array = responseObject;
  47. NSLog(@"%@",responseObject);
  48. if (array.count == 0) {
  49. SHOWERROR(@"没有搜到结果");
  50. }else{
  51. NSMutableArray *arr = [NSMutableArray array];
  52. for (NSDictionary *dic in array) {
  53. AddressBookGroupsModel *model = [[AddressBookGroupsModel alloc]initWithDictionary:dic error:nil];
  54. NSLog(@"%@",model);
  55. [arr addObject:model];
  56. }
  57. [weakSelf.addressBookModel.AddressBookGroups removeAllObjects];
  58. [weakSelf.addressBookModel.AddressBookGroups addObjectsFromArray:arr];
  59. [weakSelf.myTableView reloadData];
  60. }
  61. } failure:^(NSError * _Nonnull error) {
  62. SHOWERROR([ZYCTool handerResultData:error])
  63. }];
  64. }else{
  65. }
  66. }
  67. - (void)viewDidLoad {
  68. [super viewDidLoad];
  69. self.fd_prefersNavigationBarHidden = YES;
  70. self.pageTitleLabel.text = self.titleStr;
  71. [self getData];
  72. self.isShowEditor = YES;
  73. [self setMenu:self.isShowEditor];
  74. [self.rightButton addTarget:self action:@selector(confirmAction:) forControlEvents:UIControlEventTouchDown];
  75. }
  76. - (void)setMenu:(BOOL)isShowEditor{
  77. if (isShowEditor) {
  78. [self.allSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  79. [self.allSelectButton setImage:nil forState:UIControlStateNormal];
  80. }else{
  81. }
  82. }
  83. - (void)menuAction:(id)sender{
  84. if (self.isShowEditor) {
  85. UIButton *button = sender;
  86. if ([[button titleLabel].text isEqualToString:@"全选"]) {
  87. [self.allSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
  88. [self isSelectAllHander:YES];
  89. }else{
  90. [self.allSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  91. [self isSelectAllHander:NO];
  92. }
  93. [self.myTableView reloadData];
  94. }else{
  95. [super menuAction:sender];
  96. }
  97. }
  98. - (void)isSelectAllHander:(BOOL)isAllSelect{
  99. for (NSInteger i = 0; i < self.groupArray.count;i++) {
  100. for (WZContactModel *mode in self.groupArray[i]) {
  101. mode.isSelect = isAllSelect;
  102. }
  103. }
  104. [self countSelectNumber];
  105. }
  106. - (void)confirmAction:(UIButton*)btn{
  107. NSMutableArray *departGroupArray = [NSMutableArray array];
  108. NSMutableArray *cusGroupArray = [NSMutableArray array];
  109. NSMutableArray *departUserArray = [NSMutableArray array];
  110. NSMutableArray *cusUserArray = [NSMutableArray array];
  111. for (NSInteger i = 0 ;i < self.groupArray.count; i++) {
  112. for (WZContactModel *model in self.groupArray[i]) {
  113. if (model.isSelect) {
  114. switch (model.modelDataType) {
  115. case MailListByZu_SysGroup:
  116. [departGroupArray addObject:model];
  117. break;
  118. case MailListByZu_CusGroup:
  119. [cusGroupArray addObject:model];
  120. break;
  121. case MailListByZu_SysUser:
  122. [departUserArray addObject:model];
  123. break;
  124. case MailListByZu_CusUser:
  125. [cusUserArray addObject:model];
  126. break;
  127. }
  128. }
  129. }
  130. }
  131. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_SelectPeopleAndDepartMent object:nil userInfo:@{@"selectDepartAndPeople":@[departGroupArray,cusGroupArray,departUserArray,cusUserArray]}];
  132. [self back];
  133. }
  134. #pragma mark - 选中之后返回原控制器
  135. - (void)back{
  136. for ( int i = 0 ;i< self.navigationController.viewControllers.count;i++) {
  137. NSLog(@"%@",self.navigationController.viewControllers[i]);
  138. if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MailListByZuVC")]) {
  139. [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
  140. return;
  141. }
  142. }
  143. }
  144. //从服务器拉取数据
  145. - (void)getData{
  146. if (self.isHomePage) {
  147. WS(weakSelf);
  148. [[HttpManager sharedHttpManager] POSTUrl:Host(AddressBookGroup_ListGroup_Post) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  149. REMOVESHOW
  150. NSLog(@"通讯录首页%@",responseObject);
  151. NSDictionary *dic = responseObject;
  152. NSMutableArray *departmentsArray = dic[@"Departments"];
  153. NSMutableArray *addressBookGroups = dic[@"AddressBookGroups"];
  154. [weakSelf dictionaryToModelWithGroup:departmentsArray WidthDataType: MailListByZu_SysGroup withUser:addressBookGroups withDataType:MailListByZu_CusGroup];
  155. [weakSelf.myTableView reloadData];
  156. } failure:^(NSError * _Nonnull error) {
  157. REMOVESHOW
  158. SHOWERROR([ZYCTool handerResultData:error]);
  159. }];
  160. }else{
  161. WS(weakSelf);
  162. switch (self.pageType) {
  163. case MailListByZuPageType_Sys:{
  164. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroup_DepartemntDetail_Post] parameters:@{@"departmentId":@(self.indexId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  165. REMOVESHOW
  166. NSLog(@"=============/n 通讯录子页 系统分组 /n=================/n%@",responseObject);
  167. NSDictionary *dic = responseObject;
  168. NSArray *departments = dic[@"Departments"];
  169. NSArray *users = dic[@"Users"];
  170. [weakSelf dictionaryToModelWithGroup:departments.mutableCopy WidthDataType: MailListByZu_SysGroup withUser:users.mutableCopy withDataType:MailListByZu_SysUser];
  171. [weakSelf.myTableView reloadData];
  172. } failure:^(NSError * _Nonnull error) {
  173. REMOVESHOW
  174. SHOWERROR([ZYCTool handerResultData:error]);
  175. }];
  176. }break;
  177. case MailListByZuPageType_custom:{
  178. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroupUser_Get_Post] parameters:@{@"addressBookGroupId":@(self.indexId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  179. REMOVESHOW
  180. NSLog(@"=============/n通讯录子页 自建分组 /n=================/n%@",responseObject);
  181. NSArray *usersArrray = responseObject[@"AddressBookGroupUsers"];
  182. NSArray *groupsArrray = responseObject[@"AddressBookGroups"];
  183. [weakSelf dictionaryToModelWithGroup:groupsArrray.mutableCopy WidthDataType: MailListByZu_CusGroup withUser:usersArrray.mutableCopy withDataType:MailListByZu_CusUser];
  184. [weakSelf.myTableView reloadData];
  185. } failure:^(NSError * _Nonnull error) {
  186. REMOVESHOW
  187. SHOWERROR([ZYCTool handerResultData:error]);
  188. }];
  189. } break;
  190. }
  191. }
  192. }
  193. - (void)dictionaryToModelWithGroup:(NSMutableArray *)departmentsArray WidthDataType:(MailListDataModelType)departType withUser:(NSMutableArray *)addressBookGroups withDataType:(MailListDataModelType)userType{
  194. NSMutableArray *departmentsArray2 = [NSMutableArray array];
  195. NSMutableArray *addressBookGroups2 = [NSMutableArray array];
  196. for (NSDictionary *dic in departmentsArray) {
  197. WZContactModel *model = [[WZContactModel alloc]initWithDictionary:dic error:nil];
  198. model.modelDataType = departType;
  199. [departmentsArray2 addObject:model];
  200. }
  201. for (NSDictionary *dic in addressBookGroups) {
  202. WZContactModel *model = [[WZContactModel alloc]initWithDictionary:dic error:nil];
  203. model.modelDataType = userType;
  204. [addressBookGroups2 addObject:model];
  205. }
  206. [self.groupArray addObject:departmentsArray2];
  207. [self.groupArray addObject:addressBookGroups2];
  208. [self.groupArray addObject:@[].mutableCopy];
  209. }
  210. #pragma mark - 搜索事件处理
  211. - (void)searchhander:(TDButton *)sedner{
  212. }
  213. #pragma mark -UITableViewDelegate,UITableViewDataSource
  214. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  215. return self.groupArray.count;
  216. }
  217. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  218. return self.groupArray[section].count;
  219. }
  220. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  221. WZContactModel *model = self.groupArray[indexPath.section][indexPath.row];
  222. WS(weakSelf);
  223. [self countSelectNumber];
  224. switch (self.pageType) {
  225. case MailListByZuPageType_Sys:
  226. {
  227. if (indexPath.section == 0) {
  228. WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath];
  229. cell.iconImageView.hidden = YES;
  230. cell.nameLeftSpace.constant = 0;
  231. cell.iconWidthSpace.constant = 0;
  232. cell.nameLab.text = model.Name;
  233. model.wzDataType = MailListByZuPageType_Sys;
  234. cell.selectbuton.selected = model.isSelect;
  235. [cell.selectbuton setAction:^{
  236. model.isSelect = !model.isSelect;
  237. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  238. }];
  239. return cell;
  240. }else{
  241. if (self.isHomePage) {
  242. WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath];
  243. cell.iconImageView.hidden = YES;
  244. cell.nameLeftSpace.constant = 0;
  245. cell.iconWidthSpace.constant = 0;
  246. cell.nameLab.text = model.GroupName;
  247. cell.selectbuton.selected = model.isSelect;
  248. model.wzDataType = MailListByZuPageType_custom;
  249. [cell.selectbuton setAction:^{
  250. model.isSelect = !model.isSelect;
  251. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  252. }];
  253. return cell;
  254. }else{
  255. WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath];
  256. cell.iconWidthSpace.constant = 40;
  257. cell.nameLeftSpace.constant = 10;
  258. cell.iconImageView.hidden = NO;
  259. [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"imagePlaceholder")];
  260. cell.nameLab.text = model.Name;
  261. cell.selectbuton.selected = model.isSelect;
  262. [cell.selectbuton setAction:^{
  263. model.isSelect = !model.isSelect;
  264. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  265. }];
  266. cell.rightImgeView.hidden = YES;
  267. return cell;
  268. }
  269. }
  270. }break;
  271. default:{
  272. if (indexPath.section == 0) {
  273. WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath];
  274. cell.iconImageView.hidden = YES;
  275. cell.rightImgeView.hidden = NO;
  276. cell.nameLeftSpace.constant = 0;
  277. cell.nameLeftSpace.constant = 0;
  278. cell.nameLab.text = model.Name;
  279. cell.selectbuton.selected = model.isSelect;
  280. model.wzDataType = MailListByZuPageType_custom;
  281. [cell.selectbuton setAction:^{
  282. model.isSelect = !model.isSelect;
  283. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  284. }];
  285. return cell;
  286. }else{
  287. WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath];
  288. cell.iconImageView.hidden = YES;
  289. cell.iconWidthSpace.constant = 40;
  290. cell.nameLeftSpace.constant = 10;
  291. [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"imagePlaceholder")];
  292. cell.nameLab.text = model.Name;
  293. cell.selectbuton.selected = model.isSelect;
  294. cell.rightImgeView.hidden = YES;
  295. [cell.selectbuton setAction:^{
  296. model.isSelect = !model.isSelect;
  297. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  298. }];
  299. return cell;
  300. }
  301. }
  302. }
  303. }
  304. - (void)gotoNextPage:(NSIndexPath *)indexPath{
  305. WZContactModel *model = self.groupArray[indexPath.section][indexPath.row];
  306. SendInfoGroupVC *vc = [SendInfoGroupVC initSendInfoGroupVC];
  307. vc.isHomePage = NO;
  308. vc.pageType = model.wzDataType;
  309. vc.indexId = model.Id;
  310. vc.titleStr = ISEmptyString(model.Name) ? model.GroupName:model.Name;
  311. [self.navigationController pushViewController:vc animated:YES];
  312. }
  313. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  314. WZContactModel *model = self.groupArray[indexPath.section][indexPath.row];
  315. switch (self.pageType) {
  316. case MailListByZuPageType_Sys:
  317. {
  318. if (indexPath.section == 0) {
  319. [self gotoNextPage:indexPath];
  320. }else{
  321. if (self.isHomePage) {
  322. [self gotoNextPage:indexPath];
  323. }else{
  324. model.isSelect = !model.isSelect;
  325. [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  326. }
  327. }
  328. }break;
  329. default:{
  330. if (indexPath.section == 0) {
  331. [self gotoNextPage:indexPath];
  332. }else{
  333. model.isSelect = !model.isSelect;
  334. [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  335. }
  336. }
  337. }
  338. }
  339. - (void)countSelectNumber{
  340. NSInteger flag = 0;
  341. for (NSInteger i = 0; i<self.groupArray.count;i ++) {
  342. for (WZContactModel *model in self.groupArray[i]) {
  343. if (model.isSelect) {
  344. flag += 1;
  345. }
  346. }
  347. }
  348. if (flag == 0) {
  349. self.rightButton.enabled = NO;
  350. }else{
  351. self.rightButton.enabled = YES;
  352. [self.rightButton setTitle:[NSString stringWithFormat:@"确定(%@)",@(flag).stringValue] forState:UIControlStateNormal];
  353. }
  354. }
  355. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  356. return 65;
  357. }
  358. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  359. if (section == 0) {
  360. return [[UIView alloc] initWithFrame:CGRectZero];
  361. }else if( section == 1){
  362. return [[UIView alloc] initWithFrame:CGRectZero];
  363. }else{
  364. if (self.isHomePage) {
  365. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kGXScreenWidth,30)];
  366. UILabel *headTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(16,(30-13)/2,250, 13)];
  367. [headerView addSubview:headTitleLab];
  368. headerView.backgroundColor = UIColorHex(F5F6F8);
  369. headTitleLab.text = @"最近使用";
  370. headTitleLab.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14.f];
  371. headTitleLab.textColor = UIColorHex(999999);
  372. return headerView;
  373. }else{
  374. return nil;
  375. }
  376. }
  377. }
  378. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  379. if (section == 0) {
  380. return 0;
  381. }else if (section == 1) {
  382. return 0;
  383. }else{
  384. return self.isHomePage ? 30 : 0;
  385. }
  386. }
  387. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  388. return [[UIView alloc] initWithFrame:CGRectZero];
  389. }
  390. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  391. return 0;
  392. }
  393. #pragma mark -- setter
  394. - (NSMutableArray<NSMutableArray<WZContactModel *> *> *)groupArray{
  395. if (!_groupArray) {
  396. _groupArray = [NSMutableArray array];
  397. }
  398. return _groupArray;
  399. }
  400. - (NSMutableSet *)departmentIdsSet{
  401. if (!_departmentIdsSet) {
  402. _departmentIdsSet = [[NSMutableSet alloc]init];
  403. }
  404. return _departmentIdsSet;
  405. }
  406. - (NSMutableSet *)addressBookGroupIdsSet{
  407. if (!_addressBookGroupIdsSet) {
  408. _addressBookGroupIdsSet = [[NSMutableSet alloc]init];
  409. }
  410. return _addressBookGroupIdsSet;
  411. }
  412. @end