ListVC.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // ListVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/4.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "ListVC.h"
  9. @interface ListVC ()
  10. @property (nonatomic, readwrite, copy) NSArray *chapterListArr;
  11. @end
  12. @implementation ListVC
  13. #pragma mark -
  14. - (void)viewDidLoad {
  15. @weakify(self)
  16. [super viewDidLoad];
  17. [self configNavBar];
  18. [[RQ_HTTP_Service getChapterList] subscribeNext:^(NSArray *chapterListArr) {
  19. @strongify(self)
  20. if ([chapterListArr isKindOfClass:[NSArray class]]) {
  21. if (chapterListArr.count > 0) {
  22. self.chapterListArr = chapterListArr;
  23. }
  24. }
  25. } error:^(NSError * _Nullable error) {
  26. } completed:^{
  27. @strongify(self)
  28. [self configTable];
  29. }];
  30. }
  31. - (void)didReceiveMemoryWarning {
  32. [super didReceiveMemoryWarning];
  33. }
  34. #pragma mark -
  35. -(void)configNavBar
  36. {
  37. self.view.backgroundColor = [UIColor whiteColor];
  38. [self configNavigationBar];
  39. [self setTitle:@"章节练习"];
  40. }
  41. - (void)btnClick:(UIView*)sender {
  42. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  43. [self gotoExerciseVCWithChapterName:self.titleList[sender.tag]];
  44. } else {
  45. if ([defUser.car_type isEqualToString:@"2"]) {
  46. NSString *chapter = [self.titleList[sender.tag] objectForKey:@"chapter"];
  47. myDelegate.where = [NSString stringWithFormat:@"chapter = %@",chapter];
  48. [self gotoExerciseVC];
  49. } else {
  50. [self gotoExerciseVCWithChapterName:self.titleList[sender.tag]];
  51. }
  52. }
  53. }
  54. -(void)gotoExerciseVCWithChapterName:(NSString *)chapterName{
  55. ExerciseVC* vc = [[ExerciseVC alloc] init];
  56. vc.chapterName = chapterName;
  57. [self navPushHideTabbarToVC:vc];
  58. }
  59. -(void)configTable
  60. {
  61. NSString *string = myDelegate.subject;
  62. if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
  63. {
  64. string = @"1";
  65. }
  66. NSString *cartype = defUser.car_type;
  67. if ([defUser.car_type isEqualToString:@"C1"]) {
  68. cartype = @"C1,C2,C3";
  69. }
  70. if ([defUser.car_type isEqualToString:@"A2"]) {
  71. cartype = @"A2,B2";
  72. }
  73. if ([defUser.car_type isEqualToString:@"A1"]) {
  74. cartype = @"A1,A3,B1";
  75. }
  76. //如果是科四 除了摩托车 都是C1
  77. if ([string isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
  78. cartype = @"C1,C2,C3";
  79. }
  80. NSString *sql;
  81. NSArray *array;
  82. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  83. array = [self.chapterListArr.rac_sequence.signal map:^id _Nullable(RQDictInfoModel * dictInfoModel) {
  84. return dictInfoModel.dictValue;
  85. }].toArray;
  86. } else {
  87. if ([defUser.car_type isEqualToString:@"2"]) {
  88. sql = [NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY_CHAPTER"];
  89. array = [DB_Que_Helper queryGZPZ_EXAM_CYRYList:sql];
  90. } else {
  91. // sql=[NSString stringWithFormat:@"select * from chapter where cartype = '%@' and subject = '%@'",cartype,string];
  92. // array = [DB_Que_Helper queryList:sql];
  93. // array = [RQ_YDTQuestion_Module getChapterArr];
  94. array = [self.chapterListArr.rac_sequence.signal map:^id _Nullable(RQDictInfoModel * dictInfoModel) {
  95. return dictInfoModel.dictValue;
  96. }].toArray;
  97. }
  98. }
  99. self.titleList = [NSMutableArray arrayWithArray:array];
  100. UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:kFrame];
  101. scroll.height -= kNavOffSet;
  102. scroll.scrollEnabled = YES;
  103. [self.view addSubview:scroll];
  104. CGFloat btnX = 20;
  105. CGFloat btnY = 30 ;
  106. CGFloat btnW = kSize.width - btnX *2;
  107. CGFloat btnH = 50;
  108. CGFloat delY = 10;
  109. if (_titleList.count < 1) {
  110. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];
  111. [label setText:@"暂无章节目录" Font:Font17 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  112. label.backgroundColor = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.1];
  113. [scroll addSubview:label];
  114. }
  115. /**科目1的tag是 1-4
  116. **科目4的tag是 7-13
  117. */
  118. int tag = 0;
  119. int imgInd = 0;
  120. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  121. for (NSString* titleStr in _titleList)
  122. {
  123. CLButton* btn = [[CLButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];
  124. btn.tag = tag++;
  125. btnY = btnY + btnH + delY;
  126. btn.titleN = titleStr;
  127. btn.detailN = _countList[imgInd];
  128. btn.imgN = @"menu_order_normal_ico_f.png";
  129. btn.titleLabel.numberOfLines = 0;
  130. btn.backgroundColor = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.1];
  131. [scroll addSubview:btn];
  132. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  133. btn.layer.cornerRadius = 4;
  134. [btn.layer setMasksToBounds:YES];
  135. }
  136. } else {
  137. if ([defUser.car_type isEqualToString:@"2"]) {
  138. for (NSDictionary* dic in _titleList)
  139. {
  140. NSString *title = dic[@"title"];
  141. CLButton* btn = [[CLButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];
  142. btn.tag = tag++;
  143. btnY = btnY + btnH + delY;
  144. btn.titleN = title;
  145. btn.detailN = _countList[imgInd];
  146. btn.imgN = @"menu_order_normal_ico_f.png";
  147. btn.titleLabel.numberOfLines = 0;
  148. btn.backgroundColor = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.1];
  149. [scroll addSubview:btn];
  150. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  151. btn.layer.cornerRadius = 4;
  152. [btn.layer setMasksToBounds:YES];
  153. }
  154. } else {
  155. for (NSString* titleStr in _titleList)
  156. {
  157. CLButton* btn = [[CLButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];
  158. btn.tag = tag++;
  159. btnY = btnY + btnH + delY;
  160. btn.titleN = titleStr;
  161. btn.detailN = _countList[imgInd];
  162. btn.imgN = @"menu_order_normal_ico_f.png";
  163. btn.titleLabel.numberOfLines = 0;
  164. btn.backgroundColor = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.1];
  165. [scroll addSubview:btn];
  166. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  167. btn.layer.cornerRadius = 4;
  168. [btn.layer setMasksToBounds:YES];
  169. }
  170. }
  171. }
  172. scroll.contentSize = CGSizeMake(kSize.width, btnY + btnH +30);
  173. }
  174. -(void)gotoExerciseVC{
  175. ExerciseVC* vc = [[ExerciseVC alloc] init];
  176. [self navPushHideTabbarToVC:vc];
  177. }
  178. #pragma mark - LazyLoad
  179. - (NSArray *)chapterListArr {
  180. if (!_chapterListArr) {
  181. _chapterListArr = @[];
  182. }
  183. return _chapterListArr;
  184. }
  185. @end