OrderdetailsViewController.m 47.6 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>
18
#import "CustomWKWebViewController.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
#import "PromotionLuckyDrawModel.h"
#import "PromotionLuckDrawResultModel.h"
29 30
#import "AirPrintManager.h"
#import <WebKit/WebKit.h>
31 32
#import "PromotionJDECardModel.h"
#import "PromotionWeChatCardModel.h"
33 34
#import "PromotionChooseViewController.h"
#import "PromotionChooseNavigationController.h"
35
#import "QRViewController.h"
36 37 38 39 40


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


41

42
@interface OrderdetailsViewController ()<UITableViewDelegate,UITableViewDataSource,QLPreviewControllerDataSource,WKNavigationDelegate,confirmPromotionDelegate>
43
@property (nonatomic,strong) WKWebView *webView;
勾芒's avatar
勾芒 committed
44 45 46 47 48 49

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

勾芒's avatar
勾芒 committed
50 51 52 53 54
/**
 *  本地存储地址
 */
@property (nonatomic,copy) NSString *PDFpath;

55

56
/**
57
 *  已享受促销信息
58
 */
59
@property (nonatomic,strong) NSMutableArray *promotionInformationArray;
勾芒's avatar
勾芒 committed
60

曹云霄's avatar
曹云霄 committed
61 62 63 64 65
/**
 *  京东E卡
 */
@property (nonatomic,strong) WYPopoverController *settingsPopoverController;

66 67 68
/**
 *  客户抽奖结果
 */
69 70 71
@property (nonatomic,strong) PromotionLuckDrawResultModel *customerDrawModel;

/**
72
   消费者促销列表
73 74
 */
@property (nonatomic,strong) NSMutableArray *customerPromotionArray;
75

76 77 78 79 80
/**
   导购促销列表
 */
@property (nonatomic,strong) NSMutableArray *guidePromotionArray;

81

82 83 84 85 86
/**
 微信卡劵
 */
@property (nonatomic,strong) WeChatCardModel *weChatModel;

87 88 89 90 91
/**
 扫描微信卡劵(重试)
 */
@property (nonatomic,strong) PromotionWeChatCardModel *tempWeChatModel;

92

勾芒's avatar
勾芒 committed
93

94

95 96 97 98
@end

@implementation OrderdetailsViewController

99 100 101 102 103 104 105 106
#pragma mark - lazy
- (NSMutableArray *)sectionTitle
{
    if (!_sectionTitle) {
        _sectionTitle = [NSMutableArray arrayWithObjects:@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息", nil];
    }
    return _sectionTitle;
}
勾芒's avatar
勾芒 committed
107

108 109 110 111 112 113 114 115
- (NSMutableArray *)guidePromotionArray
{
    if (!_guidePromotionArray) {
        _guidePromotionArray = [NSMutableArray array];
    }
    return _guidePromotionArray;
}

116
- (NSMutableArray *)promotionInformationArray
117
{
118 119
    if (!_promotionInformationArray) {
        _promotionInformationArray = [NSMutableArray array];
120
    }
121
    return _promotionInformationArray;
122 123
}

124 125 126 127 128 129 130 131
- (NSMutableArray *)customerPromotionArray
{
    if (!_customerPromotionArray) {
        _customerPromotionArray = [NSMutableArray array];
    }
    return _customerPromotionArray;
}

132 133 134 135 136 137 138 139
- (WeChatCardModel *)weChatModel
{
    if (!_weChatModel) {
        _weChatModel = [[WeChatCardModel alloc]init];
    }
    return _weChatModel;
}

勾芒's avatar
勾芒 committed
140 141 142 143 144
#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
勾芒's avatar
勾芒 committed
145
    if (self.isSliding) {
曹云霄's avatar
曹云霄 committed
146
        self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
147 148 149
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
勾芒's avatar
勾芒 committed
150 151
    }
}
勾芒's avatar
勾芒 committed
152

勾芒's avatar
勾芒 committed
153 154 155 156 157
#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 开启
曹云霄's avatar
曹云霄 committed
158
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
159 160 161
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
勾芒's avatar
勾芒 committed
162
}
勾芒's avatar
勾芒 committed
163

164 165 166 167
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
168
    [self getOrderDetailsData:nil];
169 170 171 172 173 174 175
}

#pragma mark - UI
- (void)uiConfigAction
{
    self.orderDetailsTableview.dataSource = self;
    self.orderDetailsTableview.delegate = self;
勾芒's avatar
勾芒 committed
176 177
    //附加信息cell
    [self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"];
勾芒's avatar
勾芒 committed
178
    if (self.isShowPayButton) {
179 180 181 182
        [self CreateTableviewFooterView];
    }
    if (self.isShowHeaderView) {
        [self CreateTableviewHeaderView];
勾芒's avatar
勾芒 committed
183
    }
184 185
}

186

187
#pragma mark -获取订单详情、查询促销信息
188
- (void)getOrderDetailsData:(void(^)())finish
勾芒's avatar
勾芒 committed
189
{
190 191
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
曹云霄's avatar
曹云霄 committed
192
    [XBLoadingView showHUDViewWithDefault];
193
    WS(weakSelf);
194
    // 订单详情
195
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(ORDERDETAILS),self.orderCode]  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
196
        
197
         dispatch_group_leave(group);
勾芒's avatar
勾芒 committed
198
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
199
            weakSelf.orderDetails = [[OrderBill alloc]initWithDictionary:returnValue[@"data"] error:nil];
200
        }else{
曹云霄's avatar
曹云霄 committed
201
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
202
        }
