KWMCollectionCell.m 2.78 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9 10 11 12
//
//  KWMCollectionCell.m
//  iCemarose
//
//  Created by 陈荣科 on 16/9/1.
//  Copyright © 2016年 kollway. All rights reserved.
//

#import "KWMCollectionCell.h"
#import "UIImageView+WebCache.h"
#import "KWMImageUtil.h"
#import "KWMStringUtil.h"
lee committed
13
#import "BUYProductVariant+Currency.h"
houweibin committed
14

lee committed
15 16
@interface KWMCollectionCell ()

houweibin committed
17 18
@property (nonatomic, weak) IBOutlet UIView *vMore;

lee committed
19 20 21 22
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *priceSpace;

@end

houweibin committed
23 24 25 26 27 28 29 30 31
@implementation KWMCollectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.lbDiscount.textAlignment = NSTextAlignmentLeft;
    self.lbPrice.textAlignment = NSTextAlignmentRight;
}

houweibin committed
32 33 34 35 36
-(void)setIsMore:(BOOL)isMore{
    _isMore = isMore;
    self.vMore.hidden = !isMore;
}

houweibin committed
37 38 39 40
-(void)setData:(BUYProduct *)product{
    if(product!=nil){
        self.product = product;
        self.lbBrand.text = product.title;
houweibin committed
41
        NSString *imageUrl = [KWMImageUtil getProductImageUrl:product ImageSize:SmallImage];
houweibin committed
42 43 44 45 46 47 48
        NSURL *imageURL = [NSURL URLWithString:imageUrl];
        [self.ivCollectionCell sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];

        BUYProductVariant *productVariant = product.variants.firstObject;
        if(productVariant == nil){
            return;
        }
lee committed
49 50 51
//        self.discountLeft.constant = 5;
//        self.lbPrice.textAlignment = NSTextAlignmentRight;
//        self.lbDiscount.textAlignment = NSTextAlignmentLeft;
houweibin committed
52 53 54
        
        NSString *priceString,*discountStr;
        if (productVariant.compareAtPrice) {
lee committed
55 56
            self.lbPrice.hidden = NO;
            self.priceSpace.constant = 4;
lee committed
57 58
//            priceString = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.compareAtPrice]];
            priceString = productVariant.compareAtPriceFormatted;
houweibin committed
59 60 61 62 63
            NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
            NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
            self.lbPrice.attributedText = attribtStr;
        }else{
            self.lbPrice.hidden = YES;
lee committed
64
            self.lbPrice.text = nil;
lee committed
65 66 67
            self.priceSpace.constant = 0;
//            self.discountLeft.constant = -28;
//            self.lbDiscount.textAlignment = NSTextAlignmentCenter;
houweibin committed
68
        }
lee committed
69 70
//        discountStr = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:productVariant.price]];
        discountStr = productVariant.priceFormatted;
houweibin committed
71 72 73 74 75 76 77 78 79 80 81
        self.lbDiscount.text = discountStr;
    }else{
        self.lbBrand.text = @"";
        self.lbDiscount.text = @"";
        self.lbPrice.text = @"";
        [self.ivCollectionCell setImage:[UIImage imageNamed:@"ic_loading"]];
    }
}


@end