//
//  PayOrderDetailView.m
//  Open
//
//  Created by 雷俊博 on 2020/9/7.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "PayOrderDetailView.h"

@interface PayOrderDetailView ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong)UIView* contentView;

@property (nonatomic, strong)SaveOrderModel* orderModel;

@end

@implementation PayOrderDetailView
- (instancetype)initWithModel:(SaveOrderModel *)mode
{
    self = [super init];
    if (self) {
        self.orderModel = mode;
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI
{
    self.frame = [UIScreen mainScreen].bounds;
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    tap.delegate = self;
    [self addGestureRecognizer:tap];
    
    //------- 弹窗主内容 -------//
    self.contentView = [[UIView alloc] init];
    self.contentView.bounds = CGRectMake(0, 0, 295*WIDTHRADIU, 220 * WIDTHRADIU);
    self.contentView.center = self.center;
    [self addSubview:self.contentView];
    self.contentView.backgroundColor = [UIColor colorWithHex:0x137ef6];
    self.contentView.layer.cornerRadius = 15 * WIDTHRADIU;

    
    //标题
    UILabel*lb_title = [UILabel new];
    lb_title.text = @"交易详情";
    lb_title.textColor = [UIColor whiteColor];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
    [self.contentView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.offset(15 * WIDTHRADIU);
    }];
    
    //message
    UILabel*lb_message = [UILabel new];
    lb_message.text = [NSString stringWithFormat:@"%@%.2f",self.orderModel.BILL_AMS,self.orderModel.BILL_AMT.doubleValue];
    lb_message.textColor = [UIColor whiteColor];
    lb_message.font = [UIFont boldSystemFontOfSize:20 * WIDTHRADIU];
    lb_message.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:lb_message];
    [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(lb_title);
        make.top.equalTo(lb_title.mas_bottom).offset(15 * WIDTHRADIU);
    }];
    
    
    //提示
    UIView* whiteView = [[UIView alloc]init];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.cornerRadius = 10 * WIDTHRADIU;
    [self.contentView addSubview:whiteView];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_message.mas_bottom).offset(15 * WIDTHRADIU);
        make.width.offset(275 * WIDTHRADIU);
        make.height.offset(120 * WIDTHRADIU);
        make.centerX.equalTo(lb_title);
    }];
    
    
    UILabel*lb_typeTitle = [UILabel new];
    lb_typeTitle.text = @"交易类型";
    lb_typeTitle.textColor = [UIColor colorWithHex:0x808080];
    lb_typeTitle.font = [UIFont systemFontOfSize:14* WIDTHRADIU];
    [whiteView addSubview:lb_typeTitle];
    
    [lb_typeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10 * WIDTHRADIU);
        make.left.offset(8 * WIDTHRADIU);
    }];
    
    UILabel*lb_type = [UILabel new];
    lb_type.text = [self getMessageWithCode:self.orderModel.TRANTYPE message:self.orderModel.NOTE];;
    lb_type.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb_type.font = [UIFont systemFontOfSize:15* WIDTHRADIU];
    [whiteView addSubview:lb_type];
    [lb_type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lb_typeTitle);
        make.left.equalTo(lb_typeTitle.mas_right).offset(15 * WIDTHRADIU);
    }];
    
    UILabel*lb_timeTitle = [UILabel new];
    lb_timeTitle.text = @"交易时间";
    lb_timeTitle.textColor = [UIColor colorWithHex:0x808080];
    lb_timeTitle.font = [UIFont systemFontOfSize:14* WIDTHRADIU];
    [whiteView addSubview:lb_timeTitle];
    
    [lb_timeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_typeTitle.mas_bottom).offset(10 * WIDTHRADIU);
        make.left.equalTo(lb_typeTitle);
    }];
    
    UILabel*lb_time = [UILabel new];
    lb_time.text = [NSString stringWithFormat:@"%@-%@-%@ %@:%@:%@",[self.orderModel.HS_INPD substringToIndex:4],[self.orderModel.HS_INPD substringWithRange:NSMakeRange(4, 2)],[self.orderModel.HS_INPD substringFromIndex:self.orderModel.HS_INPD.length - 2],[self.orderModel.HS_INPT substringToIndex:2],[self.orderModel.HS_INPT substringWithRange:NSMakeRange(2, 2)],[self.orderModel.HS_INPT substringWithRange:NSMakeRange(4, 2)]];;
    lb_time.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb_time.font = [UIFont systemFontOfSize:15* WIDTHRADIU];
    [whiteView addSubview:lb_time];
    [lb_time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lb_timeTitle);
        make.left.equalTo(lb_type);
    }];
    
    UILabel*lb_orderTitle = [UILabel new];
    lb_orderTitle.text = @"交易流水";
    lb_orderTitle.textColor = [UIColor colorWithHex:0x808080];
    lb_orderTitle.font = [UIFont systemFontOfSize:14* WIDTHRADIU];
    [whiteView addSubview:lb_orderTitle];
    
    [lb_orderTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_timeTitle.mas_bottom).offset(10 * WIDTHRADIU);
        make.left.equalTo(lb_typeTitle);
    }];
    
    UILabel*lb_order = [UILabel new];
    lb_order.text = self.orderModel.HS_TRNN;
    lb_order.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb_order.font = [UIFont systemFontOfSize:15* WIDTHRADIU];
    [whiteView addSubview:lb_order];
    [lb_order mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lb_orderTitle);
        make.left.equalTo(lb_type);
    }];
    
    UILabel*lb_tipTitle = [UILabel new];
    lb_tipTitle.text = @"交易描述";
    lb_tipTitle.textColor = [UIColor colorWithHex:0x808080];
    lb_tipTitle.font = [UIFont systemFontOfSize:14* WIDTHRADIU];
    [whiteView addSubview:lb_tipTitle];
    
    [lb_tipTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_orderTitle.mas_bottom).offset(10 * WIDTHRADIU);
        make.left.equalTo(lb_typeTitle);
    }];
    
    UILabel*lb_tip = [UILabel new];
    lb_tip.text = self.orderModel.DESLINE;
    lb_tip.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb_tip.font = [UIFont systemFontOfSize:15* WIDTHRADIU];
    [whiteView addSubview:lb_tip];
    [lb_tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lb_tipTitle);
        make.left.equalTo(lb_type);
    }];
    
    
    
    
    

    
    
}

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isDescendantOfView:self.contentView]) {

        return NO;

    }
    
    return YES;
}

