OrderdetailsViewController.m 16.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//
//  OrderdetailsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/4.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "OrderdetailsViewController.h"
#import "OrderInformationTableViewCell.h"
#import "PersonInformationTableViewCell.h"
#import "GoodsInformationTableViewCell.h"
#import "CommodityListTableViewCell.h"
#import "AllpriceTableViewCell.h"
15
#import "SettlementViewController.h"
勾芒's avatar
勾芒 committed
16
#import "AdditionalTableViewCell.h"
勾芒's avatar
勾芒 committed
17
#import <QuickLook/QuickLook.h>
勾芒's avatar
勾芒 committed
18
#import "PDFViewController.h"
19

勾芒's avatar
勾芒 committed
20
@interface OrderdetailsViewController ()<UITableViewDelegate,UITableViewDataSource,QLPreviewControllerDataSource>
21

勾芒's avatar
勾芒 committed
22 23 24 25 26 27

/**
 *  订单详情数据
 */
@property (nonatomic,strong) OrderBill *orderDetails;

勾芒's avatar
勾芒 committed
28 29 30 31 32
/**
 *  本地存储地址
 */
@property (nonatomic,copy) NSString *PDFpath;

勾芒's avatar
勾芒 committed
33 34


35 36 37 38
@end

@implementation OrderdetailsViewController

勾芒's avatar
勾芒 committed
39

勾芒's avatar
勾芒 committed
40 41 42 43 44
#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
勾芒's avatar
勾芒 committed
45 46 47 48 49 50
    if (self.isSliding) {
        // 禁用 iOS7 返回手势
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
  
勾芒's avatar
勾芒 committed
51 52
    }
}
勾芒's avatar
勾芒 committed
53

勾芒's avatar
勾芒 committed
54 55 56 57 58 59 60 61 62
#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 开启
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}
勾芒's avatar
勾芒 committed
63 64


65 66 67 68
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
69
    [self getOrderDetailsData];
70 71 72 73 74 75 76 77 78
}



#pragma mark - UI
- (void)uiConfigAction
{
    self.orderDetailsTableview.dataSource = self;
    self.orderDetailsTableview.delegate = self;
勾芒's avatar
勾芒 committed
79 80 81
    if (self.isShowPrintButton) {
       [self CreateTableviewHeaderView];
    }
勾芒's avatar
勾芒 committed
82 83
    //附加信息cell
    [self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"];
勾芒's avatar
勾芒 committed
84
    if (self.isShowPayButton) {
勾芒's avatar
勾芒 committed
85
        
勾芒's avatar
勾芒 committed
86 87
       [self CreateTableviewFooterView];
    }
88 89
}

勾芒's avatar
勾芒 committed
90

勾芒's avatar
勾芒 committed
91
#pragma mark -获取订单详情
勾芒's avatar
勾芒 committed
92 93
- (void)getOrderDetailsData
{
勾芒's avatar
勾芒 committed
94
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
95
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/order/findOrder/",self.orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
96
        
勾芒's avatar
勾芒 committed
97
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
98 99
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
勾芒's avatar
勾芒 committed
100 101
            self.orderDetails = [[OrderBill alloc]initWithDictionary:returnValue[@"data"] error:nil];
            [self.orderDetailsTableview reloadData];
勾芒's avatar
勾芒 committed
102 103 104 105
            //默认弹出支付框
            if (self.isShowPayButton && [self.orderDetails.order.orderState isEqualToString:@"001"]) {
                [self PayButtonClick];
            }
勾芒's avatar
勾芒 committed
106 107 108 109 110
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
勾芒's avatar
勾芒 committed
111 112 113 114 115
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
116
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
117 118
    }];
}
勾芒's avatar
勾芒 committed
119 120 121 122 123





124 125 126 127 128 129 130 131
#pragma mark -TableviewHeader------根据不同的订单状态判断是否显示
- (void)CreateTableviewHeaderView
{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
    
    //预览
    UIButton *previewButton = [UIButton buttonWithType:UIButtonTypeSystem];
    previewButton.frame = CGRectMake(50, 15, 150, 30);
勾芒's avatar
勾芒 committed
132
    [previewButton setTitle:self.isDelectedButton?@"撤销订单":@"预览" forState:UIControlStateNormal];
133 134
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
135
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
136 137 138 139 140
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
勾芒's avatar
勾芒 committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    //显示撤销按钮的情况下,不显示打印按钮
    if (!self.isDelectedButton) {
     
        //打印
        UIButton *printButton = [UIButton buttonWithType:UIButtonTypeSystem];
        printButton.frame = CGRectMake(ScreenWidth-50-150, 15, 150, 30);
        [printButton setTitle:@"打印" forState:UIControlStateNormal];
        [printButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        printButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [printButton addTarget:self action:@selector(AirprintButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        printButton.layer.masksToBounds = YES;
        printButton.layer.cornerRadius = kCornerRadius;
        printButton.backgroundColor = kMainBlueColor;
        [headerView addSubview:printButton];
    }
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    
    //横线
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 59, ScreenWidth, 1)];
    lineView.backgroundColor = kTCColor(193, 193, 193);
    [headerView addSubview:lineView];
    self.orderDetailsTableview.tableHeaderView = headerView;
}

#pragma mark -TableviewFooterView------根据不同的订单状态判断支付按钮是否显示
- (void)CreateTableviewFooterView
{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
    
    //支付
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeSystem];
    payButton.frame = CGRectMake((ScreenWidth-150)/2, 30, 150, 40);
    [payButton setTitle:@"支付" forState:UIControlStateNormal];
    payButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
175
    [payButton addTarget:self action:@selector(PayButtonClick) forControlEvents:UIControlEventTouchUpInside];
176 177 178 179 180 181 182 183
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}


