// // LDChildAccountViewController.m // YouHuiProject // // Created by 小花 on 2018/7/31. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDChildAccountViewController.h" #import "LDChildOrderCell.h" #import "LDWithdrawDetailController.h" #import "LDAdWebViewController.h" #import "LDAccountHeader.h" #import "LDLinkAliPayViewController.h" #import "LDWithdrawController.h" @interface LDChildAccountViewController ()< UITableViewDelegate, UITableViewDataSource > { UIView *_sectionHeader; CGFloat rebate_account;//收入总计 CGFloat rebate_account_tx;//提现 NSInteger allTimes; LDAccountHeader *header; } @property (nonatomic, assign) NSInteger page; @property (nonatomic, strong) NSMutableArray *dataArr; @end @implementation LDChildAccountViewController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configTableView]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"我的余额"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; UIButton * nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-Fitsize(50), 0, Fitsize(100), Fitsize(30))]; nextBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; [nextBtn setImage:[UIImage imageNamed:@"Doubt"] forState:UIControlStateNormal];; nextBtn.titleLabel.font = [UIFont systemFontOfSize:Fitsize(13)]; nextBtn.titleLabel.textAlignment = NSTextAlignmentRight; [nextBtn setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:-5]; [nextBtn addTarget:self action:@selector(RightBtnAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomRightButtons:@[nextBtn]]; } -(void)RightBtnAction { LDAdWebViewController *adWeb = [[LDAdWebViewController alloc] init]; adWeb.url =Orderwithdrawal; [self.navigationController pushViewController:adWeb animated:YES]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)configTableView { self.page = 1; [self.view addSubview:self.tableView]; header = [[LDAccountHeader alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, FITSIZE(100))]; header.moneyBackBlcok = ^(NSString *blance,BOOL isLinkAliPay){ if (blance.length > 0) { if (isLinkAliPay) { //提现 LDWithdrawController *toMoney = [[LDWithdrawController alloc] init]; toMoney.moneyStr = blance; [self.navigationController pushViewController:toMoney animated:YES]; }else { LDLinkAliPayViewController *link = [[LDLinkAliPayViewController alloc] init]; [self.navigationController pushViewController:link animated:YES]; } }else { [MBProgressHUD showMessage:@"正在校验您的余额,请稍后重试"]; } }; self.tableView.tableHeaderView = header; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.page = 1; [header reloadData]; [self requestWith:YES]; } #pragma mark ------ - (void)requestWith:(BOOL)refresh { NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/commissionListNew",BaseURL]; NSDictionary *dic=@{ @"type":@(0), @"page":@(self.page) }; [LDHttp post:url params:dic success:^(id json) { if (refresh) { self.page = 1; [self.dataArr removeAllObjects]; } NSNumber *rebate = json[@"data"][@"rebate_account_yj"]; rebate_account_tx = [json[@"data"][@"rebate_account_tx"] floatValue]; rebate_account = [rebate floatValue]; NSArray *arr = [NSArray yy_modelArrayWithClass:[LDChildOrderModel class] json:json[@"data"][@"commsionList"]]; if (arr.count>0) { [self.dataArr addObjectsFromArray:arr]; [self.tableView.mj_footer endRefreshing]; }else { [self setUpNoDataView]; [self noMoreDataWithArray:arr]; } [self.tableView.mj_header endRefreshing]; [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 FITSIZE(80); } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return FITSIZE(35); } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { LDChildOrderCell *cell = [LDChildOrderCell cellWithTableView:tableView]; LDChildOrderModel *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, FITSIZE(35))]; _sectionHeader.backgroundColor = [UIColor YHColorWithHex:0xF4F4F4]; UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(FITSIZE(14), 0, SCREEN_WIDTH-FITSIZE(50), FITSIZE(35))]; priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; priceLabel.font = [UIFont systemFontOfSize:12]; priceLabel.text = [NSString stringWithFormat:@"累计收入¥%.2f 成功提现¥%.2f",rebate_account,rebate_account_tx]; [_sectionHeader addSubview:priceLabel]; return _sectionHeader; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { LDChildOrderModel *model= self.dataArr[indexPath.row]; if (model.type.integerValue == 1) {//已通过 LDWithdrawDetailController *detail = [[LDWithdrawDetailController alloc] init]; detail.detailId = model.Id; [[self currentViewController].navigationController pushViewController:detail animated:YES]; }else if (model.type.integerValue == 2) {//未通过 LDAdWebViewController *webV = [[LDAdWebViewController alloc] init]; webV.url = model.problem_url; [[self currentViewController].navigationController pushViewController:webV animated:YES]; } } - (UIViewController *)currentViewController{ UIViewController * currVC = nil; UIWindow *window = [UIApplication sharedApplication].delegate.window; UIViewController * Rootvc = window.rootViewController; do { if ([Rootvc isKindOfClass:[UINavigationController class]]) { UINavigationController * nav = (UINavigationController *)Rootvc; UIViewController * v = [nav.viewControllers lastObject]; currVC = v; Rootvc = v.presentedViewController; continue; }else if([Rootvc isKindOfClass:[UITabBarController class]]){ UITabBarController * tabVC = (UITabBarController *)Rootvc; currVC = tabVC; Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex]; continue; } } while (Rootvc!=nil); return currVC; } #pragma mark ------- layzer ------ - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) 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_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{ self.page =1; [self requestWith:YES]; }]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ self.page ++; [self requestWith:NO]; }]; } 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