// // PeriodVC.m // JSJPCoach // // Created by apple on 2017/3/20. // Copyright © 2017年 Danson. All rights reserved. #import "PeriodVC.h" #import "MinRescord.h" #import "SelectImgVC.h" @interface PeriodVC () { UILabel *subjectLabel; UIView *stuInfoView; UILabel *stuNamelabel; UILabel *allTimeLabel, *valueTimeLabel, *invalidTimeLabel, *waitTimeLabel, *mileAndSpeedLabel; NSTimer *preTimer; NSDictionary *dataDic;//带教学员信息 } @end @implementation PeriodVC - (void)viewDidLoad { [super viewDidLoad]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, kSize.width - 20, 30)]; [label setText:@"终端带教信息:" Font:26 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft]; [self.view addSubview:label]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width - 80, 20, 60, 60)]; btn.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2]; [btn setTitle:@"刷新" textColor:defGreen font:Font18 fotState:UIControlStateNormal]; [btn borderColor:defGreen width:0.9 cornorRadios:30]; [btn addTarget:self action:@selector(getStudentTrainInfos) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; label = [[UILabel alloc] initWithFrame:CGRectMake(10, 55, kSize.width - 20, 30)]; [label setText:@"带教科目:暂无" Font:Font21 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft]; [self.view addSubview:label]; subjectLabel = label; //学员info stuInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, kSize.width, kSize.height - kNavOffSet - 100)]; [self.view addSubview:stuInfoView]; label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 40, 50)]; [label setText:@"暂未查询到正在带教学员!" Font:Font18 TextColor:newTitleColor]; [stuInfoView addSubview:label]; if (defUser.isLogin) { [self getStudentTrainInfos]; } } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; if (preTimer) { [preTimer invalidate]; preTimer = nil; } } - (void)loadStudentInfoWithDic:(NSDictionary *)dic { //这里还没有生成展示学员信息的控件 或者已换学员带教 重新布局 for (UIView *view in stuInfoView.subviews) { [view removeFromSuperview]; } UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:stuInfoView.bounds]; [stuInfoView addSubview:scroll]; CGFloat x, y, w, h; x = 20; y = 5; w = 70; h = 90; UIImageView *headerImg = [[UIImageView alloc] setxywh]; headerImg.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2]; [headerImg borderColor:[UIColor whiteColor] width:.3 cornorRadios:2]; [headerImg sd_setImageWithURL:[NSURL URLWithString:dic[@"HEADIMG"]] placeholderImage:[UIImage imageNamed:@"noHeadImg"]]; [scroll addSubview:headerImg]; x += w + 10; w = kSize.width - x - 20; h = 30; //姓名 UILabel *label = [[UILabel alloc] setxywh]; [label setText:[dic[@"STATE"] isEqualToString:@"2"]?@"科目二学员":@"科目三学员" Font:Font17 TextColor:newSubTitleColor Alignment:NSTextAlignmentRight]; [scroll addSubview:label]; stuNamelabel = label; //科目 label = [[UILabel alloc] setxywh]; [label setText:dic[@"STUNAME"] Font:Font21 TextColor:newTitleColor]; [scroll addSubview:label]; y += h; //电话 label = [[UILabel alloc] setxywh]; [label setText:dic[@"PHONE"] Font:Font18 TextColor:newSubTitleColor]; [scroll addSubview:label]; y += h; //驾校 label = [[UILabel alloc] setxywh]; [label setText:dic[@"SCHOOLNAME"] Font:Font18 TextColor:newSubTitleColor]; [scroll addSubview:label]; y += h + 20; x = 15; w = kSize.width - 2*x; h = 30; label = [[UILabel alloc] setxywh]; [label setText:@"学员学时信息" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentCenter]; if (kSize.width == 320.0) { [label setText:@"学员学时信息:" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentLeft]; } [scroll addSubview:label]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(kSize.width - 120 - x, y, 120, h); btn.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2]; [btn setTitle:@"查看训练照片" textColor:defGreen font:Font18 fotState:UIControlStateNormal]; [btn borderColor:defGreen width:.6 cornorRadios:3]; [btn target:self Tag:101]; [scroll addSubview:btn]; y += h + 5; [label addViewWithRect:CGRectMake(x, y, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y + 50, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y + 75, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y + 100, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y + 125, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y + 150, w, 1) Color:newSubTitleColor]; w = w/4.0; [label addViewWithRect:CGRectMake(x, y, 1, 150) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x + w, y, 1, 150) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x + 2*w, y, 1, 150) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x + 3*w, y, 1, 150) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x + 4*w, y, 1, 150) Color:newSubTitleColor]; NSArray *titleArray = @[@"培训阶段",@"当前完成学时",@"学时审核状态",@"学时是否已传输"]; for (int i = 0; i < titleArray.count; i ++) { label = [[UILabel alloc] initWithFrame:CGRectMake(x + 5 + i*w, y + 1, w - 10, 49)]; [label setText:titleArray[i] Font:Font17 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter]; label.numberOfLines = 0; [scroll addSubview:label]; } y += 50; NSArray *subjectArray = @[@"第一阶段",@"第二阶段",@"第三阶段",@"第四阶段"]; NSArray *trainTimeArray = @[dic[@"ONE"],dic[@"TWO"],dic[@"THREE"],dic[@"FOUR"]]; NSArray *stateArray = @[dic[@"ONESTATUS"],dic[@"TWOSTATUS"],dic[@"THREESTATUS"],dic[@"FOURSTATUS"]]; NSArray *sendArray = @[dic[@"ONESEND"],dic[@"TWOSEND"],dic[@"THREESEND"],dic[@"FOURSEND"]]; for (int i = 0; i < subjectArray.count; i ++) { //阶段 label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + 1 + i*25, w, 24)]; [label setText:subjectArray[i] Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter]; [scroll addSubview:label]; //学时 label = [[UILabel alloc] initWithFrame:CGRectMake(x + w, y + 1 + i*25, w, 24)]; int time = [trainTimeArray[i] intValue]; int hour = time/60; int min = time%60; NSString *timeString = @""; if (hour == 0) { timeString = [NSString stringWithFormat:@"%d分钟",min]; }else{ timeString = [NSString stringWithFormat:@"%d时%d分",hour,min]; } [label setText:timeString Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter]; [scroll addSubview:label]; //审核状态 label = [[UILabel alloc] initWithFrame:CGRectMake(x + 2*w, y + 1 + i*25, w, 24)]; NSString *stateString = stateArray[i]; switch ([stateString intValue]) { case 0: stateString = @"不允许送审"; break; case 1: stateString = @"允许送审"; break; case 2: stateString = @"审核通过"; break; case 3: stateString = @"退回"; break; case 4: stateString = @"待审核"; break; default: stateString = @""; break; } [label setText:stateString Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter]; [scroll addSubview:label]; //是否传至交警 label = [[UILabel alloc] initWithFrame:CGRectMake(x + 3*w, y + 1 + i*25, w, 24)]; NSString *sendString = sendArray[i]; switch ([sendString intValue]) { case 0: sendString = @"未传输"; break; case 1: sendString = @"已传至运管"; break; case 2: sendString = @"已传至交警"; break; default: sendString = @""; break; } [label setText:sendString Font:Font16 TextColor:newSubTitleColor Alignment:NSTextAlignmentCenter]; [scroll addSubview:label]; } x = 15; y += 100 + 20; w = kSize.width - 2*x; h = 30; label = [[UILabel alloc] setxywh]; [label setText:@"当前培训信息" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentCenter]; if (kSize.width == 320.0) { [label setText:@"当前培训信息:" Font:Font18 TextColor:newTitleColor Alignment:NSTextAlignmentLeft]; } [scroll addSubview:label]; btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(kSize.width-120-x, y, 120, h); btn.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2]; [btn setTitle:@"查看分钟学时" textColor:defGreen font:Font18 fotState:UIControlStateNormal]; [btn borderColor:defGreen width:.6 cornorRadios:3]; [btn target:self Tag:100]; [scroll addSubview:btn]; y += h+5; [label addViewWithRect:CGRectMake(x, y, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y + 59, w, 1) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x, y, 1, 60) Color:newSubTitleColor]; [label addViewWithRect:CGRectMake(x + w, y, 1, 60) Color:newSubTitleColor]; w = w/4.0; h = 30; NSArray *titles = @[@"总时长",@"有效时长",@"无效时长",@"待审核"]; NSArray *textArray = @[dic[@"totalTime"],dic[@"vaildTime"],dic[@"noVaildTime"],dic[@"notAuditTime"]]; NSArray *colors = @[newTitleColor,[UIColor greenColor],[UIColor redColor],defGreen]; NSMutableArray *labels = [NSMutableArray arrayWithCapacity:4]; for (int i = 0; i < titles.count; i ++) { label = [[UILabel alloc] initWithFrame:CGRectMake(x + i*w, y, w, h)]; label.backgroundColor = [UIColor colorWithWhite:.7 alpha:.2]; [label setText:titles[i] Font:Font16 TextColor:newTitleColor Alignment:NSTextAlignmentCenter]; [scroll addSubview:label]; label = [[UILabel alloc] initWithFrame:CGRectMake(x + i*w, y + h, w, h)]; [label setText:[NSString stringWithFormat:@"%@分钟",textArray[i]] Font:Font16 TextColor:colors[i] Alignment:NSTextAlignmentCenter]; [scroll addSubview:label]; [labels addObject:label]; if (i != 0) { [label addViewWithRect:CGRectMake(x + i*w, y, 1, 2*h) Color:newSubTitleColor]; } } allTimeLabel = labels[0]; valueTimeLabel = labels[1]; invalidTimeLabel = labels[2]; waitTimeLabel = labels[3]; x = 20; y += 70; w = kSize.width - 2*x; h = 60; label = [[UILabel alloc] setxywh]; [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]; label.numberOfLines = 0; [scroll addSubview:label]; mileAndSpeedLabel = label; [scroll setContentSize:CGSizeMake(stuInfoView.width, CGRectGetMaxY(mileAndSpeedLabel.frame) + 100)]; } - (void)setStudentInfoWithDic:(NSDictionary *)dic { //这里已经有展示学员信息的控件了 直接填入数据 allTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"totalTime"]]; valueTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"vaildTime"]]; invalidTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"noVaildTime"]]; waitTimeLabel.text = [NSString stringWithFormat:@"%@分钟",dic[@"notAuditTime"]]; mileAndSpeedLabel.text = [NSString stringWithFormat:@"当前培训过程中,车辆平均速度为%.2fKm/h,行驶总里程为%.2fKm,有效学时占比为%.1f%%",[dic[@"avgSpeed"] floatValue],[dic[@"totalMile"] floatValue], [dic[@"vaildTime"] floatValue]/[dic[@"totalTime"] floatValue]*100]; } - (void)btnClick:(UIButton *)sender { //查看分钟学时 if (sender.tag == 100) { MinRescord *vc = [[MinRescord alloc]init]; vc.stuID = dataDic[@"STUID"]; vc.classId = dataDic[@"CLASSID"]; [self.navigationController pushViewController:vc animated:YES]; } //查看训练照片 if (sender.tag == 101) { SelectImgVC *vc = [[SelectImgVC alloc] init]; vc.skipType = 1; vc.stuDic = dataDic; [self.navigationController pushViewController:vc animated:YES]; } } #pragma mark 数据请求 - (void)getStudentTrainInfos { [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } //查询学员签到列表 科目传空 查全部 NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"coachId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]]; NSString* method = @"getStudentTrainInfos"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { RemoveHUD(); if (!root) { ShowMsg(@"查询带教学员失败,请刷新!"); return ; } if ([root[@"code"] isEqualToString:@"1"]) { //没有带教学员0.0 ShowMsg(root[@"body"]); for (UIView *view in stuInfoView.subviews) { [view removeFromSuperview]; } UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 40, 50)]; [label setText:@"暂未查询到正在带教学员!" Font:Font18 TextColor:newTitleColor]; [stuInfoView addSubview:label]; if (preTimer) { [preTimer invalidate]; preTimer = nil; } return; } dataDic = root[@"body"]; //带教科目 NSString *subjectString = @"带教科目:科目二"; if ([dataDic[@"subject"] intValue] == 3) { subjectString = @"带教科目:科目三"; } subjectLabel.text = subjectString; //生成学员信息 if (stuInfoView.subviews.count < 2) { [self loadStudentInfoWithDic:root[@"body"]]; }else{ if (![[root[@"body"] objectForKey:@"STUNAME"] isEqualToString:stuNamelabel.text]) { [self loadStudentInfoWithDic:root[@"body"]]; }else { [self setStudentInfoWithDic:root[@"body"]]; } } if (preTimer == nil) { preTimer = [NSTimer scheduledTimerWithTimeInterval:70 target:self selector:@selector(getStudentTrainInfos) userInfo:nil repeats:YES]; } }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end