Toolview.m 7.48 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10
//
//  Toolview.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "Toolview.h"
#import "CustomButton.h"
曹云霄's avatar
曹云霄 committed
11
#import "UserViewController.h"
zhu's avatar
zhu committed
12

曹云霄's avatar
曹云霄 committed
13
#define ButtonWIDTH 80 //按钮宽度
zhu's avatar
zhu committed
14 15 16 17
#define Buttoninterval 20//按钮间隔
#define ButtonRIGHT 54//按钮高度


曹云霄's avatar
曹云霄 committed
18 19
@implementation Toolview

勾芒's avatar
勾芒 committed
20

曹云霄's avatar
曹云霄 committed
21 22 23 24
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
      
曹云霄's avatar
曹云霄 committed
25
        self.backgroundColor = kTCColor(255, 255, 255);
曹云霄's avatar
曹云霄 committed
26
        [self uiConfigAction];
27
        [self addNSNotificationCenter];
曹云霄's avatar
曹云霄 committed
28 29 30 31 32 33 34
    }
    return self;
}

#pragma mark -布局
- (void)uiConfigAction
{
曹云霄's avatar
曹云霄 committed
35 36
    //阴影
    self.layer.shadowColor = [UIColor blackColor].CGColor;
37
    self.layer.shadowRadius = 10;
曹云霄's avatar
曹云霄 committed
38
    self.layer.shadowOpacity = 0.5;
曹云霄's avatar
曹云霄 committed
39

曹云霄's avatar
曹云霄 committed
40
    //图标
41 42
    UIImageView *iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, 13, 115, 35)];
    iconImage.image = TCImage(@"欧");
曹云霄's avatar
曹云霄 committed
43 44
    [self addSubview:iconImage];
    
曹云霄's avatar
曹云霄 committed
45 46 47 48 49 50 51 52 53 54
    //输入框背景
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(200, (NavigationHeight-35)/2, 220, 35)];
    backView.backgroundColor = kTCColor(242, 242, 242);
    backView.layer.masksToBounds = YES;;
    backView.layer.cornerRadius = kCornerRadius;
    backView.layer.borderWidth = 1;
    backView.layer.borderColor = kTCColor(209, 209, 209).CGColor;
    [self addSubview:backView];

    //搜索图标
曹云霄's avatar
曹云霄 committed
55 56 57
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 7.5, 20, 20)];
    imageview.image = TCImage(@"search");
    [backView addSubview:imageview];
曹云霄's avatar
曹云霄 committed
58
    
曹云霄's avatar
曹云霄 committed
59
    //输入框
勾芒's avatar
勾芒 committed
60 61 62 63 64 65
    self.inputField = [[UITextField alloc]initWithFrame:CGRectMake(45, 0, 170, 35)];
    self.inputField.borderStyle = UITextBorderStyleNone;
    self.inputField.placeholder = @"请输入关键字";
    self.inputField.font = [UIFont systemFontOfSize:12];
    self.inputField.returnKeyType = UIReturnKeySearch;
    [backView addSubview:self.inputField];
曹云霄's avatar
曹云霄 committed
66
    
曹云霄's avatar
曹云霄 committed
67 68 69 70 71 72 73
    //扫描二维码
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(backView.frame.size.width+backView.frame.origin.x+15, (NavigationHeight-20)/2, 25, 20);
    [button setBackgroundImage:TCImage(@"圆角矩形-3") forState:UIControlStateNormal];
    [button addTarget:self action:@selector(QrCodeButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
曹云霄's avatar
曹云霄 committed
74
    //按钮
曹云霄's avatar
曹云霄 committed
75
    NSString *realName = [[Shoppersmanager manager].Shoppers.employee.realName length]?[Shoppersmanager manager].Shoppers.employee.realName:@"服务导购";
曹云霄's avatar
曹云霄 committed
76
    NSArray *titleArray = [NSArray arrayWithObjects:@"功能菜单",@"公告",realName,@"我的客户",@"购物袋", nil];
曹云霄's avatar
曹云霄 committed
77
    //图片
曹云霄's avatar
曹云霄 committed
78 79
    NSArray *imageArray = [NSArray arrayWithObjects:@"dial",@"tips",@"矢量智能对象-1",@"data",@"ablum", nil];
    for (int i=1; i<titleArray.count+1; i++) {
曹云霄's avatar
曹云霄 committed
80 81 82
        
        CustomButton *button = [CustomButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(ScreenWidth-(i*ButtonWIDTH + Buttoninterval*(i-1)), 10, ButtonWIDTH, ButtonRIGHT);
曹云霄's avatar
曹云霄 committed
83
        [button setTitleColor:kMainBlueColor forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
84 85 86
        [button setTitle:[titleArray objectAtIndex_opple:i-1] forState:UIControlStateNormal];
        button.tag = 100+i-1;
        [button addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
87
        [button setImage:TCImage([imageArray objectAtIndex_opple:i-1]) forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
88
        [self addSubview:button];
曹云霄's avatar
曹云霄 committed
89
        if (i == 5) {
勾芒's avatar
勾芒 committed
90 91
            SHARED_APPDELEGATE.shoppingCarPoint = [self convertPoint:CGPointMake(button.center.x, button.center.y) toView:self.window];
        }
曹云霄's avatar
曹云霄 committed
92
    }
勾芒's avatar
勾芒 committed
93
    //创建下划线
曹云霄's avatar
曹云霄 committed
94
    CustomButton *Newbutton = (CustomButton *)[self viewWithTag:103];
勾芒's avatar
勾芒 committed
95 96
    self.underlineView = [[UIView alloc]initWithFrame:CGRectMake(Newbutton.frame.origin.x+(ButtonWIDTH-50)/2, ButtonRIGHT+8, 50, 2)];
    SHARED_APPDELEGATE.lineView = self.underlineView;
曹云霄's avatar
曹云霄 committed
97
    self.underlineView.backgroundColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
98
    [self addSubview:self.underlineView];
99 100 101 102 103
}

#pragma mark - 监听通知
- (void)addNSNotificationCenter
{
曹云霄's avatar
曹云霄 committed
104
    //刷新购物车数量
105 106 107
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshGoodsNumber:) name:REFRESHSHOPPINGCAR object:nil];
    //重置购物车数量
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetGoodNumber:) name:ADDSHOPPINGCAR object:nil];
勾芒's avatar
勾芒 committed
108
    //更改用户名
109
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeCustomerName:) name:CHANGECUSTOMERNAME object:nil];
曹云霄's avatar
曹云霄 committed
110
    //更改导购名
