commentVC.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // commentVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/1/19.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "commentVC.h"
  9. #import "RatingBar.h"
  10. @interface commentVC ()
  11. {
  12. RatingBar *bar1;
  13. RatingBar *bar2;
  14. RatingBar *bar3;
  15. RatingBar *bar4;
  16. }
  17. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *commentBottomH;
  18. @end
  19. @implementation commentVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.title = @"学员评价";
  23. self.view.backgroundColor = backGroundColor;
  24. [self configNavigationBar];
  25. _commentBottomH.constant = kSafeAreaBottomHeight;
  26. _label1.backgroundColor = backGroundColor;
  27. _label2.backgroundColor = backGroundColor;
  28. _label3.backgroundColor = backGroundColor;
  29. _label4.backgroundColor = backGroundColor;
  30. [_commentBtn setBackgroundColor:defGreen];
  31. [_commentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  32. bar1 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label1.y, 180, 30) Flag:NO];
  33. bar1.enable = YES;
  34. bar1.viewColor = backGroundColor;
  35. [self.view addSubview:bar1];
  36. bar2 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label2.y, 180, 30) Flag:NO];
  37. bar2.enable = YES;
  38. bar2.viewColor = backGroundColor;
  39. [self.view addSubview:bar2];
  40. bar3 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label3.y, 180, 30) Flag:NO];
  41. bar3.enable = YES;
  42. bar3.viewColor = backGroundColor;
  43. [self.view addSubview:bar3];
  44. bar4 = [[RatingBar alloc] initWithFrame:CGRectMake(kSize.width - 200, _label4.y, 180, 30) Flag:NO];
  45. bar4.enable = YES;
  46. bar4.viewColor = backGroundColor;
  47. [self.view addSubview:bar4];
  48. }
  49. - (void)didReceiveMemoryWarning {
  50. [super didReceiveMemoryWarning];
  51. // Dispose of any resources that can be recreated.
  52. }
  53. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  54. {
  55. [self.view endEditing:YES];
  56. }
  57. -(void)showAlert:(NSString *)msg
  58. {
  59. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  60. [alert show];
  61. }
  62. - (IBAction)clickToComment:(id)sender
  63. {
  64. if (![_commentTextView.text isEqualToString:@""])
  65. {
  66. //输入限制范本
  67. if (_commentTextView.text.length < 6) {
  68. [self showAlert:@"最少输入6个字"];
  69. return;
  70. }
  71. if (_commentTextView.text.length > 50) {
  72. [self showAlert:@"最多输入50个字"];
  73. return;
  74. }
  75. //先剔除允许出现的符号
  76. NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@",。:;!‘’“”、,.:;!'"];
  77. NSString *separatedString = [[_commentTextView.text componentsSeparatedByCharactersInSet: set]componentsJoinedByString: @""];
  78. //验证剩下的字符串是否是汉字
  79. NSString *chineseCharacter = @"^[\u4e00-\u9fa5]{0,}$";
  80. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",chineseCharacter];
  81. BOOL isRight = [predicate evaluateWithObject:separatedString];
  82. if (!isRight)
  83. {
  84. [self showAlert:@"只允许输入汉字,请检查您的输入!"];
  85. return;
  86. }
  87. }
  88. if (bar1.starNumber == 0 || bar2.starNumber == 0 || bar3.starNumber == 0 || bar4.starNumber == 0)
  89. {
  90. [self showAlert:@"请对驾校或者教练做出星级评价"];
  91. return;
  92. }
  93. [self saveEvaluate];
  94. }
  95. -(void)saveEvaluate
  96. {
  97. if (![Util connectedToNetWork]) {
  98. showMsgUnconnect();
  99. return;
  100. }
  101. NSMutableArray* arr = [NSMutableArray array];
  102. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  103. //判断 驾校教练 参数不同
  104. if ([_commentType isEqualToString:@"1"])
  105. {
  106. [arr addPro:@"bpjr" Value:defUser.userSchoolId];
  107. }
  108. if ([_commentType isEqualToString:@"2"])
  109. {
  110. [arr addPro:@"bpjr" Value:_coachzh];
  111. }
  112. [arr addPro:@"content" Value:_commentTextView.text];
  113. [arr addPro:@"type" Value:_commentType];
  114. [arr addPro:@"serviceStar" Value:[NSString stringWithFormat:@"%ld",(long)bar1.starNumber]];
  115. if ([_commentType isEqualToString:@"1"])
  116. {
  117. [arr addPro:@"siteStar" Value:[NSString stringWithFormat:@"%ld",(long)bar2.starNumber]];
  118. [arr addPro:@"teachStar" Value:@""];
  119. }
  120. if ([_commentType isEqualToString:@"2"])
  121. {
  122. [arr addPro:@"siteStar" Value:@""];
  123. [arr addPro:@"teachStar" Value:[NSString stringWithFormat:@"%ld",(long)bar3.starNumber]];
  124. }
  125. [arr addPro:@"tollStar" Value:[NSString stringWithFormat:@"%ld",(long)bar4.starNumber]];
  126. NSString* method = @"saveEvaluateCoach";
  127. [MBProgressHUD showLoadToView:self.view];
  128. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  129. [MBProgressHUD hideHUDForView:self.view];
  130. //NSLog(@"提交评论时候的参数---->%@----提交评论时候返回的数据root--%@",arr,root);
  131. if (!root)
  132. {
  133. ShowMsgFailed();
  134. return;
  135. }
  136. if ([root[@"code"] isEqualToString:@"1"])
  137. {
  138. ShowMsg(root[@"body"]);
  139. return;
  140. }
  141. [self.navigationController popViewControllerAnimated:YES];
  142. }];
  143. }
  144. @end