// // DRIncomeViewController.m // YouHuiProject // // Created by 小花 on 2018/8/3. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRIncomeViewController.h" #import "DRChildCommissionCell.h" #import "DRChildCommissionModel.h" #import "DRMonthCenterTipView.h" #import "DRCalendarView.h" #import "CCAlertShowView.h" #import "DRIncomeTopView.h" #import "DRIncomeDateTool.h" #import "ITDatePickerController.h" #import "DRWebDetailController.h" #import "DRFindBookWebViewController.h" @interface DRIncomeViewController () < UITableViewDelegate, UITableViewDataSource, ITDatePickerControllerDelegate >{ __block NSInteger page; NSInteger type; //类型 0 预估 1 完结 NSString *yearMonthDay; //日期 isDay为1:2018-08-08 isDay为0:2018-08 NSInteger isDay; //是否有日 0无 1有 } @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) DRIncomeTopView *topView; @property (nonatomic, strong) NSMutableArray *dataArr; @property (nonatomic, strong) DRCalendarView *calendarView ; @property (nonatomic, strong) CCAlertShowView *alertShowView; @end @implementation DRIncomeViewController - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [SVProgressHUD dismiss]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configTableView]; [self configRequestParam]; if (_infoIncomeType ==near_day_forecast_income) { [self canlendarAction]; } if (_yearMonth.length !=0) {//判断是否是按月统计 yearMonthDay=_yearMonth; [self changeDateS:_startDate AndString:yearMonthDay]; }else{ [self requestAndRefresh:YES]; } } - (void)configTableView { page = 1; __weak typeof(self) weakSelf = self; self.topView = [[DRIncomeTopView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, Fitsize(40))]; self.topView.calendarClick = ^{ [weakSelf canlendarAction]; }; [self.view addSubview:self.topView]; [self.view addSubview:self.tableView]; } - (void)configRequestParam { switch (self.infoIncomeType) { case this_day_forecast_income: //今日预估收入 case near_day_forecast_income://近期收入 { type = 0; isDay = 1; yearMonthDay = [DRIncomeDateTool getTodayString]; [self.navigationBar setNavTitle:@"今日预估收入"]; [self.topView setTitleStr:@"今日"]; } break; case last_day_forecast_income: //昨日预估收入 { type = 0; isDay = 1; yearMonthDay = [DRIncomeDateTool getYestodayString]; [self.navigationBar setNavTitle:@"昨日预估收入"]; [self.topView setTitleStr:@"昨日"]; } break; case last_month_forecast_income: //月预估收入 { type = 0; isDay = 0; yearMonthDay = [DRIncomeDateTool getLastMonthString]; [self.navigationBar setNavTitle:@"月预估收入"]; [self.topView setTitleStr:_yearMonth]; NSArray *array =[_yearMonth componentsSeparatedByString:@"-"]; if ( array.count >1) { [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@年%@月预估收入",array[0],array[1]]]; } } break; case last_month_settlement_income: //月结算收入 { type = 1; isDay = 0; yearMonthDay = [DRIncomeDateTool getLastMonthString]; [self.navigationBar setNavTitle:@"月结算收入"]; [self.topView setTitleStr:_yearMonth]; NSArray *array =[_yearMonth componentsSeparatedByString:@"-"]; if ( array.count >1) { [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@年%@月结算收入",array[0],array[1]]]; } } break; default: break; } self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; } - (void)configNavigationBar { self.view.backgroundColor = [UIColor whiteColor]; self.navigationBar.backgroundColor = [UIColor changeColor]; 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 *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [rightBtn setImage:[UIImage imageNamed:@"helpmonth"] forState:UIControlStateNormal]; [rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomRightButtons:@[rightBtn]]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)rightAction { DRWebDetailController *findbook = [[DRWebDetailController alloc] init]; findbook.pageType = 2; [self.navigationController pushViewController:findbook animated:YES]; } /** 日历事件 */ - (void)canlendarAction { if (isDay == 1) { if (self.alertShowView) { [self.alertShowView show]; return; } CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:self.calendarView backgroundDismissEnable:YES]; self.alertShowView = showView; [self.alertShowView show]; }else { ITDatePickerController *datePickerController = [[ITDatePickerController alloc] init]; datePickerController.tag = 100; datePickerController.delegate = self; datePickerController.showToday = NO; datePickerController.defaultDate = self.startDate; datePickerController.minimumDate = nil; datePickerController.maximumDate = nil; [self presentViewController:datePickerController animated:YES completion:nil]; } } #pragma mark - ITDatePickerControllerDelegate - (void)datePickerController:(ITDatePickerController *)datePickerController didSelectedDate:(NSDate *)date dateString:(NSString *)dateString { [self changeDateS:date AndString:dateString]; } -(void)changeDateS:(NSDate *)date AndString:(NSString *)dateString { page = 1; self.startDate = date; yearMonthDay = dateString; [self requestAndRefresh:YES]; [self.topView setTitleStr:dateString]; if (_infoIncomeType == last_month_forecast_income) {//预估 [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@预估收入",dateString]]; }else{//结算 [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@结算收入",dateString]]; } self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; } #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 110; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { DRChildCommissionCell *cell = [DRChildCommissionCell cellWithTableView:tableView]; DRChildCommissionModel *model=self.dataArr[indexPath.row]; cell.model=model; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } #pragma mark -网络请求 #pragma mark - request - (void)requestAndRefresh:(BOOL)refresh{ if (refresh) { [SVProgressHUD show]; } NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/incomeListNew",BaseURL]; NSDictionary *dic=@{ @"type":@(type), @"page":@(page), @"isDay":@(isDay), @"yearMonthDay":yearMonthDay }; [DRHttp post:url params:dic success:^(id json) { if (refresh) { [self.dataArr removeAllObjects]; } [self setTopViewInfoWithJson:json]; NSArray *arr = [NSArray yy_modelArrayWithClass:[DRChildCommissionModel class] json:json[@"data"]]; if (arr.count>0) { [self.dataArr addObjectsFromArray:arr]; [self.tableView.mj_footer endRefreshing]; }else { [self setUpNoDataView]; [self.tableView.mj_footer endRefreshingWithNoMoreData]; } [self.tableView reloadData]; [SVProgressHUD dismiss]; } failure:^(NSError *error) { [SVProgressHUD dismiss]; [self.tableView.mj_footer endRefreshing]; }]; } - (void)setTopViewInfoWithJson:(NSDictionary *)json { NSInteger orderNum = [json[@"num"] integerValue]; CGFloat allCom = [json[@"allRebate"] floatValue]; [self.topView setOrderNum:orderNum allCommission:allCom]; } - (void)setUpNoDataView { self.tableView.showNoDataView = YES; self.tableView.defaultNoDataText = @"您还没有任何订单"; self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"]; } #pragma mark ------- layzer ------ - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight+self.topView.height, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-self.topView.height) style:UITableViewStyleGrouped]; _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:^{ page ++; [self requestAndRefresh:NO]; }]; } return _tableView; } - (DRCalendarView *)calendarView { if (!_calendarView) { __weak typeof(self) weakSelf = self; _calendarView = [[DRCalendarView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-40, 0)]; _calendarView.cancelBlock = ^{ [weakSelf.alertShowView dismiss]; }; _calendarView.makeSureBlock = ^(NSString *dateStr) { if (dateStr) { yearMonthDay = dateStr; page = 1; [weakSelf requestAndRefresh:YES]; [weakSelf.topView setTitleStr:dateStr]; [weakSelf.navigationBar setNavTitle:dateStr]; weakSelf.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; [weakSelf.alertShowView dismiss]; }else { [weakSelf.alertShowView dismiss]; } }; } return _calendarView; } -(NSMutableArray *)dataArr{ if (!_dataArr) { _dataArr=[NSMutableArray array]; } return _dataArr; } @end