OrderdetailsViewController.m 48.3 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"
曹云霄's avatar
曹云霄 committed
36
#import "PromotionalReadPacketModel.h"
37 38 39 40 41


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


42

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

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

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

56

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

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

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

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

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

82

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

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

93

勾芒's avatar
勾芒 committed
94

95

96 97 98 99
@end

@implementation OrderdetailsViewController

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

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

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

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

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

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

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

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

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

181

182
#pragma mark -获取订单详情、查询促销信息
183
- (void)getOrderDetailsData:(void(^)())finish
勾芒's avatar
勾芒 committed
184
{
185 186
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
曹云霄's avatar
曹云霄 committed
187
    [XBLoadingView showHUDViewWithDefault];
188
    WS(weakSelf);
189
    // 订单详情
曹云霄's avatar
曹云霄 committed
190
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(ORDERDETAILS),self.orderCode]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
191
         dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
192
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
193
            weakSelf.orderDetails = [[OrderBill alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
194
        }else{
195
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
196
        }
197
    }withFailureBlock:^(NSError *error) {
198
        dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
199
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
200
    }];
201
    // 未支付的订单查询实时促销,否则查询历史促销
曹云霄's avatar
曹云霄 committed
202
    if (self.isShowPayButton) {
203
        // 查询实时促销信息
曹云霄's avatar
曹云霄 committed
204
        dispatch_group_enter(group);
曹云霄's avatar
曹云霄 committed
205
        [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(PROMOTIONAL),self.orderCode]   withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
206
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
207
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
208
            if (RESULT(returnValue)) {
209
                [weakSelf.promotionInformationArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
210 211
                [weakSelf.guidePromotionArray removeAllObjects];
                [weakSelf.customerPromotionArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
212
                NSArray *promotionalArray = RESPONSE(returnValue)[@"actions"];
曹云霄's avatar
曹云霄 committed
213 214
                for (NSDictionary *dict in promotionalArray) {
                    NSString *type = dict[@"type"];
215
                        // 折扣金额
曹云霄's avatar
曹云霄 committed
216 217
                    if ([type isEqualToString:deductionAction]) {
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
218 219
                        [weakSelf getConsumerAllPromotion:deductionModel withBody:deductionModel.body];
                        // 赠送商品
曹云霄's avatar
曹云霄 committed
220 221
                    }else if ([type isEqualToString:goodsAction]){
                        PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil];
222 223
                        [weakSelf getConsumerAllPromotion:goodsModel withBody:goodsModel.body];
                        // 京东E卡
曹云霄's avatar
曹云霄 committed
224
                    }else if ([type isEqualToString:JDECardAction]){
225 226
                        PromotionJDECardModel *JDECardModel = [[PromotionJDECardModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf getConsumerAllPromotion:JDECardModel withBody:JDECardModel.body];
227
                        // 转盘抽奖
曹云霄's avatar
曹云霄 committed
228
                    }else if ([type isEqualToString:lotteryAction]){
229 230 231 232 233 234
                        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
235
                    }else if ([type isEqualToString:redPackageAction]){
曹云霄's avatar
曹云霄 committed
236
                        // 现金红包
曹云霄's avatar
曹云霄 committed
237 238
                        PromotionalReadPacketModel *readPacketModel = [[PromotionalReadPacketModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf getConsumerAllPromotion:readPacketModel withBody:readPacketModel.body];
曹云霄's avatar
曹云霄 committed
239
                    }
曹云霄's avatar
曹云霄 committed
240 241
                }
            }else{
242
                [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
曹云霄's avatar
曹云霄 committed
243
            }
244
        } withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
245
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
246
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
247 248 249
        }];

    }else {
250
        // 查询历史促销信息
曹云霄's avatar
曹云霄 committed
251
        dispatch_group_enter(group);
曹云霄's avatar
曹云霄 committed
252
        [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(OLDPROMOTIONAL),self.orderCode]   withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
253 254
            
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
255
            [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
256
            if (RESULT(returnValue)) {
257
                [weakSelf.promotionInformationArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
258 259
                [weakSelf.guidePromotionArray removeAllObjects];
                [weakSelf.customerPromotionArray removeAllObjects];
曹云霄's avatar
曹云霄 committed
260
                NSArray *promotion = RESPONSE(returnValue);
曹云霄's avatar
曹云霄 committed
261 262
                for (NSDictionary *dict in promotion) {
                    TOOrderPromotionEntity *oldPromotion = [[TOOrderPromotionEntity alloc]initWithDictionary:dict error:nil];
曹云霄's avatar
曹云霄 committed
263 264 265 266 267 268 269 270 271 272 273 274
                    NSString *type = dict[@"type"];
                    // 折扣金额
                    if ([type isEqualToString:deductionAction]) {
                        if (![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                            [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                        }
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:[oldPromotion toDictionary] error:nil];
                        deductionModel.total = [oldPromotion.promotionMoney integerValue];
                        deductionModel.isSelected = YES;
                        [weakSelf getConsumerAllPromotion:deductionModel withBody:deductionModel.body];
                    // 赠送商品
                    }else if ([type isEqualToString:goodsAction]){
曹云霄's avatar
曹云霄 committed
275 276 277
                        if (![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                            [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                        }
曹云霄's avatar
曹云霄 committed
278
                        PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:[oldPromotion toDictionary] error:nil];
曹云霄's avatar
曹云霄 committed
279 280 281 282 283
                        goodsModel.count = [oldPromotion.promotionNumber integerValue];
                        Goods *goods = [[Goods alloc]init];
                        goods.name = oldPromotion.goodsName;
                        goodsModel.goods = goods;
                        goodsModel.isSelected = YES;
曹云霄's avatar
曹云霄 committed
284 285 286 287
                        [weakSelf getConsumerAllPromotion:goodsModel withBody:goodsModel.body];
                    // 京东E卡
                    }else if ([type isEqualToString:JDECardAction]){
                        PromotionJDECardModel *jdECardModel = [[PromotionJDECardModel alloc]initWithDictionary:[oldPromotion toDictionary] error:nil];
288
                        jdECardModel.total = [oldPromotion.jdecardDenomation integerValue];
曹云霄's avatar
曹云霄 committed
289 290 291 292 293 294 295 296
                        [weakSelf getConsumerAllPromotion:jdECardModel withBody:jdECardModel.body];
                    // 转盘抽奖
                    }else if ([type isEqualToString:dzpRedPackage]){
                        PromotionLuckyDrawModel *guideDrawModel = [[PromotionLuckyDrawModel alloc]initWithDictionary:[oldPromotion toDictionary] error:nil];
                        [weakSelf getConsumerAllPromotion:guideDrawModel withBody:guideDrawModel.body];
                    // 微信卡劵
                    }else if ([type isEqualToString:WeChatCard]){
                        PromotionWeChatCardModel *weChatModel = [[PromotionWeChatCardModel alloc]initWithDictionary:[oldPromotion toDictionary] error:nil];
297 298
                        weChatModel.total = [oldPromotion.wxcardDenomation integerValue];
                        [weakSelf.promotionInformationArray addObject:weChatModel];
299 300
                        self.weChatModel.wxcardNumber = oldPromotion.wxcardNumber;
                        self.weChatModel.wxcardDenomation = [oldPromotion.wxcardDenomation integerValue];
曹云霄's avatar
曹云霄 committed
301 302 303 304 305 306
                        [weakSelf getConsumerAllPromotion:weChatModel withBody:weChatModel.body];
                    // 现金红包
                    }else if ([type isEqualToString:redPackageAction]){
                        PromotionalReadPacketModel *readPacketModel = [[PromotionalReadPacketModel alloc]initWithDictionary:[oldPromotion toDictionary] error:nil];
                        readPacketModel.total = [oldPromotion.redPackageNumber integerValue];
                        [weakSelf getConsumerAllPromotion:readPacketModel withBody:readPacketModel.body];
曹云霄's avatar
曹云霄 committed
307
                    }
308
                }
曹云霄's avatar
曹云霄 committed
309 310
                if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:PROMOTIONALSTRING]) {
                    [self.sectionTitle addObject:PROMOTIONALSTRING];
311
                }
勾芒's avatar
勾芒 committed
312
            }
313
        }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
314
            dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
315
            [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
316 317
        }];
    }
318
    /// 查询客户订单抽奖状态
319
    __block RsAwardDraw *resultModel = nil;
320 321
    dispatch_group_enter(group);
    RsLotteryRequest *queryDrawState = [[RsLotteryRequest alloc]init];
322
    // 判断订单是否支付
323 324 325
    if (!self.isShowPayButton) {
       queryDrawState.orderNumberEquals = self.orderCode;
    }
326
    queryDrawState.winnerIdEquals = self.consumerID?self.consumerID:[Customermanager manager].model.fid;
曹云霄's avatar
曹云霄 committed
327
    queryDrawState.stateEquals = self.isShowPayButton?ACCOMPLISHED:USED;
328 329 330 331
    DataPage *page = [[DataPage alloc]init];
    page.page = ZERO;
    page.rows = ONE;
    queryDrawState.page = page;
曹云霄's avatar
曹云霄 committed
332
    [HTTP networkRequestWithURL:SERVERREQUESTURL(LOTTERYED)  withRequestType:ZERO withParameter:queryDrawState withReturnValueBlock:^(id returnValue) {
333
        dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
334
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
335
            NSDictionary *dict = [RESPONSE(returnValue)[@"list"] firstObject];
336 337
            resultModel = [[RsAwardDraw alloc]initWithDictionary:dict error:nil];
        }
338
    } withFailureBlock:^(NSError *error) {
339
        dispatch_group_leave(group);
曹云霄's avatar
曹云霄 committed
340
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
341
    }];
