//
//  PurchaseCell.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/8/23.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "PurchaseCell.h"
#define TitleSize 16
#define LeftMargin 90
#define TopMargin 10
#define TitleHeight 20
#define TableHeight 120

@implementation PurchaseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self bulidLayout];
    }
    return self;
}

- (void)bulidLayout
{
    self.stateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
    self.stateBtn.titleLabel.font = GXF_FOURTEENTH_SIZE;
//    self.stateBtn.backgroundColor = [UIColor redColor];

    [self.stateBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.stateBtn.enabled = NO;
    
    self.billNumberLabel = [[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, TopMargin, ScreenSize.width - LeftMargin, TitleHeight))];
    self.billNumberLabel.textColor = GXF_CONTENT_COLOR;
    self.billNumberLabel.font = GXF_SIXTEENTEH_SIZE;
    
    self.noticeNumberLabel = [[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, CGRectGetMaxY(self.billNumberLabel.frame), ScreenSize.width - LeftMargin, TitleHeight))];
    self.noticeNumberLabel.numberOfLines = 0;
    self.noticeNumberLabel.textColor = GXF_CELL_COLOR;
    self.noticeNumberLabel.font = GXF_FOURTEENTH_SIZE;
    
    self.vendorLabel = [[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, CGRectGetMaxY(self.noticeNumberLabel.frame), ScreenSize.width - LeftMargin, TitleHeight))];
    self.vendorLabel.textColor = GXF_CELL_COLOR;
    self.vendorLabel.font = GXF_FOURTEENTH_SIZE;
    
    self.createOperNameLabel = [[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, CGRectGetMaxY(self.vendorLabel.frame), ScreenSize.width - LeftMargin, TitleHeight))];
    self.createOperNameLabel.textColor = GXF_CELL_COLOR;
    self.createOperNameLabel.font = GXF_FOURTEENTH_SIZE;
    
    
    self.createTimeLabel = [[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin, CGRectGetMaxY(self.createOperNameLabel.frame), ScreenSize.width - LeftMargin, TitleHeight))];
    self.createTimeLabel.textColor = GXF_CELL_COLOR;
    self.createTimeLabel.font = GXF_FOURTEENTH_SIZE;
    
    self.lineLabel = [[UILabel alloc]initWithFrame:(CGRectMake(LeftMargin,TableHeight-1, ScreenSize.width - LeftMargin - TopMargin * 2, 1))];;
    self.lineLabel.backgroundColor = GXF_LINE_COLOR;
    
    [self.contentView addSubview:self.stateBtn];
    [self.contentView addSubview:self.billNumberLabel];
    [self.contentView addSubview:self.noticeNumberLabel];
    [self.contentView addSubview:self.vendorLabel];
    [self.contentView addSubview:self.createOperNameLabel];
    [self.contentView addSubview:self.createTimeLabel];
    [self.contentView addSubview:self.lineLabel];
    
}

- (void)setPurchaseBill:(PurchaseBill *)purchaseBill{
    self.billNumberLabel.text = [NSString stringWithFormat:@"单号：%@",purchaseBill.billNumber];
    self.noticeNumberLabel.text = [NSString stringWithFormat:@"采购通知单号：%@",purchaseBill.noticeNumber.length > 0 ? purchaseBill.noticeNumber: @"无"];
    self.vendorLabel.text = [NSString stringWithFormat:@"供应商：%@[%@]",purchaseBill.vendor_name,purchaseBill.vendor_code] ;
    self.createOperNameLabel.text = [NSString stringWithFormat:@"创建人：%@",purchaseBill.create_operName] ;
    self.createTimeLabel.text =[NSString stringWithFormat:@"创建时间：%@",purchaseBill.create_time];
    NSString *stateStr = @"";
//    if ([purchaseBill.vendor_code isEqualToString:@"0000"]) {
//        purchaseBill.state = PURCHASE_STATE_PROCESS;
//    }
    if ([purchaseBill.state isEqualToString:PURCHASE_STATE_INITIAL]) {
        self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
        stateStr = @"未提交";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"initial"]  forState:UIControlStateDisabled];
    }else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_SUBMITTED]) {
         self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
        stateStr = @"未审批";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"insurvey"] forState:UIControlStateDisabled];
    }else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_REJECTED]) {
         self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
        stateStr = @"已拒绝";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"initial"] forState:UIControlStateDisabled];
        
    }else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_SHIPPING]) {
         self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
        stateStr = @"发运中";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"insurvey"] forState:UIControlStateDisabled];
    }
    else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_FINISHED]) {
         self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
        stateStr = @"已完成";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"finish"] forState:UIControlStateDisabled];
    }else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_ABORTED]) {
         self.stateBtn.frame = CGRectMake(TopMargin *2 , TopMargin, LeftMargin - TopMargin*3, 20);
        stateStr = @"已作废";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"finish"] forState:UIControlStateDisabled];
    }else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_PROCESS]) {
//         self.stateBtn.frame = CGRectMake(0 , TopMargin, LeftMargin - TopMargin, 20);
        stateStr = @"提交系统处理";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"finish"] forState:UIControlStateDisabled];
    }else if ([purchaseBill.state isEqualToString:PURCHASE_STATE_PROCESSFAIL]) {
//         self.stateBtn.frame = CGRectMake(0 , TopMargin, LeftMargin - TopMargin, 20);
        stateStr = @"系统处理失败";
        [self.stateBtn setBackgroundImage:[UIImage imageNamed:@"finish"] forState:UIControlStateDisabled];
    }
    
    [self.stateBtn setTitle:stateStr forState:UIControlStateNormal];
}


- (void)awakeFromNib {
    // Initialization code
}

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

    // Configure the view for the selected state
}

@end
