Toolview.m 9.12 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

13
#define ButtonWIDTH 60 //按钮宽度
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 = RGB(255, 255, 255,1);
曹云霄'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
    iconImage.userInteractionEnabled = YES;
    [iconImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showHomeController)]];
曹云霄's avatar
曹云霄 committed
45 46
    [self addSubview:iconImage];
    
曹云霄's avatar
曹云霄 committed
47 48
    //输入框背景
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(200, (NavigationHeight-35)/2, 220, 35)];
曹云霄's avatar
曹云霄 committed
49
    backView.backgroundColor = RGB(242, 242, 242,1);
曹云霄's avatar
曹云霄 committed
50 51 52
    backView.layer.masksToBounds = YES;;
    backView.layer.cornerRadius = kCornerRadius;
    backView.layer.borderWidth = 1;
曹云霄's avatar
曹云霄 committed
53
    backView.layer.borderColor = RGB(209, 209, 209,1).CGColor;
曹云霄's avatar
曹云霄 committed
54 55 56
    [self addSubview:backView];

    //搜索图标
曹云霄's avatar
曹云霄 committed
57 58 59
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 7.5, 20, 20)];
    imageview.image = TCImage(@"search");
    [backView addSubview:imageview];
曹云霄's avatar
曹云霄 committed
60
    
曹云霄's avatar
曹云霄 committed
61
    //输入框
勾芒's avatar
勾芒 committed
62 63 64 65 66 67
    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
68
    
曹云霄's avatar
曹云霄 committed
69 70 71 72
    //扫描二维码
    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];