203
    }WithFailureBlock:^(NSError *error) {
204
        dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
205
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
206
    }];
曹云霄's avatar
曹云霄 committed
207
    
208
    // 未支付的订单查询实时促销,否则查询历史促销
曹云霄's avatar
曹云霄 committed
209
    if (self.isShowPayButton) {
210
        // 查询实时促销信息
曹云霄's avatar
曹云霄 committed
211
        dispatch_group_enter(group);
212
        [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(PROMOTIONAL),self.orderCode]   WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
213 214
            
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
215
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
216
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
217
                [weakSelf.promotionInformationArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
218 219
                [weakSelf.guidePromotionArray removeAllObjects];
                [weakSelf.customerPromotionArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
220 221 222
                NSArray *promotionalArray = returnValue[@"data"][@"actions"];
                for (NSDictionary *dict in promotionalArray) {
                    NSString *type = dict[@"type"];
223
                        // 折扣金额
曹云霄's avatar
曹云霄 committed
224 225
                    if ([type isEqualToString:deductionAction]) {
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
226 227
                        [weakSelf getConsumerAllPromotion:deductionModel withBody:deductionModel.body];
                        // 赠送商品
曹云霄's avatar
曹云霄 committed
228 229
                    }else if ([type isEqualToString:goodsAction]){
                        PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil];
230 231
                        [weakSelf getConsumerAllPromotion:goodsModel withBody:goodsModel.body];
                        // 京东E卡
曹云霄's avatar
曹云霄 committed
232
                    }else if ([type isEqualToString:JDECardAction]){
233 234
                        PromotionJDECardModel *JDECardModel = [[PromotionJDECardModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf getConsumerAllPromotion:JDECardModel withBody:JDECardModel.body];
235
                        // 转盘抽奖
曹云霄's avatar
曹云霄 committed
236
                    }else if ([type isEqualToString:lotteryAction]){
237 238 239 240 241 242
                        PromotionLuckyDrawModel *drawModel = [[PromotionLuckyDrawModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf getConsumerAllPromotion:drawModel withBody:drawModel.body];
                    }else if ([type isEqualToString:WeChatCard]){
                        // 微信卡劵
                        PromotionWeChatCardModel *weChatModel = [[PromotionWeChatCardModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf getConsumerAllPromotion:weChatModel withBody:weChatModel.body];
曹云霄's avatar
曹云霄 committed
243
                    }
曹云霄's avatar
曹云霄 committed
244 245
                }
            }else{
曹云霄's avatar
曹云霄 committed
246
                [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
曹云霄's avatar
曹云霄 committed
247 248 249
            }
        } WithFailureBlock:^(NSError *error) {
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
250 251
            [XBLoadingView hideHUDViewWithDefault];
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
252 253 254
        }];

    }else {
255
        // 查询历史促销信息
曹云霄's avatar
曹云霄 committed
256
        dispatch_group_enter(group);
257
        [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(OLDPROMOTIONAL),self.orderCode]   WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
258 259
            
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
260
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
261
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
262
                [weakSelf.promotionInformationArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
263 264
                [weakSelf.guidePromotionArray removeAllObjects];
                [weakSelf.customerPromotionArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
265 266 267
                NSArray *promotion = returnValue[@"data"];
                for (NSDictionary *dict in promotion) {
                    TOOrderPromotionEntity *oldPromotion = [[TOOrderPromotionEntity alloc]initWithDictionary:dict error:nil];
268
                         // 赠送商品
曹云霄's avatar
曹云霄 committed
269 270 271 272 273 274 275 276 277 278
                    if (![BaseViewController isBlankString:oldPromotion.goodsName]) {
                        if (![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                            [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                        }
                        PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]init];
                        goodsModel.count = [oldPromotion.promotionNumber integerValue];
                        Goods *goods = [[Goods alloc]init];
                        goods.name = oldPromotion.goodsName;
                        goodsModel.goods = goods;
                        goodsModel.isSelected = YES;
279
                        goodsModel.priority = oldPromotion.prority;
280
                        [weakSelf.promotionInformationArray addObject:goodsModel];
281 282
                        
                    } else if (![BaseViewController isBlankString:[oldPromotion.promotionMoney stringValue]]) {
283
                        // 抵扣金额
曹云霄's avatar
曹云霄 committed
284 285 286 287 288 289 290
                        if (![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                            [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                        }
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]init];
                        deductionModel.total = [oldPromotion.promotionMoney integerValue];
                        deductionModel.isSelected = YES;
                        deductionModel.type = @"deductionAction";
291
                        deductionModel.priority = oldPromotion.prority;
292
                        [weakSelf.promotionInformationArray addObject:deductionModel];
293
                        
294
                    } else if (![BaseViewController isBlankString:[oldPromotion.jdecardDenomation stringValue]]) {
295
                        // 京东E卡
296
                        PromotionJDECardModel *jdECardModel = [[PromotionJDECardModel alloc]init];
297
                        jdECardModel.total = [oldPromotion.jdecardDenomation integerValue];
298 299 300 301
                        jdECardModel.body = GUIDE;
                        jdECardModel.type = JDECardAction;
                        jdECardModel.priority = oldPromotion.prority;
                        [weakSelf.guidePromotionArray addObject:jdECardModel];
302 303
        
                    } else if (![BaseViewController isBlankString:[oldPromotion.redPackageCount stringValue]]) {
304
                        // 导购抽奖数
305 306 307 308
                        PromotionLuckyDrawModel *guideDrawModel = [[PromotionLuckyDrawModel alloc]init];
                        guideDrawModel.body = GUIDE;
                        guideDrawModel.priority = oldPromotion.prority;
                        [weakSelf.guidePromotionArray addObject:guideDrawModel];
309 310
                    } else if (![BaseViewController isBlankString:[oldPromotion.discountRate stringValue]]) {
                        // 抽奖折扣
311 312 313 314 315
                        PromotionLuckyDrawModel *drawResultModel = [[PromotionLuckyDrawModel alloc]init];
                        drawResultModel.descriptionString = [oldPromotion.discountRate stringValue];
                        drawResultModel.body = CONSUMER;
                        drawResultModel.priority = oldPromotion.prority;
                        [weakSelf.promotionInformationArray addObject:drawResultModel];
316 317
                    } else if (![BaseViewController isBlankString:oldPromotion.wxcardNumber]) {
                        // 微信卡劵
318 319 320 321
                        PromotionWeChatCardModel *weChatModel = [[PromotionWeChatCardModel alloc]init];
                        weChatModel.total = [oldPromotion.wxcardDenomation integerValue];
                        weChatModel.priority = oldPromotion.prority;
                        [weakSelf.promotionInformationArray addObject:weChatModel];
322 323
                        self.weChatModel.wxcardNumber = oldPromotion.wxcardNumber;
                        self.weChatModel.wxcardDenomation = [oldPromotion.wxcardDenomation integerValue];
曹云霄's avatar
曹云霄 committed
324
                    }
325
                }
326
                if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:@"促销信息"]) {
327 328
                    [self.sectionTitle addObject:@"促销信息"];
                }
勾芒's avatar
勾芒 committed
329
            }
330
        }WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
331
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
332 333
            [XBLoadingView hideHUDViewWithDefault];
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
334 335
        }];
    }
