#import "SchDetailVC.h" #import "CLButton.h" #import "STButton.h" #import "EXButton.h" #import "SchInfo.h" #import "SearchComment.h" #import "FaqVC.h" #import "ApplyVC.h" #import "descVC.h" #import "TopicesVC.h" #import "SchoolNewsVC.h" #import "MapVC.h" #import "KSchoolCell.h" @interface SchDetailVC () { UILabel *lbl00, *lbl01, *lbl02, *lbl03, *lbl10; UILabel *kName, *kPrice, *kType, *kCar, *kTime, *kAdress, *kPick; UIView *kHolder; CLButton *btn00, *btn01, *btn02, *btn3, *btn4, *btn5; UIScrollView *scroll; UITableView *mainTableView; SchInfo *schInfo; UIImageView *img00; NSMutableArray *starImgs; NSDictionary *model; NSArray *dataArray; NSArray *types; } @end @implementation SchDetailVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"驾校详情"; self.view.backgroundColor = [UIColor whiteColor]; [self configNavigationBar]; [self myInit]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - -(void)myInit { dataArray = [NSArray array]; types = @[@"陪练",@"复训",@"计时训练",@"报名",@"",@"",@""]; scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - kNavOffSet - kSafeAreaBottomHeight)]; [self.view addSubview:scroll]; [self.view setBackgroundColor:[UIColor whiteColor]]; scroll.scrollEnabled = YES; //下方按钮条 UIView* bar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - kNavOffSet - 60 - kSafeAreaBottomHeight, self.view.width, 60)]; [bar setBackgroundColor:backGroundColor]; [self.view addSubview:bar]; [self.view bringSubviewToFront:bar]; NSArray* titles = @[@"点评",@"问答"/*,@"报名"*/]; NSArray* images = @[@"img03pen.png",@"img04talk.png"/*,@"img05Rig.png"*/]; CGFloat w,bd; w = 60; // bd = (self.view.width - w*3)/4.0; bd = (self.view.width - w*2)/3.0; for (int i =0; i"]; [scroll addSubview:btn]; [btn target:self tag:10]; //更多驾校详情按钮 btn3 = btn; //添加黑色隔条 [btn addViewWithRect:SGRectMake(0, curTop-bd, 320, bd) Color:KlineColor]; label = [[UILabel alloc] initWithFrame:SGRectMake(bd, curTop, 80, dy)]; [label setText:@"驾校简介"]; [label setTextColor:contentTextColor]; [scroll addSubview:label]; lbl03= label; CGFloat lblh = 60; label = [[UILabel alloc] initWithFrame:SGRectMake(bd, curTop+dy, 320-bd*2, lblh)]; [label setNumberOfLines:0]; [label setTextColor:contentTextColor]; [scroll addSubview:label]; //简介内容 lbl10 = label; [label addViewWithRect:SGRectMake(0, curTop+dy, 320, .5) Color:KlineColor]; curTop += lblh + dy; UIButton* btnn; [btnn addViewWithRect:SGRectMake(0, curTop, 320, .5) Color:KlineColor]; btnn = [[UIButton alloc] initWithFrame:SGRectMake(0, curTop, 320, dy)]; [btnn setTitle:@"驾校新闻" textColor:defGreen font:16 fotState:UIControlStateNormal]; [btnn target:self tag:12]; [scroll addSubview:btnn]; [btnn addSelfViewWithRect:SGRectMake(0, - 1 ,320, 1) Color:KlineColor]; //驾校新闻按钮 btn4 = (CLButton*)btnn; btn = [[CLButton alloc] initWithFrame:SGRectMake(0, curTop + dy + bd, 320, dy)]; [btn setTitle:@"" textColor:contentTextColor font:NormalFont fotState:UIControlStateNormal]; [btn setImage:nil forState:UIControlStateNormal]; [btn setDetailN:@"点击加入讨论 >"]; [btn target:self tag:13]; [scroll addSubview:btn]; //跳转驾校社区按钮 btn5 = btn; [btn addSelfViewWithRect:SGRectMake(0, - bd ,320, bd) Color:KlineColor]; [btn addSelfViewWithRect:SGRectMake(0, dy ,320, bd) Color:KlineColor]; //课程信息部分 CGFloat y = curTop + 2*(dy + bd); label = [[UILabel alloc] initWithFrame:SGRectMake(bd, y, 320-bd, dy)]; [label setText:@"培训类型"]; [label setFont:[UIFont scaleSize:16]]; [label setTextColor:contentTextColor]; [scroll addSubview:label]; y += dy; //用这个表来展示数据吧 mainTableView = [[UITableView alloc] initWithFrame:SGRectMake(0, y, kSize.width, 0) style:UITableViewStylePlain]; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.scrollEnabled = NO; [scroll addSubview:mainTableView]; kHolder = [[UIView alloc] initWithFrame:SGRectMake(0, y, kSize.width, 185)]; kHolder.backgroundColor = backGroundColor; [scroll addSubview:kHolder]; label = [[UILabel alloc] initWithFrame:SGRectMake(20, 0, kSize.width - 40, 30)]; label.text = @"该驾校暂无课程信息哦~"; label.textColor = defGreen; [label addSelfViewWithRect:SGRectMake(-20, 30 ,320, 1) Color:KlineColor]; [kHolder addSubview:label]; [scroll setContentSize:CGSizeMake(kSize.width, mainTableView.y + 120)]; [self getSchInfoById]; } //这个是刷新驾校的UI -(void)freshUI { int starNum = [model[@"star"] intValue]; if (starNum == 0) { starNum = 3; } for (int i = 0; i < starNum; i ++) { UIImageView *img = starImgs[i]; img.hidden = NO; } NSString *path = nil; NSString *str; if ([model[@"headimg"] length] > 1) { path = model[@"headimg"]; } [img00 sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"nope_pic_icon.png"]]; img00.userInteractionEnabled = YES; [img00 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]]; [lbl00 setText:model[@"name"] Font:FontTitle TextColor:kTitleColor]; str = model[@"price"]; if ([str isEqualToString:@""] || [str isEqualToString:@"0"]) { str = @"¥暂无"; }else{ str = [NSString stringWithFormat:@"¥%@",str]; } [lbl01 setText:str]; [lbl02 setText:[NSString stringWithFormat:@"%@人关注",model[@"watch"]]]; [btn00 setTitle:model[@"telePhone"] forState:UIControlStateNormal]; [btn01 setTitle:model[@"address"] forState:UIControlStateNormal]; NSString *route = [NSString stringWithFormat:@"班车路线: %@",model[@"route"]]; if ([model[@"route"] length] == 0) { route = @"班车路线: 暂无"; } [btn02 setTitle:route forState:UIControlStateNormal]; [btn5 setTitle:model[@"shortName"] forState:UIControlStateNormal]; str = model[@"desc"]; if (str.length == 0) { str = @"暂无相关简介"; } [lbl10 setText:str]; [btn5 setDetailN:@"点击加入讨论 >"]; //课程信息 NSArray *kArray = model[@"products"]; if (kArray.count == 0) { [kHolder setHidden:NO]; [scroll setContentSize:CGSizeMake(kSize.width, mainTableView.y + 120)]; }else{ [kHolder setHidden:YES]; dataArray = [NSArray arrayWithArray:kArray]; mainTableView.height = 44*dataArray.count + 55; [scroll setContentSize:CGSizeMake(kSize.width, mainTableView.y + mainTableView.height + 100)]; [mainTableView reloadData]; } } -(void)btnClick:(UIButton*)sender { int tag = (int)sender.tag; if (-1 == tag) { //报名 NSString* str = model[@"jxbh"]; NSString* str1 = model[@"name"]; if (str && str1) { ApplyVC *appVC = [[ApplyVC alloc] init]; appVC.jxbh = str; appVC.jxmc = str1; [self navPushHideTabbarToVC:appVC]; }else{ ShowMsgFailed(); } } if ( 0 == tag) { NSString *telString = model[@"telePhone"]; if (!telString || telString.length < 1) { return; } UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:model[@"telePhone"] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"呼叫", nil]; [alert show]; return; } if (tag == 1) { //进入地图页面 MapVC *mapVC = [[MapVC alloc] init]; // mapVC.jxdz = model[@"address"]; mapVC.lat = [model[@"latitude"] doubleValue]; mapVC.lng = [model[@"longitude"] doubleValue]; mapVC.isJustLoad = YES; mapVC.siteName = model[@"shortName"]; [self navPushHideTabbarToVC:mapVC]; } if (tag == 2) { descVC *vc = [[descVC alloc] init]; vc.titleString = @"路线详情"; vc.desc = model[@"route"]; [self navPushHideTabbarToVC:vc]; } if (tag == 10) { descVC *vc = [[descVC alloc] init]; vc.desc = model[@"desc"]; vc.titleString = @"驾校简介"; [self navPushHideTabbarToVC:vc]; } //下面需要有驾校编号才能进入 NSString *jxbh = model[@"jxbh"]; if (!jxbh || jxbh.length < 1) { return; } if (-3 == tag) { SearchComment* vc = [[SearchComment alloc] init]; vc.bpjr = jxbh; vc.type = @"1"; [self navPushHideTabbarToVC:vc]; } if (-2 == tag) { FaqVC* vc = [FaqVC new]; [vc setJxbh:jxbh]; [self navPushHideTabbarToVC:vc]; } if (tag == 12) { //NSLog(@"新闻"); SchoolNewsVC *news = [[SchoolNewsVC alloc] init]; news.jxbh = jxbh; [self navPushHideTabbarToVC:news]; } if (tag == 13) { TopicesVC* vc = [[TopicesVC alloc] init]; vc.type = @"1"; vc.groupId = @"-1"; vc.jxbh = jxbh; vc.jxjc = model[@"shortName"]; [self navPushHideTabbarToVC:vc]; } if (tag == 14) { //NSLog(@"更多课程"); } } -(void)tapImage:(UITapGestureRecognizer *)tap { NSArray *images = model[@"schPlaces"]; if (images.count < 1) { return; } NSMutableArray *urls = [NSMutableArray array]; for (NSDictionary *dic in images) { if (dic[@"filePath"]) { [urls addObject:dic[@"filePath"]]; } } [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:urls currentIndex:0 isCanSave:YES]; } //弹出显示详细课程信息 -(void)getViewWithDic:(NSDictionary *)dic { UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(-1, kSize.height/2.0 - 80, kSize.width + 2, 200)]; vi.backgroundColor = backGroundColor; vi.layer.borderColor = defGreen.CGColor; vi.layer.borderWidth = 1; [self.view addSubview:vi]; CGFloat kx,ky,kw,kh; kx = 8; ky = 0; kw = kSize.width/2.0 - 9; kh = 30; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, ky, 2*kw - 100, kh)]; label.textColor = kTitleColor; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont scaleSize:18]; label.text = @"培训详情"; [vi addSubview:label]; EXButton* btn = [[EXButton alloc] initWithFrame:CGRectMake(kSize.width - 50, 0, 30, 30)]; [btn addTarget:self action:@selector(removeKView:) forControlEvents:UIControlEventTouchUpInside]; [btn setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor grayColor]] forState:UIControlStateNormal]; [btn setTitle:@"×" textColor:[UIColor whiteColor] font:30 fotState:UIControlStateNormal]; [vi addSubview:btn]; ky += kh + 8; label = [[UILabel alloc] initWithFrame:CGRectMake(kx, ky, kw, kh)]; label.textColor = kTitleColor; [vi addSubview:label]; kName = label; kx += kw; label = [[UILabel alloc] initWithFrame:CGRectMake(kx, ky, kw, kh)]; label.textColor = kTitleColor; [vi addSubview:label]; kPrice = label; ky += kh; label = [[UILabel alloc] initWithFrame:CGRectMake(kx, ky, kw, kh)]; label.textColor = kTitleColor; [vi addSubview:label]; kCar = label; kx -= kw; label = [[UILabel alloc] initWithFrame:CGRectMake(kx, ky, kw, kh)]; label.textColor = kTitleColor; [vi addSubview:label]; kType = label; kw *= 2; ky += kh; NSMutableArray *kLabels = [NSMutableArray arrayWithCapacity:3]; for (int i = 0; i < 3; i ++) { label = [[UILabel alloc] initWithFrame:CGRectMake(kx, ky + i*kh, kw, kh)]; label.textColor = kTitleColor; [vi addSubview:label]; [kLabels addObject:label]; } kTime = kLabels[0]; kAdress = kLabels[1]; kPick = kLabels[2]; kName.text = [NSString stringWithFormat:@"课程:%@",types[[dic[@"shopType"] intValue] - 1]]; kPrice.text = [NSString stringWithFormat:@"价格:%@%@",dic[@"price"],dic[@"priceUnit"]]; kType.text = [NSString stringWithFormat:@"证件:%@",dic[@"permitCarType"]]; kCar.text = [NSString stringWithFormat:@"车辆:%@",dic[@"carBrands"]]; kTime.text = [NSString stringWithFormat:@"学车时间:%@",dic[@"time"]]; kAdress.text = [NSString stringWithFormat:@"训练场地:%@",dic[@"address"]]; if ([dic[@"shopType"] isEqualToString:@"4"]) { kPick.text = @"接送信息:不接送"; }else{ if ([dic[@"isPick"] isEqualToString:@"0"]) { kPick.text = @"接送信息:不接送"; }else{ kPick.text = [NSString stringWithFormat:@"接送信息:%@[%@]",dic[@"pickAddress"],dic[@"pickTime"]]; } } } -(void)removeKView:(EXButton *)sender { UIView *view = sender.superview; if (view) { [view removeFromSuperview]; } } #pragma mark tableView delegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KSchoolCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kCell"]; if (cell == nil) { cell = [[KSchoolCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kCell"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } NSDictionary *dic = dataArray[indexPath.row]; cell.nameLabel.text = types[[dic[@"shopType"] intValue] - 1]; cell.priceLabel.text = dic[@"price"]; cell.unitLabel.text = dic[@"priceUnit"]; cell.carTypeLabel.text = dic[@"permitCarType"]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic = dataArray[indexPath.row]; [self getViewWithDic:dic]; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)]; headerView.backgroundColor = backGroundColor; CGFloat width = (kSize.width - 16)/7.0; CGFloat x,y,w,h,bd; x = bd = 8; y = 5; w = 2*width; h = 40; UILabel *label = [[UILabel alloc] setxywh]; label.textAlignment = NSTextAlignmentCenter; label.text = @"培训名称"; [label setFont:[UIFont scaleSize:16]]; [headerView addSubview:label]; x += 2*width; w = 2*width; label = [[UILabel alloc] setxywh]; label.textAlignment = NSTextAlignmentCenter; label.text = @"驾照"; [label setFont:[UIFont scaleSize:16]]; [headerView addSubview:label]; x += 2.5*width; label = [[UILabel alloc] setxywh]; label.textAlignment = NSTextAlignmentCenter; label.text = @"价格"; [label setFont:[UIFont scaleSize:16]]; [headerView addSubview:label]; return headerView; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 50; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ return [UIView new]; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } #pragma mark - 获取驾校信息 -(void)getSchInfoById { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; if (!_schoolId) { return; } [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:_schoolId,@"id", nil]]; NSString* method = @"getSchInfoById"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsgFailed(); return; } NSString* code = root[@"code"]; if ( 1 == code.intValue ) { [LoadingView showMsg:root[@"body"]]; return; } NSDictionary* body = root[@"body"]; model = body; [self freshUI]; }]; } #pragma mark - 呼叫功能 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (1 == buttonIndex) { NSString* str = model[@"telePhone"]; NSMutableString * url=[[NSMutableString alloc] initWithFormat:@"tel:%@",str]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; } } @end