OrderdetailsViewController.m 28.8 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"
曹云霄's avatar
曹云霄 committed
26
#import "RebateSuccessTableViewController.h"
27 28 29 30


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

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

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

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

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

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

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

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

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

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

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

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

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

勾芒's avatar
勾芒 committed
84

85 86 87 88
@end

@implementation OrderdetailsViewController

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#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
105

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

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

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

138 139 140 141
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
142
    [self getOrderDetailsData:nil];
143 144 145 146 147 148 149
}

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

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

曹云霄's avatar
曹云霄 committed
241
#pragma mark - 发放京东E卡
242 243 244 245
- (void)issueJDECard:(NSInteger)denomation andGuideId:(NSString *)guideId andOrderNumber:(NSString *)orderNumber
{
    WS(weakSelf);
    [self CreateMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
246
    NSLog(@"%@",[NSString stringWithFormat:SERVERREQUESTURL(JDECARD),denomation,guideId,orderNumber]);
247 248 249 250
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(JDECARD),denomation,guideId,orderNumber] WithRequestType:0 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
251
            [weakSelf rebateApplySuccess];
252 253 254 255 256 257 258 259 260 261 262 263 264
        }else{
            [weakSelf ErrorMBProgressView:@"京东E卡领取失败"];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
    }];
}

曹云霄's avatar
曹云霄 committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
#pragma mark - 卡劵领取成功
- (void)rebateApplySuccess
{
    RebateSuccessTableViewController *success = [self.getStoryboardWithName instantiateViewControllerWithIdentifier:@"RebateSuccessTableViewController"];
    success.titleArray = @[@"卡劵已发放到你的账户",@"查看账户",@"我知道了"];
    [success setClickEvent:^(NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
            /// 我知道了
        }else if (indexPath.row == 0)
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:OPENCONTROLLER object:@(0)];
        }
    }];
    success.preferredContentSize = CGSizeMake(315, 320);
    success.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = success.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = success.view;
    [self presentViewController:success animated:YES completion:nil];
}

曹云霄's avatar
曹云霄 committed
286
#pragma mark - 显示京东E卡
287
- (void)showJDECard
曹云霄's avatar
曹云霄 committed
288
{
曹云霄's avatar
曹云霄 committed
289
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
290
    JDEcardViewController *jdeCard = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"JDEcardViewController"];
曹云霄's avatar
曹云霄 committed
291 292 293 294
    [jdeCard setDismissJDECardBlock:^{
        [weakSelf.settingsPopoverController dismissPopoverAnimated:YES];
    }];
    jdeCard.preferredContentSize = CGSizeMake(400, 247);
曹云霄's avatar
曹云霄 committed
295 296 297 298 299
    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];
300
    self.settingsPopoverController.theme.glossShadowColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
301 302 303
    [self.settingsPopoverController presentPopoverAsDialogAnimated:YES
                                                           options:WYPopoverAnimationOptionFadeWithScale];
}
勾芒's avatar
勾芒 committed
304

305 306 307 308 309 310 311
#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
312
    [previewButton setTitle:self.isDelectedButton?@"撤销订单":@"预览" forState:UIControlStateNormal];
313 314
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
315
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
316 317 318 319 320
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
勾芒's avatar
勾芒 committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334
    //显示撤销按钮的情况下,不显示打印按钮
    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];
335 336 337 338 339 340 341 342 343 344 345 346
        
        //分享
        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
347
    }
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    //横线
    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];
366
    [payButton addTarget:self action:@selector(PayButtonClick) forControlEvents:UIControlEventTouchUpInside];
367 368 369 370 371 372 373 374
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}


375 376 377 378
#pragma mark -调出支付框
- (void)PayButtonClick
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
勾芒's avatar
勾芒 committed
379
    //支付成功
380
    WS(weakSelf);
