OrderdetailsViewController.m 48.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>
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
    [self CreateMBProgressHUDLoding];
193
    WS(weakSelf);
194
    // 订单详情
195
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(ORDERDETAILS),self.orderCode] WithCallClass:weakSelf WithRequestType:1 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 201 202 203 204 205 206 207 208
        }else{
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
        dispatch_group_leave(group);
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
209
        [weakSelf ErrorMBProgressView:error.localizedDescription];
210
    }];
曹云霄's avatar
曹云霄 committed
211
    
212
    // 未支付的订单查询实时促销,否则查询历史促销
曹云霄's avatar
曹云霄 committed
213
    if (self.isShowPayButton) {
214
        // 查询实时促销信息
曹云霄's avatar
曹云霄 committed
215 216 217 218 219 220
        dispatch_group_enter(group);
        [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(PROMOTIONAL),self.orderCode] WithCallClass:weakSelf  WithRequestType:ONE WithParameter:nil WithReturnValueBlock:^(id returnValue) {
            
            dispatch_group_leave(group);
            [weakSelf RemoveMBProgressHUDLoding];
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
221
                [weakSelf.promotionInformationArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
222 223
                [weakSelf.guidePromotionArray removeAllObjects];
                [weakSelf.customerPromotionArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
224 225 226
                NSArray *promotionalArray = returnValue[@"data"][@"actions"];
                for (NSDictionary *dict in promotionalArray) {
                    NSString *type = dict[@"type"];
227
                        // 折扣金额
曹云霄's avatar
曹云霄 committed
228 229
                    if ([type isEqualToString:deductionAction]) {
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
230 231
                        [weakSelf getConsumerAllPromotion:deductionModel withBody:deductionModel.body];
                        // 赠送商品
曹云霄's avatar
曹云霄 committed
232 233
                    }else if ([type isEqualToString:goodsAction]){
                        PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil];
234 235
                        [weakSelf getConsumerAllPromotion:goodsModel withBody:goodsModel.body];
                        // 京东E卡
曹云霄's avatar
曹云霄 committed
236
                    }else if ([type isEqualToString:JDECardAction]){
237 238
                        PromotionJDECardModel *JDECardModel = [[PromotionJDECardModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf getConsumerAllPromotion:JDECardModel withBody:JDECardModel.body];
239
                        // 转盘抽奖
曹云霄's avatar
曹云霄 committed
240
                    }else if ([type isEqualToString:lotteryAction]){
241 242 243 244 245 246
                        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
247
                    }
曹云霄's avatar
曹云霄 committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
                }
            }else{
                [weakSelf ErrorMBProgressView:returnValue[@"message"]];
            }
            
        } 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];
        }];

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

#pragma mark - 选择消费者促销项回调
- (void)confirmChoosePromotion:(NSArray<CustomPromotionModel *> *)promotionArray
{
    for (CustomPromotionModel *promotionModel in promotionArray) {
419
        for (JSONModel *originalModel in self.customerPromotionArray) {
420 421 422 423 424 425
                //微信卡劵
            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
426
                }
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
            }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
447
                }
448
            }
449
        }
450
    }
451
    if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:@"促销信息"]) {
452 453
        [self.sectionTitle addObject:@"促销信息"];
    }
454 455 456 457 458 459
    [self promotionInformationExecutionOrder];
}

#pragma mark - 促销信息执行顺序
- (void)promotionInformationExecutionOrder
{
460 461
    PromotionLuckyDrawModel *drawModel = nil;
    PromotionWeChatCardModel *weChatModel = nil;
462 463
    for (JSONModel *model in self.promotionInformationArray) {
        // 抽奖
464
        if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) {
465 466 467 468
            drawModel = (PromotionLuckyDrawModel *)model;
            if ([drawModel.body isEqualToString:GUIDE]) {
                drawModel = nil;
            }
469
        }
470 471
        // 微信卡劵支付
        if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
472 473 474 475 476
            weChatModel = (PromotionWeChatCardModel *)model;
        }
    }
    //通过促销优先级决定调用顺序
    if (drawModel.priority > weChatModel.priority) {
477
        
478 479 480 481 482 483 484 485 486
        if (!drawModel.isUsed && drawModel) {
            drawModel.isUsed = YES;
            [self queryConsumerLuckyDrawChance:drawModel];
        }else if (!weChatModel.isUsed && weChatModel) {
            weChatModel.isUsed = YES;
            [self scanWeChatCardNumber:weChatModel];
        }else{
            [self payButtonClickAction];
        }
487
        
488
    }else if (drawModel.priority < weChatModel.priority) {
489
        
490 491 492 493 494 495 496 497
        if (!weChatModel.isUsed && weChatModel) {
            weChatModel.isUsed = YES;
            [self scanWeChatCardNumber:weChatModel];;
        }else if (!drawModel.isUsed && drawModel) {
            drawModel.isUsed = YES;
            [self queryConsumerLuckyDrawChance:drawModel];
        }else{
            [self payButtonClickAction];
498
        }
499
        
500
    }else if (drawModel.priority == weChatModel.priority && drawModel && weChatModel) {
501
        
502 503 504 505 506 507 508
        if (!drawModel.isUsed && drawModel) {
            drawModel.isUsed = YES;
            [self queryConsumerLuckyDrawChance:drawModel];
        }else if (!weChatModel.isUsed && weChatModel) {
            weChatModel.isUsed = YES;
            [self scanWeChatCardNumber:weChatModel];
        }else{
509 510 511 512
            [self payButtonClickAction];
        }
    }
    [self.orderDetailsTableview reloadData];
