PlatformActivityController.m 9.2 KB

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