// // MyGradeVC.m // jiaPei // // Created by apple on 15/11/21. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "MyGradeVC.h" #import "AFView.h" #define rateX kSize.width / 320 #define rateY kSize.height / 480 #define SGRectMake(x,y,width,height) CGRectMake(x * rateX, y * rateY, width * rateX, height * rateY) @interface MyGradeVC () { AFView *afView; HolderView *holderV; /**保存各种考试成绩的称号。例如,赛车之神 */ NSArray *honors; NSArray *grades; } @end @implementation MyGradeVC - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor whiteColor]]; [self goBackByNavigation]; if (_stuName.length > 0) { [self setTitle:[NSString stringWithFormat:@"%@的成绩",_stuName]]; }else{ [self setTitle:[NSString stringWithFormat:@"学员成绩"]]; } honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"]; holderV = [[HolderView alloc] initWithFrame:kFrame]; [holderV freshBlock:^{ [self getMyStudentScore]; }]; [self.view addSubview:holderV]; [self getMyStudentScore]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 初始化 -(void)myInit{ UILabel* label; CGFloat currentTop; CGFloat lblh ,lblw; CGFloat vh=160; NSInteger x = 0; //只显示最近的9条成绩。 NSInteger lastestCnt = 9; if (grades.count < lastestCnt) { lastestCnt = grades.count; } NSMutableArray* points = [NSMutableArray array]; for (int i = 0;i < lastestCnt;i++) { NSDictionary *dic = grades[lastestCnt - i - 1]; [points addObject:[NSValue valueWithCGPoint:CGPointMake(++x, [dic[@"EI_SCORE"] intValue])]]; } afView = [[AFView alloc] initWithFrame:SGRectMake(0, 64*480/kSize.height, 320, vh)]; NSArray* xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"]; [afView setX_labels:xTitles]; [afView setMin_X:1]; [afView setMax_X:xTitles.count]; [afView setMin_Y:0]; [afView setMax_Y:100]; [afView setY_labels:@[@"0",@"20",@"40",@"60",@"80",@"100"]]; [afView setData:points];//折线图的数据。 [self.view addSubview:afView]; currentTop = vh + 64*480/kSize.height + 10; lblh = 25; lblw = 320*.2; UIScrollView* scroll = [[UIScrollView alloc] initWithFrame:SGRectMake(0, currentTop, 320, 480- currentTop)]; [self.view addSubview:scroll]; for (int y =0; y 5) { dateStr = [dateStr substringFromIndex:5]; } [label setText:dateStr]; } break; case 1: [label setTextColor:[UIColor redColor]]; [label setText:[NSString stringWithFormat:@"%@分",dic[@"EI_SCORE"]]]; break; case 2: { [label setTextColor:KContentTextColor]; int timeS = [dic[@"EI_TOTAL_TIME"] intValue]; int min = timeS/60; int sec = timeS%60; NSString *minStr = [NSString stringWithFormat:@"%d",min]; NSString *secStr = [NSString stringWithFormat:@"%d",sec]; if (min < 10) { minStr = [NSString stringWithFormat:@"0%d",min]; } if (sec < 10) { secStr = [NSString stringWithFormat:@"0%d",sec]; } [label setText:[NSString stringWithFormat:@"%@:%@",minStr,secStr]]; } break; case 3: { NSInteger score = [dic[@"EI_SCORE"] integerValue]; NSString *graHonorStr = @""; if (score < 60) { graHonorStr = honors[0]; }else if (score < 90){ graHonorStr = honors[1]; }else if (score < 93){ graHonorStr = honors[2]; }else if (score < 96){ graHonorStr = honors[3]; }else if (score < 98){ graHonorStr = honors[4]; }else{ graHonorStr = honors[5]; } [label setTextColor:defGreen]; [label setText:graHonorStr]; } break; default: break; } } } [label addViewWithRect:SGRectMake(0, lblh*grades.count, 320, .5)]; [scroll setContentSize:CGSizeMake(0, lblh*(grades.count+2)*rateY)]; [scroll setScrollEnabled:YES]; } #pragma mark 数据请求 //获取学员成绩详情 - (void)getMyStudentScore { if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * mDic = [NSMutableDictionary new]; [mDic setObject:@"" forKey:@"idcard"]; [mDic setObject:@"" forKey:@"subject"]; [mDic setObject:@"" forKey:@"score"]; [mDic setObject:@"" forKey:@"count"]; [mDic setObject:@"" forKey:@"startTime"]; [mDic setObject:@"" forKey:@"endTime"]; [mDic setObject:@"" forKey:@"jxbh"]; NSString* method = @"getStuExams"; [NetManager requestAnythingWithURL:method dictionary:mDic dataArray:nil completion:^(NSDictionary *root) { [holderV setHidden:NO]; if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } if ([root[@"body"] count] < 1) { ShowMsg(@"您的学员还未上传成绩"); return; } grades = root[@"body"]; [holderV setHidden:YES]; [self myInit]; }]; } @end