513 514 515 516 517
    [self.orderDetailsTableview layoutIfNeeded];
    //赠送商品或抵扣情况
    if (!drawModel && !weChatModel) {
        [self payButtonClickAction];
    }
518 519
}

520

521 522 523 524
#pragma mark - 扫描微信卡劵
- (void)scanWeChatCardNumber:(PromotionWeChatCardModel *)weChatModel
{
    WS(weakSelf);
525
    self.tempWeChatModel = weChatModel;
526
    QRViewController *scanVC = [[QRViewController alloc] initWithScanCompleteHandler:^(NSString *url) {
527 528 529 530 531
        [weakSelf dismissViewControllerAnimated:YES completion:^{
            weakSelf.weChatModel.wxcardNumber = url;
            [weakSelf consumerUseWeChatCard:url andOrderTotal:[weakSelf.orderDetails.order.orderPrice stringValue] andOrderNumber:self.orderCode];
        }];
    }];
532 533 534 535 536 537
    [scanVC setCancelScanBlock:^{
        for (JSONModel *model in weakSelf.promotionInformationArray) {
            if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
                [weakSelf.promotionInformationArray removeObject:model];break;
            }
        }
538 539 540 541 542
        if (!weakSelf.promotionInformationArray.count) {
            if ([weakSelf.sectionTitle containsObject:@"促销信息"]) {
                [weakSelf.sectionTitle removeLastObject];
            }
        }
543
        [weakSelf promotionInformationExecutionOrder];
544
    }];
545
    dispatch_async(dispatch_get_main_queue(), ^{
546
        [weakSelf presentViewController:scanVC animated:YES completion:nil];
547 548 549 550 551 552 553 554 555 556 557 558 559 560
    });
}

#pragma mark - 使用微信卡劵
- (void)consumerUseWeChatCard:(NSString *)number andOrderTotal:(NSString *)orderTotal andOrderNumber:(NSString *)orderNumber
{
    WS(weakSelf);
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:USEWECHATCARD,number,orderNumber,orderTotal] WithCallClass:weakSelf WithRequestType:ZERO WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            weakSelf.weChatModel.wxcardDenomation = [returnValue[@"data"][@"denomation"] integerValue];
            weakSelf.weChatModel.payNo = returnValue[@"data"][@"payNo"];
561 562 563 564 565 566
            for (JSONModel *model in weakSelf.promotionInformationArray) {
                if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
                    PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)model;
                    weChatModel.total = weakSelf.weChatModel.wxcardDenomation;break;
                }
            }
567 568 569
            [weakSelf SHOWPrompttext:[NSString stringWithFormat:@"微信卡劵(%ld元)使用成功",weakSelf.weChatModel.wxcardDenomation] ComcpleteBlock:^{
                [weakSelf promotionInformationExecutionOrder];
            }];
570
        }else{
571 572 573 574 575
            [weakSelf promptBoxWithMessage:[NSString stringWithFormat:@"微信卡劵使用失败:(%@),是否重试?",returnValue[@"msg"]] cancelBlock:^{
                [weakSelf promotionInformationExecutionOrder];
            } sureBlock:^{
                [weakSelf scanWeChatCardNumber:weakSelf.tempWeChatModel];
            }];
576 577 578 579 580 581 582 583 584 585 586 587
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
    }];
}


