// // PlatformActivityController.m // model // // Created by JuYi on 2018/7/17. // Copyright © 2018年 Mine. All rights reserved. // 平台活动 #import "PlatformActivityController.h" #import "ActivityDetailViewController.h" #import "SignUpViewController.h" #import "PlatformActivityCell.h" #import "ModelTitleView.h" // 选择按钮 @interface PlatformActivityController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *allDataArr; @property (nonatomic, strong) NSMutableArray *oneArr; @property (nonatomic, strong) NSMutableArray *twoArr; @property (nonatomic, strong) NSMutableArray *allModelArr; @property (nonatomic, strong) NSMutableArray *oneModelArr; @property (nonatomic, strong) NSMutableArray *twoModelArr; @property (nonatomic, assign) NSInteger selectIndex; //1是已报名,2未报名 @end @implementation PlatformActivityController - (NSMutableArray *)allDataArr { if (!_allDataArr) { _allDataArr = [NSMutableArray arrayWithCapacity:0]; } return _allDataArr; } - (NSMutableArray *)oneArr { if (!_oneArr) { _oneArr = [NSMutableArray arrayWithCapacity:0]; } return _oneArr; } - (NSMutableArray *)twoArr { if (!_twoArr) { _twoArr = [NSMutableArray arrayWithCapacity:0]; } return _twoArr; } - (void)viewDidLoad { [super viewDidLoad]; self.selectIndex = 0; //设置导航条 [self creatNavBar]; //设置子试图 [self creatSubViews]; [self getDataFromNetworking]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)creatNavBar { self.title = @"平台活动"; // UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 40, 40); [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal]; btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2 [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整 self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem]; } - (void)backClick { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark -- 获取平台活动 - (void)getDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].pk,@"memberpk", @"true", @"all", nil]; [YanCNetWorkManager requestPostWithURLStr:Url_dogetpartty(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { // self.allDataArr = dataDic[@"data"]; NSArray *data = dataDic[@"data"]; NSArray * array = [ActivityModel arrayOfModelsFromDictionaries:data]; self.allModelArr = [NSMutableArray new]; [self.allModelArr addObjectsFromArray:array]; [self.tableView reloadData]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (void)getParticipateDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].pk,@"PK", nil]; [YanCNetWorkManager requestPostWithURLStr:Url_doqrypartty(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { self.oneArr = dataDic[@"data"]; NSArray *data = dataDic[@"data"]; NSArray * array = [ActivityModel arrayOfModelsFromDictionaries:data]; self.oneModelArr = [NSMutableArray new]; [self.oneModelArr addObjectsFromArray:array]; [self.tableView reloadData]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (void)getNoParticipateDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].pk,@"PK", nil]; [YanCNetWorkManager requestPostWithURLStr:Url_doqrynotpartt(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { self.twoArr = dataDic[@"data"]; NSArray *data = dataDic[@"data"]; NSArray * array = [ActivityModel arrayOfModelsFromDictionaries:data]; self.twoModelArr = [NSMutableArray new]; [self.twoModelArr addObjectsFromArray:array]; [self.tableView reloadData]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (void)creatSubViews { ModelTitleView *titlesView = [[ModelTitleView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)]; titlesView.titleArr = @[@"全部", @"已报名", @"未报名"]; __weak typeof (self) weakself = self; titlesView.ModelTitleViewBlock = ^(NSInteger tag) { NSLog(@"tag %ld", tag); weakself.selectIndex = tag; if (weakself.selectIndex == 0) { [self getDataFromNetworking]; } else if (weakself.selectIndex == 1) { [self getParticipateDataFromNetworking]; } else if (weakself.selectIndex == 2) { [self getNoParticipateDataFromNetworking]; } }; [self.view addSubview:titlesView]; self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titlesView.frame), ScreenWidth, ScreenResultHeight-40) style:UITableViewStylePlain]; self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.view addSubview:self.tableView]; } #pragma mark -- UITableViewDelegate, UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (self.selectIndex == 0) { return self.allDataArr.count; } else if (self.selectIndex == 1) { return self.oneArr.count; } else { return self.twoArr.count; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellid = @"cellid"; PlatformActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid]; if (!cell) { cell = [[PlatformActivityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid]; } if (self.selectIndex == 0) { [cell setPlatformActivityCellValueWithDic:_allDataArr[indexPath.section] titleStr:@"全部"]; } else if (self.selectIndex == 1) { [cell setPlatformActivityCellValueWithDic:_oneArr[indexPath.section] titleStr:@"已报名"]; } else { [cell setPlatformActivityCellValueWithDic:_twoArr[indexPath.section] titleStr:@"未报名"]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ ActivityModel *model; if(self.selectIndex == 0){ model = [self.allModelArr objectAtIndex:indexPath.section]; }else if (self.selectIndex ==1){ model = [self.oneModelArr objectAtIndex:indexPath.section]; }else{ model = [self.twoModelArr objectAtIndex:indexPath.section]; } SignUpViewController *sVc = [[SignUpViewController alloc]init]; sVc.model = model; [self.navigationController pushViewController:sVc animated:YES]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 156; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)]; footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); return footerView; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)]; headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); return headerView; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0) { return 0.01; } else { return 10; } } @end