111 112 113
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeShoppersName:) name:CHANGESHOPPERSNAME object:nil];
    //提示抽奖信息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(promptDrawInformation:) name:PROMPTDRAWINFORMATION object:nil];
曹云霄's avatar
曹云霄 committed
114 115
}

勾芒's avatar
勾芒 committed
116
#pragma mark -刷新购物车显示数量
117
- (void)refreshGoodsNumber:(NSNotification *)object
勾芒's avatar
勾芒 committed
118
{
曹云霄's avatar
曹云霄 committed
119
    CustomButton *button = (CustomButton *)[self viewWithTag:104];
120 121 122 123 124 125
    NSInteger number = [object.object integerValue];
    if (number) {
        button.instructionsNumber += number;
    }else {
        button.instructionsNumber = 0;
    }
勾芒's avatar
勾芒 committed
126
}
127 128 129

#pragma mark - 重置购物车显示数量
- (void)resetGoodNumber:(NSNotification *)object
勾芒's avatar
勾芒 committed
130
{
曹云霄's avatar
曹云霄 committed
131
    CustomButton *button = (CustomButton *)[self viewWithTag:104];
132 133 134 135 136 137 138
    NSInteger number = [object.object integerValue];
    button.instructionsNumber = number;
}

#pragma mark - 提示抽奖机会
- (void)promptDrawInformation:(NSNotification *)object
{
曹云霄's avatar
曹云霄 committed
139
    CustomButton *button = (CustomButton *)[self viewWithTag:102];
140 141 142 143 144 145
    NSInteger number = [object.object integerValue];
    if (number) {
        button.instructionsNumber += number;
    }else{
        button.instructionsNumber = 0;
    }
勾芒's avatar
勾芒 committed
146 147
}

勾芒's avatar
勾芒 committed
148
#pragma mark -更改当前用户名
149
- (void)ChangeCustomerName:(NSNotification *)object
勾芒's avatar
勾芒 committed
150 151
{
    UIButton *button = [self viewWithTag:102];
152
    NSString *userName = object.object;
勾芒's avatar
勾芒 committed
153 154 155 156 157 158
    if (userName.length == 0 || !userName) {
        userName = @"我的客户";
    }
    [button setTitle:userName forState:UIControlStateNormal];
}

曹云霄's avatar
曹云霄 committed
159
#pragma mark -更改导购名字
160
- (void)ChangeShoppersName:(NSNotification *)object
曹云霄's avatar
曹云霄 committed
161 162
{
    UIButton *button = [self viewWithTag:101];
163
    NSString *userName = object.object;
曹云霄's avatar
曹云霄 committed
164 165 166 167 168 169
    if (userName.length == 0 || !userName) {
        userName = @"导购";
    }
    [button setTitle:userName forState:UIControlStateNormal];
}

勾芒's avatar
勾芒 committed
170

曹云霄's avatar
曹云霄 committed
171 172 173 174 175 176 177 178
#pragma mark -二维码扫描码
- (void)QrCodeButtonClickAction
{
    if ([self.delegate respondsToSelector:@selector(QrcodeButtonClick)]) {
        [self.delegate QrcodeButtonClick];
    }
}

曹云霄's avatar
曹云霄 committed
179 180 181
#pragma mark -按钮事件响应
- (void)ButtonClick:(UIButton *)button
{
曹云霄's avatar
曹云霄 committed
182 183 184
    /// 部分按钮不需要指示线
    if (button.tag == 101 || button.tag == 103 || button.tag == 104) {
        if (!(button.tag == 104 && ![Shoppersmanager manager].currentCustomer)) {
勾芒's avatar
勾芒 committed
185
            self.underlineView.hidden = NO;
曹云霄's avatar
曹云霄 committed
186
            [UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
勾芒's avatar
勾芒 committed
187 188 189 190 191 192
                CGRect frame = self.underlineView.frame;
                frame.origin.x = button.frame.origin.x+(ButtonWIDTH-50)/2;
                self.underlineView.frame = frame;
            } completion:nil];
        }
    }
曹云霄's avatar
曹云霄 committed
193
    //点击代理
曹云霄's avatar
曹云霄 committed
194 195
    if ([self.delegate respondsToSelector:@selector(ButtonClickAction:withButton:)]) {
        [self.delegate ButtonClickAction:button.tag withButton:button];
曹云霄's avatar
曹云霄 committed
196 197
    }
}
曹云霄's avatar
曹云霄 committed
198 199 200 201




勾芒's avatar
勾芒 committed
202 203 204 205 206 207






曹云霄's avatar
曹云霄 committed
208
@end