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

#import "RSaleView.h"
10
#import "SMPageControl.h"
陈俊俊's avatar
陈俊俊 committed
11 12
#define LeftWidth   50
#define ImageSize 20
13 14
#define ContentHeight 25
#define CenImageSize 40
陈俊俊's avatar
陈俊俊 committed
15 16 17 18 19 20 21 22 23 24

@interface RSaleView ()
@property (nonatomic,strong)UILabel *centerLabel;
@property (nonatomic,strong)UILabel *dateLabel;
@property (nonatomic,strong)UIButton *lastWeekLabel;
@property (nonatomic,strong)UIButton *lastYearLabel;
@property (nonatomic,strong)UILabel *rateLabel;
@property (nonatomic,strong)UILabel *averageLabel;
@property (nonatomic,strong)UIImageView *lastWeekImage;
@property (nonatomic,strong)UIImageView *lastYearImage;
25 26
@property (nonatomic,strong)SMPageControl *pageControl;
@property (nonatomic,assign)NSInteger currentPage;
陈俊俊's avatar
陈俊俊 committed
27 28 29 30 31 32 33 34 35 36 37 38


@end



@implementation RSaleView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self bulidLayout];
39 40 41 42 43 44 45 46 47
        self.currentPage = 0;
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame withPage:(NSInteger)currentPage{
    self = [super initWithFrame:frame];
    if (self) {
        self.currentPage = currentPage;
        [self bulidLayout];
陈俊俊's avatar
陈俊俊 committed
48 49 50
    }
    return self;
}
51

陈俊俊's avatar
陈俊俊 committed
52 53
- (void)bulidLayout{
    
54
    CGRect rect = CGRectMake(0, 0, self.width, self.height);
陈俊俊's avatar
陈俊俊 committed
55
  
56 57 58 59 60 61 62 63 64 65
    self.bgImage = [[UIImageView alloc]initWithFrame:rect];
    [self addSubview:self.bgImage];
    
    rect = CGRectMake(self.width/4, 20, CenImageSize, CenImageSize);
    self.cenImage = [[UIImageView alloc]initWithFrame:rect];
    self.cenImage.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:self.cenImage];
    
    
    rect = CGRectMake(self.cenImage.right+5, 20, ScreenSize.width - self.cenImage.right, ContentHeight);
陈俊俊's avatar
陈俊俊 committed
66
    self.centerLabel = [[UILabel alloc]initWithFrame:rect];
67 68
    self.centerLabel.textColor = ReportContentColor;
    self.centerLabel.font = FontSize(28);
陈俊俊's avatar
陈俊俊 committed
69 70 71
    [self addSubview:self.centerLabel];

    
72
    rect = CGRectMake(self.centerLabel.left, self.centerLabel.bottom,self.width-self.centerLabel.left, ContentHeight);
陈俊俊's avatar
陈俊俊 committed
73
    self.dateLabel = [[UILabel alloc]initWithFrame:rect];
74 75 76
    self.dateLabel.textColor = [UIColor lightGrayColor];
    self.dateLabel.font =  GXF_THREETEENTH_SIZE;
    self.dateLabel.textAlignment = NSTextAlignmentLeft;
陈俊俊's avatar
陈俊俊 committed
77 78 79 80 81
    [self addSubview:self.dateLabel];
    
    CGFloat bottomWidth = (ScreenSize.width - 20)/4;
    
    rect = CGRectMake(10, self.dateLabel.bottom + 5,bottomWidth, ContentHeight);
陈俊俊's avatar
陈俊俊 committed
82
    self.lastWeekLabel = [IBTCommon buttonWithTitle:@"" Image:nil frame:rect fontSize:15 fontColor:[UIColor lightGrayColor]];
陈俊俊's avatar
陈俊俊 committed
83 84 85 86 87 88 89 90 91
    [self addSubview:self.lastWeekLabel];
    
    rect = CGRectMake(self.lastWeekLabel.left, self.lastWeekLabel.bottom,bottomWidth,20);
    UILabel *weekLabel = [[UILabel alloc]initWithFrame:rect];
    weekLabel.textColor = [UIColor lightGrayColor];
    weekLabel.text = @"比上周同期";
    weekLabel.font = GXF_THREETEENTH_SIZE;
    weekLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:weekLabel];
