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

#import "PasengerCell.h"
#define Sale_Cell_Height  50
11 12
#define Left_Width 155
#define Left_margin 5
陈俊俊's avatar
陈俊俊 committed
13 14 15 16 17 18 19 20 21 22 23 24 25
@interface PasengerCell ()


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

@property (nonatomic, strong) NSIndexPath *indexPath;

@end


@implementation PasengerCell

陈俊俊's avatar
陈俊俊 committed
26 27 28 29 30 31 32
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildLayout];
    }
    return self;
}
陈俊俊's avatar
陈俊俊 committed
33 34 35 36 37 38 39 40 41 42

+ (CGFloat)cellHeight
{
    return Sale_Cell_Height;
}

#pragma mark - build view

- (void)buildLayout
{
陈俊俊's avatar
陈俊俊 committed
43

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

//创建视图
- (void)createView
{
    
60 61 62 63 64
    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);
陈俊俊's avatar
陈俊俊 committed
65
    
66 67 68
    self.dqLabel = [IBTCommon labelWithTitle:@"0101" frame:rect textFont:self.textFont];
    [self.contentView addSubview:self.dqLabel];

陈俊俊's avatar
陈俊俊 committed
69
    CGFloat width = (ScreenSize.width - self.dqLabel.right - 35)/2;
陈俊俊's avatar
陈俊俊 committed
70 71 72 73 74 75
    
    rect = CGRectMake(self.dqLabel.right , 0, width, Sale_Cell_Height);
    self.saleLabel = [IBTCommon labelWithTitle:@"60.0" frame:rect textFont:self.textFont];
    [self.contentView addSubview:self.saleLabel];
    
    rect = CGRectMake(self.saleLabel.right, 0, width, Sale_Cell_Height);
76
    self.lastWeekLabel = [IBTCommon buttonWithTitle:@"" Image:nil frame:rect fontSize:15 fontColor:ReportContentColor];
77
    self.lastWeekLabel.enabled = NO;
陈俊俊's avatar
陈俊俊 committed
78
    self.lastWeekLabel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;
陈俊俊's avatar
陈俊俊 committed
79 80
    [self.contentView addSubview:self.lastWeekLabel];
    
陈俊俊's avatar
陈俊俊 committed
81
    rect = CGRectMake(self.lastWeekLabel.right, 0, 35, Sale_Cell_Height);
陈俊俊's avatar
陈俊俊 committed
82
    self.detailBtn = [IBTCommon buttonWithTitle:@"" Image:[UIImage imageNamed:@"more_detail"]  frame:rect fontSize:20 fontColor:ReportBgColor];
陈俊俊's avatar
陈俊俊 committed
83 84 85 86 87
    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))];
88
    self.lineLabel.backgroundColor = GXF_LINE_COLOR;
陈俊俊's avatar
陈俊俊 committed
89
    [self.contentView addSubview:self.lineLabel];
陈俊俊's avatar
陈俊俊 committed
90 91 92 93 94
    
}


#pragma mark - update view
陈俊俊's avatar
陈俊俊 committed
95
//客单价
96
- (void)updateCellWithPrice:(Compass *)sale index:(NSIndexPath *)indexPath
陈俊俊's avatar
陈俊俊 committed
97 98
{
    self.indexPath = indexPath;
陈俊俊's avatar
陈俊俊 committed
99
    //组织name
100 101
    self.dqLabel.text = sale.orgCode;
    self.nameLabel.text = sale.orgName;
陈俊俊's avatar
陈俊俊 committed
102
    //客单价
103
    self.saleLabel.text = [sale.persales stringValue];
陈俊俊's avatar
陈俊俊 committed
104 105
    //客单价比变化率
    if ([sale.persalesChainSign isEqualToString:ReportChainSignPlus]) {
106
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateDisabled];
107
        [self.lastWeekLabel setTitleColor:ReportContentColor forState:UIControlStateNormal];
108 109
        self.saleLabel.textColor = ReportContentColor;

陈俊俊's avatar
陈俊俊 committed
110
    }else{
111
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateDisabled];
112
        [self.lastWeekLabel setTitleColor:GXF_NAVIGAYION_COLOR forState:UIControlStateNormal];
113 114
        self.saleLabel.textColor = GXF_NAVIGAYION_COLOR;

陈俊俊's avatar
陈俊俊 committed
115 116
    }
    NSString *salesYoStr = [NSString stringWithFormat:@"%@%%",sale.persalesChainRate];
117 118
    [self.lastWeekLabel setTitle:salesYoStr forState:UIControlStateNormal];
    [self setColorAndFont:sale.level];
