CustomTabbarController.m 13.1 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11

//
//  CustomTabbarController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CustomTabbarController.h"
#import "Toolview.h"
曹云霄's avatar
曹云霄 committed
12
#import "AppDelegate.h"
13 14 15
#import "SceneLibraryViewController.h"
#import "ProductLibraryViewController.h"
#import "AboutViewController.h"
曹云霄's avatar
曹云霄 committed
16 17
#import "AllCustomerViewController.h"
#import "CustomerOrderViewController.h"
曹云霄's avatar
曹云霄 committed
18
#import "UserViewController.h"
19
#import "ChangePasswordViewController.h"
勾芒's avatar
勾芒 committed
20
#import "SearchViewController.h"
勾芒's avatar
勾芒 committed
21
#import "BaseViewController.h"
勾芒's avatar
勾芒 committed
22
#import "QRViewController.h"
曹云霄's avatar
曹云霄 committed
23
#import "ExperienceCentreViewController.h"
曹云霄's avatar
曹云霄 committed
24
#import "RebateViewController.h"
曹云霄's avatar
曹云霄 committed
25 26 27
#import "GuideIntegralViewController.h"
#import "LearningCenterMainViewController.h"
#import "AnnouncementViewController.h"
28
#import "MessageViewController.h"
曹云霄's avatar
曹云霄 committed
29
#import "HomeViewController.h"
30
#import "CustomWKWebViewController.h"
曹云霄's avatar
曹云霄 committed
31

32
@interface CustomTabbarController () <TabbarButtonClickdelegate, ChangpasswordDelegate, CancelButtondelegate, UITextFieldDelegate>
勾芒's avatar
勾芒 committed
33

34
@property (nonatomic, strong) NSArray *identifierArray;
曹云霄's avatar
曹云霄 committed
35

36 37 38
/**
 *  保存按钮引用
 */
39
@property (nonatomic, strong) UIButton *Newbutton;
40

勾芒's avatar
勾芒 committed
41 42 43
/**
 *  控制器数组
 */
44
@property (nonatomic, strong) NSMutableArray *vcArray;
勾芒's avatar
勾芒 committed
45

曹云霄's avatar
曹云霄 committed
46 47 48
/**
 *  工具栏
 */
49
@property (nonatomic, strong) Toolview *toolview;
曹云霄's avatar
曹云霄 committed
50

曹云霄's avatar
曹云霄 committed
51 52 53 54
@end

@implementation CustomTabbarController

曹云霄's avatar
曹云霄 committed
55 56 57 58 59
/**
 *  UIStoryboard Identifier数组
 *
 *  @return NSArary
 */
60
- (NSArray *)identifierArray {
曹云霄's avatar
曹云霄 committed
61
    if (_identifierArray == nil) {
62 63

        _identifierArray = [NSArray arrayWithObjects:@"HomeViewController", @"SearchViewController", @"ShoppingViewController", @"ClientViewController", @"RebateViewController", @"GuideIntegralViewController", @"AnnouncementViewController", @"MessageViewController", @"SceneLibraryViewController", @"ProductLibraryViewController", @"AllCustomerViewController", @"CustomerOrderViewController", @"LearningCenterMainViewController", @"AboutViewController", nil];
曹云霄's avatar
曹云霄 committed
64
    }
勾芒's avatar
勾芒 committed
65
    return _identifierArray;
曹云霄's avatar
曹云霄 committed
66 67
}

68
- (NSMutableArray *)vcArray {
69 70 71 72 73 74
    if (!_vcArray) {
        _vcArray = [NSMutableArray array];
    }
    return _vcArray;
}

75
- (void)viewWillAppear:(BOOL)animated {
勾芒's avatar
勾芒 committed
76
    [super viewWillAppear:animated];
77
    [self.selectedViewController beginAppearanceTransition:YES animated:animated];
勾芒's avatar
勾芒 committed
78 79
}

80
- (void)viewDidAppear:(BOOL)animated {
勾芒's avatar
勾芒 committed
81 82 83 84
    [super viewDidAppear:animated];
    [self.selectedViewController endAppearanceTransition];
}

85
- (void)viewWillDisappear:(BOOL)animated {
勾芒's avatar
勾芒 committed
86
    [super viewWillDisappear:animated];
87
    [self.selectedViewController beginAppearanceTransition:NO animated:animated];
勾芒's avatar
勾芒 committed
88 89
}

