KWMOrderCell.m 5.05 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9 10 11 12 13
//
//  KWMOrderCell.m
//  iCemarose
//
//  Created by HouWeiBin on 16/8/30.
//  Copyright © 2016年 kollway. All rights reserved.
//

#import "KWMOrderCell.h"
#import "KWMImageUtil.h"
#import "UIImageView+WebCache.h"
#import "UIColor+SAMAdditions.h"
#import "KWMStringUtil.h"
lee committed
14
#import "KWMCurrencyUtil.h"
houweibin committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

@implementation KWMOrderCell{
    BOOL isShow;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    isShow = NO;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickOrder)];
    [_vContent addGestureRecognizer:tapGesture];
    [_ivImage.layer setMasksToBounds:YES];
    _ivImage.layer.cornerRadius = 1; //圆角(圆形)
    _ivImage.layer.borderColor  = [UIColor sam_colorWithHex:@"545454"].CGColor; //要设置的颜色
    _ivImage.layer.borderWidth = 1; //要设置的描边宽
}

- (void)onClickOrder{
    if ([self.delegate respondsToSelector:@selector(kwm_onClickProduct:)]) {
        NSNumber *productId = _lineItem.productId;
        [self.delegate kwm_onClickProduct:productId];
    }
}

- (void)setMarkSection:(NSInteger)markSection{
    _markSection = markSection;
}

houweibin committed
43 44 45 46 47 48 49 50
- (void)setLineCount:(NSInteger)lineCount{
    _lineCount = lineCount;
        [self.btnFooter setTitle:[NSString stringWithFormat:@"共%ld件商品,查看剩余%ld件商品",(long)lineCount,(lineCount - 4)] forState:UIControlStateNormal];
}

- (void)setImageUrl:(NSString *)imageUrl{
    NSURL *imageURL = [NSURL URLWithString:imageUrl];
    [self.ivImage sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
houweibin committed
51 52 53 54 55 56
}

- (void)setOrder:(BUYOrder *)order{
    if (order != nil) {
        _order = order;
        _lbOrderNum.text = [NSString stringWithFormat:@"订单 %@",order.identifier ? order.identifier.stringValue:@""];
lee committed
57
//        _lbTotalPrice.text = [NSString stringWithFormat:@"%@",[KWMStringUtil getEUR2CNYstring:order.totalPrice]];
lee committed
58 59
//        _lbTotalPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:order.totalPrice];
        _lbTotalPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormatted:order.totalPrice currencyCode:order.currency];
lee committed
60 61 62 63 64 65 66
        
        __block NSInteger fulfilledCount = 0;
        [order.lineItems enumerateObjectsUsingBlock:^(BUYLineItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (obj.fulfilledValue) {
                fulfilledCount += 1;
            }
        }];
lee committed
67 68
        NSString *orderStatus = order.cancelled ? @"已取消" : fulfilledCount == 0 ? @"待发货" : fulfilledCount == order.lineItems.count ? @"已发货" : @"部分发货";
        self.lbOrderStatus.text = orderStatus;
houweibin committed
69 70 71 72 73 74
    }
}

- (void)setLineItem:(BUYLineItem *)lineItem{
    if (lineItem != nil) {
        _lineItem = lineItem;
lee committed
75
//        self.lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:lineItem.price]];
lee committed
76 77
//        self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormattedByCurrencyCode:lineItem.price];
        self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormatted:lineItem.price currencyCode:@"EUR"];
houweibin committed
78 79
        self.lbName.text = lineItem.title;
        self.lbSize.text = [NSString stringWithFormat:@"x%@/%@",lineItem.quantity,lineItem.variantTitle];
houweibin committed
80 81 82 83 84 85 86 87
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

houweibin committed
88
-(void)updateUI:(NSInteger)position productCount:(NSInteger)productCount showAll:(bool)showAll{
houweibin committed
89 90 91
    isShow = showAll;//记录是否展开
    if(position == 0){
        self.vHeader.hidden = NO;
92 93
        //self.headerHeight.constant = 80;
        self.headerHeight.constant = 45;
houweibin committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    }else{
        self.vHeader.hidden = YES;
        self.headerHeight.constant = 0;
    }
    //全部没选中时,显示footView
    //选中某个section,但不选中当前的,显示footView
    if (productCount > 4) {
        self.btnFooter.hidden = NO;
        self.footHeight.constant = 40;
    }else{
        self.btnFooter.hidden = YES;
        self.footHeight.constant = 0;
    }
    
    //设置展开收起的订单footerView的title
    if (!showAll && productCount > 4) {
houweibin committed
110 111
        if (self.lineCount) {
            [self.btnFooter setTitle:[NSString stringWithFormat:@"共%ld件商品,查看剩余%ld件商品",(long)self.lineCount,(self.lineCount - 4)] forState:UIControlStateNormal];
houweibin committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
            [self.btnFooter setImage:nil forState:UIControlStateNormal];
        }
    }else if(showAll && productCount > 4){
        [self.btnFooter setImage:[UIImage imageNamed:@"button_myorder_pull-up"] forState:UIControlStateNormal];
        [self.btnFooter setTitle:@"" forState:UIControlStateNormal];
    }
}

-(void)onClickShowOther:(id)sender{
    if(self.delegate!=nil){
        [self.delegate kwm_onClickShowAllWith:_markSection And:isShow];
    }
}

-(void)onClickTransport:(id)sender{
    if(self.delegate!=nil){
        [self.delegate kwm_onClickTrandsport:_order];
    }
}

-(void)onClickCancelOrder:(id)sender{
    if(self.delegate!=nil){
        [self.delegate kwm_onClickCancelOrder:_order];
    }
}

@end