588 589 590 591 592
#pragma mark - 获取关于消费者的所有促销
- (void)getConsumerAllPromotion:(JSONModel *)model withBody:(NSString *)body
{
    if ([body isEqualToString:CONSUMER]) {
       [self.customerPromotionArray addObject:model];
593 594
    }else if ([body isEqualToString:GUIDE]) {
        [self.guidePromotionArray addObject:model];
595 596
    }
}
597

曹云霄's avatar
曹云霄 committed
598
#pragma mark - 卡劵领取成功
599
- (void)rebateApplySuccess:(NSString *)message
曹云霄's avatar
曹云霄 committed
600 601
{
    RebateSuccessTableViewController *success = [self.getStoryboardWithName instantiateViewControllerWithIdentifier:@"RebateSuccessTableViewController"];
602
    success.titleArray = @[message,@"查看账户",@"我知道了"];
曹云霄's avatar
曹云霄 committed
603 604
    [success setClickEvent:^(NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
605
            // 我知道了
曹云霄's avatar
曹云霄 committed
606 607
        }else if (indexPath.row == 0)
        {
608
            [[NSNotificationCenter defaultCenter] postNotificationName:OPENCONTROLLER object:@(3)];
曹云霄's avatar
曹云霄 committed
609 610 611 612 613 614 615 616 617 618
        }
    }];
    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
619
#pragma mark - 显示京东E卡
620
- (void)showJDECard
曹云霄's avatar
曹云霄 committed
621
{
曹云霄's avatar
曹云霄 committed
622
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
623
    JDEcardViewController *jdeCard = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"JDEcardViewController"];
曹云霄's avatar
曹云霄 committed
624 625 626 627
    [jdeCard setDismissJDECardBlock:^{
        [weakSelf.settingsPopoverController dismissPopoverAnimated:YES];
    }];
    jdeCard.preferredContentSize = CGSizeMake(400, 247);
曹云霄's avatar
曹云霄 committed
628 629 630 631 632
    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];
633
    self.settingsPopoverController.theme.glossShadowColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
634 635 636
    [self.settingsPopoverController presentPopoverAsDialogAnimated:YES
                                                           options:WYPopoverAnimationOptionFadeWithScale];
}
勾芒's avatar
勾芒 committed
637

638 639 640 641 642 643 644
#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);
645
    [previewButton setTitle:self.isShowPayButton?@"撤销订单":@"预览" forState:UIControlStateNormal];
646 647
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
648
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
649 650 651 652 653
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
654 655
    //显示支付按钮的情况下,不显示打印按钮
    if (!self.isShowPayButton) {
勾芒's avatar
勾芒 committed
656 657 658 659 660 661 662 663 664 665 666 667
     
        //打印
        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];
668 669 670 671 672 673 674 675 676 677 678 679
        
        //分享
        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
680
    }
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
    //横线
    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];
696
    payButton.titleLabel.font = [UIFont systemFontOfSize:15];
697
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
698
    [payButton addTarget:self action:@selector(payButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
699 700 701 702 703 704 705
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}

706
#pragma mark - 查询客户抽奖机会
707
- (void)queryConsumerLuckyDrawChance:(PromotionLuckyDrawModel *)model
708
{
709
    WS(weakSelf);
710 711 712 713 714 715 716 717
    //判断是否有已抽奖未使用情况
    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) {
718 719 720 721 722
                weakSelf.customerDrawModel = [[PromotionLuckDrawResultModel alloc]initWithDictionary:dict error:nil];
                if ([BaseViewController isBlankString:weakSelf.customerDrawModel.awardId]) {
                    [weakSelf SHOWPrompttext:@"未中奖"];
                }else {
                    [weakSelf SHOWPrompttext:[NSString stringWithFormat:@"恭喜你获得了 %@",weakSelf.customerDrawModel.descriptionString]];
723
                }
724
            }];
曹云霄's avatar
曹云霄 committed
725
        }];
726
    }
727 728 729 730 731
}

#pragma mark - 查询导购抽奖机会
- (void)queryGuideLuckyDrawChanceisTrue:(void(^)())finish
{
732
    // 查询是否有导购抽奖机会
曹云霄's avatar
曹云霄 committed
733
    for (id object in self.guidePromotionArray) {
734 735
        if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
            PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
736 737 738
            if ([model.body isEqualToString:GUIDE]) {
                finish();
                break;
739 740 741 742
            }
        }
    }
}
743

744
#pragma mark -调出支付框
745
- (void)payButtonClickAction
746 747
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
748 749
    settlement.preferredContentSize = CGSizeMake(380, 500);
    settlement.goodsArray = self.orderDetails.orderdetailList;
