Evaluation.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. //
  2. // PJViewController.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2017/2/17.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "Evaluation.h"
  9. #import "RatingBar.h"
  10. @interface Evaluation ()<UITextViewDelegate>
  11. {
  12. UILabel *coachNameLabel;
  13. CGRect _frame;//记录评价view尺寸
  14. NSArray * _dataArr;//记录评论列表内容
  15. NSMutableArray *_selectArr;//记录被选取的评论列表里的内容
  16. NSInteger _starCount;//记录星级
  17. NSString *_coachName;//教练名字
  18. }
  19. @property (weak, nonatomic) IBOutlet UIImageView *headImgV;
  20. @property (weak, nonatomic) IBOutlet UIView *ratingBar;
  21. @property (weak, nonatomic) IBOutlet UILabel *ratingLab;
  22. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  23. @property (weak, nonatomic) IBOutlet UITextView *textView;
  24. @property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
  25. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *textView_top;
  26. @end
  27. @implementation Evaluation
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. [self setTitle:@"课程评价"];
  31. self.navigationController.navigationBar.translucent = NO;
  32. [self configNavigationBar];
  33. //self.view.backgroundColor = backGroundColor;
  34. //获取评论栏目
  35. if (_xsDic.count != 0) {
  36. _coachName = _xsDic[@"coachName"];
  37. [self getEvaluationCoachList];
  38. }else if (_orderDic.count != 0){
  39. _coachName = _orderDic[@"coachName"];
  40. [self getGzptEvaluationCoachList];
  41. }
  42. [self myInit];
  43. }
  44. - (void)viewDidAppear:(BOOL)animated{
  45. [super viewDidAppear:YES];
  46. //记录frame
  47. _frame = _textView.frame;
  48. // NSLog(@"viewDidAppear:%@",NSStringFromCGRect(_textView.frame));
  49. }
  50. - (void)didReceiveMemoryWarning {
  51. [super didReceiveMemoryWarning];
  52. // Dispose of any resources that can be recreated.
  53. }
  54. - (void)viewDidLayoutSubviews{
  55. [super viewDidLayoutSubviews];
  56. if (kSize.height < 600) {
  57. self.textView_top.constant = 0;
  58. }
  59. CGFloat rate = kSize.height-568;
  60. _textView.frame = CGRectMake(_textView.x, _textView.y, _textView.width, _textView.height+rate/2);
  61. // NSLog(@"DidLayoutSubv:%@",NSStringFromCGRect(_textView.frame));
  62. }
  63. - (IBAction)nextBtnClick:(id)sender {
  64. if ([_textView.text isEqualToString:@"(教练哪些地方让你印象深刻?快和大家分享一下吧)"]) {
  65. ShowMsg(@"评价内容不能为空");
  66. return;
  67. }
  68. if (_textView.text.length > 100) {
  69. ShowMsg(@"评论内容不能超出100字");
  70. return;
  71. }
  72. if (_xsDic.count != 0) {
  73. [self doEvaluation];//学时评论
  74. }else if (_orderDic.count != 0){
  75. [self uploadReserveEvaluate];//订单评论
  76. }
  77. }
  78. -(void)myInit
  79. {
  80. _dataArr = [NSArray new];
  81. _selectArr = [NSMutableArray new];
  82. // _headImgV.image = [UIImage imageWithContentsOfFile:filePtah];订单无法返回头像,用name
  83. coachNameLabel = [[UILabel alloc] initWithFrame:_headImgV.bounds];
  84. [coachNameLabel setText:_coachName Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  85. [self.headImgV addSubview:coachNameLabel];
  86. // NSLog(@"%@",NSStringFromCGRect(_headImgV.frame));
  87. RatingBar * starBar = [[RatingBar alloc]initWithFrame:_ratingBar.bounds Flag:YES];
  88. starBar.starNumber =5;
  89. _starCount = starBar.starNumber;
  90. starBar.enable = YES;
  91. [starBar changeStarNumberBlock:^(NSString *starNumString) {
  92. _starCount = [starNumString integerValue];
  93. switch (_starCount) {
  94. case 0:
  95. _ratingLab.text = @"很不满意";
  96. break;
  97. case 1:
  98. _ratingLab.text = @"不满意";
  99. break;
  100. case 2:
  101. _ratingLab.text = @"一般";
  102. break;
  103. case 3:
  104. _ratingLab.text = @"满意";
  105. break;
  106. case 4:
  107. _ratingLab.text = @"非常满意";
  108. break;
  109. default:
  110. break;
  111. }
  112. }];
  113. [_ratingBar addSubview:starBar];
  114. //lableView collection
  115. //注册item类型及复用标识
  116. [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
  117. //textView
  118. //定义一个toolBar
  119. UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 50)];
  120. //设置style
  121. [topView setBarStyle:UIBarStyleDefault];
  122. //定义两个flexibleSpace的button,放在toolBar上,这样完成按钮就会在最右边
  123. UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  124. UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  125. //定义完成按钮
  126. UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(endBtnClick)];
  127. //在toolBar上加上这些按钮
  128. NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
  129. [topView setItems:buttonsArray];
  130. [_textView setInputAccessoryView:topView];
  131. }
  132. #pragma mark - UITextViewDelegate协议中的方法
  133. - (void)textViewDidBeginEditing:(UITextView *)textView
  134. {
  135. if ([_textView.text isEqualToString:@"(教练哪些地方让你印象深刻?快和大家分享一下吧)"]) {
  136. _textView.text = @"";
  137. _textView.textColor = kTitleColor;
  138. }
  139. _textView.frame = CGRectMake(10, 20, kSize.width-20, kSize.height*0.5 - 50);
  140. _textView.font = [UIFont systemFontOfSize:Font17];
  141. //@lee 写下面的上面的就不起作用了。why
  142. // _endBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  143. // _endBtn.frame = CGRectMake(kSize.width-110, 10+kSize.height*0.5 - 50, 80, 40);
  144. // [_endBtn addTarget:self action:@selector(endBtnClick) forControlEvents:UIControlEventTouchUpInside];
  145. // [self.view addSubview:_endBtn];
  146. }
  147. - (void)textViewDidEndEditing:(UITextView *)textView
  148. {
  149. if (_textView.text.length == 0) {
  150. _textView.text = @"(教练哪些地方让你印象深刻?快和大家分享一下吧)";
  151. _textView.textColor = [UIColor grayColor];
  152. }
  153. _textView.frame = _frame;
  154. _textView.font = [UIFont systemFontOfSize:15];
  155. }
  156. -(void)endBtnClick
  157. {
  158. [_textView resignFirstResponder];
  159. }
  160. #pragma mark - 数据请求
  161. -(void)getEvaluationCoachList{
  162. if (![Util connectedToNetWork]) {
  163. showMsgUnconnect();
  164. return;
  165. }
  166. NSMutableArray *arr=[NSMutableArray array];
  167. [arr addPro:@"coachId" Value:self.xsDic[@"coachId"]];
  168. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  169. NSString* method = @"getEvaluationCoachList";
  170. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  171. if (!root) {
  172. return;
  173. }
  174. if ([root[@"code"] isEqualToString:@"1"]) {
  175. ShowMsg(root[@"body"]);
  176. return;
  177. }
  178. _dataArr = root[@"body"];
  179. [_collectionView reloadData];
  180. }];
  181. }
  182. -(void)getGzptEvaluationCoachList{
  183. if (![Util connectedToNetWork]) {
  184. showMsgUnconnect();
  185. return;
  186. }
  187. NSMutableArray *arr=[NSMutableArray array];
  188. [arr addPro:@"id" Value:self.orderDic[@"coachId"]];
  189. NSString* method = @"getGzptEvaluationCoachList";
  190. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  191. if (!root) {
  192. return;
  193. }
  194. if ([root[@"code"] isEqualToString:@"1"]) {
  195. ShowMsg(root[@"body"]);
  196. return;
  197. }
  198. _dataArr = root[@"body"];
  199. [_collectionView reloadData];
  200. }];
  201. }
  202. -(void)doEvaluation{
  203. [LoadingView showHUD];
  204. if (![Util connectedToNetWork]) {
  205. showMsgUnconnect();
  206. return;
  207. }
  208. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  209. dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  210. [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  211. NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
  212. NSMutableString * mStr = [NSMutableString new];
  213. for (NSString *str in _selectArr) {
  214. [mStr appendFormat:@"%@,",str];
  215. }
  216. if (mStr.length > 0) {
  217. mStr = (NSMutableString *)[mStr substringToIndex:mStr.length-1];
  218. }
  219. NSMutableArray *arr=[NSMutableArray array];
  220. [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId];
  221. [arr addPro:@"type" Value:@"1"];//1教练员,2学时机构
  222. [arr addPro:@"evaId" Value:_xsDic[@"coachId"]];
  223. [arr addPro:@"overAll" Value:[NSString stringWithFormat:@"%d",(int)_starCount]];
  224. [arr addPro:@"part" Value:_xsDic[@"kmStr"]];
  225. [arr addPro:@"evaluateTime" Value:strDate];
  226. [arr addPro:@"itemIds" Value:mStr];
  227. [arr addPro:@"teachLevel" Value:_textView.text];
  228. [arr addPro:@"classId" Value:_xsDic[@"classId"]];
  229. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  230. NSString* method = @"doEvaluation";
  231. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  232. RemoveHUD();
  233. if (!root) {
  234. return;
  235. }
  236. if ([root[@"code"] isEqualToString:@"1"]) {
  237. ShowMsg(root[@"body"]);
  238. return;
  239. }
  240. if (_tvc.blcok) {
  241. _tvc.blcok();
  242. }
  243. [self.navigationController popViewControllerAnimated:YES];
  244. }];
  245. }
  246. -(void)uploadReserveEvaluate
  247. {
  248. [LoadingView showHUD];
  249. if (![Util connectedToNetWork]) {
  250. showMsgUnconnect();
  251. return;
  252. }
  253. NSMutableString * mStr = [NSMutableString new];
  254. for (NSString *str in _selectArr) {
  255. [mStr appendFormat:@"%@,",str];
  256. }
  257. if (mStr.length > 0) {
  258. mStr = (NSMutableString *)[mStr substringToIndex:mStr.length-1];
  259. }
  260. //{'overall':'3','part':'2','itemIds':'1,2,3','teachLevel':'撒发放','classId':'1245536456','userId':'1','objectId':'1'}
  261. NSMutableArray *arr=[NSMutableArray array];
  262. [arr addPro:@"overall" Value:[NSString stringWithFormat:@"%d",(int)_starCount]];
  263. [arr addPro:@"itemIds" Value:mStr];
  264. [arr addPro:@"teachLevel" Value:_textView.text];
  265. [arr addPro:@"classId" Value:_orderDic[@"classId"]];
  266. [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
  267. [arr addPro:@"part" Value:_orderDic[@"kmStr"]];
  268. [arr addPro:@"objectId" Value:_orderDic[@"coachId"]];
  269. NSString* method = @"uploadReserveEvaluate";
  270. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  271. RemoveHUD();
  272. if (!root) {
  273. return;
  274. }
  275. if ([root[@"code"] isEqualToString:@"1"]) {
  276. ShowMsg(root[@"body"]);
  277. return;
  278. }
  279. [self.navigationController popViewControllerAnimated:YES];
  280. }];
  281. }
  282. #pragma mark - UICollectionViewDataSource
  283. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  284. return _dataArr.count;
  285. }
  286. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  287. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  288. UILabel * lable = nil;
  289. if (cell.contentView.subviews.count == 0) {
  290. lable = [[UILabel alloc]initWithFrame:cell.bounds];
  291. // [lable borderColor:[UIColor grayColor] width:0.5 cornorRadius:1];
  292. lable.layer.borderWidth = 0.5;
  293. [cell.contentView addSubview:lable];
  294. }else{
  295. lable = (UILabel *)cell.contentView.subviews.firstObject;
  296. }
  297. NSDictionary * dic = _dataArr[indexPath.item];
  298. NSString * labelString = @"";
  299. if ([_selectArr containsObject:dic[@"ID"]]) {
  300. lable.layer.borderColor = RQ_MAIN_COLOR.CGColor;
  301. labelString = [NSString stringWithFormat:@"%@ %d",dic[@"NAME"],[dic[@"ITEMNO"] intValue] + 1];
  302. [lable setText:labelString Font:NormalFont TextColor:RQ_MAIN_COLOR Alignment:NSTextAlignmentCenter];
  303. }else{
  304. lable.layer.borderColor = kTitleColor.CGColor;
  305. labelString = [NSString stringWithFormat:@"%@ %@",dic[@"NAME"],dic[@"ITEMNO"]];
  306. [lable setText:labelString Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  307. }
  308. lable.text = labelString;
  309. return cell;
  310. }
  311. //通过代理方法可以动态指定布局对象的相关属性
  312. //指定后布局依次为准,创建布局对象时的默认设置无效
  313. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  314. CGFloat width = (kSize.width - 40 - 20 - 20)/2;
  315. return CGSizeMake(width, 30);
  316. }
  317. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
  318. NSDictionary * dic = _dataArr[indexPath.item];
  319. if ([_selectArr containsObject:dic[@"ID"]]) {
  320. [_selectArr removeObject:dic[@"ID"]];
  321. }else{
  322. if (_selectArr.count == 3) {
  323. [_selectArr removeObjectAtIndex:0];
  324. }
  325. [_selectArr addObject:dic[@"ID"]];
  326. }
  327. [collectionView reloadData];
  328. }
  329. /*
  330. #pragma mark - Navigation
  331. // In a storyboard-based application, you will often want to do a little preparation before navigation
  332. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  333. // Get the new view controller using [segue destinationViewController].
  334. // Pass the selected object to the new view controller.
  335. }
  336. */
  337. @end