// // HSQToMoneyViewController.m // YouHuiProject // // Created by 小花 on 2018/6/11. // Copyright © 2018年 kuxuan. All rights reserved. // #import "HSQToMoneyViewController.h" #import "HSQChildCommissionCell.h" #import "HSQAccountHeader.h" #import "HSQChildOrderCell.h" #import "HSQChildOrderModel.h" #import "HSQWithdrawDetailController.h" @interface HSQToMoneyViewController () < UITableViewDelegate, UITableViewDataSource > { UIView *_sectionHeader; CGFloat rebate_account;//累计成功提现 NSInteger allTimes; } @property (nonatomic, assign) NSInteger page; @property (nonatomic, strong) NSMutableArray *dataArr; @end @implementation HSQToMoneyViewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)viewDidLoad { [super viewDidLoad]; [self configTableView]; [self request]; } - (void)configTableView { self.page = 1; [self.view addSubview:self.tableView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshList:) name:RefreshWithDrawHistory object:nil]; } - (void)refreshList:(NSNotification *)noti { [self.dataArr removeAllObjects]; _page = 1; [self.tableView reloadData]; [self request]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)request { NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/commissionList",BaseURL]; NSDictionary *dic=@{ @"type":@(2), @"page":@(self.page) }; [HSQHttp post:url params:dic success:^(id json) { rebate_account = [json[@"rebate_account"] floatValue]; allTimes = [json[@"allTimes"] integerValue];; NSArray *arr = [NSArray yy_modelArrayWithClass:[HSQChildOrderModel class] json:json[@"data"]]; if (arr.count>0) { [self.dataArr addObjectsFromArray:arr]; [self.tableView.mj_footer endRefreshing]; }else { [self setUpNoDataView]; [self noMoreDataWithArray:arr]; } [self.tableView reloadData]; } failure:^(NSError *error) { [self.tableView.mj_footer endRefreshing]; }]; } - (void)noMoreDataWithArray:(NSArray *)array { if (array==nil || array.count <= 0) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; } } - (void)setUpNoDataView { self.tableView.showNoDataView = YES; self.tableView.defaultNoDataText = @"您还没有任何记录"; self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"]; } #pragma mark ------ scrollView delegate ----- - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (!self.childCanScroll) { scrollView.contentOffset = CGPointZero; } if (scrollView.contentOffset.y <= 0) { self.childCanScroll = NO; scrollView.contentOffset = CGPointZero; [[NSNotificationCenter defaultCenter] postNotificationName:@"childDetailleaveTop" object:nil];//到顶通知父视图改变状态 } } #pragma mark -------- UITableView Delegate ----- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 67; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 37; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HSQChildOrderCell *cell = [HSQChildOrderCell cellWithTableView:tableView]; HSQChildOrderModel *model = self.dataArr[indexPath.row]; cell.model=model; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { _sectionHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 37)]; _sectionHeader.backgroundColor = [UIColor YHColorWithHex:0xF4F4F4]; UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 0, 200, 37)]; priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; priceLabel.font = [UIFont systemFontOfSize:12]; priceLabel.text = [NSString stringWithFormat:@"累计成功提现%ld次,共%.2f元",(long)allTimes,rebate_account]; [_sectionHeader addSubview:priceLabel]; return _sectionHeader; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { HSQChildOrderModel *model = self.dataArr[indexPath.row]; if ([model.state_of_embodiment isEqualToString:@"1"]) { HSQWithdrawDetailController *detail = [[HSQWithdrawDetailController alloc] init]; detail.detailId = model.Id; [self.navigationController pushViewController:detail animated:YES]; } } #pragma mark ------- layzer ------ - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.estimatedRowHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ self.page ++; [self request]; }]; } return _tableView; } - (NSMutableArray *)dataArr { if (!_dataArr) { _dataArr = [NSMutableArray array]; } return _dataArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end