EvaluationAndPayVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // EvaluationAndPayVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/6/8.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "EvaluationAndPayVC.h"
  9. #import "CDPStarEvaluation.h"
  10. #import "APViewController.h"
  11. @interface EvaluationAndPayVC ()<UITextViewDelegate,CDPStarEvaluationDelegate>
  12. {
  13. UITextView *mainTV;
  14. UILabel *holderLabel;
  15. CDPStarEvaluation *serverStar;//星形评价
  16. CDPStarEvaluation *payStar;
  17. CDPStarEvaluation *teachStar;
  18. UILabel *serverLabel;//评论级别label
  19. UILabel *payLabel;
  20. UILabel *teachLabel;
  21. UILabel *timeLabel;
  22. UILabel *remarkLabel;
  23. }
  24. @end
  25. @implementation EvaluationAndPayVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. if (_isFinishEva) {
  29. self.title = @"我的评价";
  30. }else{
  31. self.title = @"评价";
  32. }
  33. [self configNavigationBar];
  34. self.view.backgroundColor = backGroundColor;
  35. [self myInit];
  36. }
  37. -(void)viewDidDisappear:(BOOL)animated
  38. {
  39. [super viewDidDisappear:animated];
  40. [self.view endEditing:YES];
  41. }
  42. -(void)myInit
  43. {
  44. // if (_isFinishEva) {
  45. // UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"支付" style:UIBarButtonItemStyleDone target:self action:@selector(clickToComplain)];
  46. // item.tintColor = defGreen;
  47. // self.navigationItem.rightBarButtonItem = item;
  48. // }
  49. CGFloat x,y,w,h,bd;
  50. x = y = bd = 10;
  51. w = kSize.width - 2*bd;
  52. h = 100;
  53. //480 568 667 736
  54. if (kSize.height > 568) {
  55. h = 150;
  56. }
  57. if (_isFinishEva) {
  58. h = 0;
  59. }else{
  60. mainTV = [[UITextView alloc] setxywh];
  61. mainTV.backgroundColor = [UIColor whiteColor];
  62. mainTV.delegate = self;
  63. mainTV.returnKeyType = UIReturnKeyDone;
  64. [self.view addSubview:mainTV];
  65. holderLabel = [[UILabel alloc] initWithFrame:CGRectMake(x + 10, y, w, 30)];
  66. holderLabel.text = @"对本次培训的评价(100字以内)";
  67. [holderLabel setFont:NormalFont TextColor:contentTextColor];
  68. [self.view addSubview:holderLabel];
  69. }
  70. //CDPStarEvaluation星形评价
  71. y += h + 2*bd;
  72. h = 20;
  73. UILabel *starLabel = [[UILabel alloc] setxywh];
  74. starLabel.text = @"星级评价:";
  75. [starLabel setFont:[UIFont scaleSize:Font17]];
  76. [self.view addSubview:starLabel];
  77. y += h + bd/2.0;
  78. h = (kSize.width-2*bd)*0.5/4.98;
  79. NSArray *nameArray = @[@"服务星级",@"收费星级",@"教学星级"];
  80. NSMutableArray *stars = [NSMutableArray arrayWithCapacity:3];
  81. NSMutableArray *labels = [NSMutableArray arrayWithCapacity:3];
  82. for (int i = 0; i < 3; i ++) {
  83. //777/156=4.98077 468/94=4.97872
  84. // w = kSize.width*0.625;
  85. // h = kSize.height*0.07042254;
  86. x = bd;
  87. w = (kSize.width-2*bd)*0.2;
  88. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + i*(h + bd/2.0), w, h)];
  89. label.text = nameArray[i];
  90. label.textAlignment = NSTextAlignmentLeft;
  91. [label setFont:[UIFont scaleSize:Font17]];
  92. [self.view addSubview:label];
  93. x += w;
  94. w = (kSize.width-2*bd)*0.5;
  95. CDPStarEvaluation *evaluation=[[CDPStarEvaluation alloc] initWithFrame:CGRectMake(x, y + i*(h + bd/2.0), w, h) onTheView:self.view];
  96. evaluation.delegate = self;
  97. evaluation.delegateTag = i;
  98. [stars addObject:evaluation];
  99. x += w;
  100. w = (kSize.width-2*bd)*0.3;
  101. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + i*(h + bd/2.0), w, h)];
  102. label.textAlignment = NSTextAlignmentRight;
  103. label.text = @"请评分";
  104. [label setFont:[UIFont scaleSize:Font17]];
  105. [self.view addSubview:label];
  106. [labels addObject:label];
  107. }
  108. serverStar = stars[0];
  109. payStar = stars[1];
  110. teachStar = stars[2];
  111. serverLabel = labels[0];
  112. payLabel = labels[1];
  113. teachLabel = labels[2];
  114. if (_isFinishEva) {
  115. x = 2*bd;
  116. y += 3*(h + bd/2.0) + 2*bd;
  117. w = kSize.width - 2*x;
  118. h = 30;
  119. timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  120. [timeLabel setText:@"" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentRight];
  121. [self.view addSubview:timeLabel];
  122. [timeLabel addViewWithRect:CGRectMake(10, y+h, kSize.width - 20, 1)];
  123. x = 2 * bd;
  124. y += h + 5;
  125. w = kSize.width - 2*x;
  126. h = 30;
  127. remarkLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  128. [remarkLabel setText:@"" Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  129. [self.view addSubview:remarkLabel];
  130. [self getOrderEvaluateById];
  131. }else{
  132. x = 2 * bd;
  133. y += 3*(h + bd/2.0) + 4*bd;
  134. w = kSize.width - 2*x;
  135. h = 50;
  136. UIButton *commentBtn = [[UIButton alloc] setxywh];
  137. [commentBtn setTitle:@"提交评价" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
  138. commentBtn.backgroundColor=[UIColor colorWithRed:242/255.0 green:130/255.0 blue:32/255.0 alpha:1];
  139. [commentBtn target:self tag:1];
  140. [self.view addSubview:commentBtn];
  141. }
  142. }
  143. //-(void)clickToComplain
  144. //{
  145. // //在这里判断下 是否已完成评价 如果评价过 则可以去支付 防止评价完退出又进来无法支付
  146. // if ([_dataDic[@"RO_STATUS"] isEqualToString:@"3"]) {
  147. // ShowMsg(@"您已完成支付");
  148. // return;
  149. // }
  150. // if (![_dataDic[@"RO_STATUS"] isEqualToString:@"2"]) {
  151. // ShowMsg(@"请先评价");
  152. // return;
  153. // }
  154. //
  155. // [self goAndPay];
  156. //}
  157. -(void)btnClick:(UIButton *)sender
  158. {
  159. [self.view endEditing:YES];
  160. if (sender.tag == 1) {
  161. if (mainTV.text.length < 1) {
  162. ShowMsg(@"请填写评论");
  163. return;
  164. }
  165. if (mainTV.text.length > 100) {
  166. ShowMsg(@"评论内容不能超出100字");
  167. return;
  168. }
  169. if (serverStar.width*5 < 0.10 || payStar.width*5 < 0.10 || teachStar.width*5 < 0.10) {
  170. ShowMsg(@"请为本次培训打分");
  171. return;
  172. }
  173. [self uploadReserveEvaluate];
  174. }
  175. }
  176. //-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  177. //{
  178. // [self goAndPay];
  179. //}
  180. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  181. {
  182. [self.view endEditing:YES];
  183. }
  184. #pragma mark textViewDelegate
  185. -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  186. {
  187. NSMutableString * content = [[NSMutableString alloc]initWithString:textView.text];
  188. [content replaceCharactersInRange:range withString:text];
  189. if (content.length < 1) {
  190. holderLabel.hidden = NO;
  191. }else{
  192. holderLabel.hidden = YES;
  193. }
  194. if ([@"\n" isEqualToString:text] == YES) {
  195. //如果是换行键 就隐藏键盘
  196. [self.view endEditing:YES];
  197. return NO;
  198. }
  199. return YES;
  200. }
  201. #pragma mark CDPStarEvaluationDelegate获得实时评价级别
  202. -(void)theCurrentCommentText:(NSString *)commentText Tag:(NSInteger)tag{
  203. switch (tag) {
  204. case 0:
  205. serverLabel.text = [NSString stringWithFormat:@"%@(%.1f分)",commentText,serverStar.width*5];
  206. break;
  207. case 1:
  208. payLabel.text = [NSString stringWithFormat:@"%@(%.1f分)",commentText,payStar.width*5];
  209. break;
  210. case 2:
  211. teachLabel.text = [NSString stringWithFormat:@"%@(%.1f分)",commentText,teachStar.width*5];
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. #pragma mark 数据请求
  218. -(void)uploadReserveEvaluate
  219. {
  220. if (![Util connectedToNetWork]) {
  221. showMsgUnconnect();
  222. return;
  223. }
  224. NSMutableArray *arr=[NSMutableArray array];
  225. [arr addPro:@"orderId" Value:_dataDic[@"RO_ID"]];
  226. [arr addPro:@"serverStar" Value:[NSString stringWithFormat:@"%.1f",serverStar.width*5]];
  227. [arr addPro:@"payStar" Value:[NSString stringWithFormat:@"%.1f",payStar.width*5]];
  228. [arr addPro:@"teachStar" Value:[NSString stringWithFormat:@"%.1f",teachStar.width*5]];
  229. [arr addPro:@"remark" Value:mainTV.text];
  230. [arr addPro:@"user" Value:defUser.sfzmhm];
  231. [arr addPro:@"userName" Value:defUser.userName];
  232. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  233. //这个类评论功能暂时用不到,下面这个接口已改
  234. NSString* method = @"uploadReserveEvaluate";
  235. [MBProgressHUD showLoadToView:self.view];
  236. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  237. [MBProgressHUD hideHUDForView:self.view];
  238. if (!root) {
  239. ShowMsgFailed();
  240. return;
  241. }
  242. if ([root[@"code"] isEqualToString:@"1"]) {
  243. ShowMsg(root[@"body"]);
  244. return;
  245. }
  246. if ([root[@"body"] isEqualToString:@"0"]) {
  247. ShowMsg(@"评价成功");
  248. //这样应该没问题吧 不管是从订单过来还是从支付页面过来 都可以这样直接返回才对哒
  249. // UIViewController *orderVC = self.navigationController.viewControllers[1];
  250. //[self.navigationController popViewControllerAnimated:YES];
  251. [self.navigationController popViewControllerAnimated:YES];
  252. }
  253. // UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"评论成功!" delegate:self cancelButtonTitle:@"支付" otherButtonTitles:nil, nil];
  254. // [alertView show];
  255. }];
  256. }
  257. -(void)getOrderEvaluateById
  258. {
  259. if (![Util connectedToNetWork]) {
  260. return;
  261. }
  262. NSMutableArray *arr=[NSMutableArray array];
  263. [arr addPro:@"orderId" Value:_dataDic[@"RO_ID"]];
  264. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  265. NSString* method = @"getOrderEvaluateById";//这个类评论功能暂时用不到,下面这个接口已改
  266. [MBProgressHUD showLoadToView:self.view];
  267. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  268. [MBProgressHUD hideHUDForView:self.view];
  269. if (!root) {
  270. ShowMsgFailed();
  271. return;
  272. }
  273. if ([root[@"code"] isEqualToString:@"1"]) {
  274. ShowMsg(root[@"body"]);
  275. return;
  276. }
  277. NSDictionary *dic = root[@"body"];
  278. timeLabel.text = [dic[@"crDate"] substringToIndex:16];
  279. NSString *contentString = [NSString stringWithFormat:@"评价:%@",dic[@"remark"]];
  280. if ([dic[@"remark"] length] < 1) {
  281. contentString = @"评价:暂无";
  282. }
  283. remarkLabel.height = [contentString heightForWid:kSize.width - 40 Font:Font17] + 10;
  284. remarkLabel.text = contentString;
  285. [serverStar setStarWithFloat:[dic[@"serverStar"] floatValue]/5.0];
  286. [payStar setStarWithFloat:[dic[@"payStar"] floatValue]/5.0];
  287. [teachStar setStarWithFloat:[dic[@"teachStar"] floatValue]/5.0];
  288. serverLabel.text = [NSString stringWithFormat:@"%@(%@分)",serverStar.commentText,dic[@"serverStar"]];
  289. payLabel.text = [NSString stringWithFormat:@"%@(%@分)",payStar.commentText,dic[@"payStar"]];
  290. teachLabel.text = [NSString stringWithFormat:@"%@(%@分)",teachStar.commentText,dic[@"teachStar"]];
  291. }];
  292. }
  293. //支付
  294. //-(void)goAndPay
  295. //{
  296. // if (_dataDic) {
  297. // APViewController *ap = [[APViewController alloc] init];
  298. // ap.orderDic = _dataDic;
  299. // [self.navigationController pushViewController:ap animated:YES];
  300. // }else{
  301. // ShowMsg(@"订单信息错误,请重试");
  302. // }
  303. //}
  304. - (void)didReceiveMemoryWarning {
  305. [super didReceiveMemoryWarning];
  306. }
  307. @end