342
    // 完成后回调
343
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
344
        
345 346 347 348 349 350 351 352
        if (self.isShowPayButton) {
            [self createTableviewFooterView];
        }
        if (self.isShowHeaderView) {
            [self createTableviewHeaderView];
        }
        self.orderDetailsTableview.emptyDataSetSource = self;
        self.orderDetailsTableview.emptyDataSetDelegate = self;
353
            // 有促销未支付情况
354
        if (weakSelf.isShowPayButton && [weakSelf.orderDetails.order.orderState isEqualToString:UNPAID] && weakSelf.customerPromotionArray.count) {
355 356 357 358
            // 有抽奖结果未使用
            if (resultModel.award) {
                weakSelf.customerDrawModel = [PromotionLuckDrawResultModel initializeWith:resultModel];
            }
曹云霄's avatar
曹云霄 committed
359
            PromotionChooseNavigationController *promotionChooseNav = [[[weakSelf class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"PromotionChooseNavigationController"];
360 361 362 363 364 365 366 367 368 369
            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];
            
370
        }else if ([weakSelf.orderDetails.order.orderState isEqualToString:UNPAID] && weakSelf.isShowPayButton && !weakSelf.customerPromotionArray.count) {
371 372 373
            // 无促销未支付情况
            [weakSelf payButtonClickAction];
            
374
        }else if (![weakSelf.orderDetails.order.orderState isEqualToString:UNPAID] && resultModel.award) {
375
            // 已支付,且有抽奖结果情况
376
            weakSelf.customerDrawModel = [PromotionLuckDrawResultModel initializeWith:resultModel];
377
        }
378 379
        if (finish) {
            finish();
380
        }
381 382 383 384 385 386 387 388
        [weakSelf.orderDetailsTableview reloadData];
    });
}