336
    /// 查询客户订单抽奖状态
337
    __block RsAwardDraw *resultModel = nil;
338 339
    dispatch_group_enter(group);
    RsLotteryRequest *queryDrawState = [[RsLotteryRequest alloc]init];
340
    // 判断订单是否支付
341 342 343
    if (!self.isShowPayButton) {
       queryDrawState.orderNumberEquals = self.orderCode;
    }
344
    queryDrawState.winnerIdEquals = self.consumerID?self.consumerID:[Customermanager manager].model.fid;
曹云霄's avatar
曹云霄 committed
345
    queryDrawState.stateEquals = self.isShowPayButton?ACCOMPLISHED:USED;
346 347 348 349
    DataPage *page = [[DataPage alloc]init];
    page.page = ZERO;
    page.rows = ONE;
    queryDrawState.page = page;
350
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(LOTTERYED)  WithRequestType:ZERO WithParameter:queryDrawState WithReturnValueBlock:^(id returnValue) {
351 352 353 354 355 356 357
        dispatch_group_leave(group);
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            NSDictionary *dict = [returnValue[@"data"][@"list"] firstObject];
            resultModel = [[RsAwardDraw alloc]initWithDictionary:dict error:nil];
        }
    } WithFailureBlock:^(NSError *error) {
        dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
358
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
359
    }];
360
    // 完成后回调
361
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
362
        
