123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- //
- // 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"
- @interface TrainInfoVC ()<UITableViewDataSource,UITableViewDelegate>
- {
- UITableView *mainTableView;
- BOOL isclose[3];
- NSInteger showMnState;// 1显示 0不显示
- NSMutableArray *modelsArray;
- NSArray<NSString *> *totalTimeArray;
- NSMutableDictionary *dataDic;
- NSMutableDictionary *otherdataDic;//里程数和审核状态
- NSDictionary *trainTimeDic;//各个阶段总学时
-
- NSMutableArray *timeArray;
- NSInteger whichOne;
-
- NSMutableArray *sureBtnsArray;//确定button数组
- NSMutableArray *sureStatusArray;//确定状态数组
- }
- @property (strong, readwrite, nonatomic) UILabel *totalMileageLabel;
- @end
- @implementation TrainInfoVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = @"我的学时";
- self.view.backgroundColor = backGroundColor;
- // if (self.skipType == 1) {
- // [self configNavigationBarDismissNav];
- // }else {
- // }
- [self configNavigationBar];
- showMnState = 0;
- for (NSDictionary * dic in defUser.userDict[@"params"]) {
- if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_MN"]) {
- showMnState = [dic[@"VALUE"] integerValue];
- }
- }
-
- NSString *pxjd = [NSString stringWithFormat:@"%@",defUser.userDict[@"pxjd"]];
- NSInteger currentSubject = [pxjd integerValue];
- if (currentSubject>=1 && currentSubject <= 4) {
- isclose[currentSubject-1] = YES;
- }
-
- [self myInit];
- }
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- [self clearData];//数据初始化(更新需调用清零)
- [self getStudentTrainCheck];//获取确认状态
- [self getTotalTrainTime];//获取总时长
-
- }
- -(void)myInit
- {
- mainTableView = [[UITableView alloc] initWithFrame:kFrame];
- mainTableView.height -= kNavOffSet;
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- mainTableView.tableFooterView = [UIView new];
- [self.view addSubview:mainTableView];
- }
- - (void)clearData{
-
- modelsArray = [NSMutableArray array];
- totalTimeArray = [NSArray array];
- timeArray = [NSMutableArray array];
- sureStatusArray = [NSMutableArray array];
- sureBtnsArray = [NSMutableArray array];
- for (int i=0; i<4; i++) {
- [sureStatusArray addObject:@"1"];
- [sureBtnsArray addObject:[NSNull null]];
- }
-
- dataDic = [NSMutableDictionary dictionaryWithCapacity:4];
-
- NSArray *array1 = [DB_Helper quearyTrain:defUser.userStuId Subject:@"1"];
- NSArray *array4 = [DB_Helper quearyTrain:defUser.userStuId Subject:@"4"];
- if (array4.count < 1) {
- array4 = [DB_Helper quearyTrain:defUser.userStuId Subject:@"3"];
- }
-
- for (int i = 1; i < 5; i ++) {
- NSMutableDictionary *rowDic = [NSMutableDictionary dictionaryWithCapacity:2];
- if (i == 1) {
- [rowDic setObject:[NSMutableArray arrayWithArray:array1] forKey:@"0"];
- }else if (i == 4) {
- [rowDic setObject:[NSMutableArray arrayWithArray:array4] forKey:@"0"];
- }else{
- [rowDic setObject:[NSMutableArray array] forKey:@"0"];
- }
- [rowDic setObject:[NSMutableArray array] forKey:@"1"];
- [dataDic setObject:rowDic forKey:[NSString stringWithFormat:@"%d",i]];
- }
- }
- #pragma mark 数据请求
- -(void)getTotalTrainTime
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"cx" Value:defUser.userDict[@"carType"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
- [arr addPro:@"isShowMn" Value:showMnState==1?@"1":@"0"];
-
- NSString* method = @"getTrainSubjectCredit";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view animated:NO];
- if (!root)
- {
-
- showMsgByAlert(self, @"请求失败");
- return;
- }
-
- if ([root[@"code"] intValue] == 1) {
- showMsgByAlert(self, root[@"body"]);
- return;
- }
-
- NSArray *array = root[@"body"];
- if (![array isKindOfClass:[NSArray class]] || array.count == 0) {
- return;
- }
- 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"]];
- }
- }
- }
-
- if (showMnState != 1) {
- //如果不显示模拟 要把模拟数据加到理论数据中
- [totalArray replaceObjectAtIndex:2 withObject:[NSString stringWithFormat:@"%d",([totalArray[1] intValue] + [totalArray[2] intValue])]];
- [totalArray replaceObjectAtIndex:4 withObject:[NSString stringWithFormat:@"%d",([totalArray[3] intValue] + [totalArray[4] intValue])]];
- }
-
- totalTimeArray = nil;
- totalTimeArray = [NSArray arrayWithArray:totalArray];
- [mainTableView reloadData];
- [self getTrainInfo];
- }];
-
- }
- //获取计时信息
- -(void)getTrainInfo
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"stuOutId" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
-
- NSString* method = @"getTrainFinish";
-
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- if (!root){
- ShowMsg(@"请求失败");
- return;
- }
- if ([root[@"code"] intValue] == 1){
- ShowMsg(root[@"msg"]);
- return;
- }
-
- if ([root[@"body"] count] < 1){
- return;
- }
- modelsArray = root[@"body"];
- if ([root[@"other"] isKindOfClass:[NSDictionary class]]) {
- otherdataDic = [NSMutableDictionary dictionaryWithDictionary:root[@"other"]];
- }
- /*
- CRI_VAILD_TIME:有效学时
- CRI_TRAIN_SUBJECT:学时阶段 1-4
- CRI_DURATION:培训学时
- PXKMTYPE:1实操 (2课堂教练==》服务器改为返回到4里面去了) 3模拟器教学 4远程教学(理论)+ (终端)理论
- TCI_PHOTO_PATH:教练员照片
- TCI_NAME:教练名称
- CRI_STARTTIME:开始时间
- CRI_ENDTIME:结束时间
- */
-
- for (NSDictionary *dic in modelsArray) {
- //解析数据
-
- switch ([dic[@"PXKMTYPE"] integerValue]) {
- case 1:
- {
- [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"1"] addObject:dic];
- }
- break;
- // case 2:
- // {
- // //这个一般用不到 【lee:18/5/11 这个东西就不应该。科一/四 终端理论学时不应该拿来替换作为本地未上传的学时】
- // [[[dataDic objectForKey:dic[@"CRI_TRAIN_SUBJECT"]] objectForKey:@"0"] 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];
- }
- break;
-
- default:
- break;
- }
-
- }
-
- [mainTableView reloadData];
- }];
-
- }
- //获取确认状态
- -(void)getStudentTrainCheck
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
- [arr addPro:@"stuId" Value:defUser.userDict[@"outId"]];
-
- NSString* method = @"getStudentTrainCheck";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
-
- if (!root || [root[@"code"] intValue] == 1)
- {
- return;
- }
-
- NSDictionary *dic = root[@"body"];
- trainTimeDic = dic;
- NSArray *arr = @[@"ONECHECK",@"TWOCHECK",@"THREECHECK",@"FOURCHECK"];
- for (int i=0; i<4; i++) {
- NSString *status = [NSString stringWithFormat:@"%@",dic[arr[i]]];
- if (![status isEqualToString:@"1"]) {
- [sureStatusArray replaceObjectAtIndex:i withObject:status];
- if ([sureBtnsArray[i] isKindOfClass:[UIButton class]]) {
- UIButton *btn = sureBtnsArray[i];
- btn.selected = YES;
- }
- }
- }
- }];
- }
- -(void)updateStudentTrainCheckWithSubject:(UIButton *)sureBtn
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString *subject = [NSString stringWithFormat:@"%ld",(long)sureBtn.tag+1-10];
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
- [arr addPro:@"stuId" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"subject" Value:subject];
- [arr addPro:@"cx" Value:defUser.userDict[@"carType"]];
-
- NSString* method = @"updateStudentTrainCheck";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- if (!root) {
- ShowMsg(@"请求失败,请重试");
- }
-
- if ([root[@"code"] intValue] == 1)
- {
- ShowMsg(root[@"body"]);
- return;
- }
-
- //确认成功
- sureBtn.selected = NO;
- [sureStatusArray replaceObjectAtIndex:sureBtn.tag-10 withObject:@"1"];
- }];
-
- }
- #pragma mark tableView delegate
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 4;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (isclose[section] == YES)
- {
- if (showMnState != 1) {
- if (section == 1) {
- return 1;
- }else {
- return 2;
- }
- }else {
- if (section == 2) {
- return 3;
- }else {
- return 2;
- }
- }
- }else {
- return 0;
- }
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSMutableArray *rowArray = (NSMutableArray *)[[dataDic objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.section + 1]] objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row]];
-
- if (showMnState != 1 && (indexPath.section == 1 || indexPath.section == 2)) {
- rowArray = (NSMutableArray *)[[dataDic objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.section + 1]] objectForKey:@"1"];
- }
-
-
- 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.x += 20;
- cell.width -= 20;
- cell.textLabel.font = [UIFont scaleSize:FontTitle];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
-
- int time = 0;
- for (TrainRecord *train in rowArray)
- {
- time += [train.trainTime intValue];
- }
- int hour = time/60;
- int min = time%60;
-
- NSString *dbTime = [NSString stringWithFormat:@"%d小时%d分钟",hour,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 if ((indexPath.section == 2 && indexPath.row == 1 && showMnState != 1) || (indexPath.section == 2 && indexPath.row == 2 && showMnState == 1)) {
- UITableViewCell *totalMileageCell = [tableView dequeueReusableCellWithIdentifier:@"foote"];
- if (!totalMileageCell) {
- totalMileageCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"totalMileageCell"];
- _totalMileageLabel = [[UILabel alloc] initWithFrame:CGRectMake(65, 0, kScreenWidth, 50)];
- [_totalMileageLabel setText:@"总里程:" Font:FontTitle TextColor:kTitleColor];
- [totalMileageCell.contentView addSubview:_totalMileageLabel];
- }
- _totalMileageLabel.text = [NSString stringWithFormat:@"总里程:%@km",otherdataDic[@"SRI_TRAIN_THREE_MILEAGE"]? : @"0"];
- return totalMileageCell;
- }else {
- //服务器数据
- NSString *titString = @"理论";
- if (indexPath.section == 1 || indexPath.section == 2) {
- titString = @"模拟";
- if (indexPath.row == 1) {
- titString = @"实操";
- }
-
- if (showMnState != 1) {
- titString = @"实操";
- }
- }
-
- NSInteger index = indexPath.section * 2 + indexPath.row - 1;
-
- if (showMnState != 1 && (indexPath.section == 1 || indexPath.section == 2)) {
- index = indexPath.section * 2;
- }
-
-
- if (indexPath.section == 3) {
- index -= 1;
- }
-
- NSString *allTimeString = @"720";
- if (totalTimeArray.count > index) {
- allTimeString = totalTimeArray[index];
- }
-
- TrainInfoTableViewCell *cell = [TrainInfoTableViewCell cellForTabelView:tableView];
- cell.titleString = titString;
- cell.allNeedTime = [allTimeString integerValue];
- cell.dataArray = rowArray;
- //在每个科目判断是否存在学时?显示审核图标 : 隐藏审核图标
- NSArray *trainTimeArr = @[trainTimeDic[@"SRI_TRAIN_ONE"]? : @"0",
- trainTimeDic[@"SRI_TRAIN_TWO"]? : @"0",
- trainTimeDic[@"SRI_TRAIN_THREE"]? : @"0",
- trainTimeDic[@"SRI_TRAIN_FOUR"]? : @"0",];
- cell.checkImg.hidden = [trainTimeArr[indexPath.section] integerValue] == 0;
- //判断审核状态(2 : 显示审核通过; 0 : 未审核 ; 其他 : 隐藏图标)
- NSArray *statusArr = @[otherdataDic[@"SRI_TRAIN_ONE_STATUS"]? : @"100",
- otherdataDic[@"SRI_TRAIN_TWO_STATUS"]? : @"100",
- otherdataDic[@"SRI_TRAIN_THREE_STATUS"]? : @"100",
- otherdataDic[@"SRI_TRAIN_FOUR_STATUS"]? : @"100"];
- cell.checkImg.selected = ([statusArr[indexPath.section] integerValue] == 2);
- return cell;
- }
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- NSString *viewId = [NSString stringWithFormat:@"headview%d",(int)section];
- UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:viewId];
- if (!view) {
- view = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:viewId];
- view.frame = CGRectMake(0, 0, kSize.width, 50);
- view.backgroundColor = backGroundColor;
- view.layer.borderWidth = .5;
- view.layer.borderColor = KlineColor.CGColor;
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 120, 50)];
-
- if (section == 0)
- {
- label.text = @"科目一";
- }
- if (section == 1)
- {
- label.text = @"科目二";
- }
- if (section == 2)
- {
- label.text = @"科目三";
- }
- if (section == 3)
- {
- label.text = @"科目四";
- }
-
- [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.tag = section;
- [btn addTarget:self action:@selector(clickToChange:) forControlEvents:UIControlEventTouchUpInside];
- [view addSubview:btn];
-
- UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- sureBtn.layer.cornerRadius = 5;
- sureBtn.layer.masksToBounds = YES;
- sureBtn.frame =CGRectMake(kSize.width-100, 10, 80, 30);
- sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- [sureBtn setTitle:@"已确认" textColor:[UIColor lightGrayColor] font:FontTitle fotState:UIControlStateNormal];
- [sureBtn setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];
- [sureBtn setTitle:@"确认学时" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateSelected];
- [sureBtn setBackgroundImage:[UIImage imageWithColor:defGreen] forState:UIControlStateSelected];
-
- [sureBtn target:self tag:10+section];
- [view addSubview:sureBtn];
- [sureBtnsArray replaceObjectAtIndex:section withObject:sureBtn];
- }
-
- for (UIView *subview in view.subviews) {
-
- if ([subview isKindOfClass:[UIImageView class]]) {
- UIImageView *secImage = (UIImageView *)subview;
- secImage.transform = isclose[section] == YES?CGAffineTransformMakeRotation(M_PI):CGAffineTransformIdentity;
- }
-
- }
-
- UIButton *sureBtn = [view.subviews lastObject];
- sureBtn.selected = [sureStatusArray[section] isEqualToString:@"0"];
-
- 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 && indexPath.row == 1 && showMnState != 1) || (indexPath.section == 2 && indexPath.row == 2 && showMnState == 1)) {
- return 45;
- }else{
- return 80;
- }
-
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 50;
- }
- -(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]];
-
- if (showMnState != 1 && (indexPath.section == 1 || indexPath.section == 2)) {
- rowArray = (NSMutableArray *)[[dataDic objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.section + 1]] objectForKey:@"1"];
- }
-
- TrainDetailVC *detail = [[TrainDetailVC alloc] init];
- 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)btnClick:(UIButton *)sender{
-
- if (sender.isSelected == NO) {
- return;
- }
-
- // if ([defUser.userDict[@"imei"] length] > 0) {
- //
- // if (![defUser.userDict[@"imei"] isEqualToString:[Tools getIDFV]]) {
- // ShowMsg(@"账号与绑定手机不匹配,请用本人手机确认学时");
- // [Tools playAudioWithString:@"账号与绑定手机不匹配,请用本人手机确认学时"];
- // [self.navigationController popViewControllerAnimated:YES];
- // return;
- // }
- // }
-
- //确认学时
- [self updateStudentTrainCheckWithSubject:sender];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|