// // TDGroupRoleVC.m // smartRhino // // Created by niuzhen on 2020/5/8. // Copyright © 2020 tederen. All rights reserved. // #import "TDGroupRoleVC.h" #import "TDGroupInfoDetailCell.h" #import "MOFSPickerManager.h" #import "GroupSquareModel.h" @interface TDGroupRoleVC () @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic, strong) NSMutableArray * dataArray; @property (nonatomic, strong) NSMutableArray * showArray; @end @implementation TDGroupRoleVC +(TDGroupRoleVC *)initTDGroupRoleVC{ TDGroupRoleVC *controller = [StoryboardManager.shared.TDGroup instantiateViewControllerWithIdentifier:@"TDGroupRoleVC"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = UIColorHex(0xF1F1F1); self.tableView.delegate = self; self.tableView.dataSource = self; [self getData]; } - (void)getData { WS(weakSelf); self.dataArray = [NSMutableArray array]; self.showArray = [NSMutableArray array]; SHOWLOADING NSString * url = [NSString stringWithFormat:@"%@%@",Host(API_APP_GROUP_Group_Category),@"0"]; [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"%@",responseObject); REMOVESHOW if ([responseObject isKindOfClass:[NSArray class]]) { for (NSDictionary * dict in responseObject) { GroupSquareModel * model = [GroupSquareModel modelWithDictionary:dict]; [weakSelf.dataArray addObject:model]; [weakSelf.showArray addObject:model.PiazzaName]; } } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { REMOVESHOW }]; } - (void)showType { WS(weakSelf); [MOFSPickerManager shareManger].pickView.toolBar.cancelBar.textColor = UIColorHex(#888888); [MOFSPickerManager shareManger].pickView.toolBar.commitBar.textColor = UIColorHex(#3979D3); MOFSPickerManager *manager = [[MOFSPickerManager alloc] init]; [manager showPickerViewWithDataArray:self.showArray tag:2 title:nil cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *string) { for (GroupSquareModel * model in weakSelf.dataArray) { if ([model.PiazzaName isEqualToString:string]) { weakSelf.model.CategroyName = string; [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update) parameters:@{@"GroupCategroyId":@(model.Id),@"Id":@(weakSelf.model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) { dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; } } } cancelBlock:^{ }]; } #pragma mark - UITableViewDelegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 4; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 65.f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WS(weakSelf); switch (indexPath.row) { case 0: { TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell2:tableView indexPath:indexPath]; cell.cell2TitleL.text = @"加入小组需要管理员同意"; [cell.cell2Switch setBlockForControlEvents:UIControlEventValueChanged block:^(id _Nonnull sender) { [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update) parameters:@{@"IsAdmin":cell.cell2Switch.isOn ? @(1) : @(2),@"Id":@(weakSelf.model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) { if (weakSelf.refreshBlock) { weakSelf.refreshBlock(); } } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; }]; [cell.cell2Switch setOn:self.model.IsAdmin]; return cell; } break; case 1: { TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell2:tableView indexPath:indexPath]; cell.cell2TitleL.text = @"只允许管理员发话题(禁言)"; [cell.cell2Switch setBlockForControlEvents:UIControlEventValueChanged block:^(id _Nonnull sender) { [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update) parameters:@{@"IsWords":cell.cell2Switch.isOn ? @"1" : @"2",@"Id":@(weakSelf.model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) { if (weakSelf.refreshBlock) { weakSelf.refreshBlock(); } } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; }]; [cell.cell2Switch setOn:self.model.IsWords]; return cell; } break; case 2: { TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell2:tableView indexPath:indexPath]; cell.cell2TitleL.text = @"小组广场可见"; [cell.cell2Switch setBlockForControlEvents:UIControlEventValueChanged block:^(id _Nonnull sender) { [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update) parameters:@{@"IsShow":cell.cell2Switch.isOn ? @"1" : @"2",@"Id":@(weakSelf.model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) { if (weakSelf.refreshBlock) { weakSelf.refreshBlock(); } } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; }]; [cell.cell2Switch setOn:self.model.IsShow]; return cell; } break; default: { TDGroupInfoDetailCell *cell = [TDGroupInfoDetailCell configCell1:tableView indexPath:indexPath]; cell.cell1TitleL.text = @"小组类型"; cell.subTitleL.hidden = NO; cell.subTitleL.text = self.model.CategroyName; return cell; } break; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 3) { if (self.showArray.count > 0) { [self showType]; } } } @end