// // TrainInfoVC.m // jiaPei // // Created by apple on 16/1/29. // Copyright © 2016年 JCZ. All rights reserved. // #import "TrainInfoVC.h" #import "TrainRecord.h" #import "TrainDetailVC.h" #import "TrainInfoTableViewCell.h" #import "TrainHoursSubTableViewCell.h" @interface TrainInfoVC () { UITableView *mainTableView; BOOL isclose[3]; NSArray *totalTimeArray; NSMutableDictionary *dataDic; NSDictionary *otherDic;//培训科目是否审核字段 NSMutableArray *timeArray; NSInteger whichOne; } @property (nonatomic, readwrite, assign) NSInteger RATIONKS; @property (nonatomic, readwrite, copy) NSString *RATIONKSMC; @end @implementation TrainInfoVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"我的学时"; self.RATIONKS = 60; self.view.backgroundColor = backGroundColor; [self configNavigationBar]; [self myInit];// [self getStudentStatusByStuOutIdNew]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self clearData];//初始化数据 [self getTotalTrainTime];//获取总需要学时 } - (void)clearData{ totalTimeArray = [NSArray array]; dataDic = [NSMutableDictionary dictionaryWithCapacity:4]; NSArray *array1 = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:@"1"]; NSArray *array4 = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:@"4"]; if (array4.count < 1) { array4 = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:@"3"]; } for (int i = 1; i < 5; i ++) { NSMutableDictionary *rowDic = [NSMutableDictionary dictionaryWithCapacity:2]; if (i == 1) { [rowDic setObject:[NSMutableArray arrayWithArray:array1] forKey:@"0"]; [rowDic setObject:[NSMutableArray array] forKey:@"2"]; [rowDic setObject:[NSMutableArray array] forKey:@"3"]; }else if (i == 4) { [rowDic setObject:[NSMutableArray arrayWithArray:array4] forKey:@"0"]; [rowDic setObject:[NSMutableArray array] forKey:@"2"]; [rowDic setObject:[NSMutableArray array] forKey:@"3"]; }else{ [rowDic setObject:[NSMutableArray array] forKey:@"0"]; } [rowDic setObject:[NSMutableArray array] forKey:@"1"]; [dataDic setObject:rowDic forKey:[NSString stringWithFormat:@"%d",i]]; } } -(void)setTotalTimeArray { /* 科目一理论 科目二模拟 科目二实操 科目三模拟 科目三实操 科目三理论 科目四理论 资格证是没有的 @"小车",@"C1",@"货车",@"A2",@"客车",@"A1",@"摩托车",@"D", @"教练",@"4",@"客运",@"1",@"货运",@"2",@"危险品",@"3",@"出租车",@"5" */ if ([RQ_USER_MANAGER.currentUser.carType isEqualToString:@"C1"]) { totalTimeArray = @[@"720",@"240",@"720",@"240",@"1200",@"600"]; }else if ([RQ_USER_MANAGER.currentUser.carType isEqualToString:@"A2"]){ totalTimeArray = @[@"600",@"120",@"2280",@"240",@"1080",@"960"]; }else if ([RQ_USER_MANAGER.currentUser.carType isEqualToString:@"A1"]){ totalTimeArray = @[@"600",@"240",@"1920",@"240",@"960",@"960"]; }else if ([RQ_USER_MANAGER.currentUser.carType isEqualToString:@"D"]){ totalTimeArray = @[@"600",@"120",@"480",@"120",@"480",@"480"]; }else{ totalTimeArray = @[@"0",@"0",@"0",@"0",@"0",@"0"]; } } -(void)myInit { mainTableView = [[UITableView alloc] initWithFrame:kFrame]; mainTableView.height -= kNavOffSet; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.estimatedSectionFooterHeight = 0; mainTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; [self.view addSubview:mainTableView]; [mainTableView registerNib:[UINib nibWithNibName:@"TrainHoursSubTableViewCell" bundle:nil] forCellReuseIdentifier:@"TrainHoursSubTableViewCell"]; } #pragma mark 数据请求 //获取总需学时 -(void)getTotalTrainTime { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray* arr = [NSMutableArray array]; [arr addPro:@"cx" Value:RQ_USER_MANAGER.currentUser.carType]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city]; [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser.outId]; NSString* method = @"getTrainSubjectCredit"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { if (!root || [root[@"code"] intValue] == 1) { [self setTotalTimeArray]; [self getTrainInfo];//获取已完成学时 return; } if (!RQObjectIsNil(root[@"other"])) { if ([root[@"other"] isKindOfClass:[NSDictionary class]]) { NSDictionary *dic = root[@"other"]; if (!RQObjectIsNil(dic[@"KS"])) { NSInteger KS = [dic[@"KS"] integerValue]; _RATIONKS = KS; } if (!RQObjectIsNil(dic[@"KSMC"])) { NSString *KSMC = [NSString stringWithFormat:@"%@",dic[@"KSMC"]]; _RATIONKSMC = KSMC; } } } NSArray *array = root[@"body"];//@[@"720",@"240",@"720",@"240",@"1200",@"600"]; NSMutableArray *totalArray = [NSMutableArray array]; for (int i = 1; i < 7; i ++) { for (NSDictionary *dic in array) { if ([dic[@"SUBJECT"] intValue] == i) { [totalArray addObject:dic[@"RATION"]]; } } } totalTimeArray = nil; totalTimeArray = [NSArray arrayWithArray:totalArray]; [self getTrainInfo];//获取已完成学时 }]; } //获取计时信息 - (void)getTrainInfo { [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray* arr = [NSMutableArray array]; [arr addPro:@"stuOutId" Value:RQ_USER_MANAGER.currentUser.outId]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city]; NSString* method = @"getTrainFinishNew"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); if (!root || [root[@"code"] intValue] != 0) { if ([root[@"body"] isKindOfClass:[NSString class]] && ![root[@"body"] isEqualToString:@""]) { ShowMsg(root[@"body"]); }else { ShowMsg(root[@"msg"]); } [mainTableView reloadData]; return; } if ([root[@"body"] isKindOfClass:[NSArray class]] && [(NSArray *)root[@"body"] count] < 1) { [mainTableView reloadData]; return; } NSArray *arr = root[@"body"]; otherDic = root[@"other"]; /* CRI_VAILD_TIME:有效学时 CRI_TRAIN_SUBJECT:学时阶段 1-4 CRI_DURATION:培训学时 PXKMTYPE:1实操 2课堂教练 3模拟器教学 4远程教练(理论) TCI_PHOTO_PATH:教练员照片 TCI_NAME:教练名称 CRI_STARTTIME:开始时间 CRI_ENDTIME:结束时间 */ for (NSDictionary *dic in arr) { //解析数据 switch ([dic[@"PXKMTYPE"] integerValue]) { case 1: { [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"1"] addObject:dic]; } break; case 2://科一/四 终端理论学时 { [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"2"] addObject:dic]; [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"3"] addObject:dic]; } break; case 3: { [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"0"] addObject:dic]; } break; case 4: { [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"1"] addObject:dic]; [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"3"] addObject:dic]; } break; default: break; } } [mainTableView reloadData]; }]; } - (void)getStudentStatusByStuOutIdNew { if (![Util connectedToNetWork]) { ShowMsg(@"请检查网络连接。"); RemoveHUD(); return; } NSMutableArray *arr = [NSMutableArray array]; [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuOutId"]; [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; NSString* method = @"getStudentStatusByStuOutIdNew"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { RemoveHUD(); if (!dict) { ShowMsgFailed(); return; } if ([dict[@"code"] intValue] != 1) { if ([(NSString *)dict[@"body"][@"history"] isEqualToString:@"1"]) { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"2019年之前报名前的旧系统学员,送审即在旧系统送审。此界面仅做参考。详情请咨询驾校工作人员" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil]; } }else { if (dict[@"body"] && [dict[@"body"] isKindOfClass:[NSString class]]) { if (![(NSString *)dict[@"body"] isEqualToString:@""]) { ShowMsg([NSString stringWithFormat:@"%@",dict[@"body"]]); }else { ShowMsg(@"暂无返回消息"); } }else { ShowMsg(dict[@"msg"]); } } }]; } #pragma mark tableView delegate -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 4; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSInteger count = 0; if (RQ_USER_MANAGER.isycbd) { /// 开启远程教育(人脸远程比对) count = (isclose[section])? 0 : ((section == 0 || section == 3)? 4 : 3); } else { count = (isclose[section])? 0 : ((section == 0 || section == 3)? 4 : 3); } return count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *section = [NSString stringWithFormat:@"%d",(int)indexPath.section + 1]; NSString *row = [NSString stringWithFormat:@"%d",(int)indexPath.row]; NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:section] objectForKey:row]; if ((indexPath.section == 0 || indexPath.section == 3) && indexPath.row == 0) { //本地学时 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; cell.backgroundColor = backGroundColor; cell.x += 20; cell.width -= 20; cell.textLabel.font = [UIFont scaleSize:FontTitle]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.selectionStyle = UITableViewCellSelectionStyleNone; } __block int time = 0; [[rowArray.rac_sequence.signal filter:^BOOL(id _Nullable value) { return [value isKindOfClass:[TrainRecord class]]; }] subscribeNext:^(TrainRecord *train) { time += [train.trainTime intValue]; }] ; int hour = time/(_RATIONKS? : 60); int min = time%(_RATIONKS? : 60); NSString *dbTime = [NSString stringWithFormat:@"%d%@%d分钟",hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),min]; if (hour == 0) { dbTime = [NSString stringWithFormat:@"%d分钟",min]; if (min == 0) { dbTime = @"0分钟"; } } if (time != 0) { cell.textLabel.text = [NSString stringWithFormat:@"理论(未上传) %@",dbTime]; }else { cell.textLabel.text = [NSString stringWithFormat:@"学时已全部上传"]; } return cell; } else { TrainHoursSubTableViewCell *trainHoursSubTableViewCell = [tableView dequeueReusableCellWithIdentifier:@"TrainHoursSubTableViewCell"]; if (!trainHoursSubTableViewCell) { trainHoursSubTableViewCell = [[NSBundle mainBundle] loadNibNamed:@"TrainHoursSubTableViewCell" owner:self options:nil].firstObject; } TrainInfoTableViewCell *trainInfoTableViewCell = [TrainInfoTableViewCell cellForTabelView:tableView]; trainInfoTableViewCell.RATIONKS = _RATIONKS; trainInfoTableViewCell.RATIONKSMC = _RATIONKSMC; switch (indexPath.section) { case 0: case 3: { switch (indexPath.row) { case 1: { if (RQ_USER_MANAGER.isycbd) { /// 开启远程教育(人脸远程比对) trainHoursSubTableViewCell.thoryHoursLabel.text = @"远程教育(理论)"; NSString *totalTimeString = [self getTotalTime:rowArray]; trainHoursSubTableViewCell.classHoursLabel.text = [NSString stringWithFormat:@"已完成%@",totalTimeString]; return trainHoursSubTableViewCell; } else { NSString *titleString = @"理论"; if(indexPath.row == 3){ titleString = @"总学时"; } trainInfoTableViewCell.titleString = titleString; trainInfoTableViewCell.allNeedTime = [(indexPath.section == 0)? (totalTimeArray.firstObject? : @"720") : (totalTimeArray.lastObject? : @"600") integerValue]; trainInfoTableViewCell.dataArray = rowArray; return trainInfoTableViewCell; } } case 2: { trainHoursSubTableViewCell.thoryHoursLabel.text = @"课堂教育(理论)"; NSString *totalTimeString = [self getTotalTime:rowArray]; trainHoursSubTableViewCell.classHoursLabel.text = [NSString stringWithFormat:@"已完成%@",totalTimeString]; return trainHoursSubTableViewCell; } case 3: { NSString *titleString = @"理论"; if(indexPath.row == 3){ titleString = @"总学时"; } trainInfoTableViewCell.titleString = titleString; trainInfoTableViewCell.allNeedTime = [(indexPath.section == 0)? (totalTimeArray.firstObject? : @"720") : (totalTimeArray.lastObject? : @"600") integerValue]; trainInfoTableViewCell.dataArray = rowArray; return trainInfoTableViewCell; } default: return trainInfoTableViewCell; } case 1: case 2: { NSInteger index = indexPath.section * 2 + indexPath.row - 1; NSString *allTimeString = @"720"; if (totalTimeArray.count > index) { allTimeString = totalTimeArray[index]; } NSString *titleString = indexPath.row == 0? @"模拟" : @"实操"; NSString *timeKey = [NSString stringWithFormat:@"%@_%@",section,row]; dataDic[timeKey] = allTimeString; trainInfoTableViewCell.mileage_label.text = @""; if(indexPath.row == 2){ titleString = @"总学时"; NSMutableArray *array_0 = (NSMutableArray *)[[dataDic objectForKey:section] objectForKey:@"0"]; NSMutableArray *array_1 = (NSMutableArray *)[[dataDic objectForKey:section] objectForKey:@"1"]; rowArray = [NSMutableArray arrayWithArray:array_0]; [rowArray addObjectsFromArray:array_1]; int value = [dataDic[[NSString stringWithFormat:@"%@_0",section]] intValue]+ [dataDic[[NSString stringWithFormat:@"%@_1",section]] intValue]; allTimeString = [NSString stringWithFormat:@"%d",value]; int mileage = 0; if(rowArray.count >0){ for (NSDictionary *item in rowArray) { mileage += [item[@"CRI_MILEAGE"] intValue]; } trainInfoTableViewCell.mileage_label.text = [NSString stringWithFormat:@"总里程:%.2f公里",mileage/1000.0]; } } trainInfoTableViewCell.titleString = titleString; trainInfoTableViewCell.allNeedTime = [allTimeString integerValue]; trainInfoTableViewCell.dataArray = rowArray; return trainInfoTableViewCell; } return trainInfoTableViewCell; } default: return trainInfoTableViewCell; } } } -(NSString *)getTotalTime:(NSMutableArray *)array { if ([array count] < 1) { return @"0分钟"; } int time = 0; for (NSDictionary *dic in array) { time += [dic[@"CRI_DURATION"] intValue];//CRI_VAILD_TIME } int hour = time/(_RATIONKS? : 60); int min = time%(_RATIONKS? : 60); NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),min]; if (hour == 0) { timeString = [NSString stringWithFormat:@"%d分钟",min]; } return timeString; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headview"]; if (!view) { view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)]; view.backgroundColor = backGroundColor; view.layer.borderWidth = .5; view.layer.borderColor = RQlineColor.CGColor; //科目 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 120, 50)]; label.tag = 1; [view addSubview:label]; //审核通过 未审核 label = [[UILabel alloc] initWithFrame:CGRectMake(200, 0, 120, 50)]; label.tag = 2; [label setText:@"" Font:FontTitle TextColor:[UIColor redColor] Alignment:NSTextAlignmentCenter]; [view addSubview:label]; UIImageView *secImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 15, 20, 20)]; secImage.image = [UIImage imageNamed:@"location_more_arrow"]; [view addSubview:secImage]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)]; [btn addTarget:self action:@selector(clickToChange:) forControlEvents:UIControlEventTouchUpInside]; [view addSubview:btn]; } for (UIView *subview in view.subviews) { if ([subview isKindOfClass:[UILabel class]]) { UILabel *label = (UILabel *)subview; if (label.tag == 1) { if (section == 0) { label.text = @"科目一"; } if (section == 1) { label.text = @"科目二"; } if (section == 2) { label.text = @"科目三"; } if (section == 3) { label.text = @"科目四"; } } if (label.tag == 2) { if ([otherDic isKindOfClass:[NSDictionary class]]) { if (section == 0) { NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:@"1"] objectForKey:@"1"]; if (rowArray.count > 0) { if ([otherDic[@"SRI_TRAIN_ONE_STATUS"] integerValue] == 2) { label.text = @"审核通过"; label.textColor = RQ_MAIN_COLOR; }else { label.text = @"未审核"; label.textColor = [UIColor redColor]; } }else { label.text = @""; } } if (section == 1) { NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:@"2"] objectForKey:@"1"]; if (rowArray.count > 0) { if ([otherDic[@"SRI_TRAIN_TWO_STATUS"] integerValue] == 2) { label.text = @"审核通过"; label.textColor = RQ_MAIN_COLOR; }else { label.text = @"未审核"; label.textColor = [UIColor redColor]; } }else { label.text = @""; } } if (section == 2) { NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:@"3"] objectForKey:@"1"]; if (rowArray.count > 0) { if ([otherDic[@"SRI_TRAIN_THREE_STATUS"] integerValue] == 2) { label.text = @"审核通过"; label.textColor = RQ_MAIN_COLOR; }else { label.text = @"未审核"; label.textColor = [UIColor redColor]; } }else { label.text = @""; } } if (section == 3) { NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:@"4"] objectForKey:@"1"]; if (rowArray.count > 0) { if ([otherDic[@"SRI_TRAIN_FOUR_STATUS"] integerValue] == 2) { label.text = @"审核通过"; label.textColor = RQ_MAIN_COLOR; }else { label.text = @"未审核"; label.textColor = [UIColor redColor]; } }else { label.text = @""; } } }else { label.text = @""; } } } if ([subview isKindOfClass:[UIImageView class]]) { UIImageView *secImage = (UIImageView *)subview; secImage.transform = isclose[section] == NO?CGAffineTransformMakeRotation(M_PI):CGAffineTransformIdentity; } if ([subview isKindOfClass:[UIButton class]]) { UIButton *btn = (UIButton *)subview; btn.tag = section; } } return view; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if ((indexPath.section == 0 || indexPath.section == 3) && indexPath.row == 0) { return 45; }else if (indexPath.section == 2) { return 100; }else{ return 80; } } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 50; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.section + 1]] objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row]]; TrainDetailVC *detail = [[TrainDetailVC alloc] init]; detail.RATIONKS = _RATIONKS; detail.RATIONKSMC = _RATIONKSMC; if (RQ_USER_MANAGER.isycbd == 1) { __block NSInteger trainTime = 0; if (rowArray.count > 0 && [rowArray.firstObject isKindOfClass:[TrainRecord class]]) { [rowArray.rac_sequence.signal subscribeNext:^(TrainRecord *record) { trainTime = trainTime + record.trainTime.integerValue; } completed:^{ if (trainTime >= 30) { detail.datasourceArray = rowArray; } }]; } else { detail.datasourceArray = rowArray; } } else { detail.datasourceArray = rowArray; } detail.type = @"2"; if ((indexPath.section == 0 || indexPath.section == 3) && indexPath.row == 0) { //本地的学时 要上传 detail.type = @"1"; } [self navPushHideTabbarToVC:detail]; } - (void)clickToChange:(UIButton *)sender { isclose[sender.tag] = !isclose[sender.tag]; [mainTableView reloadData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end