123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- //
- // TeachLogsVC.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/6/14.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "TeachLogsVC.h"
- #import "TeachLogCell.h"
- #import "MinRescord.h"
- #import "MJRefresh.h"
- @interface TeachLogsVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- UITableView *mainTableView;
- NSMutableArray *dataArray;
- int subject;
- int currentPage;
- MyGetDataType _getDataType;//加载类型
- BOOL _IS_LOADING;//正在加载的状态
-
- UISegmentedControl *_segementCtr;
- }
- @property (nonatomic,strong)HolderView *holderV;
- @end
- @implementation TeachLogsVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title = @"教学日志";
-
- [self myInit];
- }
- -(void)myInit{
-
- //四个分类列表的处理
- NSArray *items = @[@"科一",@"科二",@"科三",@"科四"];
- _segementCtr = [[UISegmentedControl alloc] initWithItems:items];
- _segementCtr.frame = CGRectMake(0, kNavOffSet, kSize.width, 40);
- _segementCtr.backgroundColor = [UIColor whiteColor];
- _segementCtr.tintColor = COLOR_THEME;
- _segementCtr.selectedSegmentIndex = 1;
- [_segementCtr addTarget:self action:@selector(changeSubject) forControlEvents:UIControlEventValueChanged];
- [self.view addSubview:_segementCtr];
- //默认显示科目二信息
- subject = 2;
- currentPage = 1;
- dataArray = [NSMutableArray array];
-
- mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavOffSet + 40, kSize.width, kSize.height - kNavOffSet - 40 - SafeAreaBottomHeight) style:UITableViewStylePlain];
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.rowHeight = 145;
- mainTableView.tableFooterView = [UIView new];
-
- [self.view addSubview:mainTableView];
-
- self.holderV = [[HolderView alloc] initWithFrame:mainTableView.frame];
- [self.holderV freshBlock:^{
- [self headerRefresh];
- }];
- [self.view addSubview:self.holderV];
-
- [self setRefreshAction];//设置刷新
- [self getTrainTimesRecords];
- }
- - (void)changeSubject {
-
- currentPage = 1;
- subject = (int)_segementCtr.selectedSegmentIndex + 1;
- [self getTrainTimesRecords];
- }
- #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{
-
- if (subject != 2 && subject != 3) {
- return;
- }
- //查看分钟学时&照片 轨迹延后做
- MinRescord * mvc = [[MinRescord alloc]init];
- mvc.stuDic = dataArray[indexPath.row];
- [self.navigationController pushViewController:mvc animated:YES];
- }
- #pragma mark 请求数据
- -(void)getTrainTimesRecords{
-
- //判断当前是否正在加载数据。如果正在加载数据,直接return。
- if (_IS_LOADING) {
- return;
- }
- _IS_LOADING=YES;
-
- if (_getDataType==MyGetDataTypeHeaderRefresh) {
- currentPage = 1;
- }
-
- NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init];
- [mdic setValue:[NSString stringWithFormat:@"%@",_schDic[@"TSI_DQBH"]] forKey:@"dqbh"];
- [mdic setValue:[NSString stringWithFormat:@"%@",_schDic[@"TSI_QXBH"]] forKey:@"qxbh"];
- [mdic setValue:[NSString stringWithFormat:@"%@",_schDic[@"TSI_INSCODE"]] forKey:@"inscode"];
- [mdic setValue:@"" forKey:@"stunum"];
- [mdic setValue:@"" forKey:@"studentName"];
- [mdic setValue:[NSString stringWithFormat:@"%d",subject] forKey:@"subject"];
- [mdic setValue:@"" forKey:@"idcard"];
- [mdic setValue:@"1" forKey:@"isPage"];
- [mdic setValue:@"10" forKey:@"pageSize"];
- [mdic setValue:[NSString stringWithFormat:@"%d",currentPage] 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;
- _holderV.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 (currentPage == 1) {
- //如果是首页 就要删除之前的数据
- [dataArray removeAllObjects];
- }
-
- [dataArray addObjectsFromArray:successDic[@"body"]];
-
- if ([successDic[@"body"] count] > 0) {
- currentPage++;
- }
-
- if ([dataArray count] > 0) {
- _holderV.hidden = YES;
- }else {
- if (currentPage == 1) {
- _holderV.hidden = NO;
- }
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [mainTableView reloadData];
- });
-
- _getDataType=MyGetDataTypeNomal;
-
- }];
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|