//
//  CustomerOrderTableViewCell.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/6.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CustomerOrderTableViewCell.h"

@implementation CustomerOrderTableViewCell

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

#pragma mark -UI
- (void)uiConfigAction
{
    self.delecteOrder.layer.masksToBounds = YES;
    self.delecteOrder.layer.cornerRadius = kCornerRadius;
    self.cellBackView.layer.masksToBounds = YES;
    self.cellBackView.layer.cornerRadius = kCornerRadius;
    
    [self.consigneeNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.orderAll.mas_left).offset(13);
        make.top.equalTo(self.orderAll.mas_bottom).offset(10);
        
    }];
}

#pragma mark -赋值
- (void)setModel:(OrderBill *)model
{
    _model = model;
    self.orderDate.text = [self dateAsString:_model.order.orderTime];
    self.orderSerialNumber.text = _model.order.orderNumber;
    self.shoppersName.text = _model.employee.userName;
    self.customerName.text = _model.consumer.name;
    [self.customerHeader sd_setImageWithURL:[NSURL URLWithString:_model.consumer.picture] placeholderImage:ReplaceImage];
    self.orderStatus.text = _model.order.orderState;
    self.styleNumber.text = _model.order.goodsNum;
    self.consigneeName.text = _model.order.receiverName;
    self.consigneePhoneNumber.text = _model.order.receiverMobile;
    self.phoneNumber.text = _model.consumer.mobile;
    self.consigneeAddress.text = _model.order.receiverAddress;
    
    NSInteger goodsAllprice = 0;
    for (TOOrderdetailEntity *goodslist in _model.orderdetailList) {
        goodsAllprice += [goodslist.goodsTotalPrice integerValue];
    }
    self.orderTotalPrice.text = [NSString stringWithFormat:@"%ld",goodsAllprice];
    
    //订单状态图片
    self.orderStateImageView.image = [BaseViewController ReturnOrderStateImageWithStateCode:[_model.order.orderState integerValue]];
    
    //订单状态文本
    self.orderStatus.text = [BaseViewController ReturnOrderStateTitleWithStateCode:[_model.order.orderState integerValue] withPoint:CGPointMake(self.orderStatus.frame.origin.x, self.orderStatus.frame.origin.y) WithCode:0];
    self.orderStatus.textColor = [BaseViewController ReturnOrderStateTitleWithStateCode:[_model.order.orderState integerValue] withPoint:CGPointMake(self.orderStatus.frame.origin.x, self.orderStatus.frame.origin.y) WithCode:1];
    
}

#pragma mark -时间转换NSDate转NSString
- (NSString*)dateAsString:(NSDate*)date {
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString * timeString = [formatter stringFromDate:date];
    return timeString;
    
}


#pragma mark -撤销订单
- (IBAction)delecteOrderButtonClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(undoOrderButtonClick:)]) {
        
        [self.delegate undoOrderButtonClick:_cellIndex];
    }
}





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

    // Configure the view for the selected state
}

@end
