OrderdetailsViewController.m 26.7 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
#import "ShareGoodsViewController.h"
20 21 22 23
#import "OrderDetailsSectionHeaderView.h"
#import "PromotionalDeductionModel.h"
#import "PromotionalGoodsModel.h"
#import "PromotionalTableViewCell.h"
曹云霄's avatar
曹云霄 committed
24 25
#import "JDEcardViewController.h"
#import "WYPopoverController.h"
26 27 28 29


NSString *const PROMOTIONALSTRING = @"促销信息";

30 31 32
/**
 *  微信卡劵
 */
33 34
NSString *const WXCardAction = @"WXCardAction";

35 36 37
/**
 *  京东E卡
 */
38 39
NSString *const JDECardAction = @"JDECardAction";

40 41 42
/**
 *  折扣金额
 */
43 44
NSString *const deductionAction = @"deductionAction";

45
/**
曹云霄's avatar
曹云霄 committed
46
 *  赠送商品
47
 */
48
NSString *const goodsAction = @"goodsAction";
49

50 51 52 53 54
/**
 *  转盘抽奖
 */
NSString *const lotteryAction = @"lotteryAction";

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

勾芒's avatar
勾芒 committed
57 58 59 60 61 62

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

勾芒's avatar
勾芒 committed
63 64 65 66 67
/**
 *  本地存储地址
 */
@property (nonatomic,copy) NSString *PDFpath;

68
/**
69
 *  促销信息<商品、折扣>
70 71 72
 */
@property (nonatomic,strong) NSMutableArray *promotionalArray;

73 74 75 76
/**
 *  促销信息<转盘抽奖、京东E卡>
 */
@property (nonatomic,strong) NSMutableArray *luckyDrawAndJDECardArray;
勾芒's avatar
勾芒 committed
77

曹云霄's avatar
曹云霄 committed
78 79 80 81 82
/**
 *  京东E卡
 */
@property (nonatomic,strong) WYPopoverController *settingsPopoverController;

勾芒's avatar
勾芒 committed
83

84 85 86 87
@end

@implementation OrderdetailsViewController

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#pragma mark - lazy
- (NSMutableArray *)promotionalArray
{
    if (!_promotionalArray) {
        _promotionalArray = [NSMutableArray array];
    }
    return _promotionalArray;
}

- (NSMutableArray *)sectionTitle
{
    if (!_sectionTitle) {
        _sectionTitle = [NSMutableArray arrayWithObjects:@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息", nil];
    }
    return _sectionTitle;
}
勾芒's avatar
勾芒 committed
104

105 106 107 108 109 110 111 112
- (NSMutableArray *)luckyDrawAndJDECardArray
{
    if (!_luckyDrawAndJDECardArray) {
        _luckyDrawAndJDECardArray = [NSMutableArray array];
    }
    return _luckyDrawAndJDECardArray;
}

勾芒's avatar
勾芒 committed
113 114 115 116 117
#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
勾芒's avatar
勾芒 committed
118
    if (self.isSliding) {
曹云霄's avatar
曹云霄 committed
119
        self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
120 121 122
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
勾芒's avatar
勾芒 committed
123 124
    }
}
勾芒's avatar
勾芒 committed
125

勾芒's avatar
勾芒 committed
126 127 128 129 130
#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 开启
曹云霄's avatar
曹云霄 committed
131
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
132 133 134
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
勾芒's avatar
勾芒 committed
135
}
勾芒's avatar
勾芒 committed
136

137 138 139 140
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
141
    [self getOrderDetailsData:NO issueJDECard:Zero andGuideId:nil andOrderNumber:nil];
142 143 144 145 146 147 148
}

