// // TeachLogForCheckVC.m // LNManager // // Created by apple on 2017/6/23. // Copyright © 2017年 lee. All rights reserved. // #import "TeachLogForCheckVC.h" #import "TeachLogCell.h" #import "MinRescord.h" #import "MJRefresh.h" #import "TrainPhotoCell.h" #import "MJPhotoBrowser.h" #import "MJPhoto.h" @interface TeachLogForCheckVC () { UITableView *mainTableView; NSMutableArray *dataArray; NSInteger _currentPageNum;//记录页书 MyGetDataType _getDataType;//加载类型 BOOL _IS_LOADING;//正在加载的状态 UIButton *trainbtn; UIButton *photoBtn; UIView *photoView; HolderView *holderV1; UICollectionView *mainCollection; NSArray *photoArray; HolderView *holderV2; } @end @implementation TeachLogForCheckVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"阶段学时信息"; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, kNavOffSet + 10, kSize.width/2.0 - 30, 40)]; [btn setTitle:@"教学日志" textColor:COLOR_THEME font:FontTitle fotState:UIControlStateNormal]; [btn borderColor:COLOR_THEME width:1 cornorRadios:3]; [btn addTarget:self action:@selector(trainAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; trainbtn = btn; btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 10, kNavOffSet + 10, kSize.width/2.0 - 30, 40)]; [btn setTitle:@"训练照片" textColor:RGB_COLOR(136,136,136) font:FontTitle fotState:UIControlStateNormal]; [btn borderColor:RGB_COLOR(136,136,136) width:1 cornorRadios:3]; [btn addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; photoBtn = btn; UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(10, kNavOffSet + 60, kSize.width - 20, 1)]; line.backgroundColor = RGB_COLOR(136,136,136); [self.view addSubview:line]; //电子教学日志 _currentPageNum = 0; dataArray = [NSMutableArray array]; mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavOffSet + 61, kSize.width, kSize.height - kNavOffSet - 61) style:UITableViewStylePlain]; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.rowHeight = 145; [self.view addSubview:mainTableView]; // [self setRefreshAction];//设置刷新 不设置分页 holderV1 = [[HolderView alloc] initWithFrame:mainTableView.frame]; [holderV1 freshBlock:^{ _currentPageNum = 0; [self getTrainTimesRecords]; }]; [self.view addSubview:holderV1]; [self getTrainTimesRecords]; //训练照片 //添加一个图片轮播器在这里 设置在屏幕右边 photoView = [[UIView alloc] initWithFrame:mainTableView.frame]; photoView.x = kSize.width; photoView.backgroundColor = [UIColor redColor]; [self.view addSubview:photoView]; photoArray = [NSArray array]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; CGFloat width = (kSize.width - 30)/3.0; [layout setItemSize:CGSizeMake(width, width + 30)]; [layout setSectionInset:UIEdgeInsetsMake(10, 5, 5, 5)]; mainCollection = [[UICollectionView alloc] initWithFrame:photoView.bounds collectionViewLayout:layout]; mainCollection.backgroundColor = KBackGroundColor; mainCollection.delegate = self; mainCollection.dataSource = self; [photoView addSubview:mainCollection]; [mainCollection registerClass:[TrainPhotoCell class] forCellWithReuseIdentifier:@"TrainPhotoCell"]; holderV2 = [[HolderView alloc] initWithFrame:mainCollection.frame]; [holderV2 freshBlock:^{ [self getTrainTimesPhotos]; }]; [photoView addSubview:holderV2]; [self getTrainTimesPhotos]; } - (void)trainAction { [trainbtn setTitleColor:COLOR_THEME forState:UIControlStateNormal]; trainbtn.layer.borderColor = COLOR_THEME.CGColor; [photoBtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal]; photoBtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor; if (mainTableView.x != 0) { [UIView animateWithDuration:.4 animations:^{ mainTableView.x = 0; photoView.x = kSize.width; }]; } } - (void)photoAction { [trainbtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal]; trainbtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor; [photoBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal]; photoBtn.layer.borderColor = COLOR_THEME.CGColor; if (photoView.x != 0) { [UIView animateWithDuration:.4 animations:^{ mainTableView.x = -kSize.width; photoView.x = 0; }]; } } #pragma mark - 下拉刷新,上拉加载 - -(void)setRefreshAction{ // 下拉加载更多 __weak typeof(self) weakSelf = self; MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakSelf headerRefresh]; }]; mainTableView.mj_header = header; MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; mainTableView.mj_footer = footer; } -(void)headerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeHeaderRefresh; //加载数据 [self getTrainTimesRecords]; [mainTableView.mj_header endRefreshing]; } -(void)footerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeFooterRefresh; //加载数据 [self getTrainTimesRecords]; [mainTableView.mj_footer endRefreshing]; } #pragma mark tableview代理相关 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ TeachLogCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellTeach"]; if (!cell) { //加载xib文件创建cell cell = [[[NSBundle mainBundle] loadNibNamed:@"TeachLogCell" owner:nil options:nil] lastObject]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } [cell setDataWithDic:dataArray[indexPath.row]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //查看分钟学时&照片 轨迹延后做 int subject = [_checkDic[@"TTI_SUBJECT"] intValue]; if (subject != 2 && subject != 3) { return; } MinRescord * mvc = [[MinRescord alloc]init]; mvc.stuDic = dataArray[indexPath.row]; [self.navigationController pushViewController:mvc animated:YES]; } #pragma mark collection delegate -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return photoArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { TrainPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TrainPhotoCell" forIndexPath:indexPath]; NSDictionary *dic = photoArray[indexPath.row]; NSString *str = dic[@"FILEPATH"]; if (!str) { str = @""; } NSString *timeStr = dic[@"TIME"]; if (timeStr.length > 16) { timeStr = [timeStr substringWithRange:NSMakeRange(5, 11)]; } cell.dateLabel.text = timeStr; [cell.imageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"暂无图片"]]; cell.imageView.tag = indexPath.row; // 事件监听 [cell.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]]; return cell; } -(void)tapImage:(UITapGestureRecognizer *)tap { NSMutableArray *photos = [NSMutableArray arrayWithCapacity:photoArray.count]; for (int i = 0; i < photoArray.count; i ++) { NSDictionary *dic = photoArray[i]; NSString *url = dic[@"FILEPATH"]; NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet]; NSString *str = [url stringByTrimmingCharactersInSet:whitespace]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0]; TrainPhotoCell *cell = (TrainPhotoCell *)[mainCollection cellForItemAtIndexPath:indexPath]; MJPhoto *photo = [[MJPhoto alloc] init]; photo.url = [NSURL URLWithString:str]; // 图片路径 photo.srcImageView = cell.imageView; // 来源于哪个UIImageView [photos addObject:photo]; } // 2.显示相册 MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init]; browser.currentPhotoIndex = tap.view.tag; // 弹出相册时显示的第一张图片是? browser.photos = photos; // 设置所有的图片 [browser show]; } #pragma mark 请求数据 -(void)getTrainTimesRecords{ //判断当前是否正在加载数据。如果正在加载数据,直接return。 if (_IS_LOADING) { return; } _IS_LOADING=YES; //获取第一页数据 NSInteger needLoadPage; needLoadPage=_currentPageNum+1; if (_getDataType==MyGetDataTypeHeaderRefresh) { needLoadPage=1; } NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:@"" forKey:@"dqbh"]; [mdic setValue:@"" forKey:@"qxbh"]; [mdic setValue:@"" forKey:@"inscode"]; [mdic setValue:_checkDic[@"TSO_STUNUM"] forKey:@"stunum"]; [mdic setValue:_checkDic[@"STUNAME"] forKey:@"studentName"]; [mdic setValue:_checkDic[@"TTI_SUBJECT"] forKey:@"subject"]; [mdic setValue:@"" forKey:@"idcard"]; [mdic setValue:@"" forKey:@"isPage"]; [mdic setValue:@"" forKey:@"pageSize"]; [mdic setValue:@"" forKey:@"currentPage"]; //判断网络是否连接 if (![NetworkManager connectedToNetWork]) { [self showMsgByAlertVCWithString:@"网络连接异常"]; return; } [MBProgressHUD hideHUDForView:self.view animated:NO]; [MBProgressHUD showHUDAddedTo:self.view animated:NO]; [NetworkManager requestWithMethod:@"trainTimesRecords" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) { _IS_LOADING=NO; holderV1.hidden = NO; [MBProgressHUD hideHUDForView:self.view animated:YES]; if (failureStr) { [self showMsgByAlertVCWithString:failureStr]; return; } if ([successDic[@"code"] isEqualToString:@"1"]) { [self showMsgByAlertVCWithString:successDic[@"msg"]]; return; } if (_getDataType==MyGetDataTypeHeaderRefresh){ [dataArray removeAllObjects]; } //追加数据 [dataArray addObjectsFromArray:successDic[@"body"]]; if (dataArray.count != 0) { holderV1.hidden = YES; } _currentPageNum=needLoadPage; [mainTableView reloadData]; _getDataType=MyGetDataTypeNomal; }]; } - (void)getTrainTimesPhotos { NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:_checkDic[@"ID"] forKey:@"stunum"]; [mdic setValue:_checkDic[@"TTI_SUBJECT"] forKey:@"subject"]; //判断网络是否连接 if (![NetworkManager connectedToNetWork]) { [self showMsgByAlertVCWithString:@"网络连接异常"]; return; } [MBProgressHUD hideHUDForView:self.view animated:NO]; [MBProgressHUD showHUDAddedTo:self.view animated:NO]; [NetworkManager requestWithMethod:@"trainTimesPhotos" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) { holderV2.hidden = NO; [MBProgressHUD hideHUDForView:self.view animated:YES]; if (failureStr) { [self showMsgByAlertVCWithString:failureStr]; return; } if ([successDic[@"code"] isEqualToString:@"1"]) { [self showMsgByAlertVCWithString:successDic[@"msg"]]; return; } photoArray = successDic[@"body"]; if (photoArray.count != 0) { holderV2.hidden = YES; } [mainCollection reloadData]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end