CNLiveTradingRecordDetailHeaderView.m 5.9 KB
//
//  CNLiveTradingRecordDetailHeaderView.m
//  CNLiveBalanceModule
//
//  Created by CNLive-zxw on 2019/9/6.
//  Copyright © 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveTradingRecordDetailHeaderView.h"
#import <Masonry/Masonry.h>
#import "CNLiveBaseKit.h"
#import "QMUIKit.h"
#import "CNLiveCategory.h"
#import <SDWebImage/SDWebImage.h>
#import "CNLiveTradingRecordModel.h"

@interface CNLiveTradingRecordDetailHeaderView ()
@property (nonatomic, strong) UIImageView *shopIcon;
@property (nonatomic, strong) UILabel *shopName;

@property (nonatomic, strong) UILabel *money;
@property (nonatomic, strong) UILabel *tips;

@end

@implementation CNLiveTradingRecordDetailHeaderView
static const NSInteger margin = 10;
static const NSInteger height = 50;

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    [self addSubview:self.shopIcon];
    [self addSubview:self.shopName];
    [self addSubview:self.money];
    [self addSubview:self.tips];
    
    [self.money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self);
    }];
    [self.tips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-margin);
        make.centerX.equalTo(self);
        make.height.offset(40);
    }];
}

- (void)setModel:(CNLiveTradingRecordListModel *)model {
    _model = model;
    if (![model.sum containsString:@"-"]) {
        self.money.text = [NSString stringWithFormat:@"+%@",model.sum];
    } else {
        self.money.text = model.sum;//[NSString stringWithFormat:@"%.2f",model.money];
    }
    if ([model.sourceType containsString:@"refill"] || [model.sourceType isEqualToString:@"group_vote"] || [model.sourceType containsString:@"refund"]) {
        // 收入
        self.tips.text = @"收款金额";
        if ([model.payType isEqualToString:@"ali"]) {
            self.shopIcon.image = [self getImageWithImageName:@"trading_record_ali_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
            self.shopName.text = @"支付宝支付";
        } else if ([model.payType isEqualToString:@"wechat"]) {
            self.shopIcon.image = [self getImageWithImageName:@"trading_record_wechat_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
            self.shopName.text = @"微信支付";
        } else if ([model.payType isEqualToString:@"wjj"]) {
            self.shopIcon.image = [self getImageWithImageName:@"trading_record_wjj_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
            self.shopName.text = @"网家家支付";
        } else if ([model.payType isEqualToString:@"union"]) {
            self.shopIcon.image =  [self getImageWithImageName:@"trading_record_union_pay" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
            self.shopName.text = @"银行卡";
        } else {
            self.shopIcon.image = [UIImage imageNamed:@""];
            self.shopName.text = @"未知";
        }
    } else if ([model.sourceType containsString:@"order"] || [model.sourceType containsString:@"payment"]) {
        // 支出
        self.tips.text = @"付款金额";
        self.shopIcon.layer.cornerRadius = 15.0;
        self.shopIcon.layer.masksToBounds = YES;
        UIImage *xw_image = [self getImageWithImageName:@"default_avatar_f" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
        [self.shopIcon sd_setImageWithURL:[NSURL URLWithString:model.iconBean.image] placeholderImage:xw_image];
        self.shopName.text = model.iconBean.nickName?model.iconBean.nickName:@"未知";
    }
    
    NSDictionary *dic = @{NSFontAttributeName:UIFontCNMake(16)};
    CGFloat width = [self.shopName.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingUsesLineFragmentOrigin |  NSStringDrawingUsesFontLeading attributes:dic context:nil].size.width+margin;
    if(width >= SCREEN_WIDTH){
        width = SCREEN_WIDTH-40;
    }
    [_shopName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset((SCREEN_WIDTH-width)/2.0+2*margin);
        make.right.mas_lessThanOrEqualTo(self.mas_right).with.offset(-margin);
        make.top.equalTo(self.mas_top).with.offset(margin);
        make.width.offset(width);
        make.height.offset(40);

    }];
    
    [_shopIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.shopName.mas_left).with.offset(-margin);
        make.centerY.equalTo(self.shopName.mas_centerY);
        make.width.height.offset(30);
    }];
}

#pragma mark - 懒加载
- (UIImageView *)shopIcon {
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        _shopIcon.contentMode = UIViewContentModeScaleAspectFill;
        _shopIcon.backgroundColor = [UIColor whiteColor];
        _shopIcon.image = [UIImage imageNamed:@"ye_wxzffs"]; //fenlei_touxiang2
    }
    return _shopIcon;
}

- (UILabel *)shopName {
    if (!_shopName) {
        _shopName = [[UILabel alloc] init];
        _shopName.textColor = [UIColor blackColor];
        _shopName.font = UIFontCNMake(16);//[UIFont fontWithName:@"PingFangSC-Regular" size:16.0f];
    }
    return _shopName;
}

- (UILabel *)money {
    if (!_money) {
        _money = [[UILabel alloc] init];
        _money.textColor = RGB(34, 34, 34);
        _money.font = UIFontCNMake(36);//[UIFont fontWithName:@"PingFangSC-Regular" size:36];
        _money.textAlignment = NSTextAlignmentCenter;
    }
    return _money;
}

- (UILabel *)tips {
    if (!_tips) {
        _tips = [[UILabel alloc] init];
        _tips.text = @"付款金额";
        _tips.textColor = RGB(156, 156, 156);
        _tips.font = UIFontCNMake(15);//[UIFont fontWithName:@"PingFangSC-Regular" size:15];
        _tips.textAlignment = NSTextAlignmentCenter;
    }
    return _tips;
}

@end