#pragma mark - 选择消费者促销项回调
- (void)confirmChoosePromotion:(NSArray<CustomPromotionModel *> *)promotionArray
{
    for (CustomPromotionModel *promotionModel in promotionArray) {
389
        for (JSONModel *originalModel in self.customerPromotionArray) {
390 391 392 393 394 395
                //微信卡劵
            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
396
                }
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
            }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
417
                }
418
            }
419
        }
420
    }
421
    if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:@"促销信息"]) {
422 423
        [self.sectionTitle addObject:@"促销信息"];
    }
424 425 426 427 428 429
    [self promotionInformationExecutionOrder];
}

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

490

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

#pragma mark - 使用微信卡劵
- (void)consumerUseWeChatCard:(NSString *)number andOrderTotal:(NSString *)orderTotal andOrderNumber:(NSString *)orderNumber
{
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
524
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
525
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:USEWECHATCARD,number,orderNumber,orderTotal]  withRequestType:ZERO withParameter:nil withReturnValueBlock:^(id returnValue) {
526
        
曹云霄's avatar
曹云霄 committed
527
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
528
        if (RESULT(returnValue)) {
529
            weakSelf.weChatModel.wxcardDenomation = [RESPONSE(returnValue)[@"denomation"] floatValue];
曹云霄's avatar
曹云霄 committed
530
            weakSelf.weChatModel.payNo = RESPONSE(returnValue)[@"payNo"];
531 532 533 534 535 536
            for (JSONModel *model in weakSelf.promotionInformationArray) {
                if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
                    PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)model;
                    weChatModel.total = weakSelf.weChatModel.wxcardDenomation;break;
                }
            }
