PlatformActivityController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // PlatformActivityController.m
  3. // model
  4. //
  5. // Created by JuYi on 2018/7/17.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 平台活动
  8. #import "PlatformActivityController.h"
  9. #import "ActivityDetailViewController.h"
  10. #import "SignUpViewController.h"
  11. #import "PlatformActivityCell.h"
  12. #import "ModelTitleView.h" // 选择按钮
  13. @interface PlatformActivityController ()<UITableViewDelegate, UITableViewDataSource>
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @property (nonatomic, strong) NSMutableArray *allDataArr;
  16. @property (nonatomic, strong) NSMutableArray *oneArr;
  17. @property (nonatomic, strong) NSMutableArray *twoArr;
  18. @property (nonatomic, strong) NSMutableArray *allModelArr;
  19. @property (nonatomic, strong) NSMutableArray *oneModelArr;
  20. @property (nonatomic, strong) NSMutableArray *twoModelArr;
  21. @property (nonatomic, assign) NSInteger selectIndex; //1是已报名,2未报名
  22. @end
  23. @implementation PlatformActivityController
  24. - (NSMutableArray *)allDataArr {
  25. if (!_allDataArr) {
  26. _allDataArr = [NSMutableArray arrayWithCapacity:0];
  27. }
  28. return _allDataArr;
  29. }
  30. - (NSMutableArray *)oneArr {
  31. if (!_oneArr) {
  32. _oneArr = [NSMutableArray arrayWithCapacity:0];
  33. }
  34. return _oneArr;
  35. }
  36. - (NSMutableArray *)twoArr {
  37. if (!_twoArr) {
  38. _twoArr = [NSMutableArray arrayWithCapacity:0];
  39. }
  40. return _twoArr;
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. self.selectIndex = 0;
  45. //设置导航条
  46. [self creatNavBar];
  47. //设置子试图
  48. [self creatSubViews];
  49. [self getDataFromNetworking];
  50. }
  51. - (void)didReceiveMemoryWarning {
  52. [super didReceiveMemoryWarning];
  53. // Dispose of any resources that can be recreated.
  54. }
  55. - (void)creatNavBar {
  56. self.title = @"平台活动";
  57. //
  58. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  59. btn.frame = CGRectMake(0, 0, 40, 40);
  60. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  61. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
  62. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  63. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  64. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  65. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  66. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  67. }
  68. - (void)backClick {
  69. [self.navigationController popViewControllerAnimated:YES];
  70. }
  71. #pragma mark -- 获取平台活动
  72. - (void)getDataFromNetworking {
  73. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  74. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].pk,@"memberpk", @"true", @"all", nil];
  75. [YanCNetWorkManager requestPostWithURLStr:Url_dogetpartty(PublicUrl) parameters:dic finish:^(id dataDic) {
  76. [MBProgressHUD hideHUDForView:self.view animated:YES];
  77. NSString *issuccess = dataDic[@"msg"];
  78. if ([issuccess isEqualToString:@"success"]) {
  79. //
  80. self.allDataArr = dataDic[@"data"];
  81. NSArray *data = dataDic[@"data"];
  82. NSArray * array = [ActivityModel arrayOfModelsFromDictionaries:data];
  83. self.allModelArr = [NSMutableArray new];
  84. [self.allModelArr addObjectsFromArray:array];
  85. [self.tableView reloadData];
  86. } else {
  87. [MBProgressHUD showInfo:@"请求失败!"];
  88. }
  89. } enError:^(NSError *error) {
  90. [MBProgressHUD hideHUDForView:self.view animated:YES];
  91. }];
  92. }
  93. - (void)getParticipateDataFromNetworking {
  94. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  95. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].pk,@"PK", nil];
  96. [YanCNetWorkManager requestPostWithURLStr:Url_doqrypartty(PublicUrl) parameters:dic finish:^(id dataDic) {
  97. [MBProgressHUD hideHUDForView:self.view animated:YES];
  98. NSString *issuccess = dataDic[@"msg"];
  99. if ([issuccess isEqualToString:@"success"]) {
  100. self.oneArr = dataDic[@"data"];
  101. NSArray *data = dataDic[@"data"];
  102. NSArray * array = [ActivityModel arrayOfModelsFromDictionaries:data];
  103. self.oneModelArr = [NSMutableArray new];
  104. [self.oneModelArr addObjectsFromArray:array];
  105. [self.tableView reloadData];
  106. } else {
  107. [MBProgressHUD showInfo:@"请求失败!"];
  108. }
  109. } enError:^(NSError *error) {
  110. [MBProgressHUD hideHUDForView:self.view animated:YES];
  111. }];
  112. }
  113. - (void)getNoParticipateDataFromNetworking {
  114. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  115. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser user].pk,@"PK", nil];
  116. [YanCNetWorkManager requestPostWithURLStr:Url_doqrynotpartt(PublicUrl) parameters:dic finish:^(id dataDic) {
  117. [MBProgressHUD hideHUDForView:self.view animated:YES];
  118. NSString *issuccess = dataDic[@"msg"];
  119. if ([issuccess isEqualToString:@"success"]) {
  120. self.twoArr = dataDic[@"data"];
  121. NSArray *data = dataDic[@"data"];
  122. NSArray * array = [ActivityModel arrayOfModelsFromDictionaries:data];
  123. self.twoModelArr = [NSMutableArray new];
  124. [self.twoModelArr addObjectsFromArray:array];
  125. [self.tableView reloadData];
  126. } else {
  127. [MBProgressHUD showInfo:@"请求失败!"];
  128. }
  129. } enError:^(NSError *error) {
  130. [MBProgressHUD hideHUDForView:self.view animated:YES];
  131. }];
  132. }
  133. - (void)creatSubViews {
  134. ModelTitleView *titlesView = [[ModelTitleView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
  135. titlesView.titleArr = @[@"全部", @"已报名", @"未报名"];
  136. __weak typeof (self) weakself = self;
  137. titlesView.ModelTitleViewBlock = ^(NSInteger tag) {
  138. NSLog(@"tag %ld", tag);
  139. weakself.selectIndex = tag;
  140. if (weakself.selectIndex == 0) {
  141. [self getDataFromNetworking];
  142. } else if (weakself.selectIndex == 1) {
  143. [self getParticipateDataFromNetworking];
  144. } else if (weakself.selectIndex == 2) {
  145. [self getNoParticipateDataFromNetworking];
  146. }
  147. };
  148. [self.view addSubview:titlesView];
  149. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titlesView.frame), ScreenWidth, ScreenResultHeight-40) style:UITableViewStylePlain];
  150. self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  151. self.tableView.delegate = self;
  152. self.tableView.dataSource = self;
  153. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  154. [self.view addSubview:self.tableView];
  155. }
  156. #pragma mark -- UITableViewDelegate, UITableViewDataSource
  157. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  158. if (self.selectIndex == 0) {
  159. return self.allDataArr.count;
  160. } else if (self.selectIndex == 1) {
  161. return self.oneArr.count;
  162. } else {
  163. return self.twoArr.count;
  164. }
  165. }
  166. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  167. return 1;
  168. }
  169. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  170. static NSString *cellid = @"cellid";
  171. PlatformActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
  172. if (!cell) {
  173. cell = [[PlatformActivityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
  174. }
  175. if (self.selectIndex == 0) {
  176. [cell setPlatformActivityCellValueWithDic:_allDataArr[indexPath.section] titleStr:@"全部"];
  177. } else if (self.selectIndex == 1) {
  178. [cell setPlatformActivityCellValueWithDic:_oneArr[indexPath.section] titleStr:@"已报名"];
  179. } else {
  180. [cell setPlatformActivityCellValueWithDic:_twoArr[indexPath.section] titleStr:@"未报名"];
  181. }
  182. return cell;
  183. }
  184. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  185. ActivityModel *model;
  186. if(self.selectIndex == 0){
  187. model = [self.allModelArr objectAtIndex:indexPath.section];
  188. }else if (self.selectIndex ==1){
  189. model = [self.oneModelArr objectAtIndex:indexPath.section];
  190. }else{
  191. model = [self.twoModelArr objectAtIndex:indexPath.section];
  192. }
  193. SignUpViewController *sVc = [[SignUpViewController alloc]init];
  194. sVc.model = model;
  195. [self.navigationController pushViewController:sVc animated:YES];
  196. }
  197. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  198. return 156;
  199. }
  200. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  201. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
  202. footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  203. return footerView;
  204. }
  205. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  206. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
  207. headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  208. return headerView;
  209. }
  210. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  211. return 0.01;
  212. }
  213. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  214. if (section == 0) {
  215. return 0.01;
  216. } else {
  217. return 10;
  218. }
  219. }
  220. @end