SaleViewCell.m 6.38 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  SaleViewCell.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/11/8.
//  Copyright © 2015年 Xummer. All rights reserved.
//

#import "SaleViewCell.h"

#define Sale_Cell_Height  50
12 13
#define Left_Width 110
#define Left_margin 5
陈俊俊's avatar
陈俊俊 committed
14 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 43 44 45 46
@interface SaleViewCell ()
{
    BOOL    hasBuildLayout;         // default, NO;
}

@property (nonatomic, strong) UIFont *textFont;
@property (nonatomic, strong) UIFont *titleFont;

@property (nonatomic, strong) NSIndexPath *indexPath;

@end


@implementation SaleViewCell


+ (CGFloat)cellHeight
{
    return Sale_Cell_Height;
}

#pragma mark - build view

- (void)buildLayout
{
    if(hasBuildLayout) {
        return;
    }
    
    hasBuildLayout = YES;
    
    
    if(self.textFont == nil) {
陈俊俊's avatar
陈俊俊 committed
47
        self.textFont = [UIFont systemFontOfSize:15];
陈俊俊's avatar
陈俊俊 committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
    }
    
    if(self.titleFont == nil) {
        self.titleFont = [UIFont systemFontOfSize:17];
    }
    
    //页面布局
    [self createView];
}

//创建视图
- (void)createView
{

62 63 64 65 66 67 68
    CGRect rect = CGRectMake(Left_margin,5, Left_Width, Sale_Cell_Height/2);
    self.nameLabel = [IBTCommon labelWithTitle:@"第一片区" frame:rect textFont:self.textFont];
    [self.contentView addSubview:self.nameLabel];
    
    rect = CGRectMake(Left_margin,self.nameLabel.bottom, Left_Width, Sale_Cell_Height/2-10);
    
    self.dqLabel = [IBTCommon labelWithTitle:@"0101" frame:rect textFont:self.textFont];
陈俊俊's avatar
陈俊俊 committed
69 70
    [self.contentView addSubview:self.dqLabel];
    
陈俊俊's avatar
陈俊俊 committed
71
    CGFloat width = (ScreenSize.width - self.dqLabel.right - 35)/3;
陈俊俊's avatar
陈俊俊 committed
72
    
陈俊俊's avatar
陈俊俊 committed
73
    rect = CGRectMake(self.dqLabel.right , 0, width+10, Sale_Cell_Height);
陈俊俊's avatar
陈俊俊 committed
74 75 76 77
    self.saleLabel = [IBTCommon labelWithTitle:@"56,080" frame:rect textFont:self.textFont];
    [self.contentView addSubview:self.saleLabel];
    
    rect = CGRectMake(self.saleLabel.right, 0, width, Sale_Cell_Height);
78
      self.lastWeekLabel = [IBTCommon buttonWithTitle:@"" Image:nil frame:rect fontSize:15 fontColor:ReportContentColor];
79
    self.lastWeekLabel.enabled = NO;
陈俊俊's avatar
陈俊俊 committed
80
    self.lastWeekLabel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;
陈俊俊's avatar
陈俊俊 committed
81 82
    [self.contentView addSubview:self.lastWeekLabel];
    
陈俊俊's avatar
陈俊俊 committed
83
    
陈俊俊's avatar
陈俊俊 committed
84
    rect = CGRectMake(self.lastWeekLabel.right, 0, width-10, Sale_Cell_Height);
陈俊俊's avatar
陈俊俊 committed
85
    self.rateLabel = [IBTCommon labelWithTitle:@"60%" frame:rect textFont:self.textFont];
86
    self.rateLabel.textColor = GXF_COMMIT_COLOR;
陈俊俊's avatar
陈俊俊 committed
87 88
    [self.contentView addSubview:self.rateLabel];

陈俊俊's avatar
陈俊俊 committed
89
    rect = CGRectMake(self.rateLabel.right, 0, 35, Sale_Cell_Height);
陈俊俊's avatar
陈俊俊 committed
90
    self.detailBtn = [IBTCommon buttonWithTitle:@"" Image:[UIImage imageNamed:@"more_detail"] frame:rect fontSize:20 fontColor:ReportBgColor];
陈俊俊's avatar
陈俊俊 committed
91 92 93 94 95
    self.detailBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [self.contentView addSubview:self.detailBtn];
    
    
    self.lineLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0, Sale_Cell_Height - 1, ScreenSize.width, 1))];
96
    self.lineLabel.backgroundColor = GXF_LINE_COLOR;
陈俊俊's avatar
陈俊俊 committed
97
    [self.contentView addSubview:self.lineLabel];
