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

#import "BaseViewController.h"

曹云霄's avatar
曹云霄 committed
11
@interface BaseViewController ()<UIPrintInteractionControllerDelegate>
曹云霄's avatar
曹云霄 committed
12 13

@property (nonatomic,strong) MBProgressHUD*TCHud;
勾芒's avatar
勾芒 committed
14
@property (nonatomic,strong) UIWebView *webView;
曹云霄's avatar
曹云霄 committed
15

勾芒's avatar
勾芒 committed
16 17 18 19 20
/**
 *  提示框
 */
@property (nonatomic,strong) PromptinformationView *promptView;

曹云霄's avatar
曹云霄 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
@end

@implementation BaseViewController


/**
 *  创建MBProgressHUD对象
 *
 *  @return MBProgressHUD
 */
- (MBProgressHUD *)TCHud
{
    if (_TCHud == nil) {
        
        _TCHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    }
    return _TCHud;
}

勾芒's avatar
勾芒 committed
40

勾芒's avatar
勾芒 committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/**
 *  初始化提示框
 *
 *  @return PromptinformationView
 */
- (PromptinformationView *)promptView
{
    if (_promptView == nil) {
        
        _promptView = [[[NSBundle mainBundle] loadNibNamed:@"PromptinformationView" owner:self options:nil] firstObject];
    }
    return _promptView;
}




勾芒's avatar
勾芒 committed
58 59 60 61 62 63 64 65 66 67
- (UIWebView *)webView
{
    if (_webView == nil) {
        
        _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    }
    return _webView;
}


曹云霄's avatar
曹云霄 committed
68 69 70
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
勾芒's avatar
勾芒 committed
71 72
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
曹云霄's avatar
曹云霄 committed
73 74 75 76 77 78 79 80 81 82
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -渐隐提示框回调
- (void)SHOWPrompttext:(NSString *)Text ComcpleteBlock:(void(^)())completed
{
83
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
曹云霄's avatar
曹云霄 committed
84 85 86 87 88 89 90 91 92 93 94 95 96
    hud.labelText = Text;
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2.0f];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (completed) {
            completed();
        }
    });
}

#pragma mark -显示MBProgressHUD等待视图
97
- (void)CreateMBProgressHUDLoding
曹云霄's avatar
曹云霄 committed
98 99 100
{
    self.TCHud.animationType = MBProgressHUDAnimationZoom;
    self.TCHud.mode = MBProgressHUDModeIndeterminate;
曹云霄's avatar
曹云霄 committed
101 102
    self.TCHud.color = [UIColor clearColor];
    self.TCHud.activityIndicatorColor = kMainBlueColor;
曹云霄's avatar
曹云霄 committed
103 104 105 106
    self.TCHud.removeFromSuperViewOnHide = YES;
}

#pragma mark -移除MBProgressHUD等待视图
107
- (void)RemoveMBProgressHUDLoding;
曹云霄's avatar
曹云霄 committed
108
{
勾芒's avatar
勾芒 committed
109 110
//    [self.TCHud hide:YES afterDelay:1];
    [self.TCHud hide:YES];
曹云霄's avatar
曹云霄 committed
111 112 113
    self.TCHud = nil;
}

114 115 116 117

#pragma mark -显示成功的提示框
- (void)SuccessMBProgressView:(NSString *)successString
{
118
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    // Set the custom view mode to show any view.
    hud.mode = MBProgressHUDModeCustomView;
    // Set an image view with a checkmark.
    UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    // Looks a bit nicer if we make it square.
    hud.square = YES;
    // Optional label text.
    hud.activityIndicatorColor = kMainBlueColor;
    hud.labelFont = [UIFont systemFontOfSize:12];
    hud.labelText = successString;
    [hud hide:YES afterDelay:1];
}

#pragma mark -显示错误的提示框
- (void)ErrorMBProgressView:(NSString *)errorString
{
勾芒's avatar
勾芒 committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
//    // Set the custom view mode to show any view.
//    hud.mode = MBProgressHUDModeText;
//    // Set an image view with a checkmark.
////    UIImage *image = [[UIImage imageNamed:@"Error"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
////    hud.customView = [[UIImageView alloc] initWithImage:image];
//    // Looks a bit nicer if we make it square.
////    hud.square = YES;
//    // Optional label text.
////    hud.activityIndicatorColor = kMainBlueColor;
//    hud.labelFont = [UIFont systemFontOfSize:12];
//    hud.labelText = errorString;
//    [hud hide:YES afterDelay:1];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
151
    hud.labelText = errorString;
勾芒's avatar
勾芒 committed
152 153 154 155 156 157 158
    hud.margin = 10.f;
    hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    hud.minSize = CGSizeMake(200, 50);
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.0f];
159 160 161
}


