// // commentVC.m // jiaPei // // Created by apple on 16/1/19. // Copyright © 2016年 JCZ. All rights reserved. // #import "commentVC.h" #import "RatingBar.h" @interface commentVC () { RatingBar *bar1; RatingBar *bar2; RatingBar *bar3; RatingBar *bar4; } @property (weak, nonatomic) IBOutlet NSLayoutConstraint *commentBottomH; @end @implementation commentVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"学员评价"; self.view.backgroundColor = backGroundColor; [self configNavigationBar]; _commentBottomH.constant = kSafeAreaBottomHeight; _label1.backgroundColor = backGroundColor; _label2.backgroundColor = backGroundColor; _label3.backgroundColor = backGroundColor; _label4.backgroundColor = backGroundColor; [_commentBtn setBackgroundColor:defGreen]; [_commentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; bar1 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label1.y, 180, 30) Flag:NO]; bar1.enable = YES; bar1.viewColor = backGroundColor; [self.view addSubview:bar1]; bar2 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label2.y, 180, 30) Flag:NO]; bar2.enable = YES; bar2.viewColor = backGroundColor; [self.view addSubview:bar2]; bar3 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label3.y, 180, 30) Flag:NO]; bar3.enable = YES; bar3.viewColor = backGroundColor; [self.view addSubview:bar3]; bar4 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label4.y, 180, 30) Flag:NO]; bar4.enable = YES; bar4.viewColor = backGroundColor; [self.view addSubview:bar4]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } -(void)showAlert:(NSString *)msg { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; } - (IBAction)clickToComment:(id)sender { if (![_commentTextView.text isEqualToString:@""]) { //输入限制范本 if (_commentTextView.text.length < 6) { [self showAlert:@"最少输入6个字"]; return; } if (_commentTextView.text.length > 50) { [self showAlert:@"最多输入50个字"]; return; } //先剔除允许出现的符号 NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@",。:;!‘’“”、,.:;!'"]; NSString *separatedString = [[_commentTextView.text componentsSeparatedByCharactersInSet: set]componentsJoinedByString: @""]; //验证剩下的字符串是否是汉字 NSString *chineseCharacter = @"^[\u4e00-\u9fa5]{0,}$"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",chineseCharacter]; BOOL isRight = [predicate evaluateWithObject:separatedString]; if (!isRight) { [self showAlert:@"只允许输入汉字,请检查您的输入!"]; return; } } if (bar1.starNumber == 0 || bar2.starNumber == 0 || bar3.starNumber == 0 || bar4.starNumber == 0) { [self showAlert:@"请对驾校或者教练做出星级评价"]; return; } [self saveEvaluate]; } -(void)saveEvaluate { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray* arr = [NSMutableArray array]; [arr addPro:@"userId" Value:defUser.userDict[@"id"]]; //判断 驾校教练 参数不同 if ([_commentType isEqualToString:@"1"]) { [arr addPro:@"bpjr" Value:defUser.userSchoolId]; } if ([_commentType isEqualToString:@"2"]) { [arr addPro:@"bpjr" Value:_coachzh]; } [arr addPro:@"content" Value:_commentTextView.text]; [arr addPro:@"type" Value:_commentType]; [arr addPro:@"serviceStar" Value:[NSString stringWithFormat:@"%ld",(long)bar1.starNumber]]; if ([_commentType isEqualToString:@"1"]) { [arr addPro:@"siteStar" Value:[NSString stringWithFormat:@"%ld",(long)bar2.starNumber]]; [arr addPro:@"teachStar" Value:@""]; } if ([_commentType isEqualToString:@"2"]) { [arr addPro:@"siteStar" Value:@""]; [arr addPro:@"teachStar" Value:[NSString stringWithFormat:@"%ld",(long)bar3.starNumber]]; } [arr addPro:@"tollStar" Value:[NSString stringWithFormat:@"%ld",(long)bar4.starNumber]]; NSString* method = @"saveEvaluateCoach"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; //NSLog(@"提交评论时候的参数---->%@----提交评论时候返回的数据root--%@",arr,root); if (!root) { ShowMsgFailed(); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } [self.navigationController popViewControllerAnimated:YES]; }]; } @end