CNLiveBalanceController.m 4.18 KB
//
//  CNLiveBalanceController.m
//  CNLiveBalanceModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveBalanceController.h"
#import "MJExtension.h"
#import <SDWebImage/SDWebImage.h>
#import "QMUIKit.h"

#import "CNUserInfoManager.h"
#import "CNLiveBaseKit.h"
#import "CNLiveServices.h"
#import "CNLiveCategory.h"

#import "CNLiveBalanceRequest.h"
#import "CNLiveBalanceNavigationBar.h"
#import "CNLiveBalanceView.h"
#import "CNLivePayCenterController.h"
#import "CNLiveBalanceDetailController.h"

@interface CNLiveBalanceController ()<CNLiveBalanceNavigationBarDelegate>
@property (nonatomic, strong) CNLiveBalanceNavigationBar *navigationBar;
@property (nonatomic, strong) CNLiveBalanceView *balanceView;

@property (nonatomic, copy) NSString *type;
@property (nonatomic, copy) NSString *ID;

@end

@implementation CNLiveBalanceController
#pragma mark - 初始化
- (instancetype)initWithType:(NSString *)type ID:(NSString *)ID{
    if(self = [super init]){
        self.type = type;
        self.ID = ID;
    }
    return self;
}
#pragma mark - 加载数据
- (void)loadData {
    [CNLiveBalanceRequest getBalance:self.type ID:self.ID block:^(BOOL isSuccess, NSString * _Nonnull number) {
        if(isSuccess){
            self.balanceView.number = number;
        }
    }];
}

#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11, *)) {
    }
    else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

    [self createSubViews];
    [self loadData];
    
}

- (void)createSubViews {
    [self.view addSubview:self.balanceView];
    [self.view addSubview:self.navigationBar];
}

#pragma mark - 状态栏
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
    
}

#pragma mark - CNLiveBalanceNavigationBarDelegate
- (void)navigationBar:(CNLiveBalanceNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
    if ([actionEvents isEqualToString:@"1"]) {
        [self goBack];
        
    }else if ([actionEvents isEqualToString:@"2"]){
        
        if ([self.type isEqualToString:@"1"]) { // 支付中心
            CNLivePayCenterController *vc = [CNLivePayCenterController new];
            [self.navigationController pushViewController:vc animated:YES];
            
        } else if ([self.type isEqualToString:@"2"]) { // 明细
            CNLiveBalanceDetailController *vc = [CNLiveBalanceDetailController new];
            vc.ID = self.ID;
            [self.navigationController pushViewController:vc animated:YES];
        }
    
    }
}

#pragma mark - 响应方法
- (void)goBack {
    if (self.presentingViewController != nil) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - 懒加载
- (CNLiveBalanceNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [[CNLiveBalanceNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
        _navigationBar.delegate = self;
        if([self.type isEqualToString:@"1"]){
            // 个人余额
            _navigationBar.title.text = @"中国网家家补贴余额";
            UIImage *image = [self getImageWithImageName:@"balance_pay_center" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
            [_navigationBar.right setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            
        }else if ([self.type isEqualToString:@"2"]){
            // 特色群组
            _navigationBar.title.text = @"余额";
            [_navigationBar.right setTitle:@"明细" forState:UIControlStateNormal];
        }
    }
    return _navigationBar;
}

- (CNLiveBalanceView *)balanceView{
    if(!_balanceView){
        _balanceView = [[CNLiveBalanceView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220+kStatusHeight)];
    }
    return _balanceView;
}

@end