RebateViewController.m 9.11 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  RebateViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/8/26.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "RebateViewController.h"
#import "PaymentsViewController.h"
#import "WithdrawalViewController.h"
曹云霄's avatar
曹云霄 committed
12 13
#import "RebateDetailsViewController.h"
#import "WithdrawalTableViewController.h"
14 15
#import "CardViewController.h"
#import "CardDetailsViewController.h"
16 17
#import "LuckyDrawViewController.h"
#import "LuckyDrawDetailsViewController.h"
曹云霄's avatar
曹云霄 committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

@interface RebateViewController ()

/**
 *  头像
 */
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;

/**
 *  账户金额
 */
@property (weak, nonatomic) IBOutlet UILabel *currentAmountLabel;

/**
 *  昨日收益
 */
@property (weak, nonatomic) IBOutlet UILabel *yesterdayAmountLabel;

/**
 *  历史收益
 */
@property (weak, nonatomic) IBOutlet UILabel *historyAmountLabel;

曹云霄's avatar
曹云霄 committed
41 42 43 44 45
/**
 *  冻结金额
 */
@property (weak, nonatomic) IBOutlet UILabel *freezeAmountLabel;

曹云霄's avatar
曹云霄 committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/**
 *  提现
 */
@property (weak, nonatomic) IBOutlet UIButton *withdrawalButton;

/**
 *  收支明细,提现进度
 */
@property (weak, nonatomic) IBOutlet UIView *contentBackgroundView;

/**
 *  当前的控制器
 */
@property (nonatomic,strong) BaseViewController *currentVC;

/**
 *  指示条
 */
@property (weak, nonatomic) IBOutlet UIView *instructionsLinesView;

/**
 *  收支明细
 */
@property (weak, nonatomic) IBOutlet UIButton *paymentsButton;

/**
 * 提现进度
 */
@property (weak, nonatomic) IBOutlet UIButton *withdrawalProgressButton;

曹云霄's avatar
曹云霄 committed
76 77 78
/**
 *  账户数据
 */
曹云霄's avatar
曹云霄 committed
79
@property (nonatomic,strong) EarningsResponse *model;
曹云霄's avatar
曹云霄 committed
80

81 82 83 84 85
/**
 *  我的卡劵包
 */
@property (weak, nonatomic) IBOutlet UIView *cardBackgroundView;

86 87 88 89 90 91 92 93 94 95 96
/**
 *  我的抽奖
 */
@property (weak, nonatomic) IBOutlet UIView *drawBackgroundView;

/**
 *  账户金额
 */
@property (weak, nonatomic) IBOutlet UIView *accountAmountView;


曹云霄's avatar
曹云霄 committed
97 98 99 100 101

@end

@implementation RebateViewController

曹云霄's avatar
曹云霄 committed
102
- (void)viewDidAppear:(BOOL)animated
103
{
曹云霄's avatar
曹云霄 committed
104
    [super viewDidAppear:animated];
105
    [[NSNotificationCenter defaultCenter] postNotificationName:PROMPTDRAWINFORMATION object:@(0)];
106 107 108
    [self getRebateDatasFromUser];
}

曹云霄's avatar
曹云霄 committed
109 110 111 112 113
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupChildViewController];
    [self uiConfigAction];
114
    [self addConstraint];
曹云霄's avatar
曹云霄 committed
115 116 117 118 119 120 121 122 123
}

#pragma mark - UI
- (void)uiConfigAction
{
    [self setupInstructionsViewOrigin:self.paymentsButton];
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:[Shoppersmanager manager].Shoppers.employee.picture] placeholderImage:ReplaceImage];
}

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
#pragma mark - 添加约束
- (void)addConstraint
{
    [self.cardBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(23);
        make.top.equalTo(self.accountAmountView.mas_bottom).offset(13);
        make.size.mas_equalTo(CGSizeMake((ScreenWidth-23*2-20)/2, 200));
    }];
    
    [self.drawBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardBackgroundView.mas_right).offset(20);
        make.top.equalTo(self.accountAmountView.mas_bottom).offset(13);
        make.size.mas_equalTo(CGSizeMake((ScreenWidth-23*2-20)/2, 200));
    }];
}

140
#pragma mark - 设置收支明细、提现进度、卡劵包
曹云霄's avatar
曹云霄 committed
141 142
- (void)setupChildViewController
{
曹云霄's avatar
曹云霄 committed
143
    PaymentsViewController *payments = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"PaymentsViewController"];
曹云霄's avatar
曹云霄 committed
144
    [self addChildViewController:payments];
145
    
曹云霄's avatar
曹云霄 committed
146
    WithdrawalViewController *withdrawal = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"WithdrawalViewController"];
曹云霄's avatar
曹云霄 committed
147 148 149 150 151
    [self addChildViewController:withdrawal];
    payments.view.frame = CGRectMake(0, 40, self.contentBackgroundView.mj_w, self.contentBackgroundView.mj_h-40);
    withdrawal.view.frame = CGRectMake(0, 40, self.contentBackgroundView.mj_w, self.contentBackgroundView.mj_h-40);
    [self.contentBackgroundView addSubview:payments.view];
    self.currentVC = payments;
152
    
153
    /// 我的卡劵
曹云霄's avatar
曹云霄 committed
154
    CardViewController *cardVc = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"CardViewController"];
