JXGroupHelperListVC.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // JXGroupHelperListVC.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/5/28.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXGroupHelperListVC.h"
  9. #import "JXAutoReplyAideVC.h"
  10. #import "JXHelperModel.h"
  11. #import "JXGroupHelperCell.h"
  12. @interface JXGroupHelperListVC () <JXGroupHelperCellDelegate>
  13. @property (nonatomic, strong) NSMutableArray *array;
  14. @property (nonatomic, strong) NSMutableArray *groupHelperArr;
  15. @property (nonatomic, assign) NSInteger cellIndex;
  16. @end
  17. @implementation JXGroupHelperListVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.heightHeader = JX_SCREEN_TOP;
  21. self.heightFooter = 0;
  22. self.isGotoBack = YES;
  23. self.isShowFooterPull = NO;
  24. self.isShowHeaderPull = NO;
  25. [self createHeadAndFoot];
  26. self.title = Localized(@"JX_GroupAssistants");
  27. _groupHelperArr = [NSMutableArray array];
  28. _array = [NSMutableArray array];
  29. [g_server queryGroupHelper:self.roomId toView:self];
  30. [g_notify addObserver:self selector:@selector(updateAddBtnStatus:) name:kUpdateChatVCGroupHelperData object:nil];
  31. }
  32. - (void)viewWillAppear:(BOOL)animated {
  33. [super viewWillAppear:animated];
  34. }
  35. - (void)updateAddBtnStatus:(NSNotification *)noti {
  36. NSDictionary *dict = noti.object;
  37. JXGroupHelperCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.cellIndex inSection:0]];
  38. if ([[dict objectForKey:@"delete"] intValue] == 1) {
  39. cell.addBtn.hidden = NO;
  40. }else {
  41. cell.addBtn.hidden = YES;
  42. }
  43. // [self.tableView reloadData];
  44. }
  45. - (void)dealloc {
  46. [g_notify removeObserver:self];
  47. }
  48. - (void)getServerData {
  49. [g_server getHelperList:(int)_page pageSize:20 toView:self];
  50. }
  51. //顶部刷新获取数据
  52. -(void)scrollToPageUp{
  53. _page = 0;
  54. [self getServerData];
  55. }
  56. -(void)scrollToPageDown{
  57. [self getServerData];
  58. }
  59. #pragma mark ---------tableView协议----------------
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  61. {
  62. NSString * identifier = [NSString stringWithFormat:@"JXGroupHelperCell_%ld",indexPath.row];
  63. JXGroupHelperCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  64. if (!cell) {
  65. cell = [[JXGroupHelperCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  66. JXHelperModel *model;
  67. if (_array.count > 0) {
  68. model = [_array objectAtIndex:indexPath.row];
  69. }
  70. cell.tag = indexPath.row;
  71. cell.delegate = self;
  72. cell.groupHelperArr = _groupHelperArr;
  73. [cell setDataWithModel:model];
  74. }
  75. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  76. [self doAutoScroll:indexPath];
  77. return cell;
  78. }
  79. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  80. {
  81. return 1;
  82. }
  83. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  84. {
  85. return _array.count;
  86. }
  87. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  88. {
  89. return 64;
  90. }
  91. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  92. self.cellIndex = indexPath.row;
  93. JXAutoReplyAideVC *vc = [[JXAutoReplyAideVC alloc] init];
  94. vc.model = [_array objectAtIndex:indexPath.row];
  95. vc.roomId = self.roomId;
  96. vc.roomJid = self.roomJid;
  97. [g_navigation pushViewController:vc animated:YES];
  98. }
  99. - (void)groupHelperCell:(JXGroupHelperCell *)cell clickAddBtnWithIndex:(NSInteger)index {
  100. self.cellIndex = index;
  101. JXHelperModel *model = [_array objectAtIndex:index];
  102. [g_server addGroupHelper:self.roomId roomJid:self.roomJid helperId:model.helperId toView:self];
  103. }
  104. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  105. [_wait stop];
  106. if( [aDownload.action isEqualToString:act_getHelperList]){
  107. [self stopLoading];
  108. if (array1.count < 20) {
  109. _footer.hidden = YES;
  110. }
  111. NSMutableArray *arr = [[NSMutableArray alloc] init];
  112. if(_page == 0){
  113. [_array removeAllObjects];
  114. for (int i = 0; i < array1.count; i++) {
  115. JXHelperModel *model = [[JXHelperModel alloc] init];
  116. [model getDataWithDict:array1[i]];
  117. [arr addObject:model];
  118. }
  119. [_array addObjectsFromArray:arr];
  120. }else{
  121. if([array1 count]>0){
  122. for (int i = 0; i < array1.count; i++) {
  123. JXHelperModel *model = [[JXHelperModel alloc] init];
  124. [model getDataWithDict:array1[i]];
  125. [arr addObject:model];
  126. }
  127. [_array addObjectsFromArray:arr];
  128. }
  129. }
  130. _page ++;
  131. [self.tableView reloadData];
  132. }
  133. // 获取群助手
  134. if ([aDownload.action isEqualToString:act_queryGroupHelper]) {
  135. NSMutableArray *arr = [[NSMutableArray alloc] init];
  136. for (int i = 0; i < array1.count; i++) {
  137. JXGroupHeplerModel *model = [[JXGroupHeplerModel alloc] init];
  138. [model getDataWithDict:array1[i]];
  139. [arr addObject:model.helperId];
  140. }
  141. _groupHelperArr = arr;
  142. [self getServerData];
  143. }
  144. if ([aDownload.action isEqualToString:act_addGroupHelper]) {
  145. [g_server showMsg:Localized(@"JX_AddSuccess")];
  146. JXGroupHelperCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.cellIndex inSection:0]];
  147. cell.addBtn.hidden = YES;
  148. [g_notify postNotificationName:kUpdateChatVCGroupHelperData object:nil];
  149. }
  150. }
  151. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  152. [_wait stop];
  153. return show_error;
  154. }
  155. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  156. [_wait stop];
  157. return show_error;
  158. }
  159. -(void) didServerConnectStart:(JXConnection*)aDownload{
  160. [_wait start];
  161. }
  162. @end