#pragma mark - UI
- (void)uiConfigAction
{
    self.orderDetailsTableview.dataSource = self;
    self.orderDetailsTableview.delegate = self;
勾芒's avatar
勾芒 committed
149 150 151
    if (self.isShowPrintButton) {
       [self CreateTableviewHeaderView];
    }
勾芒's avatar
勾芒 committed
152 153
    //附加信息cell
    [self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"];
勾芒's avatar
勾芒 committed
154 155 156
    if (self.isShowPayButton) {
       [self CreateTableviewFooterView];
    }
157 158
}

159 160
#pragma mark -获取订单详情、查询促销信息、领取京东E卡
- (void)getOrderDetailsData:(BOOL)isReceiveJDECard issueJDECard:(NSInteger)denomation andGuideId:(NSString *)guideId andOrderNumber:(NSString *)orderNumber
勾芒's avatar
勾芒 committed
161
{
162 163
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
勾芒's avatar
勾芒 committed
164
    [self CreateMBProgressHUDLoding];
165
    WS(weakSelf);
166
    //** 订单详情 */
167
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(ORDERDETAILS),self.orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
168
        
169
         dispatch_group_leave(group);
勾芒's avatar
勾芒 committed
170
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
171
            weakSelf.orderDetails = [[OrderBill alloc]initWithDictionary:returnValue[@"data"] error:nil];
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
        }else{
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
        dispatch_group_leave(group);
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
    }];
    //** 查询促销信息 */
    dispatch_group_enter(group);
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(PROMOTIONAL),self.orderCode]  WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
189
            NSArray *promotionalArray = returnValue[@"data"];
190
            [weakSelf.promotionalArray removeAllObjects];
191
            [weakSelf.luckyDrawAndJDECardArray removeAllObjects];
192 193
            for (NSDictionary *dict in promotionalArray) {
                //** 抵扣金额、京东E卡、微信卡劵 */
194
                if ([dict[@"type"] isEqualToString:deductionAction]) {
195 196
                    PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
                    deductionModel.isSelected = YES;
曹云霄's avatar
曹云霄 committed
197 198 199
                    if (promotionalArray.count && ![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                        [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                    }
200 201 202 203
                    [weakSelf.promotionalArray addObject:deductionModel];
                }else if ([dict[@"type"] isEqualToString:goodsAction]){
                    PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil];
                    goodsModel.isSelected = YES;
曹云霄's avatar
曹云霄 committed
204 205 206
                    if (promotionalArray.count && ![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                        [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                    }
207
                    [weakSelf.promotionalArray addObject:goodsModel];
208 209 210
                }else if ([dict[@"type"] isEqualToString:JDECardAction]){
                    PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
                    [weakSelf.luckyDrawAndJDECardArray addObject:deductionModel];
211
                }
勾芒's avatar
勾芒 committed
212
            }
213 214
        }else{
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
215
        }
216 217 218 219 220 221 222 223 224 225
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
    }];
226 227 228 229 230 231 232
    //** 发放京东E卡 */
    if (isReceiveJDECard) {
        dispatch_group_enter(group);
        [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(JDECARD),denomation,guideId,orderNumber] WithRequestType:0 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
            
            dispatch_group_leave(group);
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
233
                [weakSelf showJEDCard];
234 235 236 237 238 239 240 241 242 243 244 245
            }else{
                [weakSelf ErrorMBProgressView:@"京东E卡领取失败"];
            }
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
            dispatch_group_leave(group);
            [weakSelf ErrorMBProgressView:NETWORK];
        } WithFailureBlock:^(NSError *error) {
            dispatch_group_leave(group);
            [weakSelf ErrorMBProgressView:error.localizedDescription];
        }];
    }
246 247 248 249 250 251 252 253 254 255 256
    //** 完成后回调 */
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
       
        [weakSelf.orderDetailsTableview reloadData];
        //默认弹出支付框
        if (weakSelf.isShowPayButton && [weakSelf.orderDetails.order.orderState isEqualToString:@"001"]) {
            [weakSelf PayButtonClick];
        }
    });
}