陈俊俊's avatar
陈俊俊 committed
98 99 100 101 102 103
    
}


#pragma mark - update view

104
- (void)updateCellWith:(Compass *)sale index:(NSIndexPath *)indexPath
陈俊俊's avatar
陈俊俊 committed
105 106 107 108
{
    self.indexPath = indexPath;
    
    [self buildLayout];
陈俊俊's avatar
陈俊俊 committed
109
    //组织name
110 111
    self.dqLabel.text = sale.orgCode;
    self.nameLabel.text = sale.orgName;
112
    
陈俊俊's avatar
陈俊俊 committed
113 114
    //销售环比变化率
    if ([sale.salesChainSign isEqualToString:ReportChainSignPlus]) {
115
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateDisabled];
116
        [self.lastWeekLabel setTitleColor:ReportContentColor forState:UIControlStateNormal];
117 118
        self.saleLabel.textColor = ReportContentColor;

陈俊俊's avatar
陈俊俊 committed
119
    }else{
120
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateDisabled];
121
        [self.lastWeekLabel setTitleColor:GXF_NAVIGAYION_COLOR forState:UIControlStateNormal];
122
        self.saleLabel.textColor = GXF_NAVIGAYION_COLOR;
陈俊俊's avatar
陈俊俊 committed
123
    }
124 125 126
    //销售额
    self.saleLabel.text = sale.sales?[sale.sales stringValue] : @"0";
    
陈俊俊's avatar
陈俊俊 committed
127
    NSString *salesYoStr = [NSString stringWithFormat:@"%@%%",sale.salesChainRate];
128
    [self.lastWeekLabel setTitle:salesYoStr forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
129 130 131
    //销售目标达成率
    NSString *salesTargetRateStr = [NSString stringWithFormat:@"%@%%",sale.salesTargetRate];
    self.rateLabel.text = salesTargetRateStr;
132 133 134 135 136 137 138
    [self setColorAndFont:sale.level];
}
- (void)setColorAndFont:(NSInteger)level{
    if (level == 0) {
        self.dqLabel.textColor = GXF_CONTENT_COLOR;
        self.nameLabel.textColor = GXF_CONTENT_COLOR;
        self.lineLabel.hidden = NO;
139 140 141 142 143 144 145
        [self setFontLabel:17];
        [self setWidthDQ:0];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }else if (level == 1) {
        self.dqLabel.textColor = [UIColor blackColor];
        self.nameLabel.textColor = [UIColor blackColor];
        self.lineLabel.hidden = NO;
146 147 148
        [self setFontLabel:15];
        [self setWidthDQ:0];
        self.contentView.backgroundColor = [UIColor whiteColor];
149
    }else if(level == 2){
150 151 152
        self.lineLabel.hidden = NO;
        self.dqLabel.textColor = GXF_LEFTSIX_COLOR;
        self.nameLabel.textColor = GXF_LEFTSIX_COLOR;
153
        [self setWidthDQ:5];
154 155 156 157
        [self setFontLabel:13];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }else {
        self.lineLabel.hidden = YES;
158 159
        self.dqLabel.textColor = ReportTwoColor;
        self.nameLabel.textColor = ReportTwoColor;
160
        [self setFontLabel:12];
陈俊俊's avatar
陈俊俊 committed
161
         [self setWidthDQ:10];
162 163 164 165 166
        self.contentView.backgroundColor = XXFBgColor;
        
    }
}
- (void)setFontLabel:(NSInteger)fontSize{
167
    self.dqLabel.font = FontSize(fontSize-2);
168 169
    self.nameLabel.font = FontSize(fontSize);
    self.saleLabel.font = FontSize(fontSize);
170
    self.lastWeekLabel.titleLabel.font = FontSize(fontSize);
171 172 173 174 175
    self.rateLabel.font = FontSize(fontSize);
}
- (void)setWidthDQ:(NSInteger)width{
    self.lineLabel.left = width;
    self.lineLabel.width = ScreenSize.width - width;
176 177 178 179 180 181 182 183 184 185 186
    if (width > 0) {
        self.nameLabel.left = width + 5;
        self.nameLabel.width = ScreenSize.width - width - 5;
        self.dqLabel.left = width + 5;
        self.dqLabel.width = ScreenSize.width - width - 5;
    }else{
        self.nameLabel.left = 5;
        self.nameLabel.width = ScreenSize.width - 5;
        self.dqLabel.left = 5;
        self.dqLabel.width = ScreenSize.width - 5;
    }
陈俊俊's avatar
陈俊俊 committed
187 188 189 190 191 192 193 194 195
}

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

    // Configure the view for the selected state
}

@end