363 364
            // 有促销未支付情况
        if (weakSelf.isShowPayButton && [weakSelf.orderDetails.order.orderState isEqualToString:NOTPAY] && weakSelf.customerPromotionArray.count) {
365 366 367 368
            // 有抽奖结果未使用
            if (resultModel.award) {
                weakSelf.customerDrawModel = [PromotionLuckDrawResultModel initializeWith:resultModel];
            }
曹云霄's avatar
曹云霄 committed
369
            PromotionChooseNavigationController *promotionChooseNav = [[[weakSelf class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"PromotionChooseNavigationController"];
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
            PromotionChooseViewController *promotionChoose = (PromotionChooseViewController *)promotionChooseNav.visibleViewController;
            promotionChoose.promotionDelegate = self;
            promotionChoose.promotionDatasArray = weakSelf.customerPromotionArray;
            promotionChooseNav.preferredContentSize = CGSizeMake(ScreenHeight-300, ScreenHeight-300);
            promotionChooseNav.modalPresentationStyle = UIModalPresentationFormSheet;
            UIPopoverPresentationController *pop = promotionChooseNav.popoverPresentationController;
            pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
            pop.sourceView = promotionChooseNav.view;
            [self presentViewController:promotionChooseNav animated:YES completion:nil];
            
        }else if ([weakSelf.orderDetails.order.orderState isEqualToString:NOTPAY] && weakSelf.isShowPayButton && !weakSelf.customerPromotionArray.count) {
            // 无促销未支付情况
            [weakSelf payButtonClickAction];
            
        }else if (![weakSelf.orderDetails.order.orderState isEqualToString:NOTPAY] && resultModel.award) {
385
            // 已支付,且有抽奖结果情况
386
            weakSelf.customerDrawModel = [PromotionLuckDrawResultModel initializeWith:resultModel];
387
        }
388 389
        if (finish) {
            finish();
390
        }
391 392 393 394 395 396 397 398
        [weakSelf.orderDetailsTableview reloadData];
    });
}

#pragma mark - 选择消费者促销项回调
- (void)confirmChoosePromotion:(NSArray<CustomPromotionModel *> *)promotionArray
{
    for (CustomPromotionModel *promotionModel in promotionArray) {
399
        for (JSONModel *originalModel in self.customerPromotionArray) {
400 401 402 403 404 405
                //微信卡劵
            if ([originalModel isMemberOfClass:[PromotionWeChatCardModel class]]) {
                PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)originalModel;
                if ([weChatModel.body isEqualToString:promotionModel.body] && [weChatModel.type isEqualToString:promotionModel.type] && [weChatModel.descriptionString isEqualToString:promotionModel.descriptionString] && weChatModel.priority == promotionModel.priority && [weChatModel.conflicts isEqualToArray:promotionModel.conflicts]) {
                    weChatModel.isSelected = YES;
                    [self.promotionInformationArray addObject:weChatModel];
曹云霄's avatar
曹云霄 committed
406
                }
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
            }else if ([originalModel isMemberOfClass:[PromotionalDeductionModel class]]) {
                //抵扣
                PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)originalModel;
                if ([deductionModel.body isEqualToString:promotionModel.body] && [deductionModel.type isEqualToString:promotionModel.type] && [deductionModel.descriptionString isEqualToString:promotionModel.descriptionString] && deductionModel.priority == promotionModel.priority && [deductionModel.conflicts isEqualToArray:promotionModel.conflicts]) {
                    deductionModel.isSelected = YES;
                    [self.promotionInformationArray addObject:deductionModel];
                }
            }else if ([originalModel isMemberOfClass:[PromotionLuckyDrawModel class]]) {
                //抽奖
                PromotionLuckyDrawModel *drawModel = (PromotionLuckyDrawModel *)originalModel;
                if ([drawModel.body isEqualToString:promotionModel.body] && [drawModel.type isEqualToString:promotionModel.type] && [drawModel.descriptionString isEqualToString:promotionModel.descriptionString] && drawModel.priority == promotionModel.priority && [drawModel.conflicts isEqualToArray:promotionModel.conflicts]) {
                    drawModel.isSelected = YES;
                    [self.promotionInformationArray addObject:drawModel];
                }
            }else if ([originalModel isMemberOfClass:[PromotionalGoodsModel class]]) {
                //送商品
                PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)originalModel;
                if ([goodsModel.body isEqualToString:promotionModel.body] && [goodsModel.type isEqualToString:promotionModel.type] && [goodsModel.descriptionString isEqualToString:promotionModel.descriptionString] && goodsModel.priority == promotionModel.priority && [goodsModel.conflicts isEqualToArray:promotionModel.conflicts]) {
                    goodsModel.isSelected = YES;
                    [self.promotionInformationArray addObject:goodsModel];
曹云霄's avatar
曹云霄 committed
427
                }
428
            }
429
        }
430
    }
431
    if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:@"促销信息"]) {
432 433
        [self.sectionTitle addObject:@"促销信息"];
    }
434 435 436 437 438 439
    [self promotionInformationExecutionOrder];
}

