Evaluation.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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:defUser.userDict[@"city"]];
  169. NSString* method = @"getEvaluationCoachList";
  170. [MBProgressHUD showLoadToView:self.view];
  171. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  172. [MBProgressHUD hideHUDForView:self.view];
  173. if (!root) {
  174. ShowMsg(@"请求失败");
  175. return;
  176. }
  177. if ([root[@"code"] isEqualToString:@"1"]) {
  178. ShowMsg(root[@"body"]);
  179. return;
  180. }
  181. _dataArr = root[@"body"];
  182. [_collectionView reloadData];
  183. }];
  184. }
  185. -(void)getGzptEvaluationCoachList{
  186. if (![Util connectedToNetWork]) {
  187. showMsgUnconnect();
  188. return;
  189. }
  190. NSMutableArray *arr=[NSMutableArray array];
  191. [arr addPro:@"id" Value:self.orderDic[@"coachId"]];
  192. NSString* method = @"getGzptEvaluationCoachList";
  193. [MBProgressHUD showLoadToView:self.view];
  194. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  195. [MBProgressHUD hideHUDForView:self.view];
  196. if (!root) {
  197. ShowMsg(@"请求失败");
  198. return;
  199. }
  200. if ([root[@"code"] isEqualToString:@"1"]) {
  201. ShowMsg(root[@"body"]);
  202. return;
  203. }
  204. _dataArr = root[@"body"];
  205. [_collectionView reloadData];
  206. }];
  207. }
  208. -(void)doEvaluation{
  209. if (![Util connectedToNetWork]) {
  210. showMsgUnconnect();
  211. return;
  212. }
  213. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  214. dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  215. [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
  216. NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
  217. NSMutableString * mStr = [NSMutableString new];
  218. for (NSString *str in _selectArr) {
  219. [mStr appendFormat:@"%@,",str];
  220. }
  221. if (mStr.length > 0) {
  222. mStr = (NSMutableString *)[mStr substringToIndex:mStr.length-1];
  223. }
  224. NSMutableArray *arr=[NSMutableArray array];
  225. [arr addPro:@"stuOutId" Value:defUser.userDict[@"outId"]];
  226. [arr addPro:@"type" Value:@"1"];//1教练员,2学时机构
  227. [arr addPro:@"evaId" Value:_xsDic[@"coachId"]];
  228. [arr addPro:@"overAll" Value:[NSString stringWithFormat:@"%d",(int)_starCount]];
  229. // [arr addPro:@"part" Value:_xsDic[@"kmStr"]];
  230. [arr addPro:@"evaluateTime" Value:strDate];
  231. [arr addPro:@"itemIds" Value:mStr];
  232. [arr addPro:@"teachLevel" Value:_textView.text];
  233. [arr addPro:@"classId" Value:_xsDic[@"classId"]];
  234. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  235. NSString* method = @"doEvaluation";
  236. [MBProgressHUD showLoadToView:self.view];
  237. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  238. [MBProgressHUD hideHUDForView:self.view];
  239. if (!root) {
  240. return;
  241. }
  242. if ([root[@"code"] isEqualToString:@"1"]) {
  243. ShowMsg(root[@"body"]);
  244. return;
  245. }
  246. if ([root[@"code"] isEqualToString:@"0"]) {
  247. ShowMsg(root[@"msg"]);
  248. if (_tvc.blcok) {
  249. _tvc.blcok();
  250. }
  251. [self.navigationController popViewControllerAnimated:YES];
  252. }
  253. }];
  254. }
  255. //订单评论
  256. -(void)uploadReserveEvaluate
  257. {
  258. if (![Util connectedToNetWork]) {
  259. showMsgUnconnect();
  260. return;
  261. }
  262. NSMutableString * mStr = [NSMutableString new];
  263. for (NSString *str in _selectArr) {
  264. [mStr appendFormat:@"%@,",str];
  265. }
  266. if (mStr.length > 0) {
  267. mStr = (NSMutableString *)[mStr substringToIndex:mStr.length-1];
  268. }
  269. //{'overall':'3','part':'2','itemIds':'1,2,3','teachLevel':'撒发放','classId':'1245536456','userId':'1','objectId':'1'}
  270. NSMutableArray *arr=[NSMutableArray array];
  271. [arr addPro:@"overall" Value:[NSString stringWithFormat:@"%d",(int)_starCount]];
  272. [arr addPro:@"itemIds" Value:mStr];
  273. [arr addPro:@"teachLevel" Value:_textView.text];
  274. [arr addPro:@"classId" Value:_orderDic[@"classId"]];
  275. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  276. [arr addPro:@"objectId" Value:_orderDic[@"coachId"]];
  277. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  278. NSString* method = @"uploadReserveEvaluate";//订单评论
  279. [MBProgressHUD showLoadToView:self.view];
  280. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  281. [MBProgressHUD hideHUDForView:self.view];
  282. if (!root) {
  283. return;
  284. }
  285. if ([root[@"code"] isEqualToString:@"1"]) {
  286. ShowMsg(root[@"body"]);
  287. return;
  288. }
  289. if ([root[@"code"] isEqualToString:@"0"]) {
  290. ShowMsg(@"评价成功");
  291. [self.navigationController popViewControllerAnimated:YES];
  292. return;
  293. }
  294. }];
  295. }
  296. #pragma mark - UICollectionViewDataSource
  297. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  298. return _dataArr.count;
  299. }
  300. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  301. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  302. UILabel * lable = nil;
  303. if (cell.contentView.subviews.count == 0) {
  304. lable = [[UILabel alloc]initWithFrame:cell.bounds];
  305. // [lable borderColor:[UIColor grayColor] width:0.5 cornorRadios:1];
  306. lable.layer.borderWidth = 0.5;
  307. [cell.contentView addSubview:lable];
  308. }else{
  309. lable = (UILabel *)cell.contentView.subviews.firstObject;
  310. }
  311. NSDictionary * dic = _dataArr[indexPath.item];
  312. NSString * labelString = @"";
  313. if ([_selectArr containsObject:dic[@"ID"]]) {
  314. lable.layer.borderColor = defGreen.CGColor;
  315. labelString = [NSString stringWithFormat:@"%@ %d",dic[@"NAME"],[dic[@"ITEMNO"] intValue] + 1];
  316. [lable setText:labelString Font:NormalFont TextColor:defGreen Alignment:NSTextAlignmentCenter];
  317. }else{
  318. lable.layer.borderColor = kTitleColor.CGColor;
  319. labelString = [NSString stringWithFormat:@"%@ %@",dic[@"NAME"],dic[@"ITEMNO"]];
  320. [lable setText:labelString Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  321. }
  322. lable.text = labelString;
  323. return cell;
  324. }
  325. //通过代理方法可以动态指定布局对象的相关属性
  326. //指定后布局依次为准,创建布局对象时的默认设置无效
  327. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  328. CGFloat width = (kSize.width - 40 - 20 - 20)/2;
  329. return CGSizeMake(width, 30);
  330. }
  331. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
  332. NSDictionary * dic = _dataArr[indexPath.item];
  333. if ([_selectArr containsObject:dic[@"ID"]]) {
  334. [_selectArr removeObject:dic[@"ID"]];
  335. }else{
  336. if (_selectArr.count == 3) {
  337. [_selectArr removeObjectAtIndex:0];
  338. }
  339. [_selectArr addObject:dic[@"ID"]];
  340. }
  341. [collectionView reloadData];
  342. }
  343. /*
  344. #pragma mark - Navigation
  345. // In a storyboard-based application, you will often want to do a little preparation before navigation
  346. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  347. // Get the new view controller using [segue destinationViewController].
  348. // Pass the selected object to the new view controller.
  349. }
  350. */
  351. @end