| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- //
- // PlatformActivityController.m
- // model
- //
- // Created by JuYi on 2018/7/17.
- // Copyright © 2018年 Mine. All rights reserved.
- // 平台活动
- #import "PlatformActivityController.h"
- #import "PlatformActivityCell.h"
- #import "ModelTitleView.h" // 选择按钮
- #import "ActivityDetailViewController.h"
- #import "WebViewController.h"
- @interface PlatformActivityController () <UITableViewDelegate, UITableViewDataSource>
- @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 = @{@"memberpk": [ModelUser user].pk, @"all": @"true"};
- [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 = @{@"PK": [ModelUser user].pk};
- [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 = @{@"PK": [ModelUser user].pk};
- [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[indexPath.section];
- } else if (self.selectIndex == 1) {
- model = self.oneModelArr[indexPath.section];
- } else {
- model = self.twoModelArr[indexPath.section];
- }
- if (model.url.length) {
- WebViewController *webViewController = [[WebViewController alloc] init];
- webViewController.url = model.url;
- webViewController.activityPK = model.pk;
- [self.navigationController pushViewController:webViewController animated:YES];
- } else {
- ActivityDetailViewController *detailVC = [[ActivityDetailViewController alloc] init];
- detailVC.model = model;
- [self.navigationController pushViewController:detailVC 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
|