勾芒's avatar
勾芒 committed
381
    [settlement setPaySuccessReturnBlock:^{
382 383 384 385 386 387 388 389 390 391 392 393 394 395
        [weakSelf SHOWPrompttext:@"支付成功" ComcpleteBlock:^{
            weakSelf.isDelectedButton = NO;
            weakSelf.isUserInteractionEnabled = NO;
            [weakSelf CreateTableviewHeaderView];
            [weakSelf getOrderDetailsData:^{
                //** 京东E卡 */
                NSInteger totalNumber = 0;//促销卡面额
                for (id object in weakSelf.luckyDrawAndJDECardArray) {
                    if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
                        PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
                        if ([model.type isEqualToString:JDECardAction]) {
                            totalNumber += model.total;
                        }
                    }
396
                }
397 398 399 400 401
                if (totalNumber) {
                    [weakSelf issueJDECard:totalNumber andGuideId:[Shoppersmanager manager].Shoppers.employee.fid andOrderNumber:self.orderCode];
                }
            }];
        }];
402 403
        //** 无促销的情况 */
        if (self.luckyDrawAndJDECardArray.count == 0) {
404
            [weakSelf getOrderDetailsData:nil];
405
        }
406 407 408 409 410
        weakSelf.orderDetailsTableview.tableFooterView = nil;
        if (weakSelf.DelecteAndPayButtonBlock) {
            weakSelf.DelecteAndPayButtonBlock(_cellindex,@"002");
        }

勾芒's avatar
勾芒 committed
411
    }];
412
    settlement.preferredContentSize = CGSizeMake(380, 500);
勾芒's avatar
勾芒 committed
413
    settlement.goodsArray = self.orderDetails.orderdetailList;
414
    settlement.promotionalArray = self.promotionalArray;
勾芒's avatar
勾芒 committed
415
    settlement.orderCode = _orderCode;
416 417 418 419 420 421 422
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
}


423 424 425 426 427 428 429
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        case 1:
        case 2:
430
        case 4:
431 432 433 434
            return 1;
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
435
            return self.orderDetails.orderdetailList.count+1;
436 437
        }
            break;
438
        case 5:
439
        {
440
            return self.promotionalArray.count;
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
        }
            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
456
            cell.model = self.orderDetails;
457 458 459 460 461 462
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
463
            cell.model = self.orderDetails.consumer;
464 465 466 467 468 469
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
470
            cell.model = self.orderDetails.order;
471 472 473 474 475
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
476
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
477 478 479
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
480
                cell.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
481
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
482 483 484 485 486 487
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
488
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
489 490 491 492 493 494
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
495
            
勾芒's avatar
勾芒 committed
496
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
497
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
498
                return cell;
499 500
        }
            break;
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
        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;
            
521 522 523
        default:
            break;
    }
524
    return [UITableViewCell new];
525 526
}

勾芒's avatar
勾芒 committed
527

528 529 530 531 532 533 534 535 536 537
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
538
            return 110;
539 540 541 542
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
543
            return 90;
544 545 546 547 548
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
549
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
            return 75;
        }
            break;
565 566 567 568 569
        case 5:
        {
            return 44;
        }
            break;
570 571 572 573 574 575 576 577 578
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
579 580 581
    OrderDetailsSectionHeaderView *headerView = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailsSectionHeaderView"];
    headerView.sectionHeaderTitleLabel.text = [self.sectionTitle objectAtIndex_opple:section];
    return headerView;
582 583 584 585 586
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
587
    return 60;
588 589
}

590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
- (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;
        }
    }
}
606 607 608

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
609
    return self.sectionTitle.count;
610 611
}

曹云霄's avatar
曹云霄 committed
612 613 614 615

#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
曹云霄's avatar
曹云霄 committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
//    WS(weakSelf);
//    [self DownloadPDF:^(id Value) {
//        [weakSelf CreateMBProgressHUDLoding];
//        [[NetworkRequestClassManager Manager] DownloadPDFdatasWithURL:Value WithReturnValueBlock:^(id returnValue) {
//            [weakSelf RemoveMBProgressHUDLoding];
//            [weakSelf callAirprintWithdata:returnValue SuccessBlock:^{
//                [weakSelf SuccessMBProgressView:@"打印完成"];
//            } ErrorBlock:^{
//                [weakSelf ErrorMBProgressView:@"打印失败"];
//            }];
//        } WithErrorCodeBlock:^(id errorCodeValue) {
//            [weakSelf RemoveMBProgressHUDLoding];
//            [weakSelf ErrorMBProgressView:NETWORK];
//        } WithFailureBlock:^(NSError *error) {
//            [weakSelf RemoveMBProgressHUDLoding];
//            [weakSelf ErrorMBProgressView:error.localizedDescription];
//        }];
//    }];
    [self callAirprintWithURL:[NSURL URLWithString:@"https://www.baidu.com"] SuccessBlock:^{



    } ErrorBlock:^{

勾芒's avatar
勾芒 committed
640
    }];
