// // GroupSynopsisVC.m // smartRhino // // Created by niuzhen on 2020/6/15. // Copyright © 2020 tederen. All rights reserved. // #import "GroupSynopsisVC.h" #import "GroupSynopsisCell.h" #import "TDGroupInfoListModel.h" #import "GroupVerifyVC.h" #import "TDGroupInfoListVC.h" #import "GroupSynopsisUserVC.h" #import "GroupInfoVC.h" @interface GroupSynopsisVC () @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (weak, nonatomic) IBOutlet UIButton *joinBtn; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomContant; @property (strong,nonatomic) NSMutableArray *dataArray; @property (strong,nonatomic) TDGroupInfoListModel *model; @property (assign,nonatomic) BOOL show; @end @implementation GroupSynopsisVC +(GroupSynopsisVC *)initGroupSynopsisVC{ GroupSynopsisVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSynopsisVC"]; return controller; } - (NSMutableArray *)dataArray { if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.tableView.delegate = self; self.tableView.dataSource = self; [self getData]; if (self.GroupModel.IsApply) { [self setJoinStatus:1]; }else{ if (self.GroupModel.IsAdmin) { [self setJoinStatus:2]; }else{ [self setJoinStatus:3]; } } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData) name:GROUPINFOUPDATE object:nil]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)setJoinStatus:(NSInteger)index { switch (index) { case 1: { [self.joinBtn setTitle:@"申请加入已提交,请等候小组管理员批准…" forState:UIControlStateNormal]; [self.joinBtn setTitleColor:UIColorHex(0x878787) forState:UIControlStateNormal]; self.joinBtn.backgroundColor = UIColorHex(0xE5E5E5); self.joinBtn.enabled = NO; } break; case 2: { [self.joinBtn setTitle:@"加入" forState:UIControlStateNormal]; WS(weakSelf); [self.joinBtn setAction:^{ GroupVerifyVC * vc = [GroupVerifyVC initGroupVerifyVC]; vc.Id = weakSelf.GroupModel.Id; vc.SendBlock = ^{ dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf showMessage]; }); if (weakSelf.SendBlock) { weakSelf.SendBlock(); } [weakSelf setJoinStatus:1]; }; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; } break; default: { [self.joinBtn setTitle:@"加入" forState:UIControlStateNormal]; WS(weakSelf); [self.joinBtn setAction:^{ NSDictionary * paraDict = @{@"GroupId":@(self.GroupModel.Id), @"UserIds":@[@([AppUserModel sharedAppUserModel].Id)], @"UserId":@([AppUserModel sharedAppUserModel].Id), @"SourceType":@(1),///申请 }; [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Insert_User) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) { weakSelf.joinBtn.hidden = YES; if (weakSelf.JoinBlock) { weakSelf.JoinBlock(); } TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.GroupId = weakSelf.GroupModel.Id; vc.titleStr = weakSelf.GroupModel.Name; [weakSelf.navigationController pushViewController:vc animated:YES]; } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; }]; } break; } } - (void)showMessage { WS(weakSelf); UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您的申请已提交,请耐心等候!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [noOk setValue:UIColorHex(0x0F7FD9) forKey:@"_titleTextColor"]; [alertVC addAction:noOk]; [weakSelf presentViewController:alertVC animated:YES completion:nil]; } - (void)getData { WS(weakSelf); [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Detail) parameters:@{@"GroupId":@(self.GroupModel.Id)} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSLog(@"%@",responseObject); weakSelf.model = [TDGroupInfoListModel modelWithDictionary:responseObject]; [weakSelf.dataArray addObjectsFromArray:weakSelf.model.GroupUserListResult]; dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.model.IsUser) { weakSelf.bottomContant.constant = 0.f; weakSelf.joinBtn.hidden = YES; } [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { }]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 4; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WS(weakSelf); switch (indexPath.row) { case 0: { GroupSynopsisCell * cell = [GroupSynopsisCell configCell3:tableView indexPath:indexPath]; [cell setDataModel:self.model isShow:self.show]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { GroupInfoVC * vc = [GroupInfoVC initGroupInfoVC]; vc.Id = weakSelf.GroupModel.Id; vc.GroupName = weakSelf.GroupModel.Name; vc.IsOwner = weakSelf.model.IsCreator; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [cell.contentL addGestureRecognizer:tap]; cell.contentL.userInteractionEnabled = YES; cell.ShowBlcok = ^(BOOL show) { weakSelf.show = show; dispatch_async(dispatch_get_main_queue(), ^{ [tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic]; }); }; return cell; } break; case 1: { GroupSynopsisCell * cell = [GroupSynopsisCell configCell0:tableView indexPath:indexPath]; [cell setData:self.model]; cell.ClickMoreBlcok = ^{ NSLog(@"11111"); }; return cell; } break; case 2: { GroupSynopsisCell * cell = [GroupSynopsisCell configCell1:tableView indexPath:indexPath]; [cell setUserCount:self.model.MainMemberCount]; return cell; } break; default: { GroupSynopsisCell * cell = [GroupSynopsisCell configCell2:tableView indexPath:indexPath]; [cell setGroupLabel:self.model.LabelName]; return cell; } break; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; switch (indexPath.row) { case 2: { if (self.model.MainMemberListResult.count > 0) { GroupSynopsisUserVC * vc = [GroupSynopsisUserVC initGroupSynopsisUserVC]; vc.dataArray = self.model.MainMemberListResult; [self.navigationController pushViewController:vc animated:YES]; } } break; default: { } break; } } @end