陈俊俊's avatar
陈俊俊 committed
92
    self.weekLabel = weekLabel;
陈俊俊's avatar
陈俊俊 committed
93 94
    
    rect = CGRectMake(self.lastWeekLabel.right, self.lastWeekLabel.top,bottomWidth, ContentHeight);
陈俊俊's avatar
陈俊俊 committed
95
     self.lastYearLabel = [IBTCommon buttonWithTitle:@"" Image:nil frame:rect fontSize:15 fontColor:[UIColor lightGrayColor]];
陈俊俊's avatar
陈俊俊 committed
96 97 98 99 100 101 102 103 104 105 106 107 108
    [self addSubview:self.lastYearLabel];

    
    rect = CGRectMake(self.lastYearLabel.left, self.lastWeekLabel.bottom,bottomWidth,20);
    UILabel *yearLabel = [[UILabel alloc]initWithFrame:rect];
    yearLabel.textColor = [UIColor lightGrayColor];
    yearLabel.text = @"比去年同期";
    yearLabel.font = GXF_THREETEENTH_SIZE;
    yearLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:yearLabel];
    
    rect = CGRectMake(self.lastYearLabel.right,self.lastWeekLabel.top,bottomWidth, ContentHeight);
    self.rateLabel = [[UILabel alloc]initWithFrame:rect];
109
    self.rateLabel.textColor = GXF_COMMIT_COLOR;
陈俊俊's avatar
陈俊俊 committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    self.rateLabel.font =  GXF_FIFTEENTEN_SIZE;

    self.rateLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.rateLabel];
    
    rect = CGRectMake(self.rateLabel.left, self.lastWeekLabel.bottom,bottomWidth,20);
    UILabel *raLabel = [[UILabel alloc]initWithFrame:rect];
    raLabel.textColor = [UIColor lightGrayColor];
    raLabel.text = @"销售达成率";
    raLabel.font = GXF_THREETEENTH_SIZE;
    raLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:raLabel];
    
    rect = CGRectMake(self.rateLabel.right, self.lastWeekLabel.top,bottomWidth, ContentHeight);
    self.averageLabel = [[UILabel alloc]initWithFrame:rect];
125
    self.averageLabel.textColor = GXF_COMMIT_COLOR;
陈俊俊's avatar
陈俊俊 committed
126 127 128 129 130 131 132 133 134 135 136 137
    self.averageLabel.font =  GXF_FIFTEENTEN_SIZE;

    self.averageLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.averageLabel];
    
    rect = CGRectMake(self.averageLabel.left, self.lastWeekLabel.bottom,bottomWidth,20);
    UILabel *avLabel = [[UILabel alloc]initWithFrame:rect];
    avLabel.textColor = [UIColor lightGrayColor];
    avLabel.text = @"单店日均";
    avLabel.font = GXF_THREETEENTH_SIZE;
    avLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:avLabel];
陈俊俊's avatar
陈俊俊 committed
138
    self.avgLabel = avLabel;
139 140 141 142 143 144 145 146
    self.pageControl = [[SMPageControl alloc]initWithFrame:CGRectMake(0, avLabel.bottom+5, ScreenSize.width, 10)];
    self.pageControl.numberOfPages = 4;
    self.pageControl.currentPage = self.currentPage;
    self.pageControl.pageIndicatorImage = [UIImage imageNamed:@"white_point"];
    self.pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"yellow_point"];
    self.pageControl.indicatorMargin = 5.0f;
    self.pageControl.indicatorDiameter = 10.0f;
    [self addSubview:self.pageControl];