750 751
    settlement.consumerPromotionalArray = self.promotionInformationArray;
    settlement.guidePromotionArray = self.guidePromotionArray;
752
    settlement.orderCode = self.orderCode;
753
    settlement.resultModel = self.customerDrawModel;
754
    settlement.weChatModel = self.weChatModel;
755 756 757 758
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
759
    //支付成功
760
    WS(weakSelf);
勾芒's avatar
勾芒 committed
761
    [settlement setPaySuccessReturnBlock:^{
762 763 764 765

        if (weakSelf.DelecteAndPayButtonBlock) {
            weakSelf.DelecteAndPayButtonBlock(_cellindex,PAYSUCCESS);
        }
766
        [weakSelf SuccessMBProgressView:@"支付成功"];
767 768
        weakSelf.isShowPayButton = NO;
        weakSelf.isShowHeaderView = YES;
769
        weakSelf.isUserInteractionEnabled = NO;
770
        [weakSelf CreateTableviewHeaderView];
771
        weakSelf.orderDetailsTableview.tableFooterView = nil;
772 773
        __block BOOL isJDEcard = NO;//促销中是否有京东E卡;
        __block BOOL isGuideDraw = NO;//促销中是否有导购抽奖机会
774 775
        /// 刷新数据成功
        [weakSelf getOrderDetailsData:^{
776
            // 先判断促销中有无京东E卡,有则认为发放成功
曹云霄's avatar
曹云霄 committed
777
            for (id object in weakSelf.guidePromotionArray) {
778 779
                if ([object isKindOfClass:[PromotionJDECardModel class]]) {
                    PromotionJDECardModel *model = (PromotionJDECardModel *)object;
780
                    if ([model.body isEqualToString:GUIDE] && [model.type isEqualToString:JDECardAction]) {
781
                        isJDEcard = YES;break;
782 783 784
                    }
                }
            }
785
            // 查询导购抽奖机会
786 787 788
            [weakSelf queryGuideLuckyDrawChanceisTrue:^{
                isGuideDraw = YES;
            }];
789
            // 弹出框
790 791 792 793 794 795 796
            if (isJDEcard && isGuideDraw) {
                [weakSelf rebateApplySuccess:@"京东E卡、抽奖机会已放到你的账户"];
            }else if (isJDEcard && !isGuideDraw) {
                [weakSelf rebateApplySuccess:@"京东E卡已放到你的账户"];
            }else if (!isJDEcard && isGuideDraw) {
                [weakSelf rebateApplySuccess:@"抽奖机会已放到你的账户"];
            }
797
        }];
798 799
    }];
}
800

801
#pragma mark - 抽奖界面 HTML
802
- (void)showLuckyDrawControl:(NSString *)lotteryId andOrderNumber:(NSString *)orderNumber luckyDrawFinish:(void(^)(NSDictionary *dict))complete
803
{
804
    WS(weakSelf);
805
    CustomWKWebViewController *wkWebView = [[CustomWKWebViewController alloc]init];
806
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(DRAW),lotteryId,@"",orderNumber];
807 808 809 810
     NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
    wkWebView.pdfURLString = newServer;
    [wkWebView setLuckyDrawFinishBlock:^(NSDictionary *result) {
        complete(result);
勾芒's avatar
勾芒 committed
811
    }];
812
    [wkWebView setDismissLuckyDrawController:^{
813
        [weakSelf promotionInformationExecutionOrder];
814
    }];
815
    [self presentViewController:wkWebView animated:YES completion:nil];
816 817 818
}


819 820 821 822 823 824 825
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        case 1:
        case 2:
826
        case 4:
827 828 829 830
            return 1;
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
831
            return self.orderDetails.orderdetailList.count+1;
832 833
        }
            break;
834
        case 5:
835
        {
836
            return self.promotionInformationArray.count;
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
        }
            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
852
            cell.model = self.orderDetails;
853 854 855 856 857 858
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
859
            cell.model = self.orderDetails.consumer;
860 861 862 863 864 865
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
866
            cell.model = self.orderDetails.order;
867 868 869 870 871
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
872
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
873 874 875
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
876
                cell.model = self.customerDrawModel;
877
                cell.weChatModel = self.weChatModel;
878
                cell.promotionalArray = self.promotionInformationArray;
勾芒's avatar
勾芒 committed
879
                cell.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
880
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
881 882 883 884 885 886
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
887
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
888 889 890 891 892 893
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
894
            
勾芒's avatar
勾芒 committed
895
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
896
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
897
                return cell;
898 899
        }
            break;
