123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- //
- // GroupApplyViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/25.
- //
- #import "GroupApplyViewController.h"
- #import "GroupApplyMemberCell.h"
- #import "GroupApplyChooseCell.h"
- #import "UIButton+EnlargeEdge.h"
- #import "GroupApplyChooseAllCell.h"
- #import "ApplyBottomView.h"
- @interface GroupApplyViewController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) UIButton *rightButton;
- @property (nonatomic, assign) BOOL isChoose;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, assign) BOOL isChooseAll;
- @property (nonatomic, strong) ApplyBottomView *bottomView;
- @property (nonatomic, strong) NSMutableArray *chooseArray;
- @end
- @implementation GroupApplyViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self configUI];
- }
- - (void)configUI {
- [self allocTitle:@"入群申请"];
- [self.scrollView removeFromSuperview];
- _bottomView = [ApplyBottomView shareInstance];
- [self.view addSubview:self.bottomView];
- MJWeakSelf;
- [self.bottomView operationAction:^(BOOL isApprove) {
- [weakSelf operationAction:isApprove];
- }];
- [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
-
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.bottomView.mas_top).offset(10);
- }];
- [self createNavButton];
- [self resetParamenter];
- [self requestData];
- }
- - (void)operationAction:(BOOL)isApprove {
- // 判断是否选择
- NSMutableArray *memberIdArray = [self getChooseMemberArray];
- if (memberIdArray.count == 0) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择申请学员"];
- return;
- }
- NSString *audioIds = [memberIdArray componentsJoinedByString:@","];
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager imGroupMemberAuditRequest:KS_POST groupId:self.groupId auditStatus:isApprove auditIds:audioIds success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [LOADING_MANAGER KSShowMsg:@"操作成功" promptCompletion:^{
- if (self.isChooseAll) {
- [self backAction];
- }
- else {
- [self resetParamenter];
- [self requestData];
- }
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (NSMutableArray *)getChooseMemberArray {
- NSMutableArray *array = [NSMutableArray array];
- for (ApplyMemberModel *model in self.dataArray) {
- if (model.isChoose == YES) {
- [array addObject:[NSString stringWithFormat:@"%.0f",model.internalBaseClassIdentifier]];
- }
- }
- return array;
- }
- - (void)createNavButton {
- self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
- self.rightButton.frame = CGRectMake(0, 0, 80, 40);
- self.rightButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -40);
- [self.rightButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
- self.rightButton.titleLabel.font = [UIFont systemFontOfSize:16];
- [self.rightButton setTitleColor:HexRGB(0x000000) forState:UIControlStateNormal];
- [self.rightButton setTitle:@"批量操作" forState:UIControlStateNormal];
- [self.rightButton addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightButton];
- self.navigationItem.rightBarButtonItem = rightItem;
- }
- - (void)rightButtonAction {
- for (ApplyMemberModel *model in self.dataArray) {
- model.isChoose = NO;
- }
- self.isChooseAll = NO;
- self.isChoose = !self.isChoose;
- if (_isChoose) {
- [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(44);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin-30);
- }];
- [self.rightButton setTitle:@"完成" forState:UIControlStateNormal];
- }
- else {
- [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
- [self.rightButton setTitle:@"批量操作" forState:UIControlStateNormal];
- }
- [self.tableView reloadData];
- }
- - (void)resetParamenter {
- self.isChooseAll = NO;
- self.dataArray = [NSMutableArray array];
- [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
- [self.tableView reloadData];
- }
- - (void)requestData {
- [KSNetworkingManager imGroupMemberAuditListRequest: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) {
- ApplyMemberModel *model = [[ApplyMemberModel alloc] initWithDictionary:parm];
- [self.dataArray addObject:model];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- [self changePromptLabelState];
- } faliure:^(NSError * _Nonnull error) {
- if (self.networkAvaiable == NO) {
- [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
- }
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- [self changePromptLabelState];
- }];
- }
- #pragma mark ------ table data source
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- return 88.0f;
- }
- else {
- return 60.0f;
- }
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if (_isChoose) {
- return 2;
- }
- else {
- return 1;
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 0) {
- return self.dataArray.count;
- }
- else {
- return 1;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- ApplyMemberModel *model = self.dataArray[indexPath.row];
- if (_isChoose) {
- GroupApplyChooseCell *chooseCell = [tableView dequeueReusableCellWithIdentifier:@"GroupApplyChooseCell"];
- [chooseCell configWithSource:model];
- return chooseCell;
- }
- else {
- GroupApplyMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupApplyMemberCell"];
- [cell configWithSource:model];
- return cell;
-
- }
- }
- else {
- GroupApplyChooseAllCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupApplyChooseAllCell"];
- cell.isChooseAll = self.isChooseAll;
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 1) {
- self.isChooseAll = !self.isChooseAll;
- [self configAllChooseStatus];
- }
- else {
- if (_isChoose) {
- ApplyMemberModel *model = self.dataArray[indexPath.row];
- model.isChoose = !model.isChoose;
- [self refreshStatus];
- }
- }
- }
- - (void)refreshStatus {
- self.isChooseAll = YES;
- for (ApplyMemberModel *model in self.dataArray) {
- if (model.isChoose == NO) {
- self.isChooseAll = NO;
- break;
- }
- }
- [self.tableView reloadData];
- }
- - (void)configAllChooseStatus {
-
- BOOL isChoose = self.isChooseAll;
- for (ApplyMemberModel *model in self.dataArray) {
- model.isChoose = isChoose;
- }
- [self.tableView reloadData];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return [UIView new];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- return [UIView new];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- #pragma mark ------ lazying
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.showsVerticalScrollIndicator = NO;
- [_tableView registerNib:[UINib nibWithNibName:@"GroupApplyMemberCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupApplyMemberCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"GroupApplyChooseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupApplyChooseCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"GroupApplyChooseAllCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupApplyChooseAllCell"];
-
- }
- return _tableView;
- }
- /*
- #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
|