#pragma mark - 显示弹框
+(void)showViewWithModel:(SaveOrderModel *)model InVC:(UIViewController *)vc;
{
    PayOrderDetailView*baseView = [[PayOrderDetailView alloc]initWithModel:model];
    UIWindow* keyWindow = vc.view.window;
    
    if (keyWindow == nil) {
        keyWindow = [UIApplication sharedApplication].keyWindow;
    }

    [keyWindow addSubview:baseView];
}

#pragma mark -隐藏弹框
- (void)dismissUI
{
     [self removeFromSuperview];
}

#pragma mark - event response
- (void)tapClick:(UITapGestureRecognizer *)tap
{
    [self dismissUI];
}
- (void)saveBtnClick:(UIButton *)sender
{
   
    [self dismissUI];
}
//关闭
- (void)closeBtnClick:(UIButton *)sender
{
    [self dismissUI];
}


#pragma mark - private methods
- (NSString *)getMessageWithCode:(NSString *)code message:(NSString *)message
{
    NSString* returnMessage = nil;
    if ([code isEqualToString:@"2822"]) {
        returnMessage = @"提现";
    }else if ([code isEqualToString:@"7822"]){
        returnMessage = @"充值";
    }else if ([code isEqualToString:@"2894"]){
        returnMessage = @"购买";
    }else if ([code isEqualToString:@"7894"]){
        returnMessage = @"赎回";
    }else{
        returnMessage = message;
    }
    return returnMessage;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
