NewFenLeiViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //
  2. // NewFenLeiViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/31.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "NewFenLeiViewController.h"
  9. //#import "FLZLCell.h"
  10. //#import "FLZLTableViewCell.h"
  11. #import "NewFWXMViewController.h"
  12. @interface NewFenLeiViewController ()<UITableViewDataSource,UITableViewDelegate>{
  13. UITableView *newtableView;
  14. UITableView *newtableView1;
  15. NSMutableArray *dataArr1;
  16. NSMutableArray *dataArr2;
  17. NSMutableArray *dataArr3;
  18. NSMutableArray *dataArr;
  19. NSMutableArray *nameArr;
  20. NSMutableArray *nameArr1;
  21. NSMutableArray *isOpenArr;
  22. NSMutableArray *SelectArr;
  23. }
  24. @end
  25. @implementation NewFenLeiViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self setNavTitle:@"科技项目分类"];
  29. [self loaddata];
  30. [self networkRequest];
  31. [self loadUI];
  32. // Do any additional setup after loading the view.
  33. }
  34. - (void)loaddata{
  35. dataArr1 = NewMutableArrayInit;
  36. dataArr2 = NewMutableArrayInit;
  37. dataArr3 = NewMutableArrayInit;
  38. isOpenArr = NewMutableArrayInit;
  39. SelectArr = NewMutableArrayInit;
  40. dataArr = NewMutableArrayInit;
  41. nameArr = NewMutableArrayInit;
  42. nameArr1 = NewMutableArrayInit;
  43. }
  44. - (void)networkRequest
  45. {
  46. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  47. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewcategoryList parameters:parameters onSuccess:^(id requestData) {
  48. if ([requestData[@"error"] count] !=0) {
  49. for (NSDictionary *dic in requestData[@"error"]) {
  50. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  51. }
  52. }else{
  53. [dataArr3 removeAllObjects];
  54. NSMutableArray *arr = [NSMutableArray arrayWithArray:requestData[@"data"]];
  55. dataArr3 = [NSMutableArray arrayWithArray:requestData[@"data"]];
  56. for (int i = 0; i<arr.count; i++) {
  57. [nameArr addObject:arr[i][@"name"]];
  58. }
  59. for (int i = 0; i<arr.count; i++) {
  60. if (i == self.page) {
  61. NSMutableArray *zibiaoti = [NSMutableArray arrayWithArray:arr[i][@"list"]];
  62. for (int j = 0; j<zibiaoti.count; j++) {
  63. [nameArr1 addObject:zibiaoti[j][@"topLevel"]];
  64. [dataArr addObject:zibiaoti[j][@"children"]];
  65. }
  66. }
  67. }
  68. for (int i = 0; i<dataArr.count; i++) {
  69. NSString *state = @"open";
  70. [isOpenArr addObject:state];
  71. }
  72. for (int i = 0; i<nameArr.count; i++) {
  73. if (i == self.page) {
  74. NSString *state=@"open";
  75. [SelectArr addObject:state];
  76. }else{
  77. NSString *state=@"close";
  78. [SelectArr addObject:state];
  79. }
  80. }
  81. [newtableView reloadData];
  82. [newtableView1 reloadData];
  83. }
  84. } onFailure:^{
  85. }];
  86. }
  87. #pragma mark----刷新子数据
  88. - (void)shuaxinTableViewData:(NSInteger)str{
  89. [nameArr1 removeAllObjects];
  90. [dataArr removeAllObjects];
  91. [isOpenArr removeAllObjects];
  92. [SelectArr removeAllObjects];
  93. for (int i = 0; i<dataArr3.count; i++) {
  94. if (i == str) {
  95. NSMutableArray *zibiaoti = [NSMutableArray arrayWithArray:dataArr3[i][@"list"]];
  96. for (int j = 0; j<zibiaoti.count; j++) {
  97. [nameArr1 addObject:zibiaoti[j][@"topLevel"]];
  98. [dataArr addObject:zibiaoti[j][@"children"]];
  99. }
  100. }
  101. }
  102. for (int i = 0; i<dataArr.count; i++) {
  103. NSString* state=@"close";
  104. [isOpenArr addObject:state];
  105. }
  106. for (int i = 0; i<nameArr.count; i++) {
  107. if (i == str) {
  108. NSString *state=@"open";
  109. [SelectArr addObject:state];
  110. }else{
  111. NSString *state=@"close";
  112. [SelectArr addObject:state];
  113. }
  114. }
  115. [newtableView reloadData];
  116. [newtableView1 reloadData];
  117. }
  118. -(void)loadUI
  119. {
  120. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH/3, SCREEN_HEIGHT-NavHeader) backgroundColor:[UIColor colorWithString:@"#F5F5F5"] style:UITableViewStylePlain delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  121. newtableView.separatorStyle = NO;
  122. [self.view addSubview:newtableView1 = [NewControlPackage tableViewInitWithFrame:CGRectMake(SCREEN_WIDTH/3, NavHeader, SCREEN_WIDTH*2/3, SCREEN_HEIGHT-NavHeader) backgroundColor:NewWhiteColor style:UITableViewStylePlain delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:101 userInteractionEnabled:YES]];
  123. newtableView1.separatorStyle = YES;
  124. // [_collect registerClass:[HRloveCollectionViewCell class] forCellWithReuseIdentifier:@"collectcell"];
  125. }
  126. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  127. {
  128. // return self.dataDict.allKeys.count;
  129. if (tableView.tag == 100) {
  130. return 1;
  131. }else{
  132. return dataArr.count;
  133. }
  134. }
  135. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  136. {
  137. if (tableView.tag == 100) {
  138. return nameArr.count;
  139. }else if(tableView.tag == 101){
  140. NSString* state=[isOpenArr objectAtIndex:section];
  141. if ([state isEqualToString:@"open"]) {
  142. NSArray* arr=[dataArr objectAtIndex:section];
  143. return arr.count;
  144. }
  145. }
  146. return 0;
  147. }
  148. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  149. {
  150. if (tableView.tag == 100) {
  151. static NSString *Cell = @"Cell";
  152. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  153. if (cell == nil) {
  154. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  155. }
  156. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  157. cell.accessoryType = UITableViewCellAccessoryNone;
  158. // if ([SelectArr[indexPath.row] isEqualToString:@"open"]) {
  159. // cell.title.textColor = NewButtonColor;
  160. // cell.backgroundColor = NewWhiteColor;
  161. // cell.line.hidden = NO;
  162. // }else{
  163. // cell.title.textColor = NewBlackColor;
  164. // cell.backgroundColor = [UIColor colorWithString:@"#F5F5F5"];
  165. // cell.line.hidden = YES;
  166. // }
  167. // cell.title.text = nameArr[indexPath.row];
  168. return cell;
  169. }else{
  170. static NSString *Cell = @"Cell";
  171. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  172. if (cell == nil) {
  173. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  174. }
  175. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  176. cell.accessoryType = UITableViewCellAccessoryNone;
  177. // NSArray* sectionArr=[dataArr objectAtIndex:indexPath.section];
  178. // cell.title.text = sectionArr[indexPath.row][@"name"];
  179. return cell;
  180. }
  181. }
  182. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  183. {
  184. if (tableView.tag == 100) {
  185. [SelectArr removeAllObjects];
  186. for (int i = 0; i<nameArr.count; i++) {
  187. if (indexPath.row == i) {
  188. NSString *state=@"open";
  189. [SelectArr addObject:state];
  190. }else{
  191. NSString *state=@"close";
  192. [SelectArr addObject:state];
  193. }
  194. }
  195. [self shuaxinTableViewData:indexPath.row];
  196. [newtableView reloadData];
  197. }else{
  198. for (int i = 0; i<SelectArr.count; i++) {
  199. if ([SelectArr[i] isEqualToString:@"open"]) {
  200. NSLog(@"%@",dataArr3[i][@"list"][indexPath.section][@"topLevelId"]);
  201. NSMutableArray *arr = dataArr3[i][@"list"][indexPath.section][@"children"];
  202. NSLog(@"%@",arr[indexPath.row][@"id"]);
  203. NewFWXMViewController *vc = [[NewFWXMViewController alloc] init];
  204. vc.topId = dataArr3[i][@"list"][indexPath.section][@"topLevelId"];
  205. vc.secondId = arr[indexPath.row][@"id"];
  206. NewPushViewController(vc);
  207. }
  208. }
  209. }
  210. }
  211. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  212. {
  213. if (tableView.tag == 100) {
  214. return 55;
  215. }else{
  216. return 55;
  217. }
  218. }
  219. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  220. return CGFLOAT_MIN;
  221. }
  222. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  223. if (tableView.tag == 100) {
  224. return CGFLOAT_MIN;
  225. }else{
  226. return 55;
  227. }
  228. }
  229. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  230. if (tableView.tag == 100) {
  231. return [[UIView alloc] init];
  232. }else{
  233. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/3, 55)];
  234. UILabel *title = [UILabel new];
  235. if (nameArr1.count>0) {
  236. title.text = nameArr1[section];
  237. }
  238. title.font = NewFont(14);
  239. title.textColor = NewButtonColor;
  240. [title setSingleLineAutoResizeWithMaxWidth:0];
  241. [view addSubview:title];
  242. title.sd_layout
  243. .leftSpaceToView(view, 20)
  244. .heightIs(55)
  245. .topEqualToView(view);
  246. UIImageView* stateImage=[[UIImageView alloc] init];
  247. if (isOpenArr.count>0) {
  248. if ([[isOpenArr objectAtIndex:section] isEqualToString:@"open"]) {
  249. [stateImage setImage:[UIImage imageNamed:@"sectionOpen"]];
  250. }
  251. else if ([[isOpenArr objectAtIndex:section] isEqualToString:@"close"]) {
  252. [stateImage setImage:[UIImage imageNamed:@"sectionClose"]];
  253. }
  254. }else{
  255. [stateImage setImage:[UIImage imageNamed:@"sectionClose"]];
  256. }
  257. [view addSubview:stateImage];
  258. stateImage.sd_layout
  259. .rightSpaceToView(view, 15)
  260. .heightIs(7)
  261. .widthIs(13)
  262. .centerYEqualToView(view);
  263. UIButton *button = [UIButton new];
  264. NewTouchUpInside(button, buttonclick:);
  265. button.tag = 100+section;
  266. [view addSubview:button];
  267. button.sd_layout
  268. .leftEqualToView(view)
  269. .rightEqualToView(view)
  270. .topEqualToView(view)
  271. .bottomEqualToView(view);
  272. UILabel *line = [UILabel new];
  273. line.backgroundColor = NewLineGrayColor;
  274. [view addSubview:line];
  275. line.sd_layout
  276. .leftEqualToView(view)
  277. .rightEqualToView(view)
  278. .heightIs(1)
  279. .bottomEqualToView(view);
  280. return view;
  281. }
  282. }
  283. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  284. return [[UIView alloc] init];
  285. }
  286. - (void)buttonclick:(UIButton *)sender {
  287. NSString* state=[isOpenArr objectAtIndex:sender.tag-100];
  288. if ([state isEqualToString:@"open"]) {
  289. state=@"close";
  290. }else
  291. {
  292. state=@"open";
  293. }
  294. isOpenArr[sender.tag-100]=state;
  295. NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:sender.tag-100];
  296. [newtableView1 reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
  297. }
  298. - (void)didReceiveMemoryWarning {
  299. [super didReceiveMemoryWarning];
  300. // Dispose of any resources that can be recreated.
  301. }
  302. /*
  303. #pragma mark - Navigation
  304. // In a storyboard-based application, you will often want to do a little preparation before navigation
  305. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  306. // Get the new view controller using [segue destinationViewController].
  307. // Pass the selected object to the new view controller.
  308. }
  309. */
  310. @end