123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- //
- // DRAchievementViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/8/2.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRAchievementViewController.h"
- #import "DRAchievementDetailView.h"
- #import "DRAchievementHeader.h"
- #import "DRIncomeViewController.h"
- #import "DRAccountInfoModel.h"
- #import "DRCommissionMainViewController.h"
- #import "DRAchievementListCell.h"
- #import "DRChildAccountViewController.h"
- #import "DRIncomeViewController.h"
- #import "DRWebDetailController.h"
- #import "DRAccountModel.h"
- #import "DRNoDataCell.h"
- #import "DRPrivilegeReferralViewController.h"
- @interface DRAchievementViewController ()<UITableViewDelegate,UITableViewDataSource>
- {
- UILabel *guiEstimateLb;
- UILabel *guiFinalLb;
- UIButton *forecastBtn;
- UIButton *accoutnBtn ;
- NSDictionary *userinfoDic;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) UIView *header;
- @property (nonatomic, strong) DRAchievementDetailView *dayView;//日预估
- @property (nonatomic, strong) DRAchievementDetailView *monthEstimateView;//月预估
- @property (nonatomic, strong) DRAchievementDetailView *monthFinalView; //月结算
- @property (nonatomic, strong) DRAchievementHeader *achievementHeader;
- @property (nonatomic, strong) DRAccountInfoModel *accountInfoModel;
- @property(nonatomic,strong)NSArray *TodayArray;
- @property(nonatomic,strong)NSArray *dataArray;
- //结算收入类型
- @property(nonatomic,copy)NSString *acctountType;
- @end
- @implementation DRAchievementViewController
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [SVProgressHUD dismiss];
- }
- -(void)viewDidAppear:(BOOL)animated
- {
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configNavigationBar];
- [self configTableViewHeader];
- [self requestData];
- [self accountMonthSWithType:@"1"];//1预估收入2结算收入
- }
- - (void)configTableViewHeader {
- self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(110))];
- __weak typeof(self) weakSelf = self;
- //头视图
- self.achievementHeader = [[DRAchievementHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(110))];
-
- self.achievementHeader.carryOrderClick = ^{
- DRChildAccountViewController *accountDetail = [[DRChildAccountViewController alloc] init];//提现
- [weakSelf.navigationController pushViewController:accountDetail animated:YES];
-
-
- };
- [self.header addSubview:self.achievementHeader];
- [self.view addSubview:self.tableView];
- //判断是否是会员。
-
- //取值(key值同名的时候会覆盖的)
- userinfoDic =[DRUserInfoManager shareManager].userInfoDic;
- if ([userinfoDic[@"user_level"] integerValue]==1) {
- self.header.frame=CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(135));
- UIButton *accountBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, FITSIZE(115), SCREEN_WIDTH, FITSIZE(30))];
- [accountBtn setImage:[UIImage imageNamed:@"goto_detail"] forState:UIControlStateNormal];
- [accountBtn setImageEdgeInsets:UIEdgeInsetsMake(FITSIZE(7.5), SCREEN_WIDTH-FITSIZE(30), FITSIZE(7.5), FITSIZE(15))];
- accountBtn.backgroundColor =[UIColor whiteColor];
- [accountBtn addTarget:self action:@selector(accountClickBtn) forControlEvents:UIControlEventTouchUpInside];
- [self.header addSubview:accountBtn];
-
- UIImageView *imgv =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(15), FITSIZE(7.5), FITSIZE(15), FITSIZE(15))];
- imgv.image =[UIImage imageNamed:@"order_notice"];
- [accountBtn addSubview:imgv];
-
- UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), 0, FITSIZE(300), FITSIZE(30))];
- label.text=@"你还不是超级会员,成为超级会员就能购物有收益啦";
- label.textColor=[UIColor YHColorWithHex:0xFB6526];
- label.font=[UIFont systemFontOfSize:FITSIZE(12)];
- [accountBtn addSubview:label];
- }
-
-
-
-
-
- self.tableView.tableHeaderView = self.header;
- }
- #pragma mark-特权介绍
- -(void)accountClickBtn
- {
- DRPrivilegeReferralViewController *Privilege = [[DRPrivilegeReferralViewController alloc] init];
- [self.navigationController pushViewController:Privilege animated:YES];
- }
- - (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];
-
- UIButton * nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-Fitsize(50), 0, Fitsize(100), Fitsize(30))];
- nextBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- [nextBtn setTitle:@"订单明细" forState:UIControlStateNormal];
- nextBtn.titleLabel.font = [UIFont systemFontOfSize:Fitsize(13)];
- nextBtn.titleLabel.textAlignment = NSTextAlignmentRight;
- [nextBtn setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:-5];
-
- [nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
-
-
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- [self.navigationBar setCustomRightButtons:@[nextBtn]];
- }
- -(void)nextBtnAction
- {
- DRCommissionMainViewController *commissionMain = [[DRCommissionMainViewController alloc] init];
- commissionMain.showIndex = 2;
- [self.navigationController pushViewController:commissionMain animated:YES];
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)setUpNoDataView {
- self.tableView.showNoDataView = YES;
- self.tableView.noDataImageOffsetY = -70;
- self.tableView.defaultNoDataText = @"您还没有收益~";
- self.tableView.defaultNoDataImage = [UIImage imageNamed:@"no_order"];
- }
- - (void)requestData {
-
- if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
- [self.achievementHeader setAllCommission:@"0" orderNum:@"0"];
- [self setUpNoDataView];
- [self.tableView.mj_header endRefreshing];
- [self.tableView reloadData];
- }else{
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/myEarnings",BaseURL];
- [DRCacheHttp post:url params:nil success:^(id json, BOOL isCache) {
- self.accountInfoModel = [DRAccountInfoModel yy_modelWithJSON:json];
- [self.achievementHeader setAllCommission:self.accountInfoModel.all_settlement_income orderNum:self.accountInfoModel.account_balance];
- [self setAccountInfoView];
- [self.tableView.mj_header endRefreshing];
- } failure:^(NSError *error) {
- [self.tableView.mj_header endRefreshing];
- }];
- }
-
-
-
- }
- #pragma mark----按月计算收益
- -(void)accountMonthSWithType:(NSString *)types
- {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/monthEarnings",BaseURL];
- [self changeType];
- [DRCacheHttp post:url params:@{@"type":types} success:^(id json, BOOL isCache) {
- _acctountType =types;
-
- self.dataArray=[NSArray yy_modelArrayWithClass:[DRAccountModel class] json:json];
- [self.tableView reloadData];
-
- } failure:^(NSError *error) {
- [self.tableView.mj_header endRefreshing];
- }];
- }
- - (void)setAccountInfoView {
- if (self.accountInfoModel) {
- self.TodayArray = [self.accountInfoModel getTodayInfoArr];
- NSArray *monthEstimateArr = [self.accountInfoModel getMonthEstimateInfoArr];
- NSArray *monthFinalArr = [self.accountInfoModel getMonthFinalInfoArr];
- [self.monthEstimateView setAccountInfo:monthEstimateArr];
- [self.monthFinalView setAccountInfo:monthFinalArr];
-
- }
- [self.tableView reloadData];
-
- }
- #pragma mark
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
- return 0;
- }
- if (section == 1) {
- if (self.dataArray.count ==0) {
- return 1;
- }
- return self.dataArray.count;
- }
- return 2;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
- return 0;
- }
- return 2;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return FITSIZE(45);
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView *views =[[UIView alloc]initWithFrame:CGRectMake(0, FITSIZE(0), SCREEN_WIDTH, FITSIZE(45))];
- views.backgroundColor =[UIColor whiteColor];
- UILabel *finalBottomLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(10))];
- finalBottomLine.backgroundColor = [UIColor yhGrayColor];
- [views addSubview:finalBottomLine];
-
-
-
- UIButton *addbtn =[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-FITSIZE(30), FITSIZE(20), FITSIZE(15), FITSIZE(15))];
- [views addSubview:addbtn];
- addbtn.tag = section;
- [addbtn addTarget:self action:@selector(ClickBtn:) forControlEvents:UIControlEventTouchUpInside];
- if (section ==0) {
- UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(10), FITSIZE(100), FITSIZE(35))];
- label.text=@"近期收入";
- [views addSubview:label];
- [addbtn setImage:[UIImage imageNamed:@"calendar_gray"] forState:UIControlStateNormal];
-
- }else{
- [addbtn setImage:[UIImage imageNamed:@"yiwen"] forState:UIControlStateNormal];
- forecastBtn =[[UIButton alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(10), FITSIZE(60), FITSIZE(35))];
- [forecastBtn setTitle:@"预估收入" forState:UIControlStateNormal];
- forecastBtn.tag = 10000;
- [views addSubview:forecastBtn];
- [forecastBtn addTarget:self action:@selector(changeOrderBtn:) forControlEvents:UIControlEventTouchUpInside];
- UILabel *finalLine = [[UILabel alloc] initWithFrame:CGRectMake(FITSIZE(72), FITSIZE(17.5), 1, FITSIZE(20))];
- finalLine.backgroundColor = [UIColor yhGrayColor];
- [views addSubview:finalLine];
-
- accoutnBtn =[[UIButton alloc]initWithFrame:CGRectMake(FITSIZE(75), FITSIZE(10), FITSIZE(60), FITSIZE(35))];
- [accoutnBtn setTitle:@"结算收入" forState:UIControlStateNormal];
- accoutnBtn.tag = 10001;
- [accoutnBtn addTarget:self action:@selector(changeOrderBtn:) forControlEvents:UIControlEventTouchUpInside];
- [views addSubview:accoutnBtn];
-
- }
-
- [self changeType];
-
- return views;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (self.dataArray.count ==0 && indexPath.section == 1) {
- DRNoDataCell *cell = [[DRNoDataCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"nodata"];
- cell.selectionStyle =UITableViewCellSelectionStyleNone;
- return cell;
- }
- DRAchievementListCell *cell = [[DRAchievementListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
- cell.selectionStyle =UITableViewCellSelectionStyleNone;
- if (indexPath.section == 0) {
- cell.yearLabel.hidden=YES;
- if (indexPath.row == 0) {
- cell.titleLabel.text=@"今日";
-
- }else{
- cell.titleLabel.text=@"昨日";
- }
- cell.titleLabel.frame=CGRectMake(0, 0, FITSIZE(50), FITSIZE(50));
- if (self.TodayArray.count !=0) {
- cell.pricelabel.text=[NSString stringWithFormat:@"¥%.2f",[self.TodayArray[indexPath.row][1]floatValue]];
- cell.ordernumLabel.text=[NSString stringWithFormat:@"共%ld单",(long)[self.TodayArray[indexPath.row][0]integerValue]];
- }
-
- }else{
- cell.yearLabel.hidden=NO;
- if (self.dataArray.count !=0) {
- cell.model=self.dataArray[indexPath.row];
- }
-
- }
-
- cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section ==0 ) {
- if (indexPath.row == 1) {//昨日预估收入
- [self changeType:last_day_forecast_income AndDate:nil YearMonth:@""];
- }
- if (indexPath.row == 0) {//今日预估
- [self changeType:this_day_forecast_income AndDate:nil YearMonth:@""];
- }
- }
-
- if (indexPath.section ==1 && self.dataArray.count !=0) {//指定月份的结算收入
- DRAccountModel *models =self.dataArray[indexPath.row];
- if (_acctountType.integerValue == 1) {//预估收入
- [self changeType:last_month_forecast_income AndDate:[self StringTODate:models.yearAndMonth] YearMonth:models.yearAndMonth];
- }else{
- [self changeType:last_month_settlement_income AndDate:[self StringTODate:models.yearAndMonth] YearMonth:models.yearAndMonth];
-
- }
-
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 1) {
- if (self.dataArray.count ==0) {
- return FITSIZE(200);
- }
- }
- return FITSIZE(50);
- }
- #pragma mark--点击
- -(void)ClickBtn:(UIButton *)btn
- {
- if (btn.tag == 0) {//日历
- [self changeType:near_day_forecast_income AndDate:nil YearMonth:@""];
- }else{//提示
- DRWebDetailController *findbook = [[DRWebDetailController alloc] init];
- findbook.pageType = 2;
- [self.navigationController pushViewController:findbook animated:YES];
- }
- }
- -(void)changeType:(UserInfoIncomeType)type AndDate:(NSDate *)date YearMonth:(NSString *)yearmonth
- {
- DRIncomeViewController *income = [[DRIncomeViewController alloc] init];
- income.infoIncomeType =type;
- income.startDate=date;
- income.yearMonth=yearmonth;
- [self.navigationController pushViewController:income animated:YES];
- }
- - (NSDate *)StringTODate:(NSString *)sender
- {
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
- dateFormatter.dateFormat = @"YYYY-MM";
-
- [dateFormatter setMonthSymbols:[NSArray arrayWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12", nil]];
-
- NSDate * ValueDate = [dateFormatter dateFromString:sender];
-
- return ValueDate;
-
- }
- #pragma mark-----收入切换
- -(void)changeOrderBtn:(UIButton *)btn
- {
-
- if (btn.tag == 10000) {//预估收入
-
- [self accountMonthSWithType:@"1"];
- }else{
-
- [self accountMonthSWithType:@"2"];
- }
-
- }
- -(void)changeType
- {
- if (_acctountType.integerValue ==1) {
- [forecastBtn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
- [accoutnBtn setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
- forecastBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(14)];
- accoutnBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(11)];
-
- }else{
- [accoutnBtn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
- [forecastBtn setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
- accoutnBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(14)];
- forecastBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(11)];
-
- }
- }
- #pragma mark ===================== layezer ==============
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.sectionFooterHeight = 0;
- _tableView.sectionHeaderHeight = 0;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.bounces = YES;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [self requestData];
- }];
-
- }
- return _tableView;
- }
- @end
|