曹云霄's avatar
曹云霄 committed
641 642
}

曹云霄's avatar
曹云霄 committed
643

勾芒's avatar
勾芒 committed
644 645
#pragma mark -下载PDF
- (void)DownloadPDF:(void(^)(id returnValue))success
曹云霄's avatar
曹云霄 committed
646
{
曹云霄's avatar
曹云霄 committed
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
//    WS(weakSelf);
//    [self CreateMBProgressHUDLoding];
////    NSLog(@"%@",[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(DOWNLOADPDF),_orderCode]);
//    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(DOWNLOADPDF),_orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
//        
//        [weakSelf RemoveMBProgressHUDLoding];
//        NSString *url = [NSString stringWithFormat:@"%@",returnValue[@"data"]];
//        success(url);
//
//    } WithErrorCodeBlock:^(id errorCodeValue) {
//        [weakSelf RemoveMBProgressHUDLoding];
//        [weakSelf ErrorMBProgressView:NETWORK];
//    } WithFailureBlock:^(NSError *error) {
//        [weakSelf RemoveMBProgressHUDLoding];
//        [weakSelf ErrorMBProgressView:error.localizedDescription];
//    }];
    success(@"https://www.baidu.com");
勾芒's avatar
勾芒 committed
664

曹云霄's avatar
曹云霄 committed
665 666
}

勾芒's avatar
勾芒 committed
667
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
668 669
- (void)PreviewButtonClick:(UIButton *)button
{
670
    WS(weakSelf);
勾芒's avatar
勾芒 committed
671 672
    if ([button.currentTitle isEqualToString:@"预览"]) {
        [self DownloadPDF:^(id returnValue) {
勾芒's avatar
勾芒 committed
673 674 675
            PDFViewController *pdfvc = [[PDFViewController alloc]init];
            pdfvc.pdfURLString = returnValue;
            [weakSelf presentViewController:pdfvc animated:YES completion:nil];
勾芒's avatar
勾芒 committed
676
        }];
勾芒's avatar
勾芒 committed
677
        
勾芒's avatar
勾芒 committed
678 679
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
680 681 682 683 684
        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)
        {
685
            [weakSelf CreateMBProgressHUDLoding];
686
            [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),_orderCode,@"001",@"005"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
687
                [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
688
                if ([returnValue[@"code"] isEqualToNumber:@0]) {
689 690 691 692 693 694 695 696 697 698 699
                    [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
700
                    }
701
                } else {
702
                    [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
703 704 705
                }
                
            } WithErrorCodeBlock:^(id errorCodeValue) {
706
                [weakSelf RemoveMBProgressHUDLoding];
707 708 709 710
                [weakSelf ErrorMBProgressView:NETWORK];
            } WithFailureBlock:^(NSError *error) {
                [weakSelf RemoveMBProgressHUDLoding];
                [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
711 712 713
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
714
    }
勾芒's avatar
勾芒 committed
715
}
曹云霄's avatar
曹云霄 committed
716

勾芒's avatar
勾芒 committed
717 718 719 720
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
721

勾芒's avatar
勾芒 committed
722 723 724 725
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
726

勾芒's avatar
勾芒 committed
727 728 729 730
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
731

732 733 734 735 736 737
#pragma mark - 分享订单
- (void)ShareButtonClick:(UIButton *)sender
{
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
    shareController.isShareOrderbill = YES;
    shareController.orderBillNumber = self.orderCode;
曹云霄's avatar
曹云霄 committed
738
    shareController.shareImage = [UIImage imageNamed:@"Icon-83.5"];
739 740 741 742 743 744
    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];
745 746 747
}


748

749
@end