#pragma mark - 促销信息执行顺序
- (void)promotionInformationExecutionOrder
{
440 441
    PromotionLuckyDrawModel *drawModel = nil;
    PromotionWeChatCardModel *weChatModel = nil;
442 443
    for (JSONModel *model in self.promotionInformationArray) {
        // 抽奖
444
        if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) {
445 446 447 448
            drawModel = (PromotionLuckyDrawModel *)model;
            if ([drawModel.body isEqualToString:GUIDE]) {
                drawModel = nil;
            }
449
        }
450 451
        // 微信卡劵支付
        if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
452 453 454 455 456
            weChatModel = (PromotionWeChatCardModel *)model;
        }
    }
    //通过促销优先级决定调用顺序
    if (drawModel.priority > weChatModel.priority) {
457
        
458 459 460 461 462 463 464 465 466
        if (!drawModel.isUsed && drawModel) {
            drawModel.isUsed = YES;
            [self queryConsumerLuckyDrawChance:drawModel];
        }else if (!weChatModel.isUsed && weChatModel) {
            weChatModel.isUsed = YES;
            [self scanWeChatCardNumber:weChatModel];
        }else{
            [self payButtonClickAction];
        }
467
        
468
    }else if (drawModel.priority < weChatModel.priority) {
469
        
470 471 472 473 474 475 476 477
        if (!weChatModel.isUsed && weChatModel) {
            weChatModel.isUsed = YES;
            [self scanWeChatCardNumber:weChatModel];;
        }else if (!drawModel.isUsed && drawModel) {
            drawModel.isUsed = YES;
            [self queryConsumerLuckyDrawChance:drawModel];
        }else{
            [self payButtonClickAction];
478
        }
479
        
480
    }else if (drawModel.priority == weChatModel.priority && drawModel && weChatModel) {
481
        
482 483 484 485 486 487 488
        if (!drawModel.isUsed && drawModel) {
            drawModel.isUsed = YES;
            [self queryConsumerLuckyDrawChance:drawModel];
        }else if (!weChatModel.isUsed && weChatModel) {
            weChatModel.isUsed = YES;
            [self scanWeChatCardNumber:weChatModel];
        }else{
489 490 491 492
            [self payButtonClickAction];
        }
    }
    [self.orderDetailsTableview reloadData];
493 494 495 496 497
    [self.orderDetailsTableview layoutIfNeeded];
    //赠送商品或抵扣情况
    if (!drawModel && !weChatModel) {
        [self payButtonClickAction];
    }
498 499
}

500

501 502 503 504
#pragma mark - 扫描微信卡劵
- (void)scanWeChatCardNumber:(PromotionWeChatCardModel *)weChatModel
{
    WS(weakSelf);
505
    self.tempWeChatModel = weChatModel;
506
    QRViewController *scanVC = [[QRViewController alloc] initWithScanCompleteHandler:^(NSString *url) {
507 508 509 510 511
        [weakSelf dismissViewControllerAnimated:YES completion:^{
            weakSelf.weChatModel.wxcardNumber = url;
            [weakSelf consumerUseWeChatCard:url andOrderTotal:[weakSelf.orderDetails.order.orderPrice stringValue] andOrderNumber:self.orderCode];
        }];
    }];
512 513 514 515 516 517
    [scanVC setCancelScanBlock:^{
        for (JSONModel *model in weakSelf.promotionInformationArray) {
            if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
                [weakSelf.promotionInformationArray removeObject:model];break;
            }
        }
518 519 520 521 522
        if (!weakSelf.promotionInformationArray.count) {
            if ([weakSelf.sectionTitle containsObject:@"促销信息"]) {
                [weakSelf.sectionTitle removeLastObject];
            }
        }
523
        [weakSelf promotionInformationExecutionOrder];
524
    }];
525
    dispatch_async(dispatch_get_main_queue(), ^{
526
        [weakSelf presentViewController:scanVC animated:YES completion:nil];
527 528 529 530 531 532 533
    });
}

#pragma mark - 使用微信卡劵
- (void)consumerUseWeChatCard:(NSString *)number andOrderTotal:(NSString *)orderTotal andOrderNumber:(NSString *)orderNumber
{
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
534
    [XBLoadingView showHUDViewWithDefault];
535
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:USEWECHATCARD,number,orderNumber,orderTotal]  WithRequestType:ZERO WithParameter:nil WithReturnValueBlock:^(id returnValue) {
536
        
曹云霄's avatar
曹云霄 committed
537
        [XBLoadingView hideHUDViewWithDefault];
538 539 540
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            weakSelf.weChatModel.wxcardDenomation = [returnValue[@"data"][@"denomation"] integerValue];
            weakSelf.weChatModel.payNo = returnValue[@"data"][@"payNo"];
541 542 543 544 545 546
            for (JSONModel *model in weakSelf.promotionInformationArray) {
                if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
                    PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)model;
                    weChatModel.total = weakSelf.weChatModel.wxcardDenomation;break;
                }
            }
曹云霄's avatar
曹云霄 committed
547 548
            [XBLoadingView showHUDViewWithText:[NSString stringWithFormat:@"微信卡劵(%ld元)使用成功",weakSelf.weChatModel.wxcardDenomation]];
            [weakSelf promotionInformationExecutionOrder];
549
        }else{
550 551 552 553 554
            [weakSelf promptBoxWithMessage:[NSString stringWithFormat:@"微信卡劵使用失败:(%@),是否重试?",returnValue[@"msg"]] cancelBlock:^{
                [weakSelf promotionInformationExecutionOrder];
            } sureBlock:^{
                [weakSelf scanWeChatCardNumber:weakSelf.tempWeChatModel];
            }];
555
        }
556

557
    }WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
558
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
559 560 561 562
    }];
}


