HmV0.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. //
  2. // HmV0.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/13.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "HmV0.h"
  9. #import "STButton.h"
  10. #import "STButton.h"
  11. #import "SchInfo.h"
  12. #import "ExerciseVC.h"
  13. #import "SchCell.h"
  14. #import "GuideVC.h"
  15. #import "SearchBase.h"
  16. #import "VowBar.h"
  17. #import "TopicesVC.h"
  18. #import "TrafficRulesViewController.h"
  19. #import "NeighbouringVC.h"
  20. @interface HmV0()<UITableViewDataSource,UITableViewDelegate>
  21. /**驾校VC
  22. */
  23. @property(nonatomic,strong)UITableView* tableView;
  24. /**
  25. */
  26. @property(assign)BOOL isFake;
  27. @property(nonatomic,strong)NSMutableArray* schools;
  28. @end
  29. @implementation HmV0
  30. {
  31. NSMutableArray *firArr,*secArr;
  32. /**所有地区名称,加code。pcode
  33. */
  34. NSArray* areaArr;
  35. /**培训类型 1 复训 2 陪练 3 计时
  36. */
  37. NSInteger trainType;
  38. /**排列类型 1 价格 2 口碑 3 人气
  39. */
  40. NSInteger sortType;
  41. /**排列方式 1 星级由低到高 2 由高到低
  42. */
  43. NSInteger sort;
  44. NSString* dqbh,*qxbh;
  45. UIButton *footerBtn;
  46. NSArray *schArray;
  47. UILabel *kHolder;
  48. CGFloat btnY;
  49. }
  50. -(id)initWithFake:(BOOL)isFake{
  51. self = [super init];
  52. if (self) {
  53. _isFake = isFake;
  54. }
  55. return self;
  56. }
  57. -(void)viewDidLoad
  58. {
  59. [super viewDidLoad];
  60. [self myInit];
  61. }
  62. -(void)viewDidAppear:(BOOL)animated
  63. {
  64. [super viewDidAppear:animated];
  65. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  66. } else {
  67. [self getSchInfoList];
  68. }
  69. }
  70. -(void)myInit
  71. {
  72. self.view.height = self.viewH;
  73. [self.view setBackgroundColor:[UIColor whiteColor]];
  74. [self configNavigationBar];
  75. //设置为请求的参数 而不是具体数
  76. dqbh = @"";
  77. qxbh = @"";
  78. sort = 2;
  79. trainType = 1;
  80. _schools = [NSMutableArray array];
  81. schArray = [NSMutableArray array];
  82. NSInteger tag = 0;
  83. CGFloat y,h;
  84. scroll = self.zzScrollV;
  85. [self.view addSubview:scroll];
  86. // UIView* hv = [[UIView alloc] initWithFrame:CGRectMake(0, -200, 320, 200)];
  87. // [hv setBackgroundColor:backGroundColor];
  88. // [scroll addSubview:hv];
  89. NSArray* imgs1 = @[@"subject1_traffic_identify_icon.png",@"subject2_exam_experance_icon.png",@"subject1_traffic_rules_icon.png"];//@"subject1_newbie_onroad_icon.png",
  90. NSArray* btnTitles = @[@"学车流程",@"体检须知",@"学车指南"];//@"报名须知",
  91. CGFloat btnW = kSize.width/btnTitles.count;
  92. CGFloat btnH = 90;
  93. for (int i = 0; i<btnTitles.count; i++)
  94. {
  95. STButton* btn = [[STButton alloc] initWithFrame:CGRectMake(btnW*i, 0, btnW, btnH)];
  96. //h=96
  97. [btn setImage:[UIImage imageNamed:imgs1[i]] withTitle:btnTitles[i] Font:NormalFont forState:UIControlStateNormal];
  98. [scroll addSubview:btn];
  99. [btn setStyle:1];
  100. btn.tag = 1+tag++;
  101. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  102. }
  103. y = btnH + 10;
  104. UILabel* lbl10 = [[UILabel alloc] initWithFrame:CGRectMake(10, y, kSize.width, 40)];
  105. [lbl10 setText:@"驾校报名"];//推荐驾校
  106. // [scroll addSubview:lbl10];
  107. [lbl10 addViewWithRect:CGRectMake(0, y - 10, kSize.width, 10)];
  108. y += 40.5;
  109. [lbl10 addViewWithRect:CGRectMake(0, y - 0.5, kSize.width, .5)];
  110. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, y, kSize.width, 0)];
  111. _tableView.rowHeight = 100;
  112. [_tableView setScrollEnabled:NO];
  113. _tableView.dataSource = self;
  114. _tableView.delegate = self;
  115. // [scroll addSubview:_tableView];
  116. [lbl10 addViewWithRect:CGRectMake(0, y , kSize.width,1)];
  117. kHolder = [[UILabel alloc] initWithFrame:CGRectMake(20, y, kSize.width - 20, 40)];
  118. kHolder.text = @"还未查找到推荐驾校哦~";
  119. kHolder.textColor = defGreen;
  120. [kHolder addSelfViewWithRect:CGRectMake(-20, 39 ,kSize.width, 1) Color:KlineColor];
  121. // [scroll addSubview:kHolder];
  122. // y += 40; 隐藏上一行
  123. UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(0, y, kSize.width, 40)];
  124. [btn setTitle:@"查看报名点" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  125. [btn addTarget:self action:@selector(seeMoreSchools) forControlEvents:UIControlEventTouchUpInside];
  126. btn.backgroundColor = [UIColor whiteColor];
  127. [btn setBoardWid:.5 Color:KlineColor];
  128. // [scroll addSubview:btn];
  129. footerBtn = btn;
  130. btnY = footerBtn.y;
  131. h = (_schools.count > 6 ? 6 : _schools.count)* [SchCell cellHeight];
  132. [scroll setContentSize:CGSizeMake(0,_tableView.y+ h)];
  133. }
  134. -(void)btnClick:(UIButton*)sender
  135. {
  136. // NSLog(@"btn%d click",(int)sender.tag);
  137. switch (sender.tag) {
  138. case 0:
  139. myDelegate.url = @"报名须知;registerNeed";
  140. [self gotoTrafficVC];
  141. break;
  142. case 1:
  143. myDelegate.url = @"学车流程;学车流程";
  144. [self gotoTrafficVC];
  145. break;
  146. case 2:
  147. myDelegate.url = @"体检须知;体检须知";
  148. [self gotoTrafficVC];
  149. break;
  150. case 3:
  151. {
  152. GuideVC* vc = [[GuideVC alloc] init];
  153. [self navPushHideTabbarToVC:vc];
  154. }
  155. break;
  156. default:
  157. break;
  158. }
  159. }
  160. -(void)seeMoreSchools
  161. {
  162. // self.tabBarController.selectedIndex = 2;
  163. NeighbouringVC *vc = [[NeighbouringVC alloc]init];
  164. vc.isPushed = YES;
  165. [self navPushHideTabbarToVC:vc];
  166. }
  167. -(void)gotoTrafficVC
  168. {
  169. TrafficRulesViewController* vc = [[TrafficRulesViewController alloc] init];
  170. [self navPushHideTabbarToVC:vc];
  171. }
  172. #pragma mark - tableView
  173. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  174. return _schools.count;
  175. }
  176. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  177. SchCell* cell = [SchCell cellWithTableView:tableView];
  178. NSInteger row = indexPath.row;
  179. id obj = _schools[row];
  180. cell.school = obj;
  181. return cell;
  182. }
  183. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  184. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  185. SchDetailVC* vc = [[SchDetailVC alloc] init];
  186. NSDictionary *dic = schArray[indexPath.row];
  187. vc.schoolId = dic[@"id"];
  188. [self.parentViewController navPushHideTabbarToVC:vc];
  189. }
  190. #pragma mark - service
  191. /**耗时操作!请使用aSyncGetSchInfoList来调用它。
  192. */
  193. - (void)getSchInfoList {
  194. if (_isFake) {
  195. return;
  196. }
  197. if (![Util connectedToNetWork]) {
  198. showMsgUnconnect();
  199. return;
  200. }
  201. static NSString *lng = @"";
  202. static NSString *lat = @"";
  203. dqbh = @"3500";
  204. if (myDelegate.locationArray.count > 2) {
  205. if ([lng isEqualToString:[myDelegate.locationArray firstObject]]) {
  206. return;
  207. }
  208. lng = [myDelegate.locationArray firstObject];
  209. lat = [myDelegate.locationArray lastObject];
  210. dqbh = myDelegate.locationArray[1];
  211. }
  212. NSMutableArray *arr=[NSMutableArray array];
  213. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:dqbh,@"dqbh", nil]];
  214. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:lng,@"lng", nil]];
  215. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:lat,@"lat", nil]];
  216. ;
  217. NSString *method= @"getSchInfoListByTujian";//这个接口 沈阳没用
  218. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  219. //@lee 这里错误也要继续走 2018/2/7
  220. if(dict){
  221. if([dict[@"code"] isEqualToString:@"0"]){
  222. NSArray* body = dict[@"body"];
  223. if (body.count>0)
  224. {
  225. //预防 返回结果数为0.导致意外。
  226. schArray = [NSArray arrayWithArray:body];
  227. [_schools removeAllObjects];
  228. if (!_schools) {
  229. _schools = [NSMutableArray array];
  230. }
  231. for (NSDictionary* bodyItem in body) {
  232. id obj= [SchInfo schoolInfoWithDict:bodyItem];
  233. [_schools addObject:obj];
  234. }
  235. }
  236. }
  237. }
  238. [self showSchool];//里面会判断没有返回值的情况
  239. }];
  240. }
  241. -(void)showSchool
  242. {
  243. for (UIView *view in scroll.subviews) {
  244. if ([view isKindOfClass:[VowBar class]]) {
  245. [view removeFromSuperview];
  246. }
  247. }
  248. CGFloat h = _schools.count* 100;
  249. CGFloat zz = _schools.count==0?0:kHolder.height;
  250. footerBtn.y = btnY + h - zz;
  251. //加一项许愿
  252. VowBar *vowItem = [[VowBar alloc] initWithFrame:CGRectMake(0, footerBtn.bottom + 10, kFrame.size.width, VAWBAR_H) title:@"找驾校"];
  253. vowItem.countLabel.text = @"点击参与讨论>>";
  254. [vowItem.topicBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside];
  255. vowItem.topicBtn.tag = 11;
  256. [vowItem.vomBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside];
  257. vowItem.vomBtn.tag = 12;
  258. // [scroll addSubview:vowItem];
  259. [scroll setContentSize:CGSizeMake(0,CGRectGetMaxY(vowItem.frame) + SCRV_BottomH)];
  260. scroll.backgroundColor = backGroundColor;
  261. if (!_schools || _schools.count < 1){
  262. return;
  263. }
  264. kHolder.hidden = YES;
  265. _tableView.height = h;
  266. [_tableView reloadData];
  267. }
  268. -(void)vowClick:(UIButton *)btn
  269. {
  270. TopicesVC* vc = [[TopicesVC alloc] init];
  271. vc.type = @"1";
  272. if (btn.tag == 11)
  273. {
  274. vc.groupId = @"3";
  275. }else {
  276. vc.groupId = @"9";
  277. }
  278. [self navPushHideTabbarToVC:vc];
  279. }
  280. @end