73
    [button addTarget:self action:@selector(qrCodeButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
74 75
    [self addSubview:button];
    
曹云霄's avatar
曹云霄 committed
76
    //按钮
77
    NSString *realName = [[Shoppersmanager manager].shoppers.employee.realName length]?[Shoppersmanager manager].shoppers.employee.realName:@"服务导购";
78
    NSArray *titleArray = [NSArray arrayWithObjects:@"功能菜单",@"消息",@"公告",realName,@"我的客户",@"购物袋", nil];
曹云霄's avatar
曹云霄 committed
79
    //图片
80
    NSArray *imageArray = [NSArray arrayWithObjects:@"dial",@"message",@"tips",@"矢量智能对象-1",@"data",@"ablum", nil];
曹云霄's avatar
曹云霄 committed
81
    for (int i=1; i<titleArray.count+1; i++) {
曹云霄's avatar
曹云霄 committed
82 83 84
        
        CustomButton *button = [CustomButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(ScreenWidth-(i*ButtonWIDTH + Buttoninterval*(i-1)), 10, ButtonWIDTH, ButtonRIGHT);
曹云霄's avatar
曹云霄 committed
85
        [button setTitleColor:kMainBlueColor forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
86 87
        [button setTitle:[titleArray objectAtIndex_opple:i-1] forState:UIControlStateNormal];
        button.tag = 100+i-1;
88
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
89
        [button setImage:TCImage([imageArray objectAtIndex_opple:i-1]) forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
90
        [self addSubview:button];
曹云霄's avatar
曹云霄 committed
91
        if (i == titleArray.count) {
勾芒's avatar
勾芒 committed
92 93
            SHARED_APPDELEGATE.shoppingCarPoint = [self convertPoint:CGPointMake(button.center.x, button.center.y) toView:self.window];
        }
曹云霄's avatar
曹云霄 committed
94 95
        //未读公告
        if (i == 3) {
96
            button.instructionsNumber = [Shoppersmanager manager].shoppers.hasNotReadAffiche;
97
        }
曹云霄's avatar
曹云霄 committed
98 99
        //未读消息
        if (i == 2) {
100
            button.instructionsNumber = [Shoppersmanager manager].shoppers.hasNotReadNotice;
曹云霄's avatar
曹云霄 committed
101
        }
曹云霄's avatar
曹云霄 committed
102
        [self.buttonArray addObject:button];
曹云霄's avatar
曹云霄 committed
103
    }
曹云霄's avatar
曹云霄 committed
104
    [self setBadge];
曹云霄's avatar
曹云霄 committed
105
    self.underlineView.backgroundColor = kMainBlueColor;
勾芒's avatar
勾芒 committed
106
    [self addSubview:self.underlineView];
107 108 109 110 111
}

#pragma mark - 监听通知
- (void)addNSNotificationCenter
{
曹云霄's avatar
曹云霄 committed
112
    //刷新购物车数量
113
    [Notification addObserver:self selector:@selector(refreshGoodsNumber:) name:REFRESHSHOPPINGCAR object:nil];
勾芒's avatar
勾芒 committed
114
    //更改用户名
115
    [Notification addObserver:self selector:@selector(changeCustomerName:) name:CHANGECUSTOMERNAME object:nil];
曹云霄's avatar
曹云霄 committed
116
    //更改导购名
117
    [Notification addObserver:self selector:@selector(changeshoppersName:) name:CHANGEshoppersNAME object:nil];
118
    //提示未读公告
119
    [Notification addObserver:self selector:@selector(notReadAnnouncement:) name:NOTREADANNOUNCEMENT object:nil];
曹云霄's avatar
曹云霄 committed
120
    //提示未读消息
121 122 123
    [Notification addObserver:self selector:@selector(notReadMessage:) name:MESSAGE_COUNT object:nil];
    //显示消息界面
    [Notification addObserver:self selector:@selector(showMessageController:) name:NSNOTIFICATION_MESSAGE object:nil];
124 125 126 127 128 129 130 131 132
    //导购名字修改
    [Notification addObserver:self selector:@selector(refreshGuideName:) name:CHANGEGUIDENAME object:nil];
}

#pragma mark -修改导购名字
- (void)refreshGuideName:(NSNotification *)object
{
    CustomButton *button = (CustomButton *)[self viewWithTag:103];
    [button setTitle:object.object forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
133 134
}

勾芒's avatar
勾芒 committed
135
#pragma mark -刷新购物车显示数量
136
- (void)refreshGoodsNumber:(NSNotification *)object
勾芒's avatar
勾芒 committed
137
{
138
    CustomButton *button = (CustomButton *)[self viewWithTag:105];
139 140 141 142
    NSInteger number = [object.object integerValue];
    button.instructionsNumber = number;
}

143 144 145
#pragma mark - 未读公告
- (void)notReadAnnouncement:(NSNotification *)object
{
146
    CustomButton *button = (CustomButton *)[self viewWithTag:102];
147
    NSInteger number = [object.object integerValue];
148
    button.instructionsNumber -= number;
149
    [Shoppersmanager manager].shoppers.hasNotReadAffiche -= number;
曹云霄's avatar
曹云霄 committed
150
    [self setBadge];
151 152
}

曹云霄's avatar
曹云霄 committed
153 154 155 156 157
#pragma mark - 未读消息
- (void)notReadMessage:(NSNotification *)object
{
    CustomButton *button = (CustomButton *)[self viewWithTag:101];
    NSInteger number = [object.object integerValue];
158
    button.instructionsNumber -= number;
159
    [Shoppersmanager manager].shoppers.hasNotReadNotice -= number;
曹云霄's avatar
曹云霄 committed
160
    [self setBadge];
曹云霄's avatar
曹云霄 committed
161 162
}

勾芒's avatar
勾芒 committed
163
#pragma mark -更改当前用户名
164
- (void)changeCustomerName:(NSNotification *)object
勾芒's avatar
勾芒 committed
165
{
166
    UIButton *button = [self viewWithTag:104];
167
    NSString *userName = object.object;
曹云霄's avatar
曹云霄 committed
168
    if ([BaseViewController isBlankString:userName]) {
勾芒's avatar
勾芒 committed
169 170 171 172 173
        userName = @"我的客户";
    }
    [button setTitle:userName forState:UIControlStateNormal];
}

曹云霄's avatar
曹云霄 committed
174
#pragma mark -更改导购名字
175
- (void)changeshoppersName:(NSNotification *)object
曹云霄's avatar
曹云霄 committed
176
{
177
    UIButton *button = [self viewWithTag:103];
178
    NSString *userName = object.object;
曹云霄's avatar
曹云霄 committed
179
    if ([BaseViewController isBlankString:userName]) {
曹云霄's avatar
曹云霄 committed
180 181 182 183 184
        userName = @"导购";
    }
    [button setTitle:userName forState:UIControlStateNormal];
}

185 186 187 188 189 190 191
#pragma mark -显示消息界面
- (void)showMessageController:(NSNotification *)object
{
    UIButton *button = [self viewWithTag:101];
    [self buttonClick:button];
}

曹云霄's avatar
曹云霄 committed
192 193 194
#pragma mark -设置系统  Badge角标值
- (void)setBadge
{
195
    NSInteger count = [Shoppersmanager manager].shoppers.hasNotReadNotice + [Shoppersmanager manager].shoppers.hasNotReadAffiche;
曹云霄's avatar
曹云霄 committed
196 197 198 199
    [JPUSHService setBadge:count];
    [UIApplication sharedApplication].applicationIconBadgeNumber = count;
}

曹云霄's avatar
曹云霄 committed
200
#pragma mark -二维码扫描码
201
- (void)qrCodeButtonClickAction
曹云霄's avatar
曹云霄 committed
202
{
203 204
    if ([self.delegate respondsToSelector:@selector(qrcodeButtonClick)]) {
        [self.delegate qrcodeButtonClick];
曹云霄's avatar
曹云霄 committed
205 206 207
    }
}

曹云霄's avatar
曹云霄 committed
208
#pragma mark -按钮事件响应
209
- (void)buttonClick:(UIButton *)button
曹云霄's avatar
曹云霄 committed
210
{
曹云霄's avatar
曹云霄 committed
211 212 213 214 215 216 217 218 219 220
    [self switchLineViewOrigin:button.tag-100];
    if ([self.delegate respondsToSelector:@selector(buttonClickAction:withButton:)]) {
        [self.delegate buttonClickAction:button.tag withButton:button];
    }
}

#pragma mark -切换lingView位置
- (void)switchLineViewOrigin:(NSInteger)selectedIndex
{
    UIButton *button = self.buttonArray[selectedIndex];
221
    if (button.tag != 100) {
222
        if (!(button.tag == 105 && ![Shoppersmanager manager].currentCustomer)) {
勾芒's avatar
勾芒 committed
223
            self.underlineView.hidden = NO;
曹云霄's avatar
曹云霄 committed
224
            [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
勾芒's avatar
勾芒 committed
225 226
                CGRect frame = self.underlineView.frame;
                frame.origin.x = button.frame.origin.x+(ButtonWIDTH-50)/2;
227 228
                frame.origin.y = ButtonRIGHT+8;
                frame.size = CGSizeMake(50, 2);
勾芒's avatar
勾芒 committed
229 230 231 232
                self.underlineView.frame = frame;
            } completion:nil];
        }
    }
曹云霄's avatar
曹云霄 committed
233
}
曹云霄's avatar
曹云霄 committed
234

曹云霄's avatar
曹云霄 committed
235 236 237 238 239 240
#pragma mark -显示首页
- (void)showHomeController
{
    SHARED_APPDELEGATE.tabBarController.selectedIndex = 0;
}

曹云霄's avatar
曹云霄 committed
241

曹云霄's avatar
曹云霄 committed
242 243 244 245 246 247 248 249 250
#pragma mark -lazy
- (NSMutableArray *)buttonArray
{
    if (!_buttonArray) {
        _buttonArray = [NSMutableArray array];
    }
    return _buttonArray;
}

251 252 253 254 255 256 257 258 259
- (UIView *)underlineView
{
    if(!_underlineView){
        _underlineView = [[UIView alloc]init];

    }
    return _underlineView;
}

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