陈俊俊's avatar
陈俊俊 committed
147
}
陈俊俊's avatar
陈俊俊 committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
- (void)setWeekLabelStr:(NSString *)weekLabelStr{
    
    NSString *typeStr = @"";
    NSString *avStr = @"";
    if ([weekLabelStr isEqualToString:SaleEnDay]) {
        typeStr = OrderLastWeak;
        avStr = AvgLabelDay;
    }else if([weekLabelStr isEqualToString:SaleEnWeek]){
        typeStr = OrderLastWeak;
        avStr = AvgLabelWeek;
    }else if([weekLabelStr isEqualToString:SaleEnMonth]){
        typeStr = OrderLastMonth;
        avStr = AvgLabelMonth;
    }
    self.weekLabel.text = typeStr;
    self.avgLabel.text = avStr;
}
陈俊俊's avatar
陈俊俊 committed
165 166
- (void)setValueInSaleView:(Compass *)compass{
    //统计时间
167 168 169
    NSString *weekday = @"";
    if ([IBTCommon convertToDateFrom:compass.dataScope]) {
        weekday = [IBTCommon weekdayStringFromDate:[IBTCommon convertToDateFrom:compass.dataScope]];
170
    }
171
   
陈俊俊's avatar
陈俊俊 committed
172
    self.dateLabel.text = compass.dataScope?[NSString stringWithFormat:@"%@%@累计销售额",compass.dataScope,weekday]:@"无";
173
    //销售额
陈俊俊's avatar
陈俊俊 committed
174
     self.centerLabel.text = compass.sales?[IBTCommon countNumAndChangeformat:[IBTCommon stringDisposeWithFloat:[compass.sales floatValue]]]:@"---" ;
175

陈俊俊's avatar
陈俊俊 committed
176 177 178
    //销售环比变化率
    if ([compass.salesChainSign isEqualToString:ReportChainSignPlus]) {
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateNormal];
179
        [self.lastWeekLabel setTitleColor:ReportContentColor forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
180
    }else if ([compass.salesChainSign isEqualToString:ReportChainSignMinus]){
陈俊俊's avatar
陈俊俊 committed
181
        [self.lastWeekLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateNormal];
182
        [self.lastWeekLabel setTitleColor:GXF_SAVE_COLOR forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
183
    }
陈俊俊's avatar
陈俊俊 committed
184
    NSString *salesChainRateStr = compass.salesChainRate?[NSString stringWithFormat:@"%@%%",[IBTCommon stringDisposeWithFloat:[compass.salesChainRate floatValue]]]:@"---";
陈俊俊's avatar
陈俊俊 committed
185 186 187 188
    [self.lastWeekLabel setTitle:salesChainRateStr forState:UIControlStateNormal];
    //销售同比变化率
    if ([compass.salesYoYSign isEqualToString:ReportChainSignPlus]) {
        [self.lastYearLabel setImage:[UIImage imageNamed:ReportChainPlusImage] forState:UIControlStateNormal];
189
         [self.lastYearLabel setTitleColor:ReportContentColor forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
190
    }else if ([compass.salesYoYSign isEqualToString:ReportChainSignMinus]){
陈俊俊's avatar
陈俊俊 committed
191
        [self.lastYearLabel setImage:[UIImage imageNamed:ReportChainMinusImage] forState:UIControlStateNormal];
192
         [self.lastYearLabel setTitleColor:GXF_SAVE_COLOR forState:UIControlStateNormal];
陈俊俊's avatar
陈俊俊 committed
193
    }
陈俊俊's avatar
陈俊俊 committed
194
    NSString *salesYoStr = compass.salesYoYRate?[NSString stringWithFormat:@"%@%%",[IBTCommon stringDisposeWithFloat:[compass.salesYoYRate floatValue]]]:@"---";
陈俊俊's avatar
陈俊俊 committed
195 196
    [self.lastYearLabel setTitle:salesYoStr forState:UIControlStateNormal];
    //销售目标达成率
陈俊俊's avatar
陈俊俊 committed
197
    NSString *salesTargetStr = compass.salesTargetRate?[NSString stringWithFormat:@"%@%%",[IBTCommon stringDisposeWithFloat:[compass.salesTargetRate floatValue]]]:@"---";
陈俊俊's avatar
陈俊俊 committed
198 199
    self.rateLabel.text = salesTargetStr;
    //单店日均销售
陈俊俊's avatar
陈俊俊 committed
200
    NSString *dailysalesPerStr = compass.dailysalesPerStore?[NSString stringWithFormat:@"%@",[IBTCommon stringDisposeWithFloat:[compass.dailysalesPerStore floatValue]]]:@"---";
陈俊俊's avatar
陈俊俊 committed
201 202 203 204 205
    self.averageLabel.text = dailysalesPerStr;
    
}

@end