537
            NSString *message = returnValue[@"msg"];
538
            if ([[self class] isBlankString: message]) {
539
                NSString *string = [NSString stringWithFormat:@"微信卡劵(%f元)使用成功",weakSelf.weChatModel.wxcardDenomation];
540 541
                ShowAlertView(@"提示", string, @[@"我知道了"], UIAlertControllerStyleAlert, nil);

542
            }else {
543
                ShowAlertView(@"提示", message, @[@"我知道了"], UIAlertControllerStyleAlert, nil);
544
            }
曹云霄's avatar
曹云霄 committed
545
            [weakSelf promotionInformationExecutionOrder];
546
        }else{
547 548 549 550 551 552
            ShowAlertView(@"提示", [NSString stringWithFormat:@"微信卡劵使用失败:(%@),是否重试?",returnValue[@"msg"]], @[@"确认",@"取消"], UIAlertControllerStyleAlert, ^(NSInteger index) {
                if (index == ZERO) {
                    [weakSelf scanWeChatCardNumber:weakSelf.tempWeChatModel];
                }else {
                   [weakSelf promotionInformationExecutionOrder];
                }
553
            });
554
        }
555

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


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

曹云霄's avatar
曹云霄 committed
572
#pragma mark - 卡劵领取成功
573
- (void)rebateApplySuccess:(NSString *)message
曹云霄's avatar
曹云霄 committed
574
{
曹云霄's avatar
曹云霄 committed
575
    RebateSuccessTableViewController *success = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"RebateSuccessTableViewController"];
576
    success.titleArray = @[message,@"查看账户",@"我知道了"];
曹云霄's avatar
曹云霄 committed
577 578
    [success setClickEvent:^(NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
579
            // 我知道了
曹云霄's avatar
曹云霄 committed
580 581
        }else if (indexPath.row == 0)
        {
曹云霄's avatar
曹云霄 committed
582 583
            [SHARED_APPDELEGATE.tabBarController switchSelectedIndex:103];
            [SHARED_APPDELEGATE.tabBarController setSelectedIndex:4];
曹云霄'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
#pragma mark -TableviewHeader------根据不同的订单状态判断是否显示
614
- (void)createTableviewHeaderView
615 616 617 618 619
{
    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
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
628 629
    //显示支付按钮的情况下,不显示打印按钮
    if (!self.isShowPayButton) {
勾芒's avatar
勾芒 committed
630 631 632 633 634 635
        //打印
        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];
曹云霄's avatar
曹云霄 committed
636
        [printButton addTarget:self action:@selector(airprintButtonClick:) forControlEvents:UIControlEventTouchUpInside];
勾芒's avatar
勾芒 committed
637 638 639 640
        printButton.layer.masksToBounds = YES;
        printButton.layer.cornerRadius = kCornerRadius;
        printButton.backgroundColor = kMainBlueColor;
        [headerView addSubview:printButton];
641 642
    }
    if (self.isShowShareButton) {
643 644 645 646 647 648
        //分享
        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];
曹云霄's avatar
曹云霄 committed
649
        [shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
650 651 652 653
        shareButton.layer.masksToBounds = YES;
        shareButton.layer.cornerRadius = kCornerRadius;
        shareButton.backgroundColor = kMainBlueColor;
        [headerView addSubview:shareButton];
勾芒's avatar
勾芒 committed
654
    }
655 656
    //横线
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 59, ScreenWidth, 1)];
曹云霄's avatar
曹云霄 committed
657
    lineView.backgroundColor = RGB(193, 193, 193,1);
658 659 660 661 662
    [headerView addSubview:lineView];
    self.orderDetailsTableview.tableHeaderView = headerView;
}

#pragma mark -TableviewFooterView------根据不同的订单状态判断支付按钮是否显示
663
- (void)createTableviewFooterView
664 665 666 667 668 669
{
    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];
670
    payButton.titleLabel.font = [UIFont systemFontOfSize:15];