勾芒's avatar
勾芒 committed
162 163 164 165 166 167 168

#pragma mark -渐隐提示框
- (void)SHOWPrompttext:(NSString *)Text
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = Text;
    hud.margin = 10.f;
勾芒's avatar
勾芒 committed
169 170
    hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    hud.minSize = CGSizeMake(200, 50);
勾芒's avatar
勾芒 committed
171 172 173 174 175 176 177 178
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.0f];
    
}


曹云霄's avatar
曹云霄 committed
179 180 181 182 183 184 185 186 187 188 189 190 191
#pragma mark -结束MJRfresh刷新
- (void)endRefreshingForTableView:(UIScrollView *)TableView
{
    if (TableView.mj_header.isRefreshing) {
        
        [TableView.mj_header endRefreshing];
    }
    else if (TableView.mj_footer.isRefreshing)
    {
        [TableView.mj_footer endRefreshing];
    }
}

曹云霄's avatar
曹云霄 committed
192 193 194 195 196 197 198 199
#pragma mark -获得我的storyboard对象
- (UIStoryboard *)getStoryboardWithName
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    return storyboard;
}

#pragma mark 调用airPrint无线打印机
勾芒's avatar
勾芒 committed
200
- (void)callAirprintWithdata:(NSString *)PDFpath SuccessBlock:(void(^)())success ErrorBlock:(void(^)())failed
曹云霄's avatar
曹云霄 committed
201 202
{
    
勾芒's avatar
勾芒 committed
203
    NSData *mypdfdata = [NSData dataWithContentsOfFile:PDFpath];
曹云霄's avatar
曹云霄 committed
204 205 206 207 208 209 210 211 212 213 214
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    if  (pic && [UIPrintInteractionController canPrintData: mypdfdata] ) {
        pic.delegate = self;
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = @"订单明细";
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = mypdfdata;
        
勾芒's avatar
勾芒 committed
215 216 217 218 219 220 221 222 223 224 225
        void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
            if (completed)
            {
                // 执行成功后的处理
                success();
            }
            else if (!completed && error)
            {
                // 执行失败后的处理
                failed();
            }
曹云霄's avatar
曹云霄 committed
226
        };
勾芒's avatar
勾芒 committed
227 228
        
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
曹云霄's avatar
曹云霄 committed
229 230 231 232 233 234
            
            [pic presentAnimated:YES completionHandler:completionHandler];
        }
    }
}

曹云霄's avatar
曹云霄 committed
235

勾芒's avatar
勾芒 committed
236 237 238 239



#pragma mark 调用airPrint无线打印机
勾芒's avatar
勾芒 committed
240
- (void)callAirprintWithURL:(NSURL *)datasurl SuccessBlock:(void (^)())success ErrorBlock:(void (^)())failed
勾芒's avatar
勾芒 committed
241 242 243 244 245 246 247 248 249 250 251 252
{
//    NSData *mypdfdata = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"The Swift Programming Language 中文版 - v1.2" ofType:@"pdf"]];
    
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];

        pic.delegate = self;
        [self.webView loadRequest:[NSURLRequest requestWithURL:datasurl]];//网页
        pic.printFormatter = [self.webView viewPrintFormatter];//布局打印视图绘制的内容。
        
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = @"订单明细";
勾芒's avatar
勾芒 committed
253
        printInfo.duplex = UIPrintInfoDuplexShortEdge;
勾芒's avatar
勾芒 committed
254 255 256
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
    
勾芒's avatar
勾芒 committed
257 258 259 260 261 262 263 264 265 266
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
        if (completed)
        {
            // 执行成功后的处理
            success();
        }
        else if (!completed && error)
        {
            // 执行失败后的处理
            failed();
勾芒's avatar
勾芒 committed
267
        }
勾芒's avatar
勾芒 committed
268 269 270 271 272 273
    };

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        
        [pic presentAnimated:YES completionHandler:completionHandler];
    }