陈俊俊's avatar
陈俊俊 committed
119 120
}
//客流量
121
- (void)updateCellWithFlow:(Compass *)sale index:(NSIndexPath *)indexPath
陈俊俊's avatar
陈俊俊 committed
122 123 124
{
    self.indexPath = indexPath;
    //组织name
125 126
    self.dqLabel.text = sale.orgCode;
    self.nameLabel.text = sale.orgName;
陈俊俊's avatar
陈俊俊 committed
127
    //客流量
128
    self.saleLabel.text = [sale.passenger stringValue];
陈俊俊's avatar
陈俊俊 committed
129 130
    //客流量比变化率
    if ([sale.passengerChainSign isEqualToString:ReportChainSignPlus]) {
131
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateDisabled];
132
        [self.lastWeekLabel setTitleColor:ReportContentColor forState:UIControlStateNormal];
133 134
        self.saleLabel.textColor = ReportContentColor;

陈俊俊's avatar
陈俊俊 committed
135
    }else{
136
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateDisabled];
137
        [self.lastWeekLabel setTitleColor:GXF_NAVIGAYION_COLOR forState:UIControlStateNormal];
138 139
        self.saleLabel.textColor = GXF_NAVIGAYION_COLOR;

陈俊俊's avatar
陈俊俊 committed
140 141
    }
    NSString *salesYoStr = [NSString stringWithFormat:@"%@%%",sale.passengerChainRate];
142 143 144
    [self.lastWeekLabel setTitle:salesYoStr forState:UIControlStateNormal];

    [self setColorAndFont:sale.level];
陈俊俊's avatar
陈俊俊 committed
145 146
}
//毛利率
147
- (void)updateCellWithGross:(Compass *)sale index:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
148 149
    self.indexPath = indexPath;
    //组织name
150 151
    self.dqLabel.text = sale.orgCode;
    self.nameLabel.text = sale.orgName;
陈俊俊's avatar
陈俊俊 committed
152
    //毛利率
153
    self.saleLabel.text = [sale.grossprofit stringValue];
陈俊俊's avatar
陈俊俊 committed
154 155
    //毛利率比变化率
    if ([sale.grossprofitChainSign isEqualToString:ReportChainSignPlus]) {
156
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateDisabled];
157
        [self.lastWeekLabel setTitleColor:ReportContentColor forState:UIControlStateNormal];
158 159
        self.saleLabel.textColor = ReportContentColor;

陈俊俊's avatar
陈俊俊 committed
160
    }else{
161
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateDisabled];
162
        [self.lastWeekLabel setTitleColor:GXF_NAVIGAYION_COLOR forState:UIControlStateNormal];
163 164
        self.saleLabel.textColor = GXF_NAVIGAYION_COLOR;

陈俊俊's avatar
陈俊俊 committed
165 166
    }
    NSString *salesYoStr = [NSString stringWithFormat:@"%@%%",sale.grossprofitChainRate];
167 168 169 170 171 172 173 174 175
    [self.lastWeekLabel setTitle:salesYoStr forState:UIControlStateNormal];

    [self setColorAndFont:sale.level];
}

- (void)setColorAndFont:(NSInteger)level{
    if (level == 0) {
        self.dqLabel.textColor = GXF_CONTENT_COLOR;
        self.nameLabel.textColor = GXF_CONTENT_COLOR;
176 177 178 179 180 181 182
        self.lineLabel.hidden = NO;
        [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];
183 184 185 186
        self.lineLabel.hidden = NO;
        [self setFontLabel:15];
        [self setWidthDQ:0];
        self.contentView.backgroundColor = [UIColor whiteColor];
187
    }else if(level == 2){
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        self.lineLabel.hidden = NO;
        self.dqLabel.textColor = GXF_LEFTSIX_COLOR;
        self.nameLabel.textColor = GXF_LEFTSIX_COLOR;

        [self setWidthDQ:5];
        [self setFontLabel:13];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }else {
        self.lineLabel.hidden = YES;
        self.dqLabel.textColor = GXF_LEFTSIX_COLOR;
        self.nameLabel.textColor = GXF_LEFTSIX_COLOR;

        [self setFontLabel:12];
        [self setWidthDQ:0];
        self.contentView.backgroundColor = XXFBgColor;
    }
}
- (void)setFontLabel:(NSInteger)fontSize{
    self.dqLabel.font = FontSize(fontSize-1);
    self.nameLabel.font = FontSize(fontSize);
    self.saleLabel.font = FontSize(fontSize);
209
    self.lastWeekLabel.titleLabel.font = FontSize(fontSize);
210 211 212 213
}
- (void)setWidthDQ:(NSInteger)width{
    self.lineLabel.left = width;
    self.lineLabel.width = ScreenSize.width - width;
214 215 216 217 218 219 220 221 222 223 224
    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
225 226 227 228 229 230 231 232
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end