CNLiveOrderDetailContentView.m 12.1 KB
//
//  CNLiveOrderDetailContentView.m
//  CNLiveMyOrderModule
//
//  Created by 殷巧娟 on 2019/11/20.
//

#import "CNLiveOrderDetailContentView.h"
#import "Masonry.h"
#import "CNLiveCommonCategory.h"
#import "CNLiveBaseKit.h"
#import "CNLiveOrderList.h"
#define Default_Space 15
//25
#define OrderContent_H  80

@interface OrderDetailContentTitleView : UIView
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *quantityLab;
@property (nonatomic, strong) UILabel *priceLab;
@end

@implementation OrderDetailContentTitleView
- (void)dealloc {
    NSLog(@"OrderDetailContentTitleView dealloc走了吗");
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.titleLab];
        [self addSubview:self.quantityLab];
        [self addSubview:self.priceLab];
        [self p_addMasonry];
    }
    return self;
}
- (void)p_addMasonry {
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(Default_Space);
        make.top.mas_equalTo(self).mas_offset(10);
        make.right.mas_equalTo(self.quantityLab.mas_left).mas_offset(-14);
    }];
    
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).mas_offset(-Default_Space);
        make.top.mas_equalTo(self.titleLab.mas_top);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.2);
    }];
    
    [self.quantityLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.priceLab.mas_left).mas_offset(-10);
        make.top.mas_equalTo(self.titleLab.mas_top);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.2);
    }];
    
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.titleLab.mas_bottom).mas_offset(5);
    }];
}
#pragma mark -
#pragma mark - Getter
- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.text = @"种类";
        _titleLab.font = UIFontCNMake(15);
        _titleLab.textColor = KTextBlackColor;
        _titleLab.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLab;
}

- (UILabel *)quantityLab
{
    if (!_quantityLab) {
        _quantityLab = [[UILabel alloc] init];
        _quantityLab.text = @"数量";
        _quantityLab.font = UIFontCNMake(15);
        _quantityLab.textColor = KTextBlackColor;
        _quantityLab.textAlignment = NSTextAlignmentCenter;
    }
    return _quantityLab;
}

- (UILabel *)priceLab
{
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] init];
        _priceLab.text = @"价格";
        _priceLab.font = UIFontCNMake(15);
        _priceLab.textColor = KTextBlackColor;
        _priceLab.textAlignment = NSTextAlignmentRight;
    }
    return _priceLab;
}
@end
@interface OrderDetailContentItemView : UIView

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *quantityLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *bottomLine;
@property (nonatomic, strong) CNLiveEditGoodsModel *model;
@end
@implementation OrderDetailContentItemView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kWhiteColor;
        [self addSubview:self.titleLab];
        [self addSubview:self.quantityLab];
        [self addSubview:self.priceLab];
        [self addSubview:self.bottomLine];
        
        [self p_addMasonry];
    }
    return self;
}

- (void)setModel:(CNLiveEditGoodsModel *)model {
    
    _model = model;
    _titleLab.text = model.title;
    _quantityLab.text = [NSString stringWithFormat:@"x %ld", model.quantity];
    _priceLab.text = [NSString stringWithFormat:@"¥ %.2f", model.price];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:_priceLab.text];
    [string addAttribute:NSFontAttributeName value:UIFontCNMake(13) range:NSMakeRange(0, 1)];
    _priceLab.attributedText = string;
}

- (void)p_addMasonry {
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(20);
        make.width.mas_equalTo(KScreenWidth - 50);
        make.height.mas_equalTo(14);
    }];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLab.mas_left);
        make.top.mas_equalTo(self.titleLab.mas_bottom).offset(15);
        make.width.mas_equalTo(KScreenWidth - 80);
        make.height.mas_equalTo(15);
    }];
    
    [self.quantityLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).mas_offset(-14);
        make.bottom.mas_equalTo(self.priceLab.mas_bottom);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(13);
    }];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-0.5);
        make.width.mas_equalTo(KScreenWidth - 30);
        make.height.mas_equalTo(0.5);
    }];
    return;
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(Default_Space);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.mas_equalTo(self.quantityLab.mas_left).mas_offset(-10);
    }];
    
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).mas_offset(-Default_Space);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.2);
    }];
    
    [self.quantityLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.priceLab.mas_left).mas_offset(-10);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.2);
    }];
    
}

#pragma mark -
#pragma mark - Getter
- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = UIFontCNMake(15);
        _titleLab.textColor = KGray101Color;
        _titleLab.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLab;
}

- (UILabel *)quantityLab
{
    if (!_quantityLab) {
        _quantityLab = [[UILabel alloc] init];
        _quantityLab.font = UIFontCNMake(15);
        _quantityLab.textColor = KGray101Color;
        _quantityLab.textAlignment = NSTextAlignmentCenter;
    }
    return _quantityLab;
}

