PeriodVC.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. //
  2. // PeriodVC.m
  3. // JSJPCoach
  4. //
  5. // Created by apple on 2017/3/20.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. #import "PeriodVC.h"
  8. #import "MinRescord.h"
  9. #import "SelectImgVC.h"
  10. @interface PeriodVC ()
  11. {
  12. UILabel *subjectLabel;
  13. UIView *stuInfoView;
  14. UILabel *stuNamelabel;
  15. UILabel *allTimeLabel, *valueTimeLabel, *invalidTimeLabel, *waitTimeLabel, *mileAndSpeedLabel;
  16. NSTimer *preTimer;
  17. NSDictionary *dataDic;//带教学员信息
  18. }
  19. @end
  20. @implementation PeriodVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, kSize.width - 20, 30)];
  24. [label setText:@"终端带教信息:" Font:26 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft];
  25. [self.view addSubview:label];
  26. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width - 80, 20, 60, 60)];
  27. btn.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2];
  28. [btn setTitle:@"刷新" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  29. [btn borderColor:defGreen width:0.9 cornorRadios:30];
  30. [btn addTarget:self action:@selector(getStudentTrainInfos) forControlEvents:UIControlEventTouchUpInside];
  31. [self.view addSubview:btn];
  32. label = [[UILabel alloc] initWithFrame:CGRectMake(10, 55, kSize.width - 20, 30)];
  33. [label setText:@"带教科目:暂无" Font:Font21 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft];
  34. [self.view addSubview:label];
  35. subjectLabel = label;
  36. //学员info
  37. stuInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, kSize.width, kSize.height - kNavOffSet - 100)];
  38. [self.view addSubview:stuInfoView];
  39. label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 40, 50)];
  40. [label setText:@"暂未查询到正在带教学员!" Font:Font18 TextColor:newTitleColor];
  41. [stuInfoView addSubview:label];
  42. if (defUser.isLogin) {
  43. [self getStudentTrainInfos];
  44. }
  45. }
  46. -(void)viewDidDisappear:(BOOL)animated {
  47. [super viewDidDisappear:animated];
  48. if (preTimer) {
  49. [preTimer invalidate];
  50. preTimer = nil;
  51. }
  52. }
  53. - (void)loadStudentInfoWithDic:(NSDictionary *)dic {
  54. //这里还没有生成展示学员信息的控件 或者已换学员带教 重新布局
  55. for (UIView *view in stuInfoView.subviews) {
  56. [view removeFromSuperview];
  57. }
  58. UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:stuInfoView.bounds];
  59. [stuInfoView addSubview:scroll];
  60. CGFloat x, y, w, h;
  61. x = 20;
  62. y = 5;
  63. w = 70;
  64. h = 90;
  65. UIImageView *headerImg = [[UIImageView alloc] setxywh];
  66. headerImg.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2];
  67. [headerImg borderColor:[UIColor whiteColor] width:.3 cornorRadios:2];
  68. [headerImg sd_setImageWithURL:[NSURL URLWithString:dic[@"HEADIMG"]] placeholderImage:[UIImage imageNamed:@"noHeadImg"]];
  69. [scroll addSubview:headerImg];
  70. x += w + 10;
  71. w = kSize.width - x - 20;
  72. h = 30;
  73. //姓名
  74. UILabel *label = [[UILabel alloc] setxywh];
  75. [label setText:[dic[@"STATE"] isEqualToString:@"2"]?@"科目二学员":@"科目三学员" Font:Font17 TextColor:newSubTitleColor Alignment:NSTextAlignmentRight];
  76. [scroll addSubview:label];
  77. stuNamelabel = label;
  78. //科目
  79. label = [[UILabel alloc] setxywh];
  80. [label setText:dic[@"STUNAME"] Font:Font21 TextColor:newTitleColor];
  81. [scroll addSubview:label];
  82. y += h;
  83. //电话
  84. label = [[UILabel alloc] setxywh];
  85. [label setText:dic[@"PHONE"] Font:Font18 TextColor:newSubTitleColor];
  86. [scroll addSubview:label];
  87. y += h;
  88. //驾校
  89. label = [[UILabel alloc] setxywh];
  90. [label setText:dic[@"SCHOOLNAME"] Font:Font18 TextColor:newSubTitleColor];
  91. [scroll addSubview:label];
  92. y += h + 20;
  93. x = 15;
  94. w = kSize.width - 2*x;
  95. h = 30;
  96. label = [[UILabel alloc] setxywh];
  97. [label setText:@"学员学时信息" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentCenter];
  98. if (kSize.width == 320.0) {
  99. [label setText:@"学员学时信息:" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentLeft];
  100. }
  101. [scroll addSubview:label];
  102. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  103. btn.frame = CGRectMake(kSize.width - 120 - x, y, 120, h);
  104. btn.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2];
  105. [btn setTitle:@"查看训练照片" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  106. [btn borderColor:defGreen width:.6 cornorRadios:3];
  107. [btn target:self Tag:101];
  108. [scroll addSubview:btn];
  109. y += h + 5;
  110. [label addViewWithRect:CGRectMake(x, y, w, 1) Color:newSubTitleColor];
  111. [label addViewWithRect:CGRectMake(x, y + 50, w, 1) Color:newSubTitleColor];
  112. [label addViewWithRect:CGRectMake(x, y + 75, w, 1) Color:newSubTitleColor];
  113. [label addViewWithRect:CGRectMake(x, y + 100, w, 1) Color:newSubTitleColor];
  114. [label addViewWithRect:CGRectMake(x, y + 125, w, 1) Color:newSubTitleColor];
  115. [label addViewWithRect:CGRectMake(x, y + 150, w, 1) Color:newSubTitleColor];
  116. w = w/4.0;
  117. [label addViewWithRect:CGRectMake(x, y, 1, 150) Color:newSubTitleColor];
  118. [label addViewWithRect:CGRectMake(x + w, y, 1, 150) Color:newSubTitleColor];
  119. [label addViewWithRect:CGRectMake(x + 2*w, y, 1, 150) Color:newSubTitleColor];
  120. [label addViewWithRect:CGRectMake(x + 3*w, y, 1, 150) Color:newSubTitleColor];
  121. [label addViewWithRect:CGRectMake(x + 4*w, y, 1, 150) Color:newSubTitleColor];
  122. NSArray *titleArray = @[@"培训阶段",@"当前完成学时",@"学时审核状态",@"学时是否已传输"];
  123. for (int i = 0; i < titleArray.count; i ++) {
  124. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 5 + i*w, y + 1, w - 10, 49)];
  125. [label setText:titleArray[i] Font:Font17 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter];
  126. label.numberOfLines = 0;
  127. [scroll addSubview:label];
  128. }
  129. y += 50;
  130. NSArray *subjectArray = @[@"第一阶段",@"第二阶段",@"第三阶段",@"第四阶段"];
  131. NSArray *trainTimeArray = @[dic[@"ONE"],dic[@"TWO"],dic[@"THREE"],dic[@"FOUR"]];
  132. NSArray *stateArray = @[dic[@"ONESTATUS"],dic[@"TWOSTATUS"],dic[@"THREESTATUS"],dic[@"FOURSTATUS"]];
  133. NSArray *sendArray = @[dic[@"ONESEND"],dic[@"TWOSEND"],dic[@"THREESEND"],dic[@"FOURSEND"]];
  134. for (int i = 0; i < subjectArray.count; i ++) {
  135. //阶段
  136. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + 1 + i*25, w, 24)];
  137. [label setText:subjectArray[i] Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter];
  138. [scroll addSubview:label];
  139. //学时
  140. label = [[UILabel alloc] initWithFrame:CGRectMake(x + w, y + 1 + i*25, w, 24)];
  141. int time = [trainTimeArray[i] intValue];
  142. int hour = time/60;
  143. int min = time%60;
  144. NSString *timeString = @"";
  145. if (hour == 0) {
  146. timeString = [NSString stringWithFormat:@"%d分钟",min];
  147. }else{
  148. timeString = [NSString stringWithFormat:@"%d时%d分",hour,min];
  149. }
  150. [label setText:timeString Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter];
  151. [scroll addSubview:label];
  152. //审核状态
  153. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 2*w, y + 1 + i*25, w, 24)];
  154. NSString *stateString = stateArray[i];
  155. switch ([stateString intValue]) {
  156. case 0:
  157. stateString = @"不允许送审";
  158. break;
  159. case 1:
  160. stateString = @"允许送审";
  161. break;
  162. case 2:
  163. stateString = @"审核通过";
  164. break;
  165. case 3:
  166. stateString = @"退回";
  167. break;
  168. case 4:
  169. stateString = @"待审核";
  170. break;
  171. default:
  172. stateString = @"";
  173. break;
  174. }
  175. [label setText:stateString Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter];
  176. [scroll addSubview:label];
  177. //是否传至交警
  178. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 3*w, y + 1 + i*25, w, 24)];
  179. NSString *sendString = sendArray[i];
  180. switch ([sendString intValue]) {
  181. case 0:
  182. sendString = @"未传输";
  183. break;
  184. case 1:
  185. sendString = @"已传至运管";
  186. break;
  187. case 2:
  188. sendString = @"已传至交警";
  189. break;
  190. default:
  191. sendString = @"";
  192. break;
  193. }
  194. [label setText:sendString Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter];
  195. [scroll addSubview:label];
  196. }
  197. x = 15;
  198. y += 100 + 20;
  199. w = kSize.width - 2*x;
  200. h = 30;
  201. label = [[UILabel alloc] setxywh];
  202. [label setText:@"当前培训信息" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentCenter];
  203. if (kSize.width == 320.0) {
  204. [label setText:@"当前培训信息:" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentLeft];
  205. }
  206. [scroll addSubview:label];
  207. btn = [UIButton buttonWithType:UIButtonTypeSystem];
  208. btn.frame = CGRectMake(kSize.width-120-x, y, 120, h);
  209. btn.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2];
  210. [btn setTitle:@"查看分钟学时" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  211. [btn borderColor:defGreen width:.6 cornorRadios:3];
  212. [btn target:self Tag:100];
  213. [scroll addSubview:btn];
  214. y += h+5;
  215. [label addViewWithRect:CGRectMake(x, y, w, 1) Color:newSubTitleColor];
  216. [label addViewWithRect:CGRectMake(x, y + 59, w, 1) Color:newSubTitleColor];
  217. [label addViewWithRect:CGRectMake(x, y, 1, 60) Color:newSubTitleColor];
  218. [label addViewWithRect:CGRectMake(x + w, y, 1, 60) Color:newSubTitleColor];
  219. w = w/4.0;
  220. h = 30;
  221. NSArray *titles = @[@"总时长",@"有效时长",@"无效时长",@"待审核"];
  222. NSArray *textArray = @[dic[@"totalTime"],dic[@"vaildTime"],dic[@"noVaildTime"],dic[@"notAuditTime"]];
  223. NSArray *colors = @[newTitleColor,[UIColor greenColor],[UIColor redColor],defGreen];
  224. NSMutableArray *labels = [NSMutableArray arrayWithCapacity:4];
  225. for (int i = 0; i < titles.count; i ++) {
  226. label = [[UILabel alloc] initWithFrame:CGRectMake(x + i*w, y, w, h)];
  227. label.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2];
  228. [label setText:titles[i] Font:Font16 TextColor:newTitleColor Alignment:NSTextAlignmentCenter];
  229. [scroll addSubview:label];
  230. label = [[UILabel alloc] initWithFrame:CGRectMake(x + i*w, y + h, w, h)];
  231. [label setText:[NSString stringWithFormat:@"%@分钟",textArray[i]] Font:Font16 TextColor:colors[i] Alignment:NSTextAlignmentCenter];
  232. [scroll addSubview:label];
  233. [labels addObject:label];
  234. if (i != 0) {
  235. [label addViewWithRect:CGRectMake(x + i*w, y, 1, 2*h) Color:newSubTitleColor];
  236. }
  237. }
  238. allTimeLabel = labels[0];
  239. valueTimeLabel = labels[1];
  240. invalidTimeLabel = labels[2];
  241. waitTimeLabel = labels[3];
  242. x = 20;
  243. y += 70;
  244. w = kSize.width - 2*x;
  245. h = 60;
  246. label = [[UILabel alloc] setxywh];
  247. [label setText:[NSString stringWithFormat:@"当前培训过程中,车辆平均速度为%.2fKm/h,行驶总里程为%.2fKm,有效学时占比为%.1f%%",[dic[@"avgSpeed"] floatValue],[dic[@"totalMile"] floatValue]/1000.0,[dic[@"vaildTime"] floatValue]/[dic[@"totalTime"] floatValue]*100] Font:Font17 TextColor:newTitleColor];
  248. label.numberOfLines = 0;
  249. [scroll addSubview:label];
  250. mileAndSpeedLabel = label;
  251. [scroll setContentSize:CGSizeMake(stuInfoView.width, CGRectGetMaxY(mileAndSpeedLabel.frame) + 100)];
  252. }
  253. - (void)setStudentInfoWithDic:(NSDictionary *)dic {
  254. //这里已经有展示学员信息的控件了 直接填入数据
  255. allTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"totalTime"]];
  256. valueTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"vaildTime"]];
  257. invalidTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"noVaildTime"]];
  258. waitTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"notAuditTime"]];
  259. mileAndSpeedLabel.text = [NSString stringWithFormat:@"当前培训过程中,车辆平均速度为%.2fKm/h,行驶总里程为%.2fKm,有效学时占比为%.1f%%",[dic[@"avgSpeed"] floatValue],[dic[@"totalMile"] floatValue], [dic[@"vaildTime"] floatValue]/[dic[@"totalTime"] floatValue]*100];
  260. }
  261. - (void)btnClick:(UIButton *)sender {
  262. //查看分钟学时
  263. if (sender.tag == 100) {
  264. MinRescord *vc = [[MinRescord alloc]init];
  265. vc.stuID = dataDic[@"STUID"];
  266. vc.classId = dataDic[@"CLASSID"];
  267. [self.navigationController pushViewController:vc animated:YES];
  268. }
  269. //查看训练照片
  270. if (sender.tag == 101) {
  271. SelectImgVC *vc = [[SelectImgVC alloc] init];
  272. vc.skipType = 1;
  273. vc.stuDic = dataDic;
  274. [self.navigationController pushViewController:vc animated:YES];
  275. }
  276. }
  277. #pragma mark 数据请求
  278. - (void)getStudentTrainInfos
  279. {
  280. [LoadingView showHUD];
  281. if (![Util connectedToNetWork]) {
  282. showMsgUnconnect();
  283. return;
  284. }
  285. //查询学员签到列表 科目传空 查全部
  286. NSMutableArray *arr = [NSMutableArray array];
  287. [arr addPro:@"coachId" Value:defUser.userDict[@"outId"]];
  288. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  289. NSString* method = @"getStudentTrainInfos";
  290. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  291. RemoveHUD();
  292. if (!root) {
  293. ShowMsg(@"查询带教学员失败,请刷新!");
  294. return ;
  295. }
  296. if ([root[@"code"] isEqualToString:@"1"]) {
  297. //没有带教学员0.0
  298. ShowMsg(root[@"body"]);
  299. for (UIView *view in stuInfoView.subviews) {
  300. [view removeFromSuperview];
  301. }
  302. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 40, 50)];
  303. [label setText:@"暂未查询到正在带教学员!" Font:Font18 TextColor:newTitleColor];
  304. [stuInfoView addSubview:label];
  305. if (preTimer) {
  306. [preTimer invalidate];
  307. preTimer = nil;
  308. }
  309. return;
  310. }
  311. dataDic = root[@"body"];
  312. //带教科目
  313. NSString *subjectString = @"带教科目:科目二";
  314. if ([dataDic[@"subject"] intValue] == 3) {
  315. subjectString = @"带教科目:科目三";
  316. }
  317. subjectLabel.text = subjectString;
  318. //生成学员信息
  319. if (stuInfoView.subviews.count < 2) {
  320. [self loadStudentInfoWithDic:root[@"body"]];
  321. }else{
  322. if (![[root[@"body"] objectForKey:@"STUNAME"] isEqualToString:stuNamelabel.text]) {
  323. [self loadStudentInfoWithDic:root[@"body"]];
  324. }else {
  325. [self setStudentInfoWithDic:root[@"body"]];
  326. }
  327. }
  328. if (preTimer == nil) {
  329. preTimer = [NSTimer scheduledTimerWithTimeInterval:70 target:self selector:@selector(getStudentTrainInfos) userInfo:nil repeats:YES];
  330. }
  331. }];
  332. }
  333. - (void)didReceiveMemoryWarning {
  334. [super didReceiveMemoryWarning];
  335. }
  336. @end