勾芒's avatar
勾芒 committed
274 275 276
}


勾芒's avatar
勾芒 committed
277
#pragma mark -提示文本,图片
勾芒's avatar
勾芒 committed
278
- (void)PromptinformationViewWithimage:(UIImage *)image withTitle:(NSString *)title withpoint:(CGPoint)point
勾芒's avatar
勾芒 committed
279
{
勾芒's avatar
勾芒 committed
280 281 282 283
    self.promptView.tipsImage.image = image;
    self.promptView.tipsTitle.text = title;
    self.promptView.frame = CGRectMake(point.x, point.y, 250, 170);
    [self.view addSubview:self.promptView];
勾芒's avatar
勾芒 committed
284
}
勾芒's avatar
勾芒 committed
285

勾芒's avatar
勾芒 committed
286 287 288 289 290 291
#pragma mark -删除提示文本、图片
- (void)RemovePromptinformationView
{
    [self.promptView removeFromSuperview];
    self.promptView = nil;
}
勾芒's avatar
勾芒 committed
292 293 294 295




勾芒's avatar
勾芒 committed
296 297 298 299 300
#pragma mark -传入订单状态,返回当前状态图片
+ (UIImage *)ReturnOrderStateImageWithStateCode:(NSInteger)ordercode
{
   const NSArray *imageArray = [NSArray arrayWithObjects:@"已撤销",@"已完成",@"已退货", nil];
    switch (ordercode) {
勾芒's avatar
勾芒 committed
301
        case 4://退货
勾芒's avatar
勾芒 committed
302 303 304 305
        {
            return TCImage([imageArray objectAtIndex_opple:2]);
        }
            break;
勾芒's avatar
勾芒 committed
306
        case 5://作废
勾芒's avatar
勾芒 committed
307 308 309 310
        {
            return TCImage([imageArray objectAtIndex_opple:0]);
        }
            break;
勾芒's avatar
勾芒 committed
311
        case 6://完成
勾芒's avatar
勾芒 committed
312 313 314 315 316 317 318 319 320 321
        {
            return TCImage([imageArray objectAtIndex_opple:1]);
        }
            break;
            
        default:
            break;
    }
    return nil;
}
勾芒's avatar
勾芒 committed
322 323


勾芒's avatar
勾芒 committed
324 325 326
#pragma mark -传入订单状态,返回订单文本信息,字体颜色
+ (id)ReturnOrderStateTitleWithStateCode:(NSInteger)ordercode withPoint:(CGPoint)point WithCode:(NSInteger)code
{
勾芒's avatar
勾芒 committed
327

勾芒's avatar
勾芒 committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    switch (ordercode) {
        case 001://未付款
        {
            if (code) {
                return kTCColor(241, 81, 83);
            }
            return @"未付款";
        }
            break;
        case 002://已付款
        {

            if (code) {
                return kTCColor(126, 191, 53);
            }
            return @"已付款";
        }
            break;
        case 003://已发货
        {

            if (code) {
                return kTCColor(240, 180, 51);
            }
            return @"已发货";
        }
            break;
        case 004://已退货
        {

            if (code) {
                return kTCColor(153, 153, 153);
            }
            return @"已退货";
        }
            break;
        case 005://已作废
        {

            if (code) {
                return kTCColor(153, 153, 153);
            }
勾芒's avatar
勾芒 committed
370
            return @"已撤销";
勾芒's avatar
勾芒 committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
        }
            break;
        case 006://已完成
        {

            if (code) {
                return kTCColor(89, 172, 220);
            }
            return @"已完成";
        }
            break;
            
        default:
            break;
    }
    return nil;
}
勾芒's avatar
勾芒 committed
388

勾芒's avatar
勾芒 committed
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
#pragma mark -查询购物车数量
- (void)QueryShoppingCarNumber
{
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/shopcart/get/",[Customermanager manager].customerID] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            NSLog(@"更新购物车数量成功");
            [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHSHOPPINGCAR object:returnValue[@"data"]];
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        NSLog(@"更新购物车数量失败");
    }];
}

勾芒's avatar
勾芒 committed
406 407


勾芒's avatar
勾芒 committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
#pragma mark -系统提示框
- (void)promptCustomerWithString:(NSString *)message
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
    }]];
    [self presentViewController:alertVC animated:YES completion:nil];
}





勾芒's avatar
勾芒 committed
423 424 425



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