GroupApplyViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // GroupApplyViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/25.
  6. //
  7. #import "GroupApplyViewController.h"
  8. #import "GroupApplyMemberCell.h"
  9. #import "GroupApplyChooseCell.h"
  10. #import "UIButton+EnlargeEdge.h"
  11. #import "GroupApplyChooseAllCell.h"
  12. #import "ApplyBottomView.h"
  13. @interface GroupApplyViewController ()<UITableViewDelegate, UITableViewDataSource>
  14. @property (nonatomic, strong) UIButton *rightButton;
  15. @property (nonatomic, assign) BOOL isChoose;
  16. @property (nonatomic, strong) UITableView *tableView;
  17. @property (nonatomic, assign) BOOL isChooseAll;
  18. @property (nonatomic, strong) ApplyBottomView *bottomView;
  19. @property (nonatomic, strong) NSMutableArray *chooseArray;
  20. @end
  21. @implementation GroupApplyViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self configUI];
  26. }
  27. - (void)configUI {
  28. [self allocTitle:@"入群申请"];
  29. [self.scrollView removeFromSuperview];
  30. _bottomView = [ApplyBottomView shareInstance];
  31. [self.view addSubview:self.bottomView];
  32. MJWeakSelf;
  33. [self.bottomView operationAction:^(BOOL isApprove) {
  34. [weakSelf operationAction:isApprove];
  35. }];
  36. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.right.mas_equalTo(self.view);
  38. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  39. make.height.mas_equalTo(CGFLOAT_MIN);
  40. }];
  41. [self.view addSubview:self.tableView];
  42. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.right.top.mas_equalTo(self.view);
  44. make.bottom.mas_equalTo(self.bottomView.mas_top).offset(10);
  45. }];
  46. [self createNavButton];
  47. [self resetParamenter];
  48. [self requestData];
  49. }
  50. - (void)operationAction:(BOOL)isApprove {
  51. // 判断是否选择
  52. NSMutableArray *memberIdArray = [self getChooseMemberArray];
  53. if (memberIdArray.count == 0) {
  54. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择申请学员"];
  55. return;
  56. }
  57. NSString *audioIds = [memberIdArray componentsJoinedByString:@","];
  58. [LOADING_MANAGER showHUD];
  59. [KSNetworkingManager imGroupMemberAuditRequest:KS_POST groupId:self.groupId auditStatus:isApprove auditIds:audioIds success:^(NSDictionary * _Nonnull dic) {
  60. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  61. [LOADING_MANAGER KSShowMsg:@"操作成功" promptCompletion:^{
  62. if (self.isChooseAll) {
  63. [self backAction];
  64. }
  65. else {
  66. [self resetParamenter];
  67. [self requestData];
  68. }
  69. }];
  70. }
  71. else {
  72. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  73. }
  74. } faliure:^(NSError * _Nonnull error) {
  75. }];
  76. }
  77. - (NSMutableArray *)getChooseMemberArray {
  78. NSMutableArray *array = [NSMutableArray array];
  79. for (ApplyMemberModel *model in self.dataArray) {
  80. if (model.isChoose == YES) {
  81. [array addObject:[NSString stringWithFormat:@"%.0f",model.internalBaseClassIdentifier]];
  82. }
  83. }
  84. return array;
  85. }
  86. - (void)createNavButton {
  87. self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  88. self.rightButton.frame = CGRectMake(0, 0, 80, 40);
  89. self.rightButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -40);
  90. [self.rightButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
  91. self.rightButton.titleLabel.font = [UIFont systemFontOfSize:16];
  92. [self.rightButton setTitleColor:HexRGB(0x000000) forState:UIControlStateNormal];
  93. [self.rightButton setTitle:@"批量操作" forState:UIControlStateNormal];
  94. [self.rightButton addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
  95. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightButton];
  96. self.navigationItem.rightBarButtonItem = rightItem;
  97. }
  98. - (void)rightButtonAction {
  99. for (ApplyMemberModel *model in self.dataArray) {
  100. model.isChoose = NO;
  101. }
  102. self.isChooseAll = NO;
  103. self.isChoose = !self.isChoose;
  104. if (_isChoose) {
  105. [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
  106. make.height.mas_equalTo(44);
  107. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin-30);
  108. }];
  109. [self.rightButton setTitle:@"完成" forState:UIControlStateNormal];
  110. }
  111. else {
  112. [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
  113. make.height.mas_equalTo(CGFLOAT_MIN);
  114. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  115. }];
  116. [self.rightButton setTitle:@"批量操作" forState:UIControlStateNormal];
  117. }
  118. [self.tableView reloadData];
  119. }
  120. - (void)resetParamenter {
  121. self.isChooseAll = NO;
  122. self.dataArray = [NSMutableArray array];
  123. [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
  124. [self.tableView reloadData];
  125. }
  126. - (void)requestData {
  127. [KSNetworkingManager imGroupMemberAuditListRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  128. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  129. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  130. for (NSDictionary *parm in sourceArray) {
  131. ApplyMemberModel *model = [[ApplyMemberModel alloc] initWithDictionary:parm];
  132. [self.dataArray addObject:model];
  133. }
  134. }
  135. else {
  136. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  137. }
  138. [self.tableView reloadData];
  139. [self changePromptLabelState];
  140. } faliure:^(NSError * _Nonnull error) {
  141. if (self.networkAvaiable == NO) {
  142. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  143. }
  144. [self.dataArray removeAllObjects];
  145. [self.tableView reloadData];
  146. [self changePromptLabelState];
  147. }];
  148. }
  149. #pragma mark ------ table data source
  150. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  151. if (indexPath.section == 0) {
  152. return 88.0f;
  153. }
  154. else {
  155. return 60.0f;
  156. }
  157. }
  158. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  159. if (_isChoose) {
  160. return 2;
  161. }
  162. else {
  163. return 1;
  164. }
  165. }
  166. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  167. if (section == 0) {
  168. return self.dataArray.count;
  169. }
  170. else {
  171. return 1;
  172. }
  173. }
  174. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  175. if (indexPath.section == 0) {
  176. ApplyMemberModel *model = self.dataArray[indexPath.row];
  177. if (_isChoose) {
  178. GroupApplyChooseCell *chooseCell = [tableView dequeueReusableCellWithIdentifier:@"GroupApplyChooseCell"];
  179. [chooseCell configWithSource:model];
  180. return chooseCell;
  181. }
  182. else {
  183. GroupApplyMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupApplyMemberCell"];
  184. [cell configWithSource:model];
  185. return cell;
  186. }
  187. }
  188. else {
  189. GroupApplyChooseAllCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupApplyChooseAllCell"];
  190. cell.isChooseAll = self.isChooseAll;
  191. return cell;
  192. }
  193. }
  194. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  195. if (indexPath.section == 1) {
  196. self.isChooseAll = !self.isChooseAll;
  197. [self configAllChooseStatus];
  198. }
  199. else {
  200. if (_isChoose) {
  201. ApplyMemberModel *model = self.dataArray[indexPath.row];
  202. model.isChoose = !model.isChoose;
  203. [self refreshStatus];
  204. }
  205. }
  206. }
  207. - (void)refreshStatus {
  208. self.isChooseAll = YES;
  209. for (ApplyMemberModel *model in self.dataArray) {
  210. if (model.isChoose == NO) {
  211. self.isChooseAll = NO;
  212. break;
  213. }
  214. }
  215. [self.tableView reloadData];
  216. }
  217. - (void)configAllChooseStatus {
  218. BOOL isChoose = self.isChooseAll;
  219. for (ApplyMemberModel *model in self.dataArray) {
  220. model.isChoose = isChoose;
  221. }
  222. [self.tableView reloadData];
  223. }
  224. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  225. return [UIView new];
  226. }
  227. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  228. {
  229. return [UIView new];
  230. }
  231. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  232. return CGFLOAT_MIN;
  233. }
  234. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  235. return CGFLOAT_MIN;
  236. }
  237. #pragma mark ------ lazying
  238. - (UITableView *)tableView {
  239. if (!_tableView) {
  240. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  241. _tableView.backgroundColor = [UIColor clearColor];
  242. _tableView.delegate = self;
  243. _tableView.dataSource = self;
  244. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  245. _tableView.showsHorizontalScrollIndicator = NO;
  246. _tableView.showsVerticalScrollIndicator = NO;
  247. [_tableView registerNib:[UINib nibWithNibName:@"GroupApplyMemberCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupApplyMemberCell"];
  248. [_tableView registerNib:[UINib nibWithNibName:@"GroupApplyChooseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupApplyChooseCell"];
  249. [_tableView registerNib:[UINib nibWithNibName:@"GroupApplyChooseAllCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupApplyChooseAllCell"];
  250. }
  251. return _tableView;
  252. }
  253. /*
  254. #pragma mark - Navigation
  255. // In a storyboard-based application, you will often want to do a little preparation before navigation
  256. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  257. // Get the new view controller using [segue destinationViewController].
  258. // Pass the selected object to the new view controller.
  259. }
  260. */
  261. @end