90
- (void)viewDidDisappear:(BOOL)animated {
勾芒's avatar
勾芒 committed
91 92 93 94
    [super viewDidDisappear:animated];
    [self.selectedViewController endAppearanceTransition];
}

曹云霄's avatar
曹云霄 committed
95 96
- (void)viewDidLoad {
    [super viewDidLoad];
97

曹云霄's avatar
曹云霄 committed
98 99
    [self uiConfigAction];
    [self addViewcontroller];
100
    [self addNSNotification];
曹云霄's avatar
曹云霄 committed
101 102 103
}

#pragma mark -UI
104
- (void)uiConfigAction {
105
    self.tabBar.frame = CGRectMake(ZERO, ZERO, ScreenWidth, NavigationHeight);
106
    self.toolview = [[Toolview alloc] initWithFrame:CGRectMake(ZERO, ZERO, ScreenWidth, NavigationHeight)];
曹云霄's avatar
曹云霄 committed
107 108
    self.toolview.delegate = self;
    self.toolview.inputField.delegate = self;
勾芒's avatar
勾芒 committed
109
    self.delegate = self;
110 111
    [self.view addSubview:self.toolview];
    self.tabBar.hidden = YES;
112 113 114
}

#pragma mark -监听通知
115
- (void)addNSNotification {
勾芒's avatar
勾芒 committed
116
    //显示体验中心
117
    [Notification addObserver:self selector:@selector(showFollowHeart:) name:OPENFOLLOWHEARTVC object:nil];
118 119
    //显示体验中心3D
    [Notification addObserver:self selector:@selector(show3DFollowHeart:) name:OPENFOLLOWHEART3DVC object:nil];
120 121 122 123 124 125 126 127 128
    //显示消息界面
    [Notification addObserver:self selector:@selector(showMessageController:) name:NSNOTIFICATION_MESSAGE object:nil];
    //app未启动点击通知回调
    NSDictionary *dict = [UserDefault objectForKey:NSNOTIFICATION_MESSAGE];
    if (dict) {
        self.selectedIndex = 6;
        [Notification postNotificationName:NSNOTIFICATION_MESSAGE object:dict];
        [UserDefault removeObjectForKey:NSNOTIFICATION_MESSAGE];
    }
曹云霄's avatar
曹云霄 committed
129 130
}

131
#pragma mark -显示消息界面
132
- (void)showMessageController:(NSNotification *)object {
133 134
    self.selectedIndex = 6;
}
曹云霄's avatar
曹云霄 committed
135

136
#pragma mark -添加controller到viewControllers
137
- (void)addViewcontroller {
138
    NSMutableArray *controllerArray = [NSMutableArray array];
曹云霄's avatar
曹云霄 committed
139
    UIStoryboard *storyboard = nil;
140 141
    for (int i = 0; i < self.identifierArray.count; i++) {

曹云霄's avatar
曹云霄 committed
142 143
        NSString *controllString = self.identifierArray[i];
        // 公告
144
        if ([controllString isEqualToString:@"AnnouncementViewController"] || [controllString isEqualToString:@"MessageViewController"]) {
曹云霄's avatar
曹云霄 committed
145
            storyboard = [BaseViewController getAnnouncementStoryboardClass];
146
        } else if ([controllString isEqualToString:@"LearningCenterMainViewController"]) {
曹云霄's avatar
曹云霄 committed
147 148
            // 学习中心
            storyboard = [BaseViewController getLearningCenterStoryboardClass];
149
        } else if ([controllString isEqualToString:@"GuideIntegralViewController"]) {
曹云霄's avatar
曹云霄 committed
150 151
            // 积分
            storyboard = [BaseViewController getGuideIntegralStoryboardClass];
152
        } else {
曹云霄's avatar
曹云霄 committed
153 154
            storyboard = [BaseViewController getMainStoryboardClass];
        }
155
        BaseViewController *control = [storyboard instantiateViewControllerWithIdentifier:self.identifierArray[i]];
156
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:control];
157 158 159
        [self.vcArray addObject:nav];
        [controllerArray addObject:control];
    }
勾芒's avatar
勾芒 committed
160
    self.viewControllers = self.vcArray;
161
    SHARED_APPDELEGATE.allControllerArray = controllerArray;
曹云霄's avatar
曹云霄 committed
162
    SHARED_APPDELEGATE.tabBarController = self;
曹云霄's avatar
曹云霄 committed
163
    self.selectedIndex = 0;
164 165 166 167 168 169 170 171 172 173
}