155
    [self addChildViewController:cardVc];
156
    cardVc.view.frame = CGRectMake(0, 40, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h-50);
157
    [self.cardBackgroundView addSubview:cardVc.view];
158 159
    
    /// 我的抽奖
曹云霄's avatar
曹云霄 committed
160
    LuckyDrawDetailsViewController *draw = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"LuckyDrawDetailsViewController"];
161 162
    [self addChildViewController:draw];
    draw.drawValue = 0;
163
    draw.view.frame = CGRectMake(0, 40, self.drawBackgroundView.mj_w, self.drawBackgroundView.mj_h-50);
164
    [self.drawBackgroundView addSubview:draw.view];
曹云霄's avatar
曹云霄 committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
}


#pragma mark - 切换收支明细、提现进度
- (void)switchPaymentsVCAndWithdrawalVC:(BaseViewController *)newViewController
{
    [self transitionFromViewController:self.currentVC toViewController:newViewController duration:0.5 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
        if (finished) {
            [self.contentBackgroundView addSubview:newViewController.view];
            self.currentVC = newViewController;
        }
    }];
}

#pragma mark - 切换ContentController
- (IBAction)paymentsButtonAndWithdrawalButtonClick:(UIButton *)sender {
    
    if ([sender isEqual:self.paymentsButton]) {
        sender.selected = YES;
        self.withdrawalButton.selected = NO;
    }else
    {
        sender.selected = YES;
        self.paymentsButton.selected = NO;
    }
    [self setupInstructionsViewOrigin:sender];
    [self switchPaymentsVCAndWithdrawalVC:self.childViewControllers[sender.tag-100]];
}

#pragma mark - 设置指示线的位置
- (void)setupInstructionsViewOrigin:(UIButton *)sender
{
    [UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.instructionsLinesView.frame = CGRectMake(sender.mj_origin.x+(sender.mj_w-self.instructionsLinesView.mj_w)/2, self.instructionsLinesView.mj_origin.y, self.instructionsLinesView.mj_w, 2);
    } completion:nil];
}


曹云霄's avatar
曹云霄 committed
203 204 205 206 207 208
#pragma mark - 查询返利信息
- (void)getRebateDatasFromUser
{
    WS(weakSelf);
    [self CreateMBProgressHUDLoding];
    NSString *URL = [NSString stringWithFormat:@"%@/%@",REBATE,[Shoppersmanager manager].Shoppers.employee.fid];
209
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(URL) WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
210 211 212
        
        [weakSelf RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
213
            weakSelf.model = [[EarningsResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
214 215 216
             weakSelf.currentAmountLabel.text = [NSString stringWithFormat:@"%.2f",[returnValue[@"data"][@"accountTotal"] floatValue]];
             weakSelf.yesterdayAmountLabel.text = [NSString stringWithFormat:@"%.2f",[returnValue[@"data"][@"yesterdayEarnings"] floatValue]];
             weakSelf.historyAmountLabel.text = [NSString stringWithFormat:@"%.2f",[returnValue[@"data"][@"historyEarning"] floatValue]];
曹云霄's avatar
曹云霄 committed
217
            weakSelf.freezeAmountLabel.text = [NSString stringWithFormat:@"%.2f",[returnValue[@"data"][@"applytotal"] floatValue]];
曹云霄's avatar
曹云霄 committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        }else
        {
            [weakSelf SHOWPrompttext:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf SHOWPrompttext:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf SHOWPrompttext:error.localizedDescription];
    }];
}


#pragma mark - 提现
- (IBAction)withdrawalButtonClickAction:(UIButton *)sender {
    
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
237
    RebateDetailsViewController *rebateDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"RebateDetailsViewController"];
曹云霄's avatar
曹云霄 committed
238
    rebateDetails.rebateAmount = [self.model.accountTotal floatValue]-[self.model.applytotal floatValue];
曹云霄's avatar
曹云霄 committed
239
    [rebateDetails setShowApplyDetails:^(TOApplyBillEntity *entity) {
曹云霄's avatar
曹云霄 committed
240
        WithdrawalTableViewController *detailVC = [[[self class] getMainStoryboardClass]  instantiateViewControllerWithIdentifier:@"WithdrawalTableViewController"];
曹云霄's avatar
曹云霄 committed
241
        detailVC.model = entity;
曹云霄's avatar
曹云霄 committed
242 243 244 245 246
        [weakSelf.navigationController pushViewController:detailVC animated:YES];
    }];
    [self.navigationController pushViewController:rebateDetails animated:YES];
}

247 248 249
#pragma mark - 更多卡劵
- (IBAction)moreCardButtonClickAction:(UIButton *)sender {
    
曹云霄's avatar
曹云霄 committed
250
    CardDetailsViewController *cardDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"CardDetailsViewController"];
251 252
    [self.navigationController pushViewController:cardDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
253

254 255 256
#pragma mark - 更多抽奖信息
- (IBAction)moreDrawButtonClickAction:(UIButton *)sender {
    
曹云霄's avatar
曹云霄 committed
257
    LuckyDrawViewController *luckDrawDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"LuckyDrawViewController"];
258 259 260
    [self.navigationController pushViewController:luckDrawDetails animated:YES];
}

曹云霄's avatar
曹云霄 committed
261 262


曹云霄's avatar
曹云霄 committed
263
@end