671
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
672
    [payButton addTarget:self action:@selector(payButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
673 674 675 676 677 678 679
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}

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

703

704
#pragma mark -调出支付框
705
- (void)payButtonClickAction
706 707
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
708 709
    settlement.preferredContentSize = CGSizeMake(380, 500);
    settlement.goodsArray = self.orderDetails.orderdetailList;
710 711
    settlement.consumerPromotionalArray = self.promotionInformationArray;
    settlement.guidePromotionArray = self.guidePromotionArray;
712
    settlement.orderCode = self.orderCode;
713
    settlement.resultModel = self.customerDrawModel;
714
    settlement.weChatModel = self.weChatModel;
715 716 717 718
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
719
    //支付成功
720
    WS(weakSelf);
勾芒's avatar
勾芒 committed
721
    [settlement setPaySuccessReturnBlock:^{
722 723

        if (weakSelf.DelecteAndPayButtonBlock) {
724
            weakSelf.DelecteAndPayButtonBlock(_cellindex,PAID);
725
        }
726
        [XBLoadingView showHUDViewWithSuccessText:@"支付成功" completeBlock:nil];
727
        weakSelf.isShowPayButton = NO;
曹云霄's avatar
曹云霄 committed
728
        weakSelf.isShowShareButton = YES;
729
        weakSelf.isShowHeaderView = YES;
730
        weakSelf.isUserInteractionEnabled = NO;
731
        [weakSelf createTableviewHeaderView];
732
        weakSelf.orderDetailsTableview.tableFooterView = nil;
733 734
        /// 刷新数据成功
        [weakSelf getOrderDetailsData:^{
曹云霄's avatar
曹云霄 committed
735
            [weakSelf showGuidePromotionDetails];
736
        }];
737 738
    }];
}
739

曹云霄's avatar
曹云霄 committed
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
#pragma mark -弹框显示获得促销详情
- (void)showGuidePromotionDetails
{
    __block BOOL isJDEcard = NO;//促销中是否有京东E卡;
    __block BOOL isGuideDraw = NO;//促销中是否有导购抽奖机会
    __block BOOL isReadPacket = NO;//促销中是否有红包
    // 先判断促销中有无京东E卡,有则认为发放成功
    for (id object in self.guidePromotionArray) {
        if ([object isKindOfClass:[PromotionJDECardModel class]]) {
            PromotionJDECardModel *model = (PromotionJDECardModel *)object;
            if ([model.type isEqualToString:JDECardAction]) {
                isJDEcard = YES;break;
            }
        }
        // 查询促销中是否有红包
        if ([object isKindOfClass:[PromotionalReadPacketModel class]]) {
            PromotionalReadPacketModel *model = (PromotionalReadPacketModel *)object;
            if ([model.type isEqualToString:redPackageAction]) {
                isReadPacket = YES;break;
            }
        }
        // 查询导购抽奖机会
        if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
            PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
            if ([model.body isEqualToString:GUIDE]) {
                isGuideDraw = YES;break;
            }
        }
    }
    // 弹出框
    NSMutableString *mutableString = [NSMutableString string];
    if (isJDEcard) {
        [mutableString appendString:@"京东E卡、"];
    }
    if (isGuideDraw) {
        [mutableString appendString:@"抽奖机会、"];
    }
    if (isReadPacket) {
曹云霄's avatar
曹云霄 committed
778
        [mutableString appendString:@"现金红包、"];
曹云霄's avatar
曹云霄 committed
779
    }
780
    if (isJDEcard || isGuideDraw || isReadPacket) {
曹云霄's avatar
曹云霄 committed
781
        [mutableString appendString:@"已发放到您的账户"];
曹云霄's avatar
曹云霄 committed
782
        [self rebateApplySuccess:mutableString];
曹云霄's avatar
曹云霄 committed
783 784 785
    }
}

786
#pragma mark - 抽奖界面 HTML
787
- (void)showLuckyDrawControl:(NSString *)lotteryId andOrderNumber:(NSString *)orderNumber luckyDrawFinish:(void(^)(NSDictionary *dict))complete
788
{
789
    WS(weakSelf);
790
    CustomWKWebViewController *wkWebView = [[CustomWKWebViewController alloc]init];
791
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(DRAW),lotteryId,@"",orderNumber];
792
     NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
曹云霄's avatar
曹云霄 committed
793
    wkWebView.urlString = newServer;
794 795
    [wkWebView setLuckyDrawFinishBlock:^(NSDictionary *result) {
        complete(result);
勾芒's avatar
勾芒 committed
796
    }];
797
    [wkWebView setDismissLuckyDrawController:^{
798
        [weakSelf promotionInformationExecutionOrder];
799
    }];
800
    [self presentViewController:wkWebView animated:YES completion:nil];
801 802 803
}


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

