218 lines
6.7 KiB
Objective-C
218 lines
6.7 KiB
Objective-C
//
|
|
// GiMaskTimeHistoryVC.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/9/3.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "GiMaskTimeHistoryVC.h"
|
|
#import "MaskHistoryListViewCell.h"
|
|
#import "MasHistoryFirstViewCell.h"
|
|
#import "GiGaBaseAPiRequest.h"
|
|
#import "MaskHistryRecord.h"
|
|
#import <MJRefresh/MJRefresh.h>
|
|
#import "GiGaWebViewController.h"
|
|
@interface GiMaskTimeHistoryVC ()<UITableViewDelegate,UITableViewDataSource>
|
|
|
|
@property(nonatomic,strong) NSMutableArray *dataArr;
|
|
@property(nonatomic) NSUInteger currentPage;
|
|
@property(nonatomic,assign) NSInteger totalMinute;
|
|
@property(nonatomic,assign) NSInteger ranking;
|
|
@property(nonatomic,assign) NSUInteger totalPage;
|
|
//@property(nonatomic,strong) MaskHistryRecordlist *record;
|
|
@property(nonatomic,copy) NSString * guizeUrl;
|
|
@property(nonatomic) BOOL isFreshing;
|
|
|
|
|
|
@end
|
|
|
|
@implementation GiMaskTimeHistoryVC
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.dataArr = [[NSMutableArray alloc] init];
|
|
_currentPage = 1;
|
|
_totalMinute = 0;
|
|
_ranking = 0;
|
|
_isFreshing = NO;
|
|
[self addNavTitile:@"历史记录"];
|
|
// Do any additional setup after loading the view.
|
|
[self.view addSubview:self.tableView];
|
|
self.tableView.delegate = self;
|
|
self.tableView.dataSource = self;
|
|
self.tableView.backgroundColor = [UIColor whiteColor];
|
|
self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
|
|
self.tableView.sectionFooterHeight = 0;
|
|
self.tableView.estimatedSectionFooterHeight= 0;
|
|
self.tableView.estimatedSectionHeaderHeight = 0;
|
|
self.tableView.frame = CGRectMake(0,2, KMainW, self.view.bounds.size.height - SAFE_NAV_HEIGHT);
|
|
self.tableView.estimatedRowHeight = 170;
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
|
[self creatRefreshView];
|
|
[self loadDataWtih:[NSString stringWithFormat:@"%ld",_currentPage] isFresh:YES];
|
|
}
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
|
return 2;
|
|
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
if(indexPath.section ==0){
|
|
MasHistoryFirstViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MasHistoryFirstViewCell"];
|
|
if(!cell){
|
|
cell = [[[NSBundle mainBundle] loadNibNamed:@"MasHistoryFirstViewCell" owner:self options:nil] lastObject];
|
|
|
|
}
|
|
cell.timeLabe.text = [NSString stringWithFormat:@"%ld",(long)self.totalMinute];
|
|
|
|
cell.rankLabe.text = [NSString stringWithFormat:@"全国排行榜第%ld名",(long)self.ranking];
|
|
[cell.guizeBtn addTarget:self action:@selector(guizeShow) forControlEvents:UIControlEventTouchUpInside];
|
|
return cell;
|
|
}
|
|
|
|
MaskHistoryListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MaskHistoryListViewCell"];
|
|
if(!cell){
|
|
cell = [[[NSBundle mainBundle] loadNibNamed:@"MaskHistoryListViewCell" owner:self options:nil] lastObject];
|
|
|
|
}
|
|
MaskHistryRecord *recod = self.dataArr[indexPath.row];
|
|
[cell loadCellDataAt:indexPath recod:recod];
|
|
return cell;
|
|
}
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
if (section == 0) {
|
|
return 1;
|
|
}
|
|
return self.dataArr.count;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
return UITableViewAutomaticDimension;
|
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
|
if (section == 1) {
|
|
return 6;
|
|
}
|
|
return 0.1;
|
|
}
|
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
|
UIView *view = [[UIView alloc] init];
|
|
view.backgroundColor = GIGARGB(235, 235, 235, 1);
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
-(void)loadDataWtih:(NSString *)page isFresh:(BOOL)isFresh{
|
|
self.isFreshing = YES;
|
|
[self.view makeToastActivity:CSToastPositionCenter];
|
|
GiGaBaseAPiRequest *api = [GiGaBaseAPiRequest initWithRequestPath:kApiUserHistoryList method:RequestPostMethod parms:@{@"page":page,@"limit":@"10"}];
|
|
[api requstDataWithResult:^(GiGaAPIResult *result) {
|
|
[self.view hideToastActivity];
|
|
self.isFreshing = NO;
|
|
if (isFresh) {
|
|
[self.tableView.mj_header endRefreshing];
|
|
}else{
|
|
[self.tableView.mj_footer endRefreshing];
|
|
}
|
|
if (result.success) {
|
|
NSDictionary *reDic =result.dic;
|
|
|
|
self.ranking = [[reDic valueForKey:@"ranking"] integerValue];
|
|
self.totalMinute = [[reDic valueForKey:@"totalMinute"] integerValue] ;
|
|
self.guizeUrl = [reDic valueForKey:@"ruleUrl"];
|
|
|
|
|
|
NSDictionary *pageDic = reDic[@"page"];
|
|
|
|
//self.currentPage = [pageDic valueForKey:@"currPage"];
|
|
|
|
MaskHistryRecordlist *list = [[MaskHistryRecordlist alloc] initWithDictionary:pageDic error:nil];
|
|
|
|
self.totalPage = [pageDic[@"totalPage"] integerValue];
|
|
NSArray *listA = list.list;
|
|
if (isFresh) {
|
|
[self.dataArr removeAllObjects];
|
|
}
|
|
for (MaskHistryRecord *recod in listA) {
|
|
[self.dataArr addObject:recod];
|
|
}
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}else if (result.code == 401) {
|
|
//token失效
|
|
[GiGaBaseAPiRequest userTokenTimeOutGologinFromVC:self];
|
|
}else{
|
|
GIGA_ShowToast(result.message);
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
-(void)creatRefreshView{
|
|
|
|
self.tableView.mj_header = [MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
|
|
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
|
|
|
|
}
|
|
|
|
-(void)headerRefresh{
|
|
if (_isFreshing) {
|
|
[self.tableView.mj_header endRefreshing];
|
|
return;
|
|
}
|
|
|
|
[self loadDataWtih:@"0" isFresh:YES];
|
|
|
|
}
|
|
|
|
-(void)loadMore{
|
|
|
|
if (_isFreshing) {
|
|
[self.tableView.mj_footer endRefreshing];
|
|
return;
|
|
}
|
|
|
|
if (_currentPage == _totalPage) {
|
|
[self.tableView.mj_footer endRefreshingWithNoMoreData];
|
|
return;
|
|
}
|
|
|
|
|
|
if (_currentPage < _totalPage) {
|
|
_currentPage ++;
|
|
[self loadDataWtih:[NSString stringWithFormat:@"%ld",self.currentPage] isFresh:NO];
|
|
}
|
|
|
|
}
|
|
|
|
//规则
|
|
-(void)guizeShow{
|
|
|
|
if (self.guizeUrl) {
|
|
|
|
GiGaWebViewController *web = [[GiGaWebViewController alloc] init];
|
|
web.souceType = WebSourceTypeUrlLink;
|
|
web.url = self.guizeUrl;
|
|
[self.navigationController pushViewController:web animated:YES];
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@end
|