// // CoachDetailInfoVC.m // jiaPei // // Created by apple on 16/1/14. // Copyright © 2016年 JCZ. All rights reserved. // #import "CoachDetailInfoVC.h" #import "commentVC.h" #import "CoachCell.h" #import "HolderView.h" @interface CoachDetailInfoVC () { UITableView *mainTableView; HolderView *holderV; NSArray *coachsArray; NSArray *commentsArray; NSString *telephone; BOOL isCommented[2]; BOOL isLoad; } @end @implementation CoachDetailInfoVC - (void)viewDidLoad { [super viewDidLoad]; coachsArray = [NSArray array]; commentsArray = [NSArray array]; isLoad = NO; [self myInit]; [self getMyCoachInfos]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBarHidden = NO; if (isLoad) { [self getComments]; } isLoad = YES; } -(void)myInit { [self setTitle:@"我的教练"]; self.navigationController.navigationBar.translucent = NO; [self configNavigationBar]; mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain]; mainTableView.height -= kNavOffSet; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.rowHeight = 450; [self.view addSubview:mainTableView]; holderV = [[HolderView alloc] initWithFrame:mainTableView.frame]; [holderV freshBlock:^{ [self getMyCoachInfos]; }]; [self.view addSubview:holderV]; } #pragma mark 异步获取教练信息 -(void)getMyCoachInfos { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; if (!defUser.userDict[@"outId"]) { holderV.hidden = NO; return; } if ([defUser.userDict[@"outId"] isEqualToString:@""]) { holderV.hidden = NO; return; } [arr addPro:@"stuOutId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; NSString* method = @"getMyCoachInfos"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { holderV.hidden = NO; [MBProgressHUD hideHUDForView:self.view]; // NSLog(@"教练列表---->%@",root); if (!root) { [LoadingView showMsg:@"刷新失败!"]; return; } NSString* code = root[@"code"]; if (code.intValue >0) { [LoadingView showMsg:root[@"body"]]; return; } NSArray* body = root[@"body"]; if (body.count < 1) { [LoadingView showMsg:@"查询不到您的教练"]; return; } //我的教练 coachsArray = body; //NSLog(@"教练刷新表"); [self getComments]; holderV.hidden = YES; [mainTableView reloadData]; }]; } #pragma mark 异步获取评论列表 -(void)getComments { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray* arr = [NSMutableArray array]; [arr addPro:@"userId" Value:defUser.userDict[@"id"]]; [arr addPro:@"type" Value:@"2"]; NSString* method = @"getMyEvaluate"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; // NSLog(@"获取自己评论返回----%@的数据%@",arr,commentsArray); if (!root || [root[@"code"] intValue] == 1) { return; } commentsArray = root[@"body"]; if (commentsArray.count < 1) { return; } //NSLog(@"评价刷新表"); [mainTableView reloadData]; }]; } #pragma mark 对教练评价 -(void)clickToComment:(UIButton *)btn { if (isCommented[btn.tag]) { //NSLog(@"已评价,要在btn显示上做改动--第几个按钮-- %ld",(long)btn.tag); return; } commentVC *VC = [[commentVC alloc] init]; VC.commentType = @"2"; VC.coachzh = [coachsArray[btn.tag] objectForKey:@"SFZHM"];; [self navPushHideTabbarToVC:VC]; } #pragma mark tableView delegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return coachsArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CoachCell *cell = [tableView dequeueReusableCellWithIdentifier:@"coachCell"]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"CoachCell" owner:nil options:nil] firstObject]; [cell.commentBtn addTarget:self action:@selector(clickToComment:) forControlEvents:UIControlEventTouchUpInside]; [cell.commentBtn setTitleColor:defGreen forState:UIControlStateNormal]; [cell.commentBtn.layer setBorderWidth:.7]; [cell.commentBtn.layer setBorderColor:defGreen.CGColor]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.commentBtn.tag = indexPath.row; //教练信息获取的内容 NSDictionary *dic = coachsArray[indexPath.row]; //头像地址 //NSLog(@"%@",[imgPreFix stringByAppendingString:dic[@"HEADIMG"]]); NSString *url = [Tools imageStringWithPhotoString:dic[@"PHOTO"] HeadImgString:dic[@"HEADIMG"] Type:1]; [cell.headImg sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"drawer_head"]]; cell.name.text = [NSString stringWithFormat:@"姓名: %@",dic[@"NAME"]]; cell.sex.text = [NSString stringWithFormat:@"性别: %@",[dic[@"SEX"] intValue]==1?@"男":@"女"]; cell.score.text = [NSString stringWithFormat:@"综合评分:%@",dic[@"SCORE"]]; if ([dic[@"SCORE"] isEqualToString:@""] || !dic[@"SCORE"]) { cell.score.text = @"综合评分:暂无"; } cell.carType.text = [NSString stringWithFormat:@"带教车型:%@",dic[@"CARTYPE"]]; cell.school.text = [NSString stringWithFormat:@"所属驾校:%@",dic[@"SCHOOLNAME"]]; NSString *KM = @""; if ([dic[@"SUBJECT"] isEqualToString:@"2"]) { KM = @"科二"; } if ([dic[@"SUBJECT"] isEqualToString:@"3"]) { KM = @"科三"; } cell.teachTypeLabel.text = KM; NSString *tel = [NSString stringWithFormat:@"%@ %@",dic[@"TELPHONE"],dic[@"MOBILE"]]; if ([dic[@"TELPHONE"] isEqualToString:@""] || ![[dic allKeys]containsObject:@"TELPHONE"]) { tel = dic[@"MOBILE"]; if ([dic[@"MOBILE"] isEqualToString:@""]) { tel = @"暂无"; } telephone = tel; } else { telephone = dic[@"TELPHONE"]; } //电话按钮 [cell.telBtn addTarget:self action:@selector(clickToTel) forControlEvents:UIControlEventTouchUpInside]; //字体颜色 NSString *string = [NSString stringWithFormat:@"联系方式:%@",tel]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"联系方式:%@",tel]]; NSInteger length = string.length - 5; [str addAttribute:NSForegroundColorAttributeName value:defGreen range:NSMakeRange(5,length)]; cell.tel.attributedText = str; cell.bar1.starNumber = [dic[@"STAR"] integerValue]; //教练评论获取的内容 遍历根据coachSFZHM获取某教练的评论 NSDictionary *commentDic; for (NSDictionary *cDic in commentsArray) { if ([cDic[@"bpjr"] isEqualToString:dic[@"SFZHM"]]) { commentDic = [[NSDictionary alloc] initWithDictionary:cDic]; break; } } if (commentDic.allKeys.count != 0) { isCommented[indexPath.row] = YES; [cell.commentBtn setBackgroundColor:backGroundColor]; [cell.commentBtn setTitle:@"已评价" forState:UIControlStateNormal]; [cell.commentBtn setHidden:YES]; cell.bar1.starNumber = [commentDic[@"star"] integerValue]; cell.bar2.starNumber = [commentDic[@"serviceStar"] integerValue]; cell.bar3.starNumber = [commentDic[@"teachStar"] integerValue]; cell.bar4.starNumber = [commentDic[@"tollStar"] integerValue]; if ([commentDic[@"star"] isEqualToString:@""]) { cell.bar1.starNumber = 3; } if ([commentDic[@"serviceStar"] isEqualToString:@""]) { cell.bar2.starNumber = 3; } if ([commentDic[@"teachStar"] isEqualToString:@""]) { cell.bar3.starNumber = 3; } if ([commentDic[@"tollStar"] isEqualToString:@""]) { cell.bar4.starNumber = 3; } if ([cell.score.text isEqualToString:@"综合评分:暂无"]) { if (![commentDic[@"score"] isEqualToString:@""]) { cell.score.text = [NSString stringWithFormat:@"综合评分:%@",commentDic[@"score"]]; } } cell.comment.text = commentDic[@"content"]; } return cell; } -(void)clickToTel { if (telephone.length == 0 || [telephone isEqualToString:@"暂无"]) { return; } UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:telephone delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"呼叫", nil]; [alert show]; return; } #pragma mark - 呼叫功能 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (1 == buttonIndex) { NSMutableString * url=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephone]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end