// // SchoolInfoVC.m // jiaPei // // Created by apple on 15/11/7. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "SchoolInfoVC.h" #import "commentVC.h" #import "RatingBar.h" #import "SchDetailVC.h" #import "SelectSchoolVC.h" @interface SchoolInfoVC () @property (weak, nonatomic) IBOutlet UILabel *nameLbl; @property (weak, nonatomic) IBOutlet UILabel *addrLbl; @property (weak, nonatomic) IBOutlet UILabel *cntLbl; @property (weak, nonatomic) IBOutlet UILabel *areaLbl; @property (weak, nonatomic) IBOutlet UILabel *telLbl; @property (weak, nonatomic) IBOutlet UIImageView *headImg; @end @implementation SchoolInfoVC { NSDictionary *schoolDic; NSDictionary *comment; UIButton *commentBtn; RatingBar *starBar1; RatingBar *starBar2; RatingBar *starBar3; RatingBar *starBar4; BOOL isLoad; } @synthesize schoolId; -(instancetype)init { self = [super initWithNibName:@"SchoolInfoVC" bundle:nil]; return self; } #pragma mark - - (void)viewDidLoad { [super viewDidLoad]; isLoad = NO; [self myInit]; [self getMySchInfo]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (isLoad) { [self getCommentsList]; } isLoad = YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)myInit{ [self setTitle:@"我的驾校"]; [self configNavigationBar]; self.navigationController.navigationBar.translucent = NO; [_headImg setBackgroundColor:defGreen]; //如果是身份证登录 可以评论 如果是第三方且没有绑定身份证 就是更改驾校的按钮 commentBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; if ([defUser.userDict[@"outId"] length] < 1) { //还未绑定身份证信息 第三方登录的 或者身份证登录但是不入计时平台 [commentBtn setTitle:@"选驾校" forState:UIControlStateNormal]; [commentBtn setTitleColor:defGreen forState:UIControlStateNormal]; [commentBtn addTarget:self action:@selector(clickToSelectschool) forControlEvents:UIControlEventTouchUpInside]; }else{ [commentBtn setBackgroundColor:defGreen]; [commentBtn setTitle:@"评价" forState:UIControlStateNormal]; [commentBtn addTarget:self action:@selector(clickToComment) forControlEvents:UIControlEventTouchUpInside]; } UIBarButtonItem* bbi = [[UIBarButtonItem alloc] initWithCustomView:commentBtn]; self.navigationItem.rightBarButtonItem = bbi; starBar1 = [[RatingBar alloc] initWithFrame:SGRectMake(140, 225, 180, 25*480/kSize.height) Flag:NO]; starBar1.enable = NO; [self.view addSubview:starBar1]; starBar2 = [[RatingBar alloc] initWithFrame:SGRectMake(140, 253, 180, 25*480/kSize.height) Flag:NO]; starBar2.enable = NO; [self.view addSubview:starBar2]; starBar3 = [[RatingBar alloc] initWithFrame:SGRectMake(140, 281, 180, 25*480/kSize.height) Flag:NO]; starBar3.enable = NO; [self.view addSubview:starBar3]; starBar4 = [[RatingBar alloc] initWithFrame:SGRectMake(140, 309, 180, 25*480/kSize.height) Flag: NO]; starBar4.enable = NO; [self.view addSubview:starBar4]; _commentLabel.numberOfLines = 0; } #pragma mark 异步获取驾校信息 -(void)getMySchInfo { schoolId = defUser.userSchoolId; if (!schoolId || [schoolId isEqualToString:@""]) { ShowMsg(@"找不到您的驾校"); return; } if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"jxbh" Value:schoolId]; NSString* method = @"getMySchInfo"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { [LoadingView showMsg:@"网络请求失败!"]; return; } NSString* code = root[@"code"]; if (code.intValue >0) { [LoadingView showMsg:@"请求失败!"]; return; } NSDictionary* body = root[@"body"]; if (body.allKeys.count < 1) { return; } schoolDic = [[NSDictionary alloc] initWithDictionary:body]; //NSLog(@"获取驾校信息body--%@",body); defUser.userSchDict = body; [self getCommentsList]; [self freshUI]; }]; } -(void)freshUI { starBar1.starNumber = [schoolDic[@"star"] intValue]; starBar2.starNumber = [schoolDic[@"serviceStar"] intValue]; starBar3.starNumber = [schoolDic[@"siteStar"] intValue]; starBar4.starNumber = [schoolDic[@"tollStar"] intValue]; _vipImg.hidden = ![schoolDic[@"vip"] intValue]; self.nameLbl.text = schoolDic[@"name"]; self.addrLbl.text = schoolDic[@"address"]; self.cntLbl.text = schoolDic[@"score"]; self.areaLbl.text = schoolDic[@"xlczmj"]; self.telLbl.text = schoolDic[@"telePhone"]; if ([schoolDic[@"headImg"] length] > 0) { NSString *path = schoolDic[@"headImg"]; if (![path hasPrefix:@"http"]){ path = [imgPreFix stringByAppendingString:path]; } [self.headImg sd_setImageWithURL:[NSURL URLWithString:path]]; } } #pragma mark 异步获取评论列表 -(void)getCommentsList { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray* arr = [NSMutableArray array]; [arr addPro:@"userId" Value:defUser.userDict[@"id"]]; [arr addPro:@"type" Value:@"1"]; NSString* method = @"getMyEvaluate"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; //NSLog(@"返回驾校的----%@评论 ----%@",arr,root); if (!root || [root[@"code"] intValue] == 1) { return; } if ([[root[@"body"] firstObject] count] < 1) { return; } //返回数据为一条的时候是字典 comment = [[NSDictionary alloc] initWithDictionary:[root[@"body"] firstObject]]; [commentBtn setTitle:@"已评价" forState:UIControlStateNormal]; commentBtn.width = 80; commentBtn.userInteractionEnabled = NO; [self freshComment:comment]; }]; } -(void)freshComment:(NSDictionary *)dic { starBar1.starNumber = [dic[@"star"] intValue]; starBar2.starNumber = [dic[@"serviceStar"] intValue]; starBar3.starNumber = [dic[@"siteStar"] intValue]; starBar4.starNumber = [dic[@"tollStar"] intValue]; _commentLabel.text = dic[@"content"]; } #pragma mark 添加评论信息 -(void)clickToComment { //不用判断已评价 因为已关掉用户交互了 commentVC *VC = [[commentVC alloc] init]; VC.commentType = @"1"; [self navPushHideTabbarToVC:VC]; } //重新选择驾校 - (void)clickToSelectschool { SelectSchoolVC *selectVC = [[SelectSchoolVC alloc] init]; selectVC.skipType = @"3"; [self navPushHideTabbarToVC:selectVC]; } #pragma mark tableView delegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; if (comment && comment.allKeys.count != 0) { //这里边是评论内容的key值 cell.textLabel.text = comment[@"content"]; cell.textLabel.numberOfLines = 0; } else { cell.textLabel.text = @"您还未添加评论哦!"; } return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (comment && comment.allKeys.count != 0) { return 80; } return 44; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.1; } #pragma mark - delegate -(void)finishFailRequest:(NSError *)error{ //NSLog(@"我是代理1吧,我在schoolInfoVC"); } -(void)finishSuccessRequest:(NSString *)xml{ //NSLog(@"我是代理2吧,我在schoolInfoVC"); } - (IBAction)goToDetail:(id)sender { SchDetailVC* schVC = [[SchDetailVC alloc] init]; schVC.schoolId = schoolDic[@"id"]; [self navPushHideTabbarToVC:schVC]; } @end