184 185 186 187
#pragma mark -调出支付框
- (void)PayButtonClick
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
勾芒's avatar
勾芒 committed
188 189 190 191
    //支付成功
    [settlement setPaySuccessReturnBlock:^{
        
        [self getOrderDetailsData];
勾芒's avatar
勾芒 committed
192
        self.isDelectedButton = NO;
勾芒's avatar
勾芒 committed
193 194
        [self CreateTableviewHeaderView];
        self.orderDetailsTableview.tableFooterView = nil;
勾芒's avatar
勾芒 committed
195 196 197
        if (self.DelecteAndPayButtonBlock) {
            self.DelecteAndPayButtonBlock(_cellindex,@"002");
        }
勾芒's avatar
勾芒 committed
198
    }];
199
    settlement.preferredContentSize = CGSizeMake(380, 500);
勾芒's avatar
勾芒 committed
200
    settlement.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
201
    settlement.orderCode = _orderCode;
202 203 204 205 206 207 208
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
}


209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        {
            return 1;
        }
            break;
        case 1:
        {
            return 1;
        }
            break;
        case 2:
        {
            return 1;
        }
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
230
            return self.orderDetails.orderdetailList.count+1;
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
        }
            break;
        case 4:
        {
           return 1;
        }
            break;
            
        default:
            break;
    }
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.section) {
        case 0://订单信息
        {
            OrderInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
252
            cell.model = self.orderDetails;
253 254 255 256 257 258
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
259
            cell.model = self.orderDetails.consumer;
260 261 262 263 264 265
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
266
            cell.model = self.orderDetails.order;
267 268 269 270 271
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
272
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
273 274 275
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
276
                cell.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
277
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
278 279 280 281 282 283
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
284
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
285 286 287 288 289 290
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
勾芒's avatar
勾芒 committed
291 292 293 294
            //是否显示
            if (_isShowattachment) {
             
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
295
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
296
                
勾芒's avatar
勾芒 committed
297 298
                return cell;
            }
299 300 301 302 303 304 305 306
        }
            break;
        default:
            break;
    }
    return nil;
}

勾芒's avatar
勾芒 committed
307 308 309 310




311 312 313 314 315 316 317 318 319 320
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
321
            return 110;
322 323 324 325
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
326
            return 90;
327 328 329 330 331
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
332
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
333 334 335 336 337 338 339 340 341 342 343 344
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
勾芒's avatar
勾芒 committed
345 346 347 348 349
            //是否显示附件信息
            if (!_isShowattachment) {
                
                return 0;
            }
350 351 352 353 354 355 356 357 358 359 360 361 362
            return 75;
        }
            break;
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
        
勾芒's avatar
勾芒 committed
363
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
364
    //区头文字
勾芒's avatar
勾芒 committed
365 366 367 368
    UILabel *Titlelabe = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 50)];
    Titlelabe.text = [NSString stringWithFormat:@"       %@",[self.sectionTitle objectAtIndex_opple:section]];
    view.backgroundColor = kTCColor(236, 236, 236);
    Titlelabe.backgroundColor = [UIColor whiteColor];
369 370 371 372 373 374 375 376 377
    Titlelabe.font = [UIFont systemFontOfSize:13];
    [view addSubview:Titlelabe];
    return view;
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
378
    return 60;
379 380 381 382 383 384
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
385
    return self.sectionTitle.count;
386 387
}

曹云霄's avatar
曹云霄 committed
388 389 390 391

