TeachLogForCheckVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. //
  2. // TeachLogForCheckVC.m
  3. // LNManager
  4. //
  5. // Created by apple on 2017/6/23.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "TeachLogForCheckVC.h"
  9. #import "TeachLogCell.h"
  10. #import "MinRescord.h"
  11. #import "MJRefresh.h"
  12. #import "TrainPhotoCell.h"
  13. #import "MJPhotoBrowser.h"
  14. #import "MJPhoto.h"
  15. @interface TeachLogForCheckVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
  16. {
  17. UITableView *mainTableView;
  18. NSMutableArray *dataArray;
  19. NSInteger _currentPageNum;//记录页书
  20. MyGetDataType _getDataType;//加载类型
  21. BOOL _IS_LOADING;//正在加载的状态
  22. UIButton *trainbtn;
  23. UIButton *photoBtn;
  24. UIView *photoView;
  25. HolderView *holderV1;
  26. UICollectionView *mainCollection;
  27. NSArray *photoArray;
  28. HolderView *holderV2;
  29. }
  30. @end
  31. @implementation TeachLogForCheckVC
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.navigationItem.title = @"阶段学时信息";
  35. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, kNavOffSet + 10, kSize.width/2.0 - 30, 40)];
  36. [btn setTitle:@"教学日志" textColor:COLOR_THEME font:FontTitle fotState:UIControlStateNormal];
  37. [btn borderColor:COLOR_THEME width:1 cornorRadios:3];
  38. [btn addTarget:self action:@selector(trainAction) forControlEvents:UIControlEventTouchUpInside];
  39. [self.view addSubview:btn];
  40. trainbtn = btn;
  41. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 10, kNavOffSet + 10, kSize.width/2.0 - 30, 40)];
  42. [btn setTitle:@"训练照片" textColor:RGB_COLOR(136,136,136) font:FontTitle fotState:UIControlStateNormal];
  43. [btn borderColor:RGB_COLOR(136,136,136) width:1 cornorRadios:3];
  44. [btn addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside];
  45. [self.view addSubview:btn];
  46. photoBtn = btn;
  47. UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(10, kNavOffSet + 60, kSize.width - 20, 1)];
  48. line.backgroundColor = RGB_COLOR(136,136,136);
  49. [self.view addSubview:line];
  50. //电子教学日志
  51. _currentPageNum = 0;
  52. dataArray = [NSMutableArray array];
  53. mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavOffSet + 61, kSize.width, kSize.height - kNavOffSet - 61) style:UITableViewStylePlain];
  54. mainTableView.delegate = self;
  55. mainTableView.dataSource = self;
  56. mainTableView.rowHeight = 145;
  57. [self.view addSubview:mainTableView];
  58. // [self setRefreshAction];//设置刷新 不设置分页
  59. holderV1 = [[HolderView alloc] initWithFrame:mainTableView.frame];
  60. [holderV1 freshBlock:^{
  61. _currentPageNum = 0;
  62. [self getTrainTimesRecords];
  63. }];
  64. [self.view addSubview:holderV1];
  65. [self getTrainTimesRecords];
  66. //训练照片
  67. //添加一个图片轮播器在这里 设置在屏幕右边
  68. photoView = [[UIView alloc] initWithFrame:mainTableView.frame];
  69. photoView.x = kSize.width;
  70. photoView.backgroundColor = [UIColor redColor];
  71. [self.view addSubview:photoView];
  72. photoArray = [NSArray array];
  73. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  74. CGFloat width = (kSize.width - 30)/3.0;
  75. [layout setItemSize:CGSizeMake(width, width + 30)];
  76. [layout setSectionInset:UIEdgeInsetsMake(10, 5, 5, 5)];
  77. mainCollection = [[UICollectionView alloc] initWithFrame:photoView.bounds collectionViewLayout:layout];
  78. mainCollection.backgroundColor = KBackGroundColor;
  79. mainCollection.delegate = self;
  80. mainCollection.dataSource = self;
  81. [photoView addSubview:mainCollection];
  82. [mainCollection registerClass:[TrainPhotoCell class] forCellWithReuseIdentifier:@"TrainPhotoCell"];
  83. holderV2 = [[HolderView alloc] initWithFrame:mainCollection.frame];
  84. [holderV2 freshBlock:^{
  85. [self getTrainTimesPhotos];
  86. }];
  87. [photoView addSubview:holderV2];
  88. [self getTrainTimesPhotos];
  89. }
  90. - (void)trainAction {
  91. [trainbtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  92. trainbtn.layer.borderColor = COLOR_THEME.CGColor;
  93. [photoBtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal];
  94. photoBtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor;
  95. if (mainTableView.x != 0) {
  96. [UIView animateWithDuration:.4 animations:^{
  97. mainTableView.x = 0;
  98. photoView.x = kSize.width;
  99. }];
  100. }
  101. }
  102. - (void)photoAction {
  103. [trainbtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal];
  104. trainbtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor;
  105. [photoBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  106. photoBtn.layer.borderColor = COLOR_THEME.CGColor;
  107. if (photoView.x != 0) {
  108. [UIView animateWithDuration:.4 animations:^{
  109. mainTableView.x = -kSize.width;
  110. photoView.x = 0;
  111. }];
  112. }
  113. }
  114. #pragma mark - 下拉刷新,上拉加载 -
  115. -(void)setRefreshAction{
  116. // 下拉加载更多
  117. __weak typeof(self) weakSelf = self;
  118. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  119. [weakSelf headerRefresh];
  120. }];
  121. mainTableView.mj_header = header;
  122. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  123. [weakSelf footerRefresh];
  124. }];
  125. mainTableView.mj_footer = footer;
  126. }
  127. -(void)headerRefresh{
  128. //设置获取数据的方式
  129. _getDataType=MyGetDataTypeHeaderRefresh;
  130. //加载数据
  131. [self getTrainTimesRecords];
  132. [mainTableView.mj_header endRefreshing];
  133. }
  134. -(void)footerRefresh{
  135. //设置获取数据的方式
  136. _getDataType=MyGetDataTypeFooterRefresh;
  137. //加载数据
  138. [self getTrainTimesRecords];
  139. [mainTableView.mj_footer endRefreshing];
  140. }
  141. #pragma mark tableview代理相关
  142. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  143. return dataArray.count;
  144. }
  145. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  146. TeachLogCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellTeach"];
  147. if (!cell) {
  148. //加载xib文件创建cell
  149. cell = [[[NSBundle mainBundle] loadNibNamed:@"TeachLogCell" owner:nil options:nil] lastObject];
  150. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  151. }
  152. [cell setDataWithDic:dataArray[indexPath.row]];
  153. return cell;
  154. }
  155. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  156. //查看分钟学时&照片 轨迹延后做
  157. int subject = [_checkDic[@"TTI_SUBJECT"] intValue];
  158. if (subject != 2 && subject != 3) {
  159. return;
  160. }
  161. MinRescord * mvc = [[MinRescord alloc]init];
  162. mvc.stuDic = dataArray[indexPath.row];
  163. [self.navigationController pushViewController:mvc animated:YES];
  164. }
  165. #pragma mark collection delegate
  166. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  167. {
  168. return photoArray.count;
  169. }
  170. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  171. {
  172. TrainPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TrainPhotoCell" forIndexPath:indexPath];
  173. NSDictionary *dic = photoArray[indexPath.row];
  174. NSString *str = dic[@"FILEPATH"];
  175. if (!str) {
  176. str = @"";
  177. }
  178. NSString *timeStr = dic[@"TIME"];
  179. if (timeStr.length > 16) {
  180. timeStr = [timeStr substringWithRange:NSMakeRange(5, 11)];
  181. }
  182. cell.dateLabel.text = timeStr;
  183. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"暂无图片"]];
  184. cell.imageView.tag = indexPath.row;
  185. // 事件监听
  186. [cell.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]];
  187. return cell;
  188. }
  189. -(void)tapImage:(UITapGestureRecognizer *)tap
  190. {
  191. NSMutableArray *photos = [NSMutableArray arrayWithCapacity:photoArray.count];
  192. for (int i = 0; i < photoArray.count; i ++) {
  193. NSDictionary *dic = photoArray[i];
  194. NSString *url = dic[@"FILEPATH"];
  195. NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
  196. NSString *str = [url stringByTrimmingCharactersInSet:whitespace];
  197. NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
  198. TrainPhotoCell *cell = (TrainPhotoCell *)[mainCollection cellForItemAtIndexPath:indexPath];
  199. MJPhoto *photo = [[MJPhoto alloc] init];
  200. photo.url = [NSURL URLWithString:str]; // 图片路径
  201. photo.srcImageView = cell.imageView; // 来源于哪个UIImageView
  202. [photos addObject:photo];
  203. }
  204. // 2.显示相册
  205. MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
  206. browser.currentPhotoIndex = tap.view.tag; // 弹出相册时显示的第一张图片是?
  207. browser.photos = photos; // 设置所有的图片
  208. [browser show];
  209. }
  210. #pragma mark 请求数据
  211. -(void)getTrainTimesRecords{
  212. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  213. if (_IS_LOADING) {
  214. return;
  215. }
  216. _IS_LOADING=YES;
  217. //获取第一页数据
  218. NSInteger needLoadPage;
  219. needLoadPage=_currentPageNum+1;
  220. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  221. needLoadPage=1;
  222. }
  223. NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init];
  224. [mdic setValue:@"" forKey:@"dqbh"];
  225. [mdic setValue:@"" forKey:@"qxbh"];
  226. [mdic setValue:@"" forKey:@"inscode"];
  227. [mdic setValue:_checkDic[@"TSO_STUNUM"] forKey:@"stunum"];
  228. [mdic setValue:_checkDic[@"STUNAME"] forKey:@"studentName"];
  229. [mdic setValue:_checkDic[@"TTI_SUBJECT"] forKey:@"subject"];
  230. [mdic setValue:@"" forKey:@"idcard"];
  231. [mdic setValue:@"" forKey:@"isPage"];
  232. [mdic setValue:@"" forKey:@"pageSize"];
  233. [mdic setValue:@"" forKey:@"currentPage"];
  234. //判断网络是否连接
  235. if (![NetworkManager connectedToNetWork]) {
  236. [self showMsgByAlertVCWithString:@"网络连接异常"];
  237. return;
  238. }
  239. [MBProgressHUD hideHUDForView:self.view animated:NO];
  240. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  241. [NetworkManager requestWithMethod:@"trainTimesRecords" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  242. _IS_LOADING=NO;
  243. holderV1.hidden = NO;
  244. [MBProgressHUD hideHUDForView:self.view animated:YES];
  245. if (failureStr) {
  246. [self showMsgByAlertVCWithString:failureStr];
  247. return;
  248. }
  249. if ([successDic[@"code"] isEqualToString:@"1"]) {
  250. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  251. return;
  252. }
  253. if (_getDataType==MyGetDataTypeHeaderRefresh){
  254. [dataArray removeAllObjects];
  255. }
  256. //追加数据
  257. [dataArray addObjectsFromArray:successDic[@"body"]];
  258. if (dataArray.count != 0) {
  259. holderV1.hidden = YES;
  260. }
  261. _currentPageNum=needLoadPage;
  262. [mainTableView reloadData];
  263. _getDataType=MyGetDataTypeNomal;
  264. }];
  265. }
  266. - (void)getTrainTimesPhotos {
  267. NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init];
  268. [mdic setValue:_checkDic[@"ID"] forKey:@"stunum"];
  269. [mdic setValue:_checkDic[@"TTI_SUBJECT"] forKey:@"subject"];
  270. //判断网络是否连接
  271. if (![NetworkManager connectedToNetWork]) {
  272. [self showMsgByAlertVCWithString:@"网络连接异常"];
  273. return;
  274. }
  275. [MBProgressHUD hideHUDForView:self.view animated:NO];
  276. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  277. [NetworkManager requestWithMethod:@"trainTimesPhotos" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  278. holderV2.hidden = NO;
  279. [MBProgressHUD hideHUDForView:self.view animated:YES];
  280. if (failureStr) {
  281. [self showMsgByAlertVCWithString:failureStr];
  282. return;
  283. }
  284. if ([successDic[@"code"] isEqualToString:@"1"]) {
  285. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  286. return;
  287. }
  288. photoArray = successDic[@"body"];
  289. if (photoArray.count != 0) {
  290. holderV2.hidden = YES;
  291. }
  292. [mainCollection reloadData];
  293. }];
  294. }
  295. - (void)didReceiveMemoryWarning {
  296. [super didReceiveMemoryWarning];
  297. // Dispose of any resources that can be recreated.
  298. }
  299. @end