123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //
- // TrainDetailVC.m
- // jiaPei
- //
- // Created by apple on 16/1/29.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "TrainDetailVC.h"
- #import "TrainRecord.h"
- #import "DES3Util.h"
- #import "HolderView.h"
- #import "Evaluation.h"
- #import "orderCommentVC.h"
- #import "OrbitVC.h"
- #import "TrainDetailCell.h"
- @interface TrainDetailVC ()<UITableViewDataSource,UITableViewDelegate>
- {
- UITableView *mainTable;
- }
- @end
- @implementation TrainDetailVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self configNavigationBar];
- self.view.backgroundColor = backGroundColor;
- self.title = @"学时详细";
-
-
- if ([self.type isEqualToString:@"1"])
- {
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"上传" style:UIBarButtonItemStyleDone target:self action:@selector(clickToUpdate)];
- item.tintColor = defGreen;
- if (defUser.isycbd != 1) {
- self.navigationItem.rightBarButtonItem = item;
- }
- }
-
-
- mainTable = [[UITableView alloc] initWithFrame:kFrame];
- mainTable.height -= kNavOffSet;
- mainTable.delegate = self;
- mainTable.dataSource = self;
- [self.view addSubview:mainTable];
-
- if (_datasourceArray.count < 1) {
- HolderView *placeHolder = [[HolderView alloc] initWithFrame:mainTable.frame];
- [self.view addSubview:placeHolder];
- }
- }
- -(void)clickToUpdate
- {
- [self upLoadTrainRecord];
- }
- -(void)upLoadTrainRecord{
-
- if (_datasourceArray.count < 1) {
- ShowMsg(@"本地无学时明细!");
- return;
- }
- //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
- [self uploadMoreTrainRecordWithArray:_datasourceArray];
- }
- - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString* str = @"";
- for (TrainRecord *record in trainArray) {
-
- str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
- }
-
- TrainRecord *record = [trainArray firstObject];
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]];
-
- NSString* method = @"uploadMoreTrainRecord";
-
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
-
- [MBProgressHUD hideHUDForView:self.view];
-
- if (!dict) {
- ShowMsg(@"操作失败");
- return;
- }
- if ([dict[@"code"] isEqualToString:@"90"]) {
- UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
-
- [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-
- [LoginViewController loginFromVC:self];
- }]];
- [self presentViewController:alertFind animated:true completion:nil];
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"0"]) {
- for (TrainRecord *record in trainArray) {
-
- [DB_Helper updateTrainState:record];
- }
-
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
- [alert show];
-
- self.datasourceArray = [NSMutableArray array];
- [mainTable reloadData];
- }
- }];
- }
- #pragma mark tableView delegate
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.datasourceArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([self.type isEqualToString:@"1"])//
- {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- TrainRecord *train = (TrainRecord *)self.datasourceArray[indexPath.row];
-
- if (train.endTime.length > 10) {
- cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",train.beginTime,[train.endTime substringFromIndex:10]];
- }else{
- cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",train.beginTime,train.endTime];
- }
-
- int time = [train.trainTime intValue];
- int min = time%60;
- int hour = time/60;
- NSString *timeString = [NSString stringWithFormat:@"%d小时%d分钟",hour,min];
- if (hour == 0)
- {
- timeString = [NSString stringWithFormat:@"%d分钟",min];
- }
- cell.detailTextLabel.text = [NSString stringWithFormat:@"持续时间:%@",timeString];
-
- return cell;
- }else{
- /*
- CRI_VAILD_TIME:有效学时
- CRI_TRAIN_SUBJECT:学时阶段 1-4
- CRI_DURATION:培训学时
- PXKMTYPE:1实操 2课堂教练 3模拟器教学 4远程教练(理论)
- TCI_PHOTO_PATH:教练员照片
- TCI_NAME:教练名称
- CRI_STARTTIME:开始时间
- CRI_ENDTIME:结束时间
-
- CRI_SECOND_AUDIT_RESULT --二次审核结果 0审核通过 1审核不通过 2待审核
- CRI_SECOND_AUDIT_REASON --二次审核结果原因
- CRI_AUDIT_USERNAME --二次审核人
- CRI_AUDIT_TIME --二次审核时间
- */
-
- NSDictionary *dic = self.datasourceArray[indexPath.row];
-
- //显示按钮
- TrainDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trainDetailCell"];
- if (cell == nil) {
- cell= [[[NSBundle mainBundle]loadNibNamed:@"TrainDetailCell" owner:nil options:nil] firstObject];
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- [cell updateWith:dic];
-
- if ([dic[@"PXKMTYPE"] isEqualToString:@"1"]) {
- [cell.orbitBtn addTarget:self action:@selector(lookOrbit:) forControlEvents:UIControlEventTouchUpInside];
- cell.orbitBtn.tag = indexPath.row *2 + 1;
- [cell.commentBtn target:self tag:indexPath.row *2];
- cell.commentBtn.width = 0;
- return cell;
-
- }else{
-
- [cell.orbitBtn removeFromSuperview];
- [cell.commentBtn removeFromSuperview];
-
- return cell;
- }
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (![self.type isEqualToString:@"1"]) {
- NSDictionary *dic = self.datasourceArray[indexPath.row];
- //PXKMTYPE:1实操 (2课堂教练==》服务器改为返回到4里面去了) 3模拟器教学 4远程教学(理论)+ (终端)理论
- //实操的带有评价
- if ([dic[@"PXKMTYPE"] isEqualToString:@"1"]) {
- return [TrainDetailCell heightForDic:self.datasourceArray[indexPath.row]];
- }else{
- return [TrainDetailCell heightForDic:self.datasourceArray[indexPath.row]] - 30;
- }
- }
-
- return 44;
- }
- - (void)lookOrbit:(UIButton *)sender {
- NSDictionary *dic = self.datasourceArray[(sender.tag - 1)/2];
- OrbitVC * orc = [[OrbitVC alloc]init];
- orc.orderId = dic[@"ID"];
- orc.type = @"2";
- [self navPushHideTabbarToVC:orc];
- }
- - (void)btnClick:(UIButton *)sender {
- NSDictionary *dic = self.datasourceArray[sender.tag/2];
- if (sender.selected == YES) {
-
- //查看学时评价
- NSMutableDictionary * xsDic = [NSMutableDictionary new];
- [xsDic setValue:dic[@"TCI_ID"] forKey:@"coachId"];
- [xsDic setValue:dic[@"CRI_CLASSID"] forKey:@"classId"];
- [xsDic setValue:dic[@"TCI_NAME"] forKey:@"coachName"];
-
- orderCommentVC *cmVC = [[orderCommentVC alloc]init];
- cmVC.type = 2;
- cmVC.dic = xsDic;
- [self navPushHideTabbarToVC:cmVC];
- }else{
- //进行学时评价
- NSMutableDictionary * xsDic = [NSMutableDictionary new];
- [xsDic setValue:dic[@"CRI_TRAIN_SUBJECT"] forKey:@"kmStr"];
- [xsDic setValue:dic[@"TCI_ID"] forKey:@"coachId"];
- [xsDic setValue:dic[@"CRI_CLASSID"] forKey:@"classId"];
- [xsDic setValue:dic[@"TCI_NAME"] forKey:@"coachName"];
-
- Evaluation * evc = [[Evaluation alloc]init];
- evc.xsDic = xsDic;
- evc.tvc = self;
- __block NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithDictionary:dic];
- __weak typeof(self) weakSelf = self;
- self.blcok = ^(){
- sender.selected = YES;
- [mDic setObject:@"1" forKey:@"CRI_STU_EVALUATE"];
- [weakSelf.datasourceArray replaceObjectAtIndex:sender.tag/2 withObject:mDic];
- };
-
- [self navPushHideTabbarToVC:evc];
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [UIView new];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return .1;
- }
- - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath*)indexPath {
- @weakify(self)
- //删除
- TrainRecord *train = (TrainRecord *)self.datasourceArray[indexPath.row];
- UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
- @strongify(self)
- [self.datasourceArray removeObject:train];
- [DB_Helper deleteTrain:train];
- [mainTable reloadData];
- }];
- UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:([self.type isEqualToString:@"1"] && defUser.isycbd == 1)? @[deleteRowAction] : @[]];
- return configuration;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|