// // YMMineFootPrintViewController.m // YUMI // // Created by YUMI on 2022/7/26. // #import "XPMineFootPrintViewController.h" ///Third #import #import ///Tool #import "DJDKMIMOMColor.h" #import "YUMIMacroUitls.h" #import "NSArray+Safe.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() ///列表 @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 = [DJDKMIMOMColor secondTextColor]; header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor]; self.tableView.mj_header = header; MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)]; footer.stateLabel.textColor = [DJDKMIMOMColor 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:YMLocalizedString(@"XPMineFootPrintViewController0")]; 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.leading.trailing.top.mas_equalTo(self.view); make.height.mas_equalTo(kNavigationHeight); }]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.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 showSuccessToast:YMLocalizedString(@"XPMineFootPrintViewController1")]; [self headerRefresh]; } - (void)collectRoomSuccess { [self showSuccessToast:YMLocalizedString(@"XPMineFootPrintViewController2")]; } #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 xpSafeObjectAtIndex: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 = YMLocalizedString(@"XPMineFootPrintViewController3"); return cell; } - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){ [tableView setEditing:NO animated:YES]; __weak typeof(self) weakSelf = self; UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:YMLocalizedString(@"XPMineFootPrintViewController4") handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { XPMineFootPrintModel *item = [weakSelf.datasource xpSafeObjectAtIndex:indexPath.row]; [weakSelf.presenter cleanFootPrint:item.roomUid]; completionHandler(true); }]; UIContextualAction *collectAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:YMLocalizedString(@"XPMineFootPrintViewController5") handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { XPMineFootPrintModel *item = [weakSelf.datasource xpSafeObjectAtIndex:indexPath.row]; [weakSelf.presenter collectRoomWithRoomUid:item.roomUid]; completionHandler(true); }]; deleteAction.backgroundColor = [DJDKMIMOMColor textThirdColor]; collectAction.backgroundColor = UIColorFromRGB(0xFFA027); UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[collectAction, deleteAction]]; actions.performsFirstActionWithFullSwipe = NO; return actions; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (self.datasource.count == 0) { return 85; } else { return 66; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.datasource.count > 0) { XPMineFootPrintModel *model = [self.datasource xpSafeObjectAtIndex: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:nil]; } #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