563 564 565 566 567
#pragma mark - 获取关于消费者的所有促销
- (void)getConsumerAllPromotion:(JSONModel *)model withBody:(NSString *)body
{
    if ([body isEqualToString:CONSUMER]) {
       [self.customerPromotionArray addObject:model];
568 569
    }else if ([body isEqualToString:GUIDE]) {
        [self.guidePromotionArray addObject:model];
570 571
    }
}
572

曹云霄's avatar
曹云霄 committed
573
#pragma mark - 卡劵领取成功
574
- (void)rebateApplySuccess:(NSString *)message
曹云霄's avatar
曹云霄 committed
575
{
曹云霄's avatar
曹云霄 committed
576
    RebateSuccessTableViewController *success = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"RebateSuccessTableViewController"];
577
    success.titleArray = @[message,@"查看账户",@"我知道了"];
曹云霄's avatar
曹云霄 committed
578 579
    [success setClickEvent:^(NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
580
            // 我知道了
曹云霄's avatar
曹云霄 committed
581 582
        }else if (indexPath.row == 0)
        {
583
            [[NSNotificationCenter defaultCenter] postNotificationName:OPENCONTROLLER object:@(3)];
曹云霄's avatar
曹云霄 committed
584 585 586 587 588 589 590 591 592 593
        }
    }];
    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
594
#pragma mark - 显示京东E卡
595
- (void)showJDECard
曹云霄's avatar
曹云霄 committed
596
{
曹云霄's avatar
曹云霄 committed
597
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
598
    JDEcardViewController *jdeCard = [[[weakSelf class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"JDEcardViewController"];
曹云霄's avatar
曹云霄 committed
599 600 601 602
    [jdeCard setDismissJDECardBlock:^{
        [weakSelf.settingsPopoverController dismissPopoverAnimated:YES];
    }];
    jdeCard.preferredContentSize = CGSizeMake(400, 247);
曹云霄's avatar
曹云霄 committed
603 604 605 606 607
    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];
608
    self.settingsPopoverController.theme.glossShadowColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
609 610 611
    [self.settingsPopoverController presentPopoverAsDialogAnimated:YES
                                                           options:WYPopoverAnimationOptionFadeWithScale];
}
勾芒's avatar
勾芒 committed
612

613 614 615 616 617 618 619
#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);
620
    [previewButton setTitle:self.isShowPayButton?@"撤销订单":@"预览" forState:UIControlStateNormal];
621 622
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
623
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
624 625 626 627 628
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
629 630
    //显示支付按钮的情况下,不显示打印按钮
    if (!self.isShowPayButton) {
勾芒's avatar
勾芒 committed
631 632 633 634 635 636 637 638 639 640 641 642
     
        //打印
        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];
643 644 645 646 647 648 649 650 651 652 653 654
        
        //分享
        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
655
    }
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
    //横线
    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];
671
    payButton.titleLabel.font = [UIFont systemFontOfSize:15];
672
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
673
    [payButton addTarget:self action:@selector(payButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
674 675 676 677 678 679 680
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}

681
#pragma mark - 查询客户抽奖机会
682
- (void)queryConsumerLuckyDrawChance:(PromotionLuckyDrawModel *)model
683
{
684
    WS(weakSelf);
685 686 687 688 689 690 691 692
    //判断是否有已抽奖未使用情况
    if (![[self class] isBlankString:self.customerDrawModel.drawId]) {
        [self promptCustomerTitle:@"我知道了" withMessage:@"您有一个抽奖结果未使用,本次支付会默认使用" finish:^{
            [weakSelf promotionInformationExecutionOrder];
        }];
    }else {
        [self promptCustomerTitle:@"马上参与" withMessage:@"恭喜您获得一次大转盘抽奖机会!" finish:^{
            [weakSelf showLuckyDrawControl:model.lottery.uuid andOrderNumber:weakSelf.orderCode luckyDrawFinish:^(NSDictionary *dict) {
693 694
                weakSelf.customerDrawModel = [[PromotionLuckDrawResultModel alloc]initWithDictionary:dict error:nil];
                if ([BaseViewController isBlankString:weakSelf.customerDrawModel.awardId]) {
曹云霄's avatar
曹云霄 committed
695
                    [XBLoadingView showHUDViewWithText:@"未中奖"];
696
                }else {
曹云霄's avatar
曹云霄 committed
697
                    [XBLoadingView showHUDViewWithText:[NSString stringWithFormat:@"恭喜你获得了 %@",weakSelf.customerDrawModel.descriptionString]];
698
                }
699
            }];
曹云霄's avatar
曹云霄 committed
700
        }];
701
    }
702 703 704 705 706
}

#pragma mark - 查询导购抽奖机会
- (void)queryGuideLuckyDrawChanceisTrue:(void(^)())finish
{
707
    // 查询是否有导购抽奖机会
曹云霄's avatar
曹云霄 committed
708
    for (id object in self.guidePromotionArray) {
709 710
        if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
            PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
711 712 713
            if ([model.body isEqualToString:GUIDE]) {
                finish();
                break;
714 715 716 717
            }
        }
    }
}
718