曹云霄's avatar
曹云霄 committed
257 258 259 260 261 262 263 264 265 266 267 268 269
#pragma mark - 显示京东E卡
- (void)showJEDCard
{
    JDEcardViewController *jdeCard = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"JDEcardViewController"];
    jdeCard.preferredContentSize = CGSizeMake(500, 400);
    self.settingsPopoverController = [[WYPopoverController alloc] initWithContentViewController:jdeCard];
    self.settingsPopoverController.popoverLayoutMargins = UIEdgeInsetsMake(10, 20, 10, 20);
    self.settingsPopoverController.wantsDefaultContentAppearance = NO;
    self.settingsPopoverController.theme.fillBottomColor = [UIColor clearColor];
    self.settingsPopoverController.theme.fillTopColor = [UIColor clearColor];
    [self.settingsPopoverController presentPopoverAsDialogAnimated:YES
                                                           options:WYPopoverAnimationOptionFadeWithScale];
}
勾芒's avatar
勾芒 committed
270

271 272 273 274 275 276 277
#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
278
    [previewButton setTitle:self.isDelectedButton?@"撤销订单":@"预览" forState:UIControlStateNormal];
279 280
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
281
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
282 283 284 285 286
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
勾芒's avatar
勾芒 committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300
    //显示撤销按钮的情况下,不显示打印按钮
    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];
301 302 303 304 305 306 307 308 309 310 311 312
        
        //分享
        UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
        shareButton.frame = CGRectMake(ScreenWidth-50-350, 15, 150, 30);
        [shareButton setTitle:@"分享" forState:UIControlStateNormal];
        [shareButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        shareButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [shareButton addTarget:self action:@selector(ShareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        shareButton.layer.masksToBounds = YES;
        shareButton.layer.cornerRadius = kCornerRadius;
        shareButton.backgroundColor = kMainBlueColor;
        [headerView addSubview:shareButton];
勾芒's avatar
勾芒 committed
313
    }
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    //横线
    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];
332
    [payButton addTarget:self action:@selector(PayButtonClick) forControlEvents:UIControlEventTouchUpInside];
333 334 335 336 337 338 339 340
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}


341 342 343 344
#pragma mark -调出支付框
- (void)PayButtonClick
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
勾芒's avatar
勾芒 committed
345
    //支付成功
346
    WS(weakSelf);
勾芒's avatar
勾芒 committed
347 348
    [settlement setPaySuccessReturnBlock:^{
        
349
        weakSelf.isDelectedButton = NO;
350
        weakSelf.isUserInteractionEnabled = NO;
351
        [weakSelf CreateTableviewHeaderView];
352
        //** 京东E卡 */
353
        for (id object in self.luckyDrawAndJDECardArray) {
354 355 356
            if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
                PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
                if ([model.type isEqualToString:JDECardAction]) {
357
                    [weakSelf getOrderDetailsData:YES issueJDECard:model.total andGuideId:[Shoppersmanager manager].Shoppers.employee.fid andOrderNumber:self.orderCode];break;
358 359 360
                }
            }
        }
361 362 363 364 365
        weakSelf.orderDetailsTableview.tableFooterView = nil;
        if (weakSelf.DelecteAndPayButtonBlock) {
            weakSelf.DelecteAndPayButtonBlock(_cellindex,@"002");
        }

勾芒's avatar
勾芒 committed
366
    }];
367
    settlement.preferredContentSize = CGSizeMake(380, 500);
勾芒's avatar
勾芒 committed
368
    settlement.goodsArray = self.orderDetails.orderdetailList;
369
    settlement.promotionalArray = self.promotionalArray;
勾芒's avatar
勾芒 committed
370
    settlement.orderCode = _orderCode;
371 372 373 374 375 376 377
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
}


378 379 380 381 382 383 384
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        case 1:
        case 2:
385
        case 4:
386 387 388 389
            return 1;
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
390
            return self.orderDetails.orderdetailList.count+1;
391 392
        }
            break;
393
        case 5:
394
        {
395
            return self.promotionalArray.count;
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
        }
            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
411
            cell.model = self.orderDetails;
412 413 414 415 416 417
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
418
            cell.model = self.orderDetails.consumer;
419 420 421 422 423 424
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
425
            cell.model = self.orderDetails.order;