#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
勾芒's avatar
勾芒 committed
392
    [self DownloadPDF:^(id Value) {
勾芒's avatar
勾芒 committed
393
        
勾芒's avatar
勾芒 committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407
        [self CreateMBProgressHUDLoding];
        [[NetworkRequestClassManager Manager] DownloadPDFdatasWithURL:Value WithReturnValueBlock:^(id returnValue) {
            
            [self RemoveMBProgressHUDLoding];
            [self callAirprintWithdata:returnValue SuccessBlock:^{
                [self SuccessMBProgressView:@"打印完成"];
            } ErrorBlock:^{
                [self ErrorMBProgressView:@"打印失败"];
            }];
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
            
        } WithFailureBlock:^(id error) {
            [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
408
        }];
勾芒's avatar
勾芒 committed
409
    }];
曹云霄's avatar
曹云霄 committed
410 411 412
}


勾芒's avatar
勾芒 committed
413 414
#pragma mark -下载PDF
- (void)DownloadPDF:(void(^)(id returnValue))success
曹云霄's avatar
曹云霄 committed
415
{
勾芒's avatar
勾芒 committed
416
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
417
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/order/UrlOfprintPDF/",_orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
418
        
勾芒's avatar
勾芒 committed
419
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
420
        NSString *url = [NSString stringWithFormat:@"%@%@",PDFSERADDRESS,returnValue[@"data"]];
勾芒's avatar
勾芒 committed
421
        success(url);
勾芒's avatar
勾芒 committed
422

勾芒's avatar
勾芒 committed
423
        
勾芒's avatar
勾芒 committed
424 425 426
    } WithErrorCodeBlock:^(id errorCodeValue) {
        [self RemoveMBProgressHUDLoding];
        [self ErrorMBProgressView:@"网络中断"];
勾芒's avatar
勾芒 committed
427 428 429
    } WithFailureBlock:^(id error) {
        [self RemoveMBProgressHUDLoding];
    }];
曹云霄's avatar
曹云霄 committed
430 431
}

勾芒's avatar
勾芒 committed
432

勾芒's avatar
勾芒 committed
433
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
434 435
- (void)PreviewButtonClick:(UIButton *)button
{
勾芒's avatar
勾芒 committed
436
    if ([button.currentTitle isEqualToString:@"预览"]) {
勾芒's avatar
勾芒 committed
437 438
        
        __weak typeof(self) weakSelf = self;
勾芒's avatar
勾芒 committed
439 440
        [self DownloadPDF:^(id returnValue) {
            
勾芒's avatar
勾芒 committed
441 442 443 444 445 446 447 448 449
//            self.PDFpath = returnValue;
//            QLPreviewController *previewController = [[QLPreviewController alloc] init];
//            previewController.dataSource = weakSelf;
//            previewController.navigationController.navigationBarHidden = YES;
//            [weakSelf presentViewController:previewController animated:YES completion:nil];
            
            PDFViewController *pdfvc = [[PDFViewController alloc]init];
            pdfvc.pdfURLString = returnValue;
            [weakSelf presentViewController:pdfvc animated:YES completion:nil];
勾芒's avatar
勾芒 committed
450
        }];
勾芒's avatar
勾芒 committed
451
        
勾芒's avatar
勾芒 committed
452 453
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
454 455 456 457 458 459 460 461 462
        __weak typeof(self) weakSelf = self;
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请确认是否撤销订单" preferredStyle:UIAlertControllerStyleAlert];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)
        {
            [self CreateMBProgressHUDLoding];
            [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@/%@/%@",ServerAddress,@"/order/updateOrderState/",_orderCode,@"001",@"005"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
463
                
勾芒's avatar
勾芒 committed
464 465 466 467 468 469 470 471 472 473 474 475 476
                [self RemoveMBProgressHUDLoding];
                if ([returnValue[@"code"] isEqualToNumber:@0]) {
                    
                    [self SuccessMBProgressView:@"撤销成功"];
                    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 0)];
                    self.orderDetailsTableview.tableHeaderView = view;
                    self.orderDetailsTableview.tableFooterView = nil;
                    self.orderDetails.order.orderState = @"005";
                    [self.orderDetailsTableview reloadData];
                    
                    if (self.DelecteAndPayButtonBlock) {
                        self.DelecteAndPayButtonBlock(_cellindex,@"005");
                    }
勾芒's avatar
勾芒 committed
477
                }
勾芒's avatar
勾芒 committed
478 479 480 481 482 483 484 485 486 487 488 489 490
                else
                {
                    [self ErrorMBProgressView:returnValue[@"message"]];
                }
                
            } WithErrorCodeBlock:^(id errorCodeValue) {
                
            } WithFailureBlock:^(id error) {
                
                [self RemoveMBProgressHUDLoding];
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
491
    }
勾芒's avatar
勾芒 committed
492
}
曹云霄's avatar
曹云霄 committed
493

勾芒's avatar
勾芒 committed
494 495 496 497
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
498

勾芒's avatar
勾芒 committed
499 500 501 502
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
503

504 505 506 507 508 509 510
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
勾芒's avatar
勾芒 committed
511

勾芒's avatar
勾芒 committed
512 513 514 515
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
516 517 518 519 520 521 522 523

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


@end