JXChatLogMoveSelectVC.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // JXChatLogMoveSelectVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/6/5.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXChatLogMoveSelectVC.h"
  9. #import "JXCell.h"
  10. #import "QCheckBox.h"
  11. #import "JXChatLogQRCodeVC.h"
  12. @interface JXChatLogMoveSelectVC ()
  13. @property (nonatomic, strong) NSMutableArray *array;
  14. @property (nonatomic, strong) NSSet * existSet;
  15. @property (nonatomic, strong) NSMutableArray *selUserIdArray;
  16. @property (nonatomic, strong) NSMutableArray *selUserNameArray;
  17. @property (nonatomic, strong) UIButton *nextBtn;
  18. @property (nonatomic, strong) NSMutableArray *checkBoxArr;
  19. @property (nonatomic, strong) UILabel *countLabel;
  20. @end
  21. @implementation JXChatLogMoveSelectVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. self.heightHeader = JX_SCREEN_TOP;
  26. self.heightFooter = JX_SCREEN_BOTTOM;
  27. self.isGotoBack = YES;
  28. //self.view.frame = g_window.bounds;
  29. self.isShowFooterPull = NO;
  30. [self createHeadAndFoot];
  31. _array = [NSMutableArray array];
  32. _selUserIdArray = [NSMutableArray array];
  33. _selUserNameArray = [NSMutableArray array];
  34. _checkBoxArr = [NSMutableArray array];
  35. self.title = Localized(@"JX_ChooseAChat");
  36. UIButton *allSelect = [UIButton buttonWithType:UIButtonTypeSystem];
  37. [allSelect setTitle:Localized(@"JX_CheckAll") forState:UIControlStateNormal];
  38. [allSelect setTitle:Localized(@"JX_Cencal") forState:UIControlStateSelected];
  39. [allSelect setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  40. [allSelect setTitleColor:THEMECOLOR forState:UIControlStateSelected];
  41. allSelect.tintColor = [UIColor clearColor];
  42. allSelect.titleLabel.font = [UIFont systemFontOfSize:14.0];
  43. allSelect.frame = CGRectMake(JX_SCREEN_WIDTH-27-15, JX_SCREEN_TOP-15-14, 30, 14);
  44. [allSelect addTarget:self action:@selector(allSelect:) forControlEvents:UIControlEventTouchUpInside];
  45. [self.tableHeader addSubview:allSelect];
  46. self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 100, 14)];
  47. self.countLabel.textColor = THEMECOLOR;
  48. self.countLabel.font = SYSFONT(14);
  49. self.countLabel.text = @"迁移数量(0)";
  50. [self.tableFooter addSubview:self.countLabel];
  51. self.nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 60-15, 9, 60, 27)];
  52. self.nextBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
  53. self.nextBtn.backgroundColor = THEMECOLOR;
  54. self.nextBtn.layer.masksToBounds = YES;
  55. self.nextBtn.layer.cornerRadius = 2.f;
  56. [self.nextBtn setTitle:Localized(@"JX_Confirm") forState:UIControlStateNormal];
  57. [self.nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  58. [self.nextBtn addTarget:self action:@selector(nextBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  59. [self.tableFooter addSubview:self.nextBtn];
  60. [self getArrayData];
  61. }
  62. - (void)allSelect:(UIButton *)btn {
  63. btn.selected = !btn.selected;
  64. [_selUserIdArray removeAllObjects];
  65. [_selUserNameArray removeAllObjects];
  66. if (btn.selected) {
  67. for (JXMsgAndUserObject *userObj in _array) {
  68. [_selUserIdArray addObject:userObj.user.userId];
  69. [_selUserNameArray addObject:userObj.user.userNickname];
  70. }
  71. }
  72. [_checkBoxArr removeAllObjects];
  73. [self showCountLabelText];
  74. [self.tableView reloadData];
  75. }
  76. - (void)nextBtnAction:(UIButton *)btn {
  77. if (!_selUserIdArray.count) {
  78. [g_App showAlert:Localized(@"JX_SelectGroupUsers")];
  79. return;
  80. }
  81. JXChatLogQRCodeVC *vc = [[JXChatLogQRCodeVC alloc] init];
  82. vc.selUserIdArray = [_selUserIdArray copy];
  83. [g_navigation pushViewController:vc animated:YES];
  84. [self actionQuit];
  85. }
  86. - (void)didSelectedCheckBox:(QCheckBox *)checkbox checked:(BOOL)checked{
  87. JXMsgAndUserObject *userObj = _array[checkbox.tag % 10000];
  88. if(checked){
  89. BOOL flag = NO;
  90. for (NSInteger i = 0; i < _selUserIdArray.count; i ++) {
  91. NSString *selUserId = _selUserIdArray[i];
  92. if ([selUserId isEqualToString:userObj.user.userId]) {
  93. flag = YES;
  94. return;
  95. }
  96. }
  97. [_selUserIdArray addObject:userObj.user.userId];
  98. [_selUserNameArray addObject:userObj.user.userNickname];
  99. }
  100. else{
  101. [_selUserIdArray removeObject:userObj.user.userId];
  102. [_selUserNameArray removeObject:userObj.user.userNickname];
  103. }
  104. [self showCountLabelText];
  105. }
  106. -(void)getArrayData{
  107. _array=[[JXMessageObject sharedInstance] fetchRecentChat];
  108. }
  109. #pragma mark ---------tableView协议----------------
  110. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  111. {
  112. return _array.count;
  113. }
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  115. {
  116. JXCell *cell=nil;
  117. NSString* cellName = [NSString stringWithFormat:@"selVC_%d",(int)indexPath.row];
  118. // cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  119. // QCheckBox* btn;
  120. // if (!cell) {
  121. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  122. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  123. QCheckBox* btn = [[QCheckBox alloc] initWithDelegate:self];
  124. btn.frame = CGRectMake(13, 18.5, 22, 22);
  125. [cell addSubview:btn];
  126. // }
  127. JXMsgAndUserObject *userObj=_array[indexPath.row];
  128. btn.tag = indexPath.section * 10000 + indexPath.row;
  129. BOOL flag = NO;
  130. for (NSInteger i = 0; i < _selUserIdArray.count; i ++) {
  131. NSString *selUserId = _selUserIdArray [i];
  132. if ([userObj.user.userId isEqualToString:selUserId]) {
  133. flag = YES;
  134. break;
  135. }
  136. }
  137. btn.checked = flag;
  138. [_checkBoxArr addObject:btn];
  139. // cell = [[JXCell alloc] init];
  140. [_table addToPool:cell];
  141. cell.title = userObj.user.userNickname;
  142. // cell.subtitle = user.userId;
  143. cell.bottomTitle = [TimeUtil formatDate:userObj.user.timeCreate format:@"MM-dd HH:mm"];
  144. cell.userId = userObj.user.userId;
  145. cell.isSmall = YES;
  146. [cell headImageViewImageWithUserId:nil roomId:nil];
  147. CGFloat headX = 13*2+22;
  148. cell.headImageView.frame = CGRectMake(headX,9.5,40,40);
  149. cell.headImageView.layer.cornerRadius = cell.headImageView.frame.size.width / 2;
  150. cell.lbTitle.frame = CGRectMake(CGRectGetMaxX(cell.headImageView.frame)+15, 21.5, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(cell.headImageView.frame)-14, 16);
  151. cell.lbSubTitle.frame = CGRectMake(CGRectGetMaxX(cell.headImageView.frame)+15, cell.lbSubTitle.frame.origin.y, JX_SCREEN_WIDTH - 55 -CGRectGetMaxX(cell.headImageView.frame)-14, cell.lbSubTitle.frame.size.height);
  152. cell.lineView.frame = CGRectMake(CGRectGetMaxX(cell.headImageView.frame)+15,59-LINE_WH,JX_SCREEN_WIDTH,LINE_WH);
  153. // 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);
  154. // 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);
  155. return cell;
  156. }
  157. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  158. {
  159. QCheckBox *checkBox = nil;
  160. for (NSInteger i = 0; i < _checkBoxArr.count; i ++) {
  161. QCheckBox *btn = _checkBoxArr[i];
  162. if (btn.tag / 10000 == indexPath.section && btn.tag % 10000 == indexPath.row) {
  163. checkBox = btn;
  164. break;
  165. }
  166. }
  167. checkBox.selected = !checkBox.selected;
  168. [self didSelectedCheckBox:checkBox checked:checkBox.selected];
  169. [self showCountLabelText];
  170. }
  171. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  172. {
  173. return 59;
  174. }
  175. - (void)showCountLabelText {
  176. self.countLabel.text = [NSString stringWithFormat:@"迁移数量(%ld)",_selUserIdArray.count];
  177. }
  178. /*
  179. #pragma mark - Navigation
  180. // In a storyboard-based application, you will often want to do a little preparation before navigation
  181. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  182. // Get the new view controller using [segue destinationViewController].
  183. // Pass the selected object to the new view controller.
  184. }
  185. */
  186. @end