//
//  WithDrawTopCell.m
//  Open
//
//  Created by 雷俊博 on 2020/10/26.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "WithDrawTopCell.h"
#import "LSLDecimalNumberTool.h"

@interface WithDrawTopCell ()

/**
 *  标题
 */
@property (nonatomic, strong)UILabel* titleLabel;

/**
 *  数量
 */
@property (nonatomic, strong)UILabel* amountLabel;


@property (nonatomic, strong)UIButton* btn_tx;

@end

@implementation WithDrawTopCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithHex:0xf98505];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        //1.创建标题
        UILabel* lb_title = [UILabel new];
        lb_title.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        lb_title.textColor = [UIColor whiteColor];
        [self.contentView addSubview:lb_title];
        self.titleLabel = lb_title;
        
        //2.创建金额label
        UILabel* lb_amount = [UILabel new];
        lb_amount.font = [UIFont systemFontOfSize:30 * WIDTHRADIU];
        lb_amount.textColor = [UIColor whiteColor];
        [self.contentView addSubview:lb_amount];
        self.amountLabel = lb_amount;
        
        
        //3.灵活理财
        UIButton *btn_tx = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn_tx setTitle:@"灵活理财" forState:UIControlStateNormal];
        btn_tx.backgroundColor = [UIColor colorWithHex:0xf45610];
        [btn_tx setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn_tx.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        btn_tx.frame = CGRectMake(ScreenWidth - 80 * WIDTHRADIU, 37 * WIDTHRADIU, 80 * WIDTHRADIU, 30 * WIDTHRADIU);
        [btn_tx addTarget:self action:@selector(btn_LCClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:btn_tx];
        self.btn_tx = btn_tx;
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:btn_tx.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft) cornerRadii:CGSizeMake(15 * WIDTHRADIU,15 * WIDTHRADIU)];

        //圆角大小
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

        maskLayer.frame = btn_tx.bounds;

        maskLayer.path = maskPath.CGPath;

        btn_tx.layer.mask = maskLayer;

        
        
        [self configFrame];
    }
    return self;
}
- (void)configFrame
{
    self.titleLabel.text = @"我的钱包(元)";
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(15 * WIDTHRADIU);
        make.left.offset(20 * WIDTHRADIU);
    }];
    
    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(15 * WIDTHRADIU);
    }];
}



#pragma mark - public methods
- (void)refreshData
{

    NSDictionary *dic = [getPeopleID totalCoins];
    
    NSNumber *currentotalProfit = dic[@"currentotalProfit"];
                 
    self.amountLabel.text = [getPeopleID totalCoins] ? [LSLDecimalNumberTool stringWithDecimalNumber:currentotalProfit.doubleValue] : @"0.0";
    
}


+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"WithDrawTopCell";
    
    WithDrawTopCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        cell = [[WithDrawTopCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}


#pragma mark - event response
- (void)btn_LCClick:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickEarnMoneyBtnClickWithCell:)]) {
        [self.delegate clickEarnMoneyBtnClickWithCell:self];
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}




@end
