// // YOUPAIHROperationRecordVC.m // VQU // // Created by xiaohaoran on 2021/11/8. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHROperationRecordVC.h" #import "YOUPAIHROperationRecordCell.h" #import "UIScrollView+LZRefresh.h" #import "YOUPAIHROperationRecordModel.h" @interface YOUPAIHROperationRecordVC () @property(nonatomic,strong)UITableView *youpaiptableView; @property (nonatomic, assign) NSInteger youpaippage; @property (nonatomic, strong) NSMutableArray *youpaipdataSource; @end @implementation YOUPAIHROperationRecordVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"操作记录"; [self youpaiptableView]; @weakify(self); [self.youpaiptableView setRefreshHeaderWithBlock:^{ @strongify(self); [self youpaifrequestRankListWithStatus:kRefreshHeader]; }]; [self.youpaiptableView.mj_header beginRefreshing]; } /// 设置加载更多 - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{ @weakify(self); [self.youpaiptableView setRefreshFooter:hidden withBlock:^{ @strongify(self); [self youpaifrequestRankListWithStatus:kRefreshFooter]; }]; } - (void)youpaifrequestRankListWithStatus:(kRefreshStatus)status{ if (status == kRefreshFooter) { self.youpaippage ++; }else{ self.youpaippage = 1; } @weakify(self); [LCHttpHelper requestWithURLString:ChatRoom_operationLog parameters:@{@"page":@(self.youpaippage),@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); [self.youpaiptableView endRefreshing:kRefreshAll]; NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 if (status != kRefreshFooter) { [self.youpaipdataSource removeAllObjects]; } NSDictionary *data = [dict objectForKey:@"data"]; NSArray *list = [YOUPAIHROperationRecordModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]]; [self.youpaipdataSource addObjectsFromArray:list]; [self.youpaiptableView reloadData]; NSInteger totalPage = [data[@"total_page"] integerValue]; [self youpaifrefreshFooterWithHidden:self.youpaippage >= totalPage]; if (self.youpaipdataSource.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } } failure:^(NSError *error) { @strongify(self); [self.youpaiptableView endRefreshing:kRefreshAll]; }]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 68; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHROperationRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HROperationRecordID" forIndexPath:indexPath];; if (cell == nil) { cell = [[YOUPAIHROperationRecordCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HROperationRecordID"]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; cell.backgroundColor = LCBkgColor; YOUPAIHROperationRecordModel *model = self.youpaipdataSource[indexPath.row]; cell.youpaipmodel = model; return cell; } -(UITableView *)youpaiptableView { if (_youpaiptableView == nil) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; [self.view addSubview:_youpaiptableView]; [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(NavBarHeight); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-SafeHeight); }]; _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; _youpaiptableView.backgroundColor = [UIColor clearColor]; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.showsHorizontalScrollIndicator = NO; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } [_youpaiptableView registerClass:[YOUPAIHROperationRecordCell class] forCellReuseIdentifier:@"HROperationRecordID"]; } return _youpaiptableView; } -(NSMutableArray *)youpaipdataSource{ if (_youpaipdataSource == nil) { _youpaipdataSource = [NSMutableArray new]; } return _youpaipdataSource; } @end