719
#pragma mark -调出支付框
720
- (void)payButtonClickAction
721 722
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
723 724
    settlement.preferredContentSize = CGSizeMake(380, 500);
    settlement.goodsArray = self.orderDetails.orderdetailList;
725 726
    settlement.consumerPromotionalArray = self.promotionInformationArray;
    settlement.guidePromotionArray = self.guidePromotionArray;
727
    settlement.orderCode = self.orderCode;
728
    settlement.resultModel = self.customerDrawModel;
729
    settlement.weChatModel = self.weChatModel;
730 731 732 733
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
734
    //支付成功
735
    WS(weakSelf);
勾芒's avatar
勾芒 committed
736
    [settlement setPaySuccessReturnBlock:^{
737 738 739 740

        if (weakSelf.DelecteAndPayButtonBlock) {
            weakSelf.DelecteAndPayButtonBlock(_cellindex,PAYSUCCESS);
        }
741
        [XBLoadingView showHUDViewWithSuccessText:@"支付成功" completeBlock:nil];
742 743
        weakSelf.isShowPayButton = NO;
        weakSelf.isShowHeaderView = YES;
744
        weakSelf.isUserInteractionEnabled = NO;
745
        [weakSelf CreateTableviewHeaderView];
746
        weakSelf.orderDetailsTableview.tableFooterView = nil;
747 748
        __block BOOL isJDEcard = NO;//促销中是否有京东E卡;
        __block BOOL isGuideDraw = NO;//促销中是否有导购抽奖机会
749 750
        /// 刷新数据成功
        [weakSelf getOrderDetailsData:^{
751
            // 先判断促销中有无京东E卡,有则认为发放成功
曹云霄's avatar
曹云霄 committed
752
            for (id object in weakSelf.guidePromotionArray) {
753 754
                if ([object isKindOfClass:[PromotionJDECardModel class]]) {
                    PromotionJDECardModel *model = (PromotionJDECardModel *)object;
755
                    if ([model.body isEqualToString:GUIDE] && [model.type isEqualToString:JDECardAction]) {
756
                        isJDEcard = YES;break;
757 758 759
                    }
                }
            }
760
            // 查询导购抽奖机会
761 762 763
            [weakSelf queryGuideLuckyDrawChanceisTrue:^{
                isGuideDraw = YES;
            }];
764
            // 弹出框
765 766 767 768 769 770 771
            if (isJDEcard && isGuideDraw) {
                [weakSelf rebateApplySuccess:@"京东E卡、抽奖机会已放到你的账户"];
            }else if (isJDEcard && !isGuideDraw) {
                [weakSelf rebateApplySuccess:@"京东E卡已放到你的账户"];
            }else if (!isJDEcard && isGuideDraw) {
                [weakSelf rebateApplySuccess:@"抽奖机会已放到你的账户"];
            }
772
        }];
773 774
    }];
}
775

776
#pragma mark - 抽奖界面 HTML
777
- (void)showLuckyDrawControl:(NSString *)lotteryId andOrderNumber:(NSString *)orderNumber luckyDrawFinish:(void(^)(NSDictionary *dict))complete
778
{
779
    WS(weakSelf);
780
    CustomWKWebViewController *wkWebView = [[CustomWKWebViewController alloc]init];
781
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(DRAW),lotteryId,@"",orderNumber];
782
     NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
曹云霄's avatar
曹云霄 committed
783
    wkWebView.urlString = newServer;
784 785
    [wkWebView setLuckyDrawFinishBlock:^(NSDictionary *result) {
        complete(result);
勾芒's avatar
勾芒 committed
786
    }];
787
    [wkWebView setDismissLuckyDrawController:^{
788
        [weakSelf promotionInformationExecutionOrder];
789
    }];
790
    [self presentViewController:wkWebView animated:YES completion:nil];
791 792 793
}


794 795 796 797 798 799 800
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        case 1:
        case 2:
801
        case 4:
802 803 804 805
            return 1;
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
806
            return self.orderDetails.orderdetailList.count+1;
807 808
        }
            break;
809
        case 5:
810
        {
811
            return self.promotionInformationArray.count;
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
        }
            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
827
            cell.model = self.orderDetails;
828 829 830 831 832 833
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
834
            cell.model = self.orderDetails.consumer;
835 836 837 838 839 840
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
841
            cell.model = self.orderDetails.order;
842 843 844 845 846
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
847
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
848 849 850
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
851
                cell.model = self.customerDrawModel;
852
                cell.weChatModel = self.weChatModel;
853
                cell.promotionalArray = self.promotionInformationArray;
勾芒's avatar
勾芒 committed
854
                cell.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
855
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
856 857 858 859 860 861
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
862
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
863 864 865 866 867 868
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
869
            
勾芒's avatar
勾芒 committed
870
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
871
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
872
                return cell;
873 874
        }
            break;
875 876 877
        case 5://促销信息
        {
            PromotionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PromotionalTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
878
            cell.userInteractionEnabled = self.isUserInteractionEnabled;
879
            cell.model = self.customerDrawModel;
880
            cell.promotionModel = self.promotionInformationArray[indexPath.row];
881 882 883 884
            return cell;
        }
            break;
            
