JXSelectGroupSendVC.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // JXSelectGroupSendVC.m
  3. // shiku_im
  4. //
  5. // Created by IMAC on 2019/8/14.
  6. // Copyright © 2019 Reese. All rights reserved.
  7. //
  8. #import "JXSelectGroupSendVC.h"
  9. #import "QCheckBox.h"
  10. #import "JXCell.h"
  11. @interface JXSelectGroupSendVC ()
  12. @property (nonatomic,strong)NSMutableArray *groupArray;
  13. @property (nonatomic,strong)NSMutableArray *checkBoxArr;
  14. @end
  15. @implementation JXSelectGroupSendVC
  16. - (instancetype)initWithTitle:(NSString *)title{
  17. self = [super init];
  18. if (self) {
  19. self.titleString = title;
  20. }
  21. return self;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.title = self.titleString;
  26. self.heightHeader = JX_SCREEN_TOP;
  27. self.heightFooter = 0;
  28. self.isGotoBack = YES;
  29. self.isShowFooterPull = NO;
  30. self.isShowHeaderPull = NO;
  31. [self createHeadAndFoot];
  32. UIButton *allSelect = [UIButton buttonWithType:UIButtonTypeSystem];
  33. [allSelect setTitle:Localized(@"JX_Confirm") forState:UIControlStateNormal];
  34. if (THESIMPLESTYLE) {
  35. [allSelect setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  36. }else{
  37. [allSelect setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  38. }
  39. allSelect.tintColor = [UIColor clearColor];
  40. allSelect.frame = CGRectMake(JX_SCREEN_WIDTH - 70, JX_SCREEN_TOP - 34, 60, 24);
  41. [allSelect addTarget:self action:@selector(confirmBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  42. [self.tableHeader addSubview:allSelect];
  43. _checkBoxArr = [NSMutableArray array];
  44. //群组获取
  45. if ([self.titleString isEqualToString:SELECTGroup]) {
  46. self.groupArray = [NSMutableArray arrayWithArray:[[JXUserObject sharedInstance] fetchAllRoomsFromLocal]];
  47. }
  48. //通讯录好友获取
  49. if ([self.titleString isEqualToString:SELECTMaillist]) {
  50. NSMutableArray *mailListArr = [[JXAddressBook sharedInstance] fetchAllAddressBook];
  51. NSMutableArray *allUserArr = [[JXUserObject sharedInstance] fetchAllUserFromLocal];
  52. NSDictionary *phoneNumDict = [[JXAddressBook sharedInstance] getMyAddressBook];
  53. self.groupArray = [NSMutableArray array];
  54. for (JXAddressBook *maillist in mailListArr) {
  55. if (phoneNumDict[maillist.toTelephone]) {
  56. for (JXUserObject *user in allUserArr) {
  57. if ([maillist.toUserId isEqualToString:user.userId]) {
  58. [self.groupArray addObject:user];
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. - (void)confirmBtnAction:(UIButton *)btn{
  66. if ([self.delegate respondsToSelector:@selector(selectVC:selectArray:)]) {
  67. [self.delegate selectVC:self selectArray:_seletedArray];
  68. }
  69. [self actionQuit];
  70. }
  71. - (void)didSelectedCheckBox:(QCheckBox *)checkbox checked:(BOOL)checked{
  72. if ([self.titleString isEqualToString:SELECTGroup]) {
  73. JXUserObject *groupObj = _groupArray[checkbox.tag - 10086];
  74. if(checked){
  75. [_seletedArray addObject:groupObj];
  76. }
  77. else{
  78. NSInteger index = -1;
  79. for (NSInteger i = 0; i < _seletedArray.count; i ++) {
  80. JXUserObject *selGroup = _seletedArray[i];
  81. if ([selGroup.roomId isEqualToString:groupObj.roomId]) {
  82. index = i;
  83. break;
  84. }
  85. }
  86. if (index >= 0) {
  87. [_seletedArray removeObjectAtIndex:index];
  88. }
  89. }
  90. }
  91. if ([self.titleString isEqualToString:SELECTMaillist]) {
  92. JXUserObject *groupObj = _groupArray[checkbox.tag - 10086];
  93. if(checked){
  94. [_seletedArray addObject:groupObj];
  95. }
  96. else{
  97. NSInteger index = -1;
  98. for (NSInteger i = 0; i < _seletedArray.count; i ++) {
  99. JXUserObject *selGroup = _seletedArray[i];
  100. if ([selGroup.userId isEqualToString:groupObj.userId]) {
  101. index = i;
  102. break;
  103. }
  104. }
  105. if (index >= 0) {
  106. [_seletedArray removeObjectAtIndex:index];
  107. }
  108. }
  109. }
  110. }
  111. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  112. return _groupArray.count;
  113. }
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  115. JXUserObject *user = _groupArray[indexPath.row];
  116. NSString *userId = user.userId;
  117. NSString *userName = user.userNickname;
  118. JXCell *cell = nil;
  119. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SendCell"];
  120. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  121. QCheckBox* btn = [[QCheckBox alloc] initWithDelegate:self];
  122. btn.frame = CGRectMake(20, 15, 25, 25);
  123. [cell addSubview:btn];
  124. cell.title = userName;
  125. cell.userId = userId;
  126. cell.isSmall = YES;
  127. if (user.roomId) {
  128. [cell headImageViewImageWithUserId:userId roomId:user.roomId];
  129. }else{
  130. [cell headImageViewImageWithUserId:nil roomId:nil];
  131. }
  132. cell.headImageView.frame = CGRectMake(cell.headImageView.frame.origin.x + 50, cell.headImageView.frame.origin.y, cell.headImageView.frame.size.width, cell.headImageView.frame.size.height);
  133. cell.lbTitle.frame = CGRectMake(cell.lbTitle.frame.origin.x + 50, cell.lbTitle.frame.origin.y, cell.lbTitle.frame.size.width, cell.lbTitle.frame.size.height);
  134. cell.lineView.frame = CGRectMake(cell.lbTitle.frame.origin.x, cell.lineView.frame.origin.y, JX_SCREEN_WIDTH-cell.lbTitle.frame.origin.x, cell.lineView.frame.size.height);
  135. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  136. BOOL flag = NO;
  137. for (NSInteger i = 0; i < _seletedArray.count; i ++) {
  138. JXUserObject *userObj = _seletedArray[i];
  139. if ([userObj.userId isEqualToString:userId]) {
  140. flag = YES;
  141. break;
  142. }
  143. }
  144. btn.tag = 10086 + indexPath.row;
  145. btn.selected = flag;
  146. [_checkBoxArr addObject:btn];
  147. return cell;
  148. }
  149. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  150. {
  151. return 54;
  152. }
  153. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  154. JXCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  155. QCheckBox *checkBox = [cell viewWithTag:10086 + indexPath.row];
  156. checkBox.selected = !checkBox.selected;
  157. [self didSelectedCheckBox:checkBox checked:checkBox.selected];
  158. }
  159. @end