#pragma mark -移除系统自带的UITabBarButton
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    for (UIView *view in self.tabBar.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [view removeFromSuperview];
        }
    }
曹云霄's avatar
曹云霄 committed
174
}
曹云霄's avatar
曹云霄 committed
175

176 177
#pragma amrk - TabbarButtonClickdelegate代理
- (void)buttonClickAction:(NSInteger)Buttontag withButton:(UIButton *)button {
曹云霄's avatar
曹云霄 committed
178 179
    [self.toolview.inputField resignFirstResponder];
    [self dismissViewControllerAnimated:NO completion:nil];
180
    _Newbutton = button;
曹云霄's avatar
曹云霄 committed
181
    switch (Buttontag) {
182

183
        case MENU:
184

曹云霄's avatar
曹云霄 committed
185
            [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
186

曹云霄's avatar
曹云霄 committed
187
            break;
188
        case MESSAGE: {
189
            self.selectedIndex = 7;
190 191
        } break;
        case NOTICE: {
192
            self.selectedIndex = 6;
193
        } break;
194
        case SHOPPING_GUIDE:
195

曹云霄's avatar
曹云霄 committed
196
        {
197
            UserViewController *userVC = [[UserViewController alloc] init];
198
            userVC.delegate = self;
199
            userVC.preferredContentSize = CGSizeMake(260, 230);
曹云霄's avatar
曹云霄 committed
200 201 202 203
            userVC.modalPresentationStyle = UIModalPresentationPopover;
            UIPopoverPresentationController *pop = userVC.popoverPresentationController;
            pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
            pop.sourceView = userVC.view;
204
            pop.barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
曹云霄's avatar
曹云霄 committed
205
            [self presentViewController:userVC animated:YES completion:nil];
206
        } break;
207
        case CUSTOMER:
208

曹云霄's avatar
曹云霄 committed
209
            self.selectedIndex = 3;
210

曹云霄's avatar
曹云霄 committed
211
            break;
212
        case SHOPPING_CAR:
勾芒's avatar
勾芒 committed
213 214
            //必须设置当前客户才能跳转到购物车
            if (![Shoppersmanager manager].currentCustomer) {
215

216
                [XBLoadingView showHUDViewWithText:@"必须设置当前客户才能访问购物车"];
217 218
            } else {

曹云霄's avatar
曹云霄 committed
219
                self.selectedIndex = 2;
勾芒's avatar
勾芒 committed
220
            }
221

曹云霄's avatar
曹云霄 committed
222
            break;
223

曹云霄's avatar
曹云霄 committed
224 225
        default:
            break;
曹云霄's avatar
曹云霄 committed
226
    }
曹云霄's avatar
曹云霄 committed
227 228
}

229
#pragma mark -修改密码点击
230 231 232 233 234 235 236 237 238 239 240 241 242
- (void)changPasswordButtonClick {
    [self dismissViewControllerAnimated:NO
                             completion:^{
                                 ChangePasswordViewController *changpassword = [[ChangePasswordViewController alloc] init];
                                 changpassword.delegate = self;
                                 changpassword.preferredContentSize = CGSizeMake(260, 180);
                                 changpassword.modalPresentationStyle = UIModalPresentationPopover;
                                 UIPopoverPresentationController *pop = changpassword.popoverPresentationController;
                                 pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
                                 pop.sourceView = changpassword.view;
                                 pop.barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_Newbutton];
                                 [self presentViewController:changpassword animated:YES completion:nil];
                             }];
曹云霄's avatar
曹云霄 committed
243
}
244 245

#pragma mark -取消按钮
246 247 248 249 250 251 252 253 254 255 256 257 258
- (void)cancelButtonClick {
    [self dismissViewControllerAnimated:NO
                             completion:^{
                                 UserViewController *userVC = [[UserViewController alloc] init];
                                 userVC.delegate = self;
                                 userVC.preferredContentSize = CGSizeMake(260, 230);
                                 userVC.modalPresentationStyle = UIModalPresentationPopover;
                                 UIPopoverPresentationController *pop = userVC.popoverPresentationController;
                                 pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
                                 pop.sourceView = userVC.view;
                                 pop.barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_Newbutton];
                                 [self presentViewController:userVC animated:YES completion:nil];
                             }];
259 260
}