885 886 887
        default:
            break;
    }
888
    return [UITableViewCell new];
889 890
}

勾芒's avatar
勾芒 committed
891

892 893 894 895 896 897 898 899 900 901
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
902
            return 110;
903 904 905 906
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
907
            return 90;
908 909 910 911 912
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
913
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
            return 75;
        }
            break;
929 930 931 932 933
        case 5:
        {
            return 44;
        }
            break;
934 935 936 937 938 939 940 941 942
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
943 944 945
    OrderDetailsSectionHeaderView *headerView = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailsSectionHeaderView"];
    headerView.sectionHeaderTitleLabel.text = [self.sectionTitle objectAtIndex_opple:section];
    return headerView;
946 947 948 949 950
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
951
    return 60;
952 953
}

954 955
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
//    if (indexPath.section == 5 && self.isUserInteractionEnabled) {
//        PromotionalTableViewCell *promotionalCell = [tableView cellForRowAtIndexPath:indexPath];
//        id object = self.promotionInformationArray[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;
//            // 刷新总金额
//            [self.orderDetailsTableview reloadData];
//        }
//    }
971
}
972 973 974

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
975
    return self.sectionTitle.count;
976 977
}

曹云霄's avatar
曹云霄 committed
978 979 980
#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
981 982
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].Shoppers.employee.departid,self.orderCode];
    NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
983 984 985 986
    self.webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newServer]]];
    self.webView.navigationDelegate = self;
}
曹云霄's avatar
曹云霄 committed
987

988 989 990
#pragma mark - <WKNavigationDelegate>
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation
{
曹云霄's avatar
曹云霄 committed
991
    [XBLoadingView showHUDViewWithDefault];
992 993 994 995
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
曹云霄's avatar
曹云霄 committed
996
    [XBLoadingView hideHUDViewWithDefault];
997
    [AirPrintManager printOrderWithdataSoure:[webView viewPrintFormatter] printSuccess:^{
998
        [XBLoadingView showHUDViewWithSuccessText:@"打印成功" completeBlock:nil];
999
    } printError:^{
曹云霄's avatar
曹云霄 committed
1000
        [XBLoadingView showHUDViewWithText:@"打印失败"];
勾芒's avatar
勾芒 committed
1001
    }];
曹云霄's avatar
曹云霄 committed
1002 1003
}

1004 1005
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
曹云霄's avatar
曹云霄 committed
1006
    [XBLoadingView showHUDViewWithText:@"操作失败"];
1007 1008 1009
}


勾芒's avatar
勾芒 committed
1010
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
1011 1012
- (void)PreviewButtonClick:(UIButton *)button
{
1013
    WS(weakSelf);
勾芒's avatar
勾芒 committed
1014
    if ([button.currentTitle isEqualToString:@"预览"]) {
1015 1016 1017
        NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].Shoppers.employee.departid,self.orderCode];
        NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
        CustomWKWebViewController *pdfvc = [[CustomWKWebViewController alloc]init];
曹云霄's avatar
曹云霄 committed
1018
        pdfvc.urlString = newServer;
1019
        [weakSelf presentViewController:pdfvc animated:YES completion:nil];
勾芒's avatar
勾芒 committed
1020
        
勾芒's avatar
勾芒 committed
1021 1022
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
1023 1024 1025 1026 1027
        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)
        {
曹云霄's avatar
曹云霄 committed
1028
            [XBLoadingView showHUDViewWithDefault];
1029
            [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),_orderCode,@"001",@"005"]  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
1030
                [XBLoadingView hideHUDViewWithDefault];
勾芒's avatar
勾芒 committed
1031
                if ([returnValue[@"code"] isEqualToNumber:@0]) {
1032
                    [XBLoadingView showHUDViewWithSuccessText:@"撤销成功" completeBlock:nil];
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
                    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
1043
                    }
1044
                } else {
曹云霄's avatar
曹云霄 committed
1045
                    [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
1046
                }
1047
            } WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
1048 1049
                [XBLoadingView hideHUDViewWithDefault];
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
1050 1051 1052
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
1053
    }
勾芒's avatar
勾芒 committed
1054
}
曹云霄's avatar
曹云霄 committed
1055

勾芒's avatar
勾芒 committed
1056 1057 1058 1059
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
1060

勾芒's avatar
勾芒 committed
1061 1062 1063 1064
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
1065

勾芒's avatar
勾芒 committed
1066 1067 1068 1069
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
1070

1071 1072 1073 1074 1075 1076
#pragma mark - 分享订单
- (void)ShareButtonClick:(UIButton *)sender
{
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
    shareController.isShareOrderbill = YES;
    shareController.orderBillNumber = self.orderCode;
曹云霄's avatar
曹云霄 committed
1077
    shareController.shareImage = [UIImage imageNamed:@"Icon-83.5"];
1078 1079 1080 1081 1082 1083
    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];
1084 1085 1086
}


1087

1088
@end