426 427 428 429 430
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
431
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
432 433 434
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
435
                cell.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
436
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
437 438 439 440 441 442
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
443
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
444 445 446 447 448 449
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
450
            
勾芒's avatar
勾芒 committed
451
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
452
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
453
                return cell;
454 455
        }
            break;
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
        case 5://促销信息
        {
            PromotionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PromotionalTableViewCell" forIndexPath:indexPath];
            NSString *describe = nil;
            id object = self.promotionalArray[indexPath.row];
            if ([object isKindOfClass:[PromotionalGoodsModel class]]) {
                PromotionalGoodsModel *goodsModel = object;
                cell.accessoryType = goodsModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
                describe = [NSString stringWithFormat:@"赠送商品:%@%ld",goodsModel.goods.name,goodsModel.count];
            }else if ([object isKindOfClass:[PromotionalDeductionModel class]]){
                PromotionalDeductionModel *deductionModel = self.promotionalArray[indexPath.row];
                cell.accessoryType = deductionModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
                describe = [NSString stringWithFormat:@"折扣金额:%ld",deductionModel.total];
            }
            cell.promotionalTitleLabel.text = describe;
            cell.userInteractionEnabled = self.isUserInteractionEnabled;
            return cell;
        }
            break;
            
476 477 478
        default:
            break;
    }
479
    return [UITableViewCell new];
480 481
}

勾芒's avatar
勾芒 committed
482

483 484 485 486 487 488 489 490 491 492
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
493
            return 110;
494 495 496 497
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
498
            return 90;
499 500 501 502 503
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
504
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
            return 75;
        }
            break;
520 521 522 523 524
        case 5:
        {
            return 44;
        }
            break;
525 526 527 528 529 530 531 532 533
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
534 535 536
    OrderDetailsSectionHeaderView *headerView = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailsSectionHeaderView"];
    headerView.sectionHeaderTitleLabel.text = [self.sectionTitle objectAtIndex_opple:section];
    return headerView;
537 538 539 540 541
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
542
    return 60;
543 544
}

545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 5) {
        PromotionalTableViewCell *promotionalCell = [tableView cellForRowAtIndexPath:indexPath];
        id object = self.promotionalArray[indexPath.row];
        if ([object isKindOfClass:[PromotionalGoodsModel class]]) {
            PromotionalGoodsModel *goodsModel = object;
            goodsModel.isSelected = !goodsModel.isSelected;
            promotionalCell.accessoryType = goodsModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
        }else if ([object isKindOfClass:[PromotionalDeductionModel class]]){
            PromotionalDeductionModel *deductionModel = object;
            deductionModel.isSelected = !deductionModel.isSelected;
            promotionalCell.accessoryType = deductionModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
        }
    }
}
561 562 563

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
564
    return self.sectionTitle.count;
565 566
}

曹云霄's avatar
曹云霄 committed
567 568 569 570

#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
571
    WS(weakSelf);
勾芒's avatar
勾芒 committed
572
    [self DownloadPDF:^(id Value) {
573
        [weakSelf CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
574 575
        [[NetworkRequestClassManager Manager] DownloadPDFdatasWithURL:Value WithReturnValueBlock:^(id returnValue) {
            
576 577 578
            [weakSelf RemoveMBProgressHUDLoding];
            [weakSelf callAirprintWithdata:returnValue SuccessBlock:^{
                [weakSelf SuccessMBProgressView:@"打印完成"];
勾芒's avatar
勾芒 committed
579
            } ErrorBlock:^{
580
                [weakSelf ErrorMBProgressView:@"打印失败"];
勾芒's avatar
勾芒 committed
581 582 583 584 585
            }];
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
            
        } WithFailureBlock:^(id error) {
586
            [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
587
        }];
勾芒's avatar
勾芒 committed
588
    }];
曹云霄's avatar
曹云霄 committed
589 590 591
}


勾芒's avatar
勾芒 committed
592 593
#pragma mark -下载PDF
- (void)DownloadPDF:(void(^)(id returnValue))success
曹云霄's avatar
曹云霄 committed
594
{
595
    WS(weakSelf);
勾芒's avatar
勾芒 committed
596
    [self CreateMBProgressHUDLoding];
597
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(DOWNLOADPDF),_orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
598
        
599
        [weakSelf RemoveMBProgressHUDLoding];
600
        NSString *url = [NSString stringWithFormat:@"%@",returnValue[@"data"]];
勾芒's avatar
勾芒 committed
601
        success(url);
勾芒's avatar
勾芒 committed
602

勾芒's avatar
勾芒 committed
603
    } WithErrorCodeBlock:^(id errorCodeValue) {
604 605
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:@"网络中断"];
勾芒's avatar
勾芒 committed
606
    } WithFailureBlock:^(id error) {
607
        [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
608
    }];
