//
//  BCRechargeFinishController.m
//  Open
//
//  Created by 雷俊博 on 2020/12/3.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "BCRechargeFinishController.h"

@interface BCRechargeFinishController ()<UIScrollViewDelegate>

@property (nonatomic, strong)UIScrollView* scrollView;

@end

@implementation BCRechargeFinishController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    //禁止页面左侧滑动返回，注意，如果仅仅需要禁止此单个页面返回，还需要在viewWillDisapper下开放侧滑权限
       // 禁用返回手势
       //禁止手势返回
       id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
       UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
       [self.view addGestureRecognizer:pan];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.scrollView];
    
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y <= 0) {
        scrollView.contentOffset = CGPointMake(0, 0);
    }
}


#pragma mark - event response
- (void)confirmBtnClick:(UIButton *)sender {
    [self.navigationController setNavigationBarHidden:NO];
    if (self.navigationController.tabBarController.selectedIndex == 0) {
        [self.navigationController popToViewController:self.navigationController.viewControllers[2] animated:YES];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:KKSBBCGETBalanceNotificationName object:nil];
    }else if (self.navigationController.tabBarController.selectedIndex == 1){
        self.navigationController.tabBarController.selectedIndex = 1;
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}


#pragma mark - 获取当前时间戳

-(NSString *)getNowTimeTimestamp3{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    
    
    return [formatter stringFromDate:datenow];
}

#pragma mark - getters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - TAB_BAR_HEIGHT)];
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.delegate = self;
        
        //topView
        //顶部背景色
        UIView* bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 189* WIDTHRADIU + cl_kStatusBarHeight)];
        bgView.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [_scrollView addSubview:bgView];
        
        
        //成功图标
        UIImageView* successImg = [[UIImageView alloc]init];
        successImg.image = [UIImage imageNamed:@"shaohouchuli"];
        [bgView addSubview:successImg];
        [successImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(bgView);
            make.top.offset(cl_kStatusBarHeight + 20 * WIDTHRADIU);
            make.width.height.offset(75 * WIDTHRADIU);
        }];
        
        //购买成功
        UILabel*lb_success = [[UILabel alloc]init];
        lb_success.text = @"充值处理中";
        lb_success.textColor = [UIColor whiteColor];
        lb_success.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
        lb_success.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:lb_success];
        [lb_success mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(bgView);
            make.top.equalTo(successImg.mas_bottom).offset(10 * WIDTHRADIU);
        }];
        
        UIView* cardView = [[UIView alloc]initWithFrame:CGRectMake(10 * WIDTHRADIU, 159* WIDTHRADIU + cl_kStatusBarHeight, ScreenWidth - 20 * WIDTHRADIU, 300 * WIDTHRADIU)];
        cardView.backgroundColor = [UIColor whiteColor];
        [_scrollView addSubview:cardView];
        
        UIBezierPath *cornerRadiusPath = [UIBezierPath bezierPathWithRoundedRect:cardView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(16, 16)];

        CAShapeLayer *cornerRadiusLayer = [ [CAShapeLayer alloc ] init];

        cornerRadiusLayer.frame = cardView.bounds;

        cornerRadiusLayer.path = cornerRadiusPath.CGPath;
        cardView.layer.mask = cornerRadiusLayer;
        
        UIImageView* icon1 = [[UIImageView alloc]init];
        icon1.image = [UIImage imageNamed:@"savesuccessStep1"];
        [cardView addSubview:icon1];
        [icon1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(15 * WIDTHRADIU);
            make.top.offset(10 * WIDTHRADIU);
            make.width.height.offset(20 * WIDTHRADIU);
        }];
        
        UILabel*lb_message1 = [[UILabel alloc]init];
        lb_message1.text = @"充值申请已提交,等待银行处理";
        lb_message1.textColor = [UIColor colorWithHex:0x4d4d4d];
        lb_message1.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
        lb_message1.textAlignment = NSTextAlignmentLeft;
        [cardView addSubview:lb_message1];
        [lb_message1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(icon1.mas_right).offset(5 * WIDTHRADIU);
            make.centerY.equalTo(icon1);
            make.right.offset(-15 * WIDTHRADIU);
        }];
        
        UILabel*lb_time1 = [[UILabel alloc]init];
        lb_time1.text = [self getNowTimeTimestamp3];
        lb_time1.textColor = [UIColor colorWithHex:0x808080];
        lb_time1.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        lb_time1.textAlignment = NSTextAlignmentLeft;
        [cardView addSubview:lb_time1];
        [lb_time1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lb_message1);
            make.top.equalTo(lb_message1.mas_bottom).offset(4 * WIDTHRADIU);
        }];
        
        
        UIImageView* icon2 = [[UIImageView alloc]init];
        icon2.image = [UIImage imageNamed:@"savesuccessStep2"];
        [cardView addSubview:icon2];
        [icon2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(15 * WIDTHRADIU);
            make.top.equalTo(lb_time1.mas_bottom).offset(30 * WIDTHRADIU);
            make.width.height.offset(20 * WIDTHRADIU);
        }];
        
        UILabel*lb_message2 = [[UILabel alloc]init];
        lb_message2.text = @"预计到账时间";
        lb_message2.textColor = [UIColor colorWithHex:0x808080];
        lb_message2.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
        lb_message2.textAlignment = NSTextAlignmentLeft;
        [cardView addSubview:lb_message2];
        [lb_message2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(icon2.mas_right).offset(5 * WIDTHRADIU);
            make.centerY.equalTo(icon2);
            make.right.offset(-15 * WIDTHRADIU);
        }];
        
        UILabel*lb_time2 = [[UILabel alloc]init];
        lb_time2.text = @"预计2小时到账,具体到账实际以收款银行入款时间为准,最迟下一个工作日到账";
        lb_time2.textColor = [UIColor colorWithHex:0x808080];
        lb_time2.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        lb_time2.textAlignment = NSTextAlignmentLeft;
        lb_time2.numberOfLines = 0;
        [cardView addSubview:lb_time2];
        [lb_time2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lb_message2);
            make.top.equalTo(lb_message2.mas_bottom).offset(4 * WIDTHRADIU);
            make.right.offset(-15 * WIDTHRADIU);
        }];
        
        
        UIButton * confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [confirmBtn setTitle:@"完成" forState:UIControlStateNormal];
        confirmBtn.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        confirmBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        confirmBtn.layer.cornerRadius = 5;
        [confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [cardView addSubview:confirmBtn];
        
        [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5 * WIDTHRADIU);
            make.right.offset(-5 * WIDTHRADIU);
            make.top.equalTo(lb_time2.mas_bottom).offset(40 * WIDTHRADIU);
            make.height.offset(45 * WIDTHRADIU);
        }];
        
        
        
    }
    return _scrollView;
}
/*
#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