- (UILabel *)priceLab
{
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] init];
        _priceLab.font = UIFontCNMake(15);
        _priceLab.textColor = KGray101Color;
        _priceLab.textAlignment = NSTextAlignmentLeft;
    }
    return _priceLab;
}
- (UILabel *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine = [[UILabel alloc] init];
        _bottomLine.backgroundColor = KGray227Color;
    }
    return _bottomLine;
}
@end
@interface OrderDetailContentCollectView : UIView
@property (nonatomic, strong) NSMutableArray *modelArr;
@property (nonatomic ,strong) NSArray <CNLiveEditGoodsModel *>*  goodsInfo;

@end
@implementation OrderDetailContentCollectView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kWhiteColor;
    }
    return self;
}
- (void)setModelArr:(NSMutableArray *)modelArr {
    
    __block OrderDetailContentItemView *tempView;
    
    for (int i = 0 ; i < modelArr.count; i ++ ) {
        
        OrderDetailContentItemView *contentView = [[OrderDetailContentItemView alloc] init];
        contentView.model = (CNLiveEditGoodsModel *)modelArr[i];
        [self addSubview:contentView];
        
        [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self);
            make.height.mas_equalTo(OrderContent_H);
            if (tempView) {
                make.top.mas_equalTo(contentView.mas_bottom);
            } else {
                make.top.mas_equalTo(0);
            }
            tempView = contentView;
        }];
        
    }
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(OrderContent_H*modelArr.count);
    }];
}
- (void)setGoodsInfo:(NSArray <CNLiveEditGoodsModel *>*)goodsInfo {
    
    __block OrderDetailContentItemView *tempView;
    
    for (int i = 0 ; i < goodsInfo.count; i ++ ) {
        
        OrderDetailContentItemView *contentView = [[OrderDetailContentItemView alloc] init];
        contentView.model = (CNLiveEditGoodsModel *)goodsInfo[i];
        [self addSubview:contentView];
        
        [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self);
            make.height.mas_equalTo(OrderContent_H);
            if (tempView) {
                make.top.mas_equalTo(tempView.mas_bottom);
            } else {
                make.top.mas_equalTo(0);
            }
            tempView = contentView;
        }];
    }
    
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(OrderContent_H*[goodsInfo count]);
    }];
}
@end
@interface CNLiveOrderDetailContentView ()
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) OrderDetailContentTitleView *contentTitleView;
@property (nonatomic, strong) OrderDetailContentCollectView *contentCollectView;
@end
@implementation CNLiveOrderDetailContentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kWhiteColor;
        [self addSubview:self.titleLab];
        [self addSubview:self.line];
        //        [self addSubview:self.contentTitleView];
        [self addSubview:self.contentCollectView];
        [self p_addMasonry];
    }
    return self;
}

- (void)setList:(CNLiveOrderList *)list {
    CNLiveOrderListOrderItem *orderItem = list.orderItem;
    
    if ([orderItem.goodsInfo count] > 0) {
        _contentCollectView.goodsInfo = orderItem.goodsInfo;
    } else {
        NSMutableArray *modelArr = [[NSMutableArray alloc] init];
        CNLiveEditGoodsModel *goodsModel = [[CNLiveEditGoodsModel alloc] init];
        goodsModel.title = orderItem.title;
        goodsModel.quantity = orderItem.quantity;
        goodsModel.price = orderItem.price;
        [modelArr addObject:goodsModel];
        _contentCollectView.modelArr = modelArr;
    }
    
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentCollectView.mas_bottom).mas_offset(5);
    }];
}

- (void)p_addMasonry {
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(15);
        make.top.mas_equalTo(self).mas_offset(15);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLab.mas_bottom).mas_offset(15);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo(KScreenWidth-20);
        make.height.mas_equalTo(0.5);
    }];
    
    
    [self.contentCollectView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.line.mas_bottom);
        make.left.right.mas_equalTo(self);
    }];
}

#pragma mark -
#pragma mark - Getter
- (OrderDetailContentTitleView *)contentTitleView
{
    if (!_contentTitleView) {
        _contentTitleView = [[OrderDetailContentTitleView alloc] init];
    }
    return _contentTitleView;
}

- (OrderDetailContentCollectView *)contentCollectView
{
    if (!_contentCollectView) {
        _contentCollectView = [[OrderDetailContentCollectView alloc] init];
    }
    return _contentCollectView;
}

- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = KTextBlackColor;
        _titleLab.font = UIFontCNMake(15);
        _titleLab.text = @"商品信息";
    }
    return _titleLab;
}
- (UIView *)line
{
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = KCommonLineColor;
    }
    return _line;
}
@end