900 901 902
        case 5://促销信息
        {
            PromotionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PromotionalTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
903
            cell.userInteractionEnabled = self.isUserInteractionEnabled;
904
            cell.model = self.customerDrawModel;
905
            cell.promotionModel = self.promotionInformationArray[indexPath.row];
906 907 908 909
            return cell;
        }
            break;
            
910 911 912
        default:
            break;
    }
913
    return [UITableViewCell new];
914 915
}

勾芒's avatar
勾芒 committed
916

917 918 919 920 921 922 923 924 925 926
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
927
            return 110;
928 929 930 931
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
932
            return 90;
933 934 935 936 937
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
938
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
            return 75;
        }
            break;
954 955 956 957 958
        case 5:
        {
            return 44;
        }
            break;
959 960 961 962 963 964 965 966 967
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
968 969 970
    OrderDetailsSectionHeaderView *headerView = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailsSectionHeaderView"];
    headerView.sectionHeaderTitleLabel.text = [self.sectionTitle objectAtIndex_opple:section];
    return headerView;
971 972 973 974 975
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
976
    return 60;
977 978
}

979 980
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
//    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];
//        }
//    }
996
}
997 998 999

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
1000
    return self.sectionTitle.count;
1001 1002
}

曹云霄's avatar
曹云霄 committed
1003 1004 1005
#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
1006 1007
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].Shoppers.employee.departid,self.orderCode];
    NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
1008 1009 1010 1011
    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
1012

1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
#pragma mark - <WKNavigationDelegate>
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation
{
    [self CreateMBProgressHUDLoding];
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    [self RemoveMBProgressHUDLoding];
    WS(weakSelf);
    [AirPrintManager printOrderWithdataSoure:[webView viewPrintFormatter] printSuccess:^{
        [weakSelf SuccessMBProgressView:@"打印成功"];
    } printError:^{
1026
        [weakSelf ErrorMBProgressView:@"打印失败"];
勾芒's avatar
勾芒 committed
1027
    }];
曹云霄's avatar
曹云霄 committed
1028 1029
}

1030 1031 1032 1033 1034 1035
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
    [self ErrorMBProgressView:@"操作失败"];
}


勾芒's avatar
勾芒 committed
1036
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
1037 1038
- (void)PreviewButtonClick:(UIButton *)button
{
1039
    WS(weakSelf);
勾芒's avatar
勾芒 committed
1040
    if ([button.currentTitle isEqualToString:@"预览"]) {
1041 1042 1043 1044 1045
        NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].Shoppers.employee.departid,self.orderCode];
        NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
        CustomWKWebViewController *pdfvc = [[CustomWKWebViewController alloc]init];
        pdfvc.pdfURLString = newServer;
        [weakSelf presentViewController:pdfvc animated:YES completion:nil];
勾芒's avatar
勾芒 committed
1046
        
勾芒's avatar
勾芒 committed
1047 1048
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
1049 1050 1051 1052 1053
        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)
        {
1054
            [weakSelf CreateMBProgressHUDLoding];
1055
            [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),_orderCode,@"001",@"005"] WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
1056
                [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
1057
                if ([returnValue[@"code"] isEqualToNumber:@0]) {
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
                    [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
1069
                    }
1070
                } else {
1071
                    [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
1072 1073 1074
                }
                
            } WithErrorCodeBlock:^(id errorCodeValue) {
1075
                [weakSelf RemoveMBProgressHUDLoding];
1076 1077 1078 1079
                [weakSelf ErrorMBProgressView:NETWORK];
            } WithFailureBlock:^(NSError *error) {
                [weakSelf RemoveMBProgressHUDLoding];
                [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
1080 1081 1082
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
1083
    }
勾芒's avatar
勾芒 committed
1084
}
曹云霄's avatar
曹云霄 committed
1085

勾芒's avatar
勾芒 committed
1086 1087 1088 1089
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
1090

勾芒's avatar
勾芒 committed
1091 1092 1093 1094
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
1095

勾芒's avatar
勾芒 committed
1096 1097 1098 1099
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
1100

1101 1102 1103 1104 1105 1106
#pragma mark - 分享订单
- (void)ShareButtonClick:(UIButton *)sender
{
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
    shareController.isShareOrderbill = YES;
    shareController.orderBillNumber = self.orderCode;
曹云霄's avatar
曹云霄 committed
1107
    shareController.shareImage = [UIImage imageNamed:@"Icon-83.5"];
1108 1109 1110 1111 1112 1113
    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];
1114 1115 1116
}


1117

1118
@end