//
//  MoneyView.m
//  ALand
//
//  Created by Z on 16/3/22.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "MoneyView.h"
#import "MBLabelWithFontAdapter.h"
@interface MoneyView ()

@property (weak, nonatomic) IBOutlet UILabel *labelMoney;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *labelMonthIncome;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *labelMonthSale;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *labelMonthOrder;
@property (weak, nonatomic) IBOutlet UIButton *buttonEye;//tag为1，则显示星号，tag为0，显示金额
@property (nonatomic, copy) NSString *realMoney;
@end


@implementation MoneyView

- (void)awakeFromNib {
    self.buttonEye.imageView.contentMode = UIViewContentModeScaleAspectFit;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"hideMoney"];
        
        if ([str isEqualToString:@"YES"]) {
            self.buttonEye.tag = 1;
            self.labelMoney.text = @"******";
            [self.buttonEye setImage:[UIImage imageNamed:@"Invisible_icon"] forState:UIControlStateNormal];
        }else{
            
        }
    });
}

- (IBAction)buttonEyeAction:(UIButton *)sender {
    if (sender.tag == 0) {
        self.labelMoney.text = @"******";
        sender.tag = 1;
        [sender setImage:[UIImage imageNamed:@"Invisible_icon"] forState:UIControlStateNormal];
        [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"hideMoney"];
        
    }else{
        self.labelMoney.text = self.realMoney;
        sender.tag = 0;
        [sender setImage:[UIImage imageNamed:@"eyeOpen"] forState:UIControlStateNormal];
        [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"hideMoney"];
    }
    
}

- (void)setMoneyView:(JavencommissionAccountModel *)model {
    self.labelMonthIncome.text = [NSString stringWithFormat:@"%.2f",model.monthlyIncome];
    self.labelMonthSale.text = [NSString stringWithFormat:@"%.2f",model.monthlySales];
    self.labelMonthOrder.text = [NSString stringWithFormat:@"%.0f",model.monthlyOrderCount];
    [self setMoneyNumber:[NSString stringWithFormat:@"%.2f", model.accumulatedIncome]];
}

//设置总收入金额
- (void)setMoneyNumber:(NSString *)number{
    if (self.buttonEye.tag == 1) {
        self.realMoney = number;
    }else{
        self.realMoney = number;
        self.labelMoney.text = number;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
