Files
yinmeng-ios/xplan-ios/Main/Mine/View/XPMineFootPrintViewController.m
2022-08-03 17:01:17 +08:00

221 lines
7.2 KiB
Objective-C

//
// XPMineFootPrintViewController.m
// xplan-ios
//
// Created by GreenLand on 2022/7/26.
//
#import "XPMineFootPrintViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
///Model
#import "XPMineFootPrintModel.h"
///View
#import "XPMineFootPrintTableViewCell.h"
#import "XPMineVisitorEmptyTableViewCell.h"
#import "XPFootPrintNavView.h"
///P
#import "XPMineFootPrintPresenter.h"
#import "XPMineFootPrintProtocol.h"
///VC
#import "XPRoomViewController.h"
@interface XPMineFootPrintViewController()<UITableViewDelegate,UITableViewDataSource, XPMineFootPrintProtocol, XPFootPrintNavViewDelegate>
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSMutableArray *datasource;
///当前页数
@property (nonatomic,assign) int page;
///更多数据
@property (nonatomic,assign) BOOL hasNoMoreData;
@property (nonatomic, strong) XPFootPrintNavView *navView;
@end
@implementation XPMineFootPrintViewController
- (XPMineFootPrintPresenter *)createPresenter {
return [[XPMineFootPrintPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderAndFooterRrfresh];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - 下拉刷新
- (void)initHeaderAndFooterRrfresh {
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
header.stateLabel.textColor = [ThemeColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [ThemeColor secondTextColor];
self.tableView.mj_header = header;
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
footer.stateLabel.textColor = [ThemeColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.tableView.mj_footer = footer;
[self headerRefresh];
}
#pragma mark - 刷新的fangfa
- (void)headerRefresh {
self.page = 1;
[self.presenter getFootPrintListWithPage:self.page pageSize:20 state:0];
}
- (void)footerRefresh {
if (self.hasNoMoreData) {
[self showErrorToast:@"没有更多进房记录了"];
return;
}
self.page++;
[self.presenter getFootPrintListWithPage:self.page pageSize:20 state:1];
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.navView];
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.view);
make.top.mas_equalTo(self.navView.mas_bottom);
}];
}
#pragma mark - XPMineFootPrintProtocol
- (void)getFootPrintListSuccess:(NSArray *)array state:(int)state {
if (state == 0) {
[self.datasource removeAllObjects];
[self.tableView.mj_header endRefreshing];
}
[self.tableView.mj_footer endRefreshing];
if (array.count > 0) {
self.hasNoMoreData = NO;
[self.datasource addObjectsFromArray:array];
} else {
self.hasNoMoreData = YES;
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
[self.tableView reloadData];
}
- (void)getFootPrintListFail:(int)state {
if (state == 0) {
[self.tableView.mj_header endRefreshing];
} else {
[self.tableView.mj_footer endRefreshing];
}
}
///清除进房记录成功
- (void)cleanFootPrintSuccess {
[self headerRefresh];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource.count > 0 ? self.datasource.count : 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count > 0) {
XPMineFootPrintTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineFootPrintTableViewCell class])];
if (cell == nil) {
cell = [[XPMineFootPrintTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineFootPrintTableViewCell class])];
}
cell.item = [self.datasource objectAtIndex:indexPath.row];
return cell;
}
XPMineVisitorEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPMineVisitorEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
}
cell.emptyTitle = @"暂无进房记录";
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count == 0) {
return 85;
} else {
return 66;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
XPMineFootPrintModel *model = self.datasource[indexPath.row];
if (model.roomUid.integerValue > 0) {
[XPRoomViewController openRoom:model.roomUid viewController:self];
}
}
#pragma mark - XPFootPrintNavViewDelegate
///点击了返回按钮
- (void)xPFootPrintNavView:(XPFootPrintNavView *)view didClickBackButton:(UIButton *)sender {
[self.navigationController popViewControllerAnimated:YES];
}
///点击了清除按钮
- (void)xPFootPrintNavView:(XPFootPrintNavView *)view didClickClearButton:(UIButton *)sender {
[self.presenter cleanFootPrint];
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.rowHeight = 65;
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPMineVisitorEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
[_tableView registerClass:[XPMineFootPrintTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineFootPrintTableViewCell class])];
}
return _tableView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
- (XPFootPrintNavView *)navView {
if (!_navView) {
_navView = [[XPFootPrintNavView alloc] init];
_navView.delegate = self;
}
return _navView;
}
@end