曹云霄's avatar
曹云霄 committed
261
#pragma mark -二维码扫描
262
- (void)qrcodeButtonClick {
曹云霄's avatar
曹云霄 committed
263
    WS(weakSelf);
264
    // 判断应用是否有使用相机的权限
265
    if ([BaseViewController determineCameraPermissions]) {
曹云霄's avatar
曹云霄 committed
266
        QRViewController *qrVC = [[QRViewController alloc] initWithScanCompleteHandler:^(NSString *url) {
267 268 269 270 271 272 273
            [weakSelf dismissViewControllerAnimated:YES
                                         completion:^{
                                             ProductLibraryViewController *product = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:8];
                                             product.barcode = url;
                                             SHARED_APPDELEGATE.lineView.hidden = YES;
                                             weakSelf.selectedIndex = 8;
                                         }];
274
        }];
曹云霄's avatar
曹云霄 committed
275 276 277 278
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf presentViewController:qrVC animated:YES completion:nil];
        });
    }
勾芒's avatar
勾芒 committed
279 280 281
}

#pragma mark -搜索框代理方法
282
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
曹云霄's avatar
曹云霄 committed
283
    self.selectedIndex = 1;
勾芒's avatar
勾芒 committed
284 285 286 287
    return YES;
}

#pragma mark -Search按钮
288
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
289
    if (![BaseViewController isBlankString:textField.text]) {
勾芒's avatar
勾芒 committed
290
        [textField resignFirstResponder];
291
        [Notification postNotificationName:SEARCHSTRING object:textField.text];
勾芒's avatar
勾芒 committed
292 293
    }
    return YES;
曹云霄's avatar
曹云霄 committed
294 295
}

勾芒's avatar
勾芒 committed
296
#pragma mark -自定义选中
297
- (void)setSelectedIndex:(NSUInteger)selectedIndex {
勾芒's avatar
勾芒 committed
298
    [super setSelectedIndex:selectedIndex];
299
    [self didSelectNavigationController:[SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:selectedIndex]];
勾芒's avatar
勾芒 committed
300 301
}

302
#pragma mark -返回根视图控制器
303 304
- (void)didSelectNavigationController:(UIViewController *)viewController {
    if ([[viewController.navigationController.viewControllers firstObject] isKindOfClass:NSClassFromString(@"UIMoreListController")]) {
305
        [viewController.navigationController popToViewController:viewController.navigationController.viewControllers[1] animated:YES];
306
    } else {
307
        [viewController.navigationController popToRootViewControllerAnimated:YES];
勾芒's avatar
勾芒 committed
308 309 310
    }
}

曹云霄's avatar
曹云霄 committed
311
#pragma mark -  切换tabbar selectedIndex
312 313
- (void)switchSelectedIndex:(NSInteger)selectedIndex {
    [self.toolview switchLineViewOrigin:selectedIndex - 100];
曹云霄's avatar
曹云霄 committed
314 315
}

勾芒's avatar
勾芒 committed
316
#pragma mark -推出体验中心控制器
317
- (void)showFollowHeart:(NSNotification *)objc {
318 319 320 321 322 323
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"OppleMain" bundle:nil];
    ExperienceCentreViewController *ExperienceCenter = [storyboard instantiateViewControllerWithIdentifier:@"ExperienceCentre"];
    ExperienceCenter.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *popover = ExperienceCenter.popoverPresentationController;
    popover.sourceView = ExperienceCenter.view;
    [self presentViewController:ExperienceCenter animated:YES completion:nil];
勾芒's avatar
勾芒 committed
324 325
}

326 327 328
#pragma mark -推出3D体验中心控制器
- (void)show3DFollowHeart:(NSNotification *)objc
{
曹云霄's avatar
曹云霄 committed
329 330
    MyclientEntityModel *user = [Customermanager manager].model;
    if (user == nil) {
331
        ShowAlertView(@"提示", @"请先指定当前客户", @[@"我知道了"], UIAlertControllerStyleAlert, nil);
曹云霄's avatar
曹云霄 committed
332 333 334
        return;
    }
    LoginResult *shopper = [Shoppersmanager manager].shoppers;
335 336
    CustomWKWebViewController *webView = [[CustomWKWebViewController alloc] init];
    webView.type = Announcement;
曹云霄's avatar
曹云霄 committed
337
    webView.urlString = [NSString stringWithFormat:BAJIE3D,user.fid,shopper.employee.departid,shopper.employee.fid];
338 339 340
    [self presentViewController:webView animated:YES completion:nil];
    
}
勾芒's avatar
勾芒 committed
341

曹云霄's avatar
曹云霄 committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355














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