123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //
- // GroupMemberViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/24.
- //
- #import "GroupMemberViewController.h"
- #import <SCIndexView.h>
- #import <UITableView+SCIndexView.h>
- #import "GroupMemberListCell.h"
- #import "GroupMemberModel.h"
- #import "KSChatConversationViewController.h"
- #import "KSUserDetailViewController.h"
- #import "UserInfoManager.h"
- @interface GroupMemberViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *sourceIndexArray;
- @property (nonatomic, strong) NSMutableArray *sourceArray;
- @end
- @implementation GroupMemberViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"群成员"];
- [self configUI];
- [self requestData];
- }
- - (void)resetSource {
- [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
- [self.sourceArray removeAllObjects];
- [self.dataArray removeAllObjects];
- self.sourceIndexArray = [NSMutableArray array];
- self.tableView.sc_indexViewDataSource = self.sourceIndexArray;
- [self.tableView reloadData];
- }
- - (void)requestData {
- [self.sourceArray removeAllObjects];
- [KSNetworkingManager imGroupMemberAllRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- for (NSDictionary *parm in sourceArray) {
- if ([parm isKindOfClass:[NSNull class]]) {
- continue;
- }
- GroupMemberModel *model = [[GroupMemberModel alloc] initWithDictionary:parm];
- [self.sourceArray addObject:model];
- }
- [self evaluateMessge];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
-
- }
- - (void)evaluateMessge {
- // 异步线程处理数据
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSMutableArray *sortArr = [NSMutableArray array];
- for (GroupMemberModel *model in self.sourceArray) {
- NSString *firstLetter = [NSString getFirstLetterFromString:model.nickname];
- model.firstLetter = firstLetter;
- if (![sortArr containsObject:firstLetter]) {
- [sortArr addObject:firstLetter];
- }
- }
- if (sortArr) {
- // 排序
- [sortArr sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
- return [obj1 compare:obj2 options:NSCaseInsensitiveSearch];
- }];
- }
- // 将#移动到最后
- NSMutableArray *tempArray = [NSMutableArray array];
- for (NSString *letterStr in sortArr) {
- if ([letterStr isEqualToString:@"#"]) {
- [tempArray addObject:@"#"];
- }
- }
-
- // 删除和添加操作在遍历完成后进行
- if (tempArray.count) {
-
- [sortArr removeObjectsInArray:tempArray];
- [sortArr addObjectsFromArray:tempArray];
- }
-
- for (NSString *sortStr in sortArr) {
- NSMutableArray *filterArray = [NSMutableArray array];
- for (GroupMemberModel *subModel in self.sourceArray) {
- if ([sortStr isEqualToString:subModel.firstLetter]) {
- [filterArray addObject:subModel];
- }
- }
- [self.dataArray addObject:filterArray];
- }
- self.sourceIndexArray = sortArr;
- // 主线程刷新
- dispatch_async(dispatch_get_main_queue(), ^{
- self.tableView.sc_indexViewDataSource = self.sourceIndexArray;
- [self.tableView reloadData];
- [self changePromptLabelState];
-
- });
- });
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.tableView];
- SCIndexViewConfiguration *indexConfiguration = [SCIndexViewConfiguration configuration];
- indexConfiguration.indexItemSelectedBackgroundColor = THEMECOLOR;
- indexConfiguration.indicatorBackgroundColor = THEMECOLOR;
- self.tableView.sc_indexViewConfiguration = indexConfiguration;
- self.tableView.sc_translucentForTableViewInNavigationBar = YES;
- }
- #pragma mark -- table data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (self.dataArray.count > section) {
- NSArray *filterArray = self.dataArray[section];
- return filterArray.count;
- }
- return 0;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return self.sourceIndexArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- GroupMemberListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupMemberListCell"];
- NSArray *filterArray = self.dataArray[indexPath.section];
- GroupMemberModel *model = filterArray[indexPath.row];
- MJWeakSelf;
- [cell configWithSource:model callback:^(NSString * _Nonnull targetId, NSString * _Nonnull name, BOOL showDetail) {
- if (showDetail) {
- [weakSelf showUserDetail:targetId];
- }
- else {
- [weakSelf chatUser:targetId];
- }
- }];
-
- return cell;
- }
- - (void)showUserDetail:(NSString *)targetId {
- if (USER_MANAGER.userInfo.customerService) {
- KSUserDetailViewController *ctrl = [[KSUserDetailViewController alloc] init];
- ctrl.imUserId = targetId;
- ctrl.fromSingleChat = NO;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (void)chatUser:(NSString *)targetId {
- if ([NSString isEmptyString:targetId]) {
- return;
- }
- TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
- model.userID = targetId;
- KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
- ctrl.conversation = model;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 30;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
- view.backgroundColor = [UIColor clearColor];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(24, 0, kScreenWidth - 48, 30)];
- label.textColor = HexRGB(0x999999);
- label.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
- [view addSubview:label];
- label.textAlignment = NSTextAlignmentLeft;
- NSString *titleStr = self.sourceIndexArray[section];
- label.text = titleStr;
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- #pragma mark ---- lazying
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = 80;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.backgroundColor = [UIColor clearColor];
- [_tableView registerNib:[UINib nibWithNibName:@"GroupMemberListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupMemberListCell"];
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
- bottomView.backgroundColor = [UIColor clearColor];
- _tableView.tableFooterView = bottomView;
- }
- return _tableView;
- }
- - (NSMutableArray *)sourceIndexArray {
- if (!_sourceIndexArray) {
- _sourceIndexArray = [NSMutableArray array];
- }
- return _sourceIndexArray;
- }
- - (NSMutableArray *)sourceArray {
- if (!_sourceArray) {
- _sourceArray = [NSMutableArray array];
- }
- return _sourceArray;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|