// // PJViewController.m // jiaPei // // Created by EchoShacolee on 2017/2/17. // Copyright © 2017年 JCZ. All rights reserved. // #import "Evaluation.h" #import "RatingBar.h" @interface Evaluation () { UILabel *coachNameLabel; CGRect _frame;//记录评价view尺寸 NSArray * _dataArr;//记录评论列表内容 NSMutableArray *_selectArr;//记录被选取的评论列表里的内容 NSInteger _starCount;//记录星级 NSString *_coachName;//教练名字 } @property (weak, nonatomic) IBOutlet UIImageView *headImgV; @property (weak, nonatomic) IBOutlet UIView *ratingBar; @property (weak, nonatomic) IBOutlet UILabel *ratingLab; @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (weak, nonatomic) IBOutlet UITextView *textView; @property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *textView_top; @end @implementation Evaluation - (void)viewDidLoad { [super viewDidLoad]; [self setTitle:@"课程评价"]; self.navigationController.navigationBar.translucent = NO; [self configNavigationBar]; //self.view.backgroundColor = backGroundColor; //获取评论栏目 if (_xsDic.count != 0) { _coachName = _xsDic[@"coachName"]; [self getEvaluationCoachList]; }else if (_orderDic.count != 0){ _coachName = _orderDic[@"coachName"]; [self getGzptEvaluationCoachList]; } [self myInit]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:YES]; //记录frame _frame = _textView.frame; // NSLog(@"viewDidAppear:%@",NSStringFromCGRect(_textView.frame)); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; if (kSize.height < 600) { self.textView_top.constant = 0; } CGFloat rate = kSize.height-568; _textView.frame = CGRectMake(_textView.x, _textView.y, _textView.width, _textView.height+rate/2); // NSLog(@"DidLayoutSubv:%@",NSStringFromCGRect(_textView.frame)); } - (IBAction)nextBtnClick:(id)sender { if ([_textView.text isEqualToString:@"(教练哪些地方让你印象深刻?快和大家分享一下吧)"]) { ShowMsg(@"评价内容不能为空"); return; } if (_textView.text.length > 100) { ShowMsg(@"评论内容不能超出100字"); return; } if (_xsDic.count != 0) { [self doEvaluation];//学时评论 }else if (_orderDic.count != 0){ [self uploadReserveEvaluate];//订单评论 } } -(void)myInit { _dataArr = [NSArray new]; _selectArr = [NSMutableArray new]; // _headImgV.image = [UIImage imageWithContentsOfFile:filePtah];订单无法返回头像,用name coachNameLabel = [[UILabel alloc] initWithFrame:_headImgV.bounds]; [coachNameLabel setText:_coachName Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter]; [self.headImgV addSubview:coachNameLabel]; // NSLog(@"%@",NSStringFromCGRect(_headImgV.frame)); RatingBar * starBar = [[RatingBar alloc]initWithFrame:_ratingBar.bounds Flag:YES]; starBar.starNumber =5; _starCount = starBar.starNumber; starBar.enable = YES; [starBar changeStarNumberBlock:^(NSString *starNumString) { _starCount = [starNumString integerValue]; switch (_starCount) { case 0: _ratingLab.text = @"很不满意"; break; case 1: _ratingLab.text = @"不满意"; break; case 2: _ratingLab.text = @"一般"; break; case 3: _ratingLab.text = @"满意"; break; case 4: _ratingLab.text = @"非常满意"; break; default: break; } }]; [_ratingBar addSubview:starBar]; //lableView collection //注册item类型及复用标识 [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellId"]; //textView //定义一个toolBar UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 50)]; //设置style [topView setBarStyle:UIBarStyleDefault]; //定义两个flexibleSpace的button,放在toolBar上,这样完成按钮就会在最右边 UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil]; //定义完成按钮 UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(endBtnClick)]; //在toolBar上加上这些按钮 NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil]; [topView setItems:buttonsArray]; [_textView setInputAccessoryView:topView]; } #pragma mark - UITextViewDelegate协议中的方法 - (void)textViewDidBeginEditing:(UITextView *)textView { if ([_textView.text isEqualToString:@"(教练哪些地方让你印象深刻?快和大家分享一下吧)"]) { _textView.text = @""; _textView.textColor = kTitleColor; } _textView.frame = CGRectMake(10, 20, kSize.width-20, kSize.height*0.5 - 50); _textView.font = [UIFont systemFontOfSize:Font17]; //@lee 写下面的上面的就不起作用了。why // _endBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // _endBtn.frame = CGRectMake(kSize.width-110, 10+kSize.height*0.5 - 50, 80, 40); // [_endBtn addTarget:self action:@selector(endBtnClick) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:_endBtn]; } - (void)textViewDidEndEditing:(UITextView *)textView { if (_textView.text.length == 0) { _textView.text = @"(教练哪些地方让你印象深刻?快和大家分享一下吧)"; _textView.textColor = [UIColor grayColor]; } _textView.frame = _frame; _textView.font = [UIFont systemFontOfSize:15]; } -(void)endBtnClick { [_textView resignFirstResponder]; } #pragma mark - 数据请求 -(void)getEvaluationCoachList{ if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"coachId" Value:self.xsDic[@"coachId"]]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city]; NSString* method = @"getEvaluationCoachList"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { if (!root) { return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } _dataArr = root[@"body"]; [_collectionView reloadData]; }]; } -(void)getGzptEvaluationCoachList{ if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"id" Value:self.orderDic[@"coachId"]]; NSString* method = @"getGzptEvaluationCoachList"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { if (!root) { return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } _dataArr = root[@"body"]; [_collectionView reloadData]; }]; } -(void)doEvaluation{ [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *strDate = [dateFormatter stringFromDate:[NSDate date]]; NSMutableString * mStr = [NSMutableString new]; for (NSString *str in _selectArr) { [mStr appendFormat:@"%@,",str]; } if (mStr.length > 0) { mStr = (NSMutableString *)[mStr substringToIndex:mStr.length-1]; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId]; [arr addPro:@"type" Value:@"1"];//1教练员,2学时机构 [arr addPro:@"evaId" Value:_xsDic[@"coachId"]]; [arr addPro:@"overAll" Value:[NSString stringWithFormat:@"%d",(int)_starCount]]; [arr addPro:@"part" Value:_xsDic[@"kmStr"]]; [arr addPro:@"evaluateTime" Value:strDate]; [arr addPro:@"itemIds" Value:mStr]; [arr addPro:@"teachLevel" Value:_textView.text]; [arr addPro:@"classId" Value:_xsDic[@"classId"]]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city]; NSString* method = @"doEvaluation"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); if (!root) { return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } if (_tvc.blcok) { _tvc.blcok(); } [self.navigationController popViewControllerAnimated:YES]; }]; } -(void)uploadReserveEvaluate { [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableString * mStr = [NSMutableString new]; for (NSString *str in _selectArr) { [mStr appendFormat:@"%@,",str]; } if (mStr.length > 0) { mStr = (NSMutableString *)[mStr substringToIndex:mStr.length-1]; } //{'overall':'3','part':'2','itemIds':'1,2,3','teachLevel':'撒发放','classId':'1245536456','userId':'1','objectId':'1'} NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"overall" Value:[NSString stringWithFormat:@"%d",(int)_starCount]]; [arr addPro:@"itemIds" Value:mStr]; [arr addPro:@"teachLevel" Value:_textView.text]; [arr addPro:@"classId" Value:_orderDic[@"classId"]]; [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id]; [arr addPro:@"part" Value:_orderDic[@"kmStr"]]; [arr addPro:@"objectId" Value:_orderDic[@"coachId"]]; NSString* method = @"uploadReserveEvaluate"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); if (!root) { return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } [self.navigationController popViewControllerAnimated:YES]; }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _dataArr.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath]; UILabel * lable = nil; if (cell.contentView.subviews.count == 0) { lable = [[UILabel alloc]initWithFrame:cell.bounds]; // [lable borderColor:[UIColor grayColor] width:0.5 cornorRadius:1]; lable.layer.borderWidth = 0.5; [cell.contentView addSubview:lable]; }else{ lable = (UILabel *)cell.contentView.subviews.firstObject; } NSDictionary * dic = _dataArr[indexPath.item]; NSString * labelString = @""; if ([_selectArr containsObject:dic[@"ID"]]) { lable.layer.borderColor = RQ_MAIN_COLOR.CGColor; labelString = [NSString stringWithFormat:@"%@ %d",dic[@"NAME"],[dic[@"ITEMNO"] intValue] + 1]; [lable setText:labelString Font:NormalFont TextColor:RQ_MAIN_COLOR Alignment:NSTextAlignmentCenter]; }else{ lable.layer.borderColor = kTitleColor.CGColor; labelString = [NSString stringWithFormat:@"%@ %@",dic[@"NAME"],dic[@"ITEMNO"]]; [lable setText:labelString Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentCenter]; } lable.text = labelString; return cell; } //通过代理方法可以动态指定布局对象的相关属性 //指定后布局依次为准,创建布局对象时的默认设置无效 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = (kSize.width - 40 - 20 - 20)/2; return CGSizeMake(width, 30); } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath{ NSDictionary * dic = _dataArr[indexPath.item]; if ([_selectArr containsObject:dic[@"ID"]]) { [_selectArr removeObject:dic[@"ID"]]; }else{ if (_selectArr.count == 3) { [_selectArr removeObjectAtIndex:0]; } [_selectArr addObject:dic[@"ID"]]; } [collectionView reloadData]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end