勾芒's avatar
勾芒 committed
901

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

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
953 954 955
    OrderDetailsSectionHeaderView *headerView = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailsSectionHeaderView"];
    headerView.sectionHeaderTitleLabel.text = [self.sectionTitle objectAtIndex_opple:section];
    return headerView;
956 957 958 959 960
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
961
    return 60;
962 963
}

964 965
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
//    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];
//        }
//    }
981
}
982 983 984

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
985
    return self.sectionTitle.count;
986 987
}

曹云霄's avatar
曹云霄 committed
988
#pragma mark -打印订单
曹云霄's avatar
曹云霄 committed
989
- (void)airprintButtonClick:(UIButton *)button
曹云霄's avatar
曹云霄 committed
990
{
991
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].shoppers.employee.departid,self.orderCode];
992
    NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
993 994 995 996
    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
997

998 999 1000
#pragma mark - <WKNavigationDelegate>
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation
{
曹云霄's avatar
曹云霄 committed
1001
    [XBLoadingView showHUDViewWithDefault];
1002 1003 1004 1005
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
曹云霄's avatar
曹云霄 committed
1006
    [XBLoadingView hideHUDViewWithDefault];
1007
    [AirPrintManager printOrderWithdataSoure:[webView viewPrintFormatter] printSuccess:^{
1008
        [XBLoadingView showHUDViewWithSuccessText:@"打印成功" completeBlock:nil];
1009
    } printError:^{
曹云霄's avatar
曹云霄 committed
1010
        [XBLoadingView showHUDViewWithText:@"打印失败"];
勾芒's avatar
勾芒 committed
1011
    }];
曹云霄's avatar
曹云霄 committed
1012 1013
}

1014 1015
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
曹云霄's avatar
曹云霄 committed
1016
    [XBLoadingView showHUDViewWithText:@"操作失败"];
1017 1018 1019
}


勾芒's avatar
勾芒 committed
1020
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
1021 1022
- (void)PreviewButtonClick:(UIButton *)button
{
1023
    WS(weakSelf);
勾芒's avatar
勾芒 committed
1024
    if ([button.currentTitle isEqualToString:@"预览"]) {
1025
        NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].shoppers.employee.departid,self.orderCode];
1026 1027
        NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
        CustomWKWebViewController *pdfvc = [[CustomWKWebViewController alloc]init];
曹云霄's avatar
曹云霄 committed
1028
        pdfvc.urlString = newServer;
1029
        [weakSelf presentViewController:pdfvc animated:YES completion:nil];
勾芒's avatar
勾芒 committed
1030
        
勾芒's avatar
勾芒 committed
1031 1032
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
1033 1034 1035 1036 1037
        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
1038
            [XBLoadingView showHUDViewWithDefault];
1039
            [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),_orderCode,UNPAID,CANCELED]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
1040
                [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
1041
                if (RESULT(returnValue)) {
1042
                    [XBLoadingView showHUDViewWithSuccessText:@"撤销成功" completeBlock:nil];
1043 1044 1045 1046 1047
                    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];
1048
                    weakSelf.orderDetails.order.orderState = CANCELED;
1049 1050 1051
                    weakSelf.isUserInteractionEnabled = NO;
                    [weakSelf.orderDetailsTableview reloadData];
                    if (weakSelf.DelecteAndPayButtonBlock) {
1052
                        weakSelf.DelecteAndPayButtonBlock(_cellindex,CANCELED);
勾芒's avatar
勾芒 committed
1053
                    }
1054
                } else {
1055
                    [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
1056
                }
1057
            } withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
1058 1059
                [XBLoadingView hideHUDViewWithDefault];
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
1060 1061 1062
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
1063
    }
勾芒's avatar
勾芒 committed
1064
}
曹云霄's avatar
曹云霄 committed
1065

勾芒's avatar
勾芒 committed
1066 1067 1068 1069
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
1070

勾芒's avatar
勾芒 committed
1071 1072 1073 1074
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
1075

1076
#pragma mark - 分享订单
曹云霄's avatar
曹云霄 committed
1077
- (void)shareButtonClick:(UIButton *)sender
1078 1079
{
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
1080 1081
    shareController.type = SHARE_ORDER;
    shareController.shareID = self.orderCode;
曹云霄's avatar
曹云霄 committed
1082
    shareController.shareImage = [UIImage imageNamed:@"Icon-83.5"];
1083 1084 1085 1086 1087 1088
    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];
1089 1090
}

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"加载失败" attributes:nil];
}

1107

1108

1109
@end