曹云霄's avatar
曹云霄 committed
609 610
}

勾芒's avatar
勾芒 committed
611

勾芒's avatar
勾芒 committed
612
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
613 614
- (void)PreviewButtonClick:(UIButton *)button
{
615
    WS(weakSelf);
勾芒's avatar
勾芒 committed
616 617 618
    if ([button.currentTitle isEqualToString:@"预览"]) {
        [self DownloadPDF:^(id returnValue) {
            
勾芒's avatar
勾芒 committed
619 620 621 622 623 624 625 626 627
//            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
628
        }];
勾芒's avatar
勾芒 committed
629
        
勾芒's avatar
勾芒 committed
630 631
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
632 633 634 635 636
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"请确认是否撤销订单" preferredStyle:UIAlertControllerStyleAlert];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)
        {
637
            [weakSelf CreateMBProgressHUDLoding];
638
            [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),_orderCode,@"001",@"005"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
639
                [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
640
                if ([returnValue[@"code"] isEqualToNumber:@0]) {
641 642 643 644 645 646 647 648 649 650 651
                    [weakSelf SuccessMBProgressView:@"撤销成功"];
                    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
                    [weakSelf.orderDetailsTableview beginUpdates];
                    weakSelf.orderDetailsTableview.tableHeaderView = view;
                    weakSelf.orderDetailsTableview.tableFooterView = nil;
                    [weakSelf.orderDetailsTableview endUpdates];
                    weakSelf.orderDetails.order.orderState = @"005";
                    weakSelf.isUserInteractionEnabled = NO;
                    [weakSelf.orderDetailsTableview reloadData];
                    if (weakSelf.DelecteAndPayButtonBlock) {
                        weakSelf.DelecteAndPayButtonBlock(_cellindex,@"005");
勾芒's avatar
勾芒 committed
652
                    }
勾芒's avatar
勾芒 committed
653
                }
勾芒's avatar
勾芒 committed
654 655
                else
                {
656
                    [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
657 658 659 660 661 662
                }
                
            } WithErrorCodeBlock:^(id errorCodeValue) {
                
            } WithFailureBlock:^(id error) {
                
663
                [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
664 665 666
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
667
    }
勾芒's avatar
勾芒 committed
668
}
曹云霄's avatar
曹云霄 committed
669

勾芒's avatar
勾芒 committed
670 671 672 673
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
674

勾芒's avatar
勾芒 committed
675 676 677 678
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
679

勾芒's avatar
勾芒 committed
680 681 682 683
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
684

685 686 687 688 689 690
#pragma mark - 分享订单
- (void)ShareButtonClick:(UIButton *)sender
{
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
    shareController.isShareOrderbill = YES;
    shareController.orderBillNumber = self.orderCode;
曹云霄's avatar
曹云霄 committed
691
    shareController.shareImage = [UIImage imageNamed:@"Icon-83.5"];
692 693 694 695 696 697
    shareController.preferredContentSize = CGSizeMake(290, 120);
    shareController.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *popover = shareController.popoverPresentationController;
    popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
    popover.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:sender];
    [self presentViewController:shareController animated:YES completion:nil];
698 699 700
}


701

702
@end