123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- //
- // RecordVC_New.m
- // jiaPei
- //
- // Created by EchoShacolee on 2018/3/26.
- // Copyright © 2018年 JCZ. All rights reserved.
- //
- #import "RecordVC_New.h"
- #import "HolderView.h"
- #import "RecordCell_New.h"
- #import "NSArray+ex.h"
- #import <MJRefresh.h>
- typedef NS_ENUM(NSInteger, MyGetDataType) {
- //正常请求数据
- MyGetDataTypeNomal=0,
- //下拉刷新请求数据
- MyGetDataTypeHeaderRefresh,
- //上拉加载更多请求数据
- MyGetDataTypeFooterRefresh
- };
- @interface RecordVC_New ()
- {
- HolderView *holderV;
- NSArray *teachTypes;
- NSMutableArray *rArray;
-
- NSInteger currentPage;
- MyGetDataType _getDataType;//加载类型
- BOOL _IS_LOADING;//正在加载的状态
- }
- @end
- @implementation RecordVC_New
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = @"培训记录";
- self.tableView.backgroundColor = backGroundColor;
- self.tableView.tableFooterView = [UIView new];
- [self configNavigationBar];
-
- holderV = [[HolderView alloc] initWithFrame:self.tableView.bounds];
- [self.view addSubview:holderV];
-
- currentPage = 1;
- _IS_LOADING = NO;
- _getDataType = MyGetDataTypeNomal;
- rArray = [NSMutableArray new];
- teachTypes = [NSArray array];
-
- [self getTeachTypes];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - 下拉刷新,上拉加载 -
- -(void)setRefreshAction{
- // 下拉加载更多
- __weak typeof(self) weakSelf = self;
- MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf headerRefresh];
- }];
- self.tableView.mj_header = header;
-
- MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
-
- self.tableView.mj_footer = footer;
-
- }
- -(void)headerRefresh{
-
- //设置获取数据的方式
- _getDataType=MyGetDataTypeHeaderRefresh;
- //加载数据
- [self getMyTeachLogs];
- [self.tableView.mj_header endRefreshing];
- }
- -(void)footerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeFooterRefresh;
- //加载数据
- [self getMyTeachLogs];
- [self.tableView.mj_footer endRefreshing];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return rArray.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- RecordCell_New *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseId"];
- if (!cell) {
- cell = [[[NSBundle mainBundle]loadNibNamed:@"RecordCell_New" owner:nil options:nil] lastObject];
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- }
-
- NSDictionary *dic = rArray[indexPath.row];
- NSString *teachStyle;
- if (teachTypes.count != 0) {
- teachStyle = [teachTypes h_safeObjectAtIndex:[dic[@"TL_TEACH_ID"] integerValue] - 1];
- }
-
- NSString *remarkS = [NSString stringWithFormat:@"%d、[%@]",(int)indexPath.row + 1,teachStyle];
- NSMutableAttributedString * aString = [[NSMutableAttributedString alloc] initWithString:remarkS];
-
- [aString addAttribute:NSForegroundColorAttributeName
- value:[UIColor orangeColor]
- range:NSMakeRange(2, 1)];
- [aString addAttribute:NSForegroundColorAttributeName
- value:[UIColor orangeColor]
- range:NSMakeRange(remarkS.length - 1, 1)];
- cell.titleLab.attributedText = aString;
-
- NSString *km = [dic[@"TL_SUBJECT"] isEqualToString:@"2"]?@"科二":@"科三";
- cell.subjectLab.text = km;
-
- NSString *dateString = dic[@"TL_CRDATE"];
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
- [formatter setDateFormat:@"yyyy-MM-dd"];
- NSDate *cDate = [formatter dateFromString:dateString];
- [formatter setDateFormat:@"MM.dd.yyyy"];
- dateString = [formatter stringFromDate:cDate];
- cell.timeLab.text = dateString;
-
- cell.contentLab.text = @"";
- if ([dic[@"TL_REMARK"] length] > 0) {
- cell.contentLab.text = [NSString stringWithFormat:@"备注: %@",dic[@"TL_REMARK"]];
- }
-
- if (cell.contentLab.text.length > 0) {
-
- NSString *remarkString = cell.contentLab.text;
- NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:remarkString];
-
- [aAttributedString addAttribute:NSForegroundColorAttributeName
- value:[UIColor orangeColor]
- range:NSMakeRange(0, 3)];
- [aAttributedString addAttribute:NSForegroundColorAttributeName
- value:contentTextColor
- range:NSMakeRange(3, remarkString.length - 3)];
- cell.contentLab.attributedText = aAttributedString;
- }
- return cell;
-
- }
- #pragma mark - 网络请求
- -(void)getTeachTypes
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
-
- [arr addPro:@"subject" Value:@""];
- [arr addPro:@"type" Value:@"1"];
-
- NSString* method = @"getTeachTypes";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- //NSLog(@"类型---->%@----->%@",arr,root);
-
- if (!root) {
- [LoadingView showMsg:@"请求失败"];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- [LoadingView showMsg:root[@"body"]];
- return;
- }
-
- NSMutableArray *types = [NSMutableArray array];
- for (NSDictionary *dic in root[@"body"]) {
-
- [types addObject:dic[@"TC_TEACH_TYPE"]];
- }
- teachTypes = [NSArray arrayWithArray:types];
-
- [self getMyTeachLogs];
- }];
-
- }
- -(void)getMyTeachLogs
- {
- //判断当前是否正在加载数据。如果正在加载数据,直接return。
- if (_IS_LOADING) {
- return;
- }
- _IS_LOADING=YES;
-
- if (_getDataType==MyGetDataTypeHeaderRefresh) {
- currentPage = 1;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"queryValue" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
-
- NSString* method = @"getMyTeachLogs";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- _IS_LOADING=NO;
- [MBProgressHUD hideHUDForView:self.view];
- holderV.hidden = NO;
-
- if (!root) {
- [LoadingView showMsg:@"操作失败"];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- [LoadingView showMsg:root[@"body"]];
- return;
- }
-
- if (currentPage == 1) {
- rArray = [NSMutableArray arrayWithArray:root[@"body"]];
- }else{
- [rArray addObjectsFromArray:root[@"body"]];
- }
-
- if (rArray.count != 0) {
- [holderV setHidden:YES];
- }
-
- if ([root[@"body"] count] == 0) {
- ShowMsg(@"已加载全部数据");
- return;
- }else{
- currentPage += 1;
- }
-
- [self.tableView reloadData];
- }];
-
- }
- @end
|