TeachLogForCheckVC.m 13 KB

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