OrderdetailsViewController.m 37.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
#import "LuckyDrawModel.h"
28
#import "LuckDrawResultModel.h"
29 30
#import "AirPrintManager.h"
#import <WebKit/WebKit.h>
31 32 33 34 35


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


36

37 38
@interface OrderdetailsViewController ()<UITableViewDelegate,UITableViewDataSource,QLPreviewControllerDataSource,WKNavigationDelegate>
@property (nonatomic,strong) WKWebView *webView;
勾芒's avatar
勾芒 committed
39 40 41 42 43 44

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

勾芒's avatar
勾芒 committed
45 46 47 48 49
/**
 *  本地存储地址
 */
@property (nonatomic,copy) NSString *PDFpath;

50
/**
51
 *  促销信息<商品、折扣>
52 53 54
 */
@property (nonatomic,strong) NSMutableArray *promotionalArray;

55 56 57 58
/**
 *  促销信息<转盘抽奖、京东E卡>
 */
@property (nonatomic,strong) NSMutableArray *luckyDrawAndJDECardArray;
勾芒's avatar
勾芒 committed
59

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

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

勾芒's avatar
勾芒 committed
70

71 72 73 74
@end

@implementation OrderdetailsViewController

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#pragma mark - lazy
- (NSMutableArray *)promotionalArray
{
    if (!_promotionalArray) {
        _promotionalArray = [NSMutableArray array];
    }
    return _promotionalArray;
}

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

92 93 94 95 96 97 98 99
- (NSMutableArray *)luckyDrawAndJDECardArray
{
    if (!_luckyDrawAndJDECardArray) {
        _luckyDrawAndJDECardArray = [NSMutableArray array];
    }
    return _luckyDrawAndJDECardArray;
}

勾芒's avatar
勾芒 committed
100 101 102 103 104
#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
勾芒's avatar
勾芒 committed
105
    if (self.isSliding) {
曹云霄's avatar
曹云霄 committed
106
        self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
107 108 109
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
勾芒's avatar
勾芒 committed
110 111
    }
}
勾芒's avatar
勾芒 committed
112

勾芒's avatar
勾芒 committed
113 114 115 116 117
#pragma mark -视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 开启
曹云霄's avatar
曹云霄 committed
118
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
119 120 121
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
勾芒's avatar
勾芒 committed
122
}
勾芒's avatar
勾芒 committed
123

124 125 126 127
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
128
    [self getOrderDetailsData:nil];
129 130 131 132 133 134 135
}

#pragma mark - UI
- (void)uiConfigAction
{
    self.orderDetailsTableview.dataSource = self;
    self.orderDetailsTableview.delegate = self;
136
    if (self.isShowHeaderView) {
勾芒's avatar
勾芒 committed
137 138
       [self CreateTableviewHeaderView];
    }
勾芒's avatar
勾芒 committed
139 140
    //附加信息cell
    [self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"];
勾芒's avatar
勾芒 committed
141 142 143
    if (self.isShowPayButton) {
       [self CreateTableviewFooterView];
    }
144 145
}

146

147
#pragma mark -获取订单详情、查询促销信息
148
- (void)getOrderDetailsData:(void(^)())finish
勾芒's avatar
勾芒 committed
149
{
150 151
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
勾芒's avatar
勾芒 committed
152
    [self CreateMBProgressHUDLoding];
153
    WS(weakSelf);
154
    /// 订单详情
155
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",SERVERREQUESTURL(ORDERDETAILS),self.orderCode] WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
156
        
157
         dispatch_group_leave(group);
勾芒's avatar
勾芒 committed
158
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
159
            weakSelf.orderDetails = [[OrderBill alloc]initWithDictionary:returnValue[@"data"] error:nil];
160 161 162 163 164 165 166 167 168
        }else{
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
        dispatch_group_leave(group);
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
169
        [weakSelf ErrorMBProgressView:error.localizedDescription];
170
    }];
曹云霄's avatar
曹云霄 committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    
    /// 未支付的订单查询实时促销,否则查询历史促销
    if (self.isShowPayButton) {
        /// 查询实时促销信息
        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]) {
                NSArray *promotionalArray = returnValue[@"data"][@"actions"];
                [weakSelf.promotionalArray removeAllObjects];
                [weakSelf.luckyDrawAndJDECardArray removeAllObjects];
                for (NSDictionary *dict in promotionalArray) {
                    NSString *type = dict[@"type"];
186
                        /// 折扣金额
曹云霄's avatar
曹云霄 committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
                    if ([type isEqualToString:deductionAction]) {
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
                        deductionModel.isSelected = YES;
                        if (promotionalArray.count && ![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                            [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                        }
                        [weakSelf.promotionalArray addObject:deductionModel];
                        /// 赠送商品
                    }else if ([type isEqualToString:goodsAction]){
                        PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil];
                        goodsModel.isSelected = YES;
                        if (promotionalArray.count && ![weakSelf.sectionTitle containsObject:PROMOTIONALSTRING]) {
                            [weakSelf.sectionTitle addObject:PROMOTIONALSTRING];
                        }
                        [weakSelf.promotionalArray addObject:goodsModel];
                        /// 京东E卡
                    }else if ([type isEqualToString:JDECardAction]){
                        PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf.luckyDrawAndJDECardArray addObject:deductionModel];
                        /// 转盘抽奖
                    }else if ([type isEqualToString:lotteryAction]){
                        LuckyDrawModel *model = [[LuckyDrawModel alloc]initWithDictionary:dict error:nil];
                        [weakSelf.luckyDrawAndJDECardArray addObject:model];
曹云霄's avatar
曹云霄 committed
210
                    }
曹云霄's avatar
曹云霄 committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                }
            }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 {
        /// 查询历史促销信息
        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]) {
                NSArray *promotion = returnValue[@"data"];
                [weakSelf.promotionalArray removeAllObjects];
                [weakSelf.luckyDrawAndJDECardArray removeAllObjects];
                for (NSDictionary *dict in promotion) {
                    TOOrderPromotionEntity *oldPromotion = [[TOOrderPromotionEntity alloc]initWithDictionary:dict error:nil];
239
                         /// 赠送商品
曹云霄's avatar
曹云霄 committed
240 241 242 243 244 245 246 247 248 249 250
                    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;
                        [weakSelf.promotionalArray addObject:goodsModel];
251 252 253
                        
                    } else if (![BaseViewController isBlankString:[oldPromotion.promotionMoney stringValue]]) {
                        /// 促销金额
曹云霄's avatar
曹云霄 committed
254 255 256 257 258 259 260 261
                        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";
                        [weakSelf.promotionalArray addObject:deductionModel];
262
                        
263
                    } else if (![BaseViewController isBlankString:[oldPromotion.jdecardDenomation stringValue]]) {
264 265 266 267 268 269
                        /// 判断京东E卡
                        PromotionalDeductionModel *model = [[PromotionalDeductionModel alloc]init];
                        model.total = [oldPromotion.jdecardDenomation integerValue];
                        model.body = GUIDE;
                        model.type = JDECardAction;
                        [weakSelf.luckyDrawAndJDECardArray addObject:model];
270 271 272 273 274 275
        
                    } else if (![BaseViewController isBlankString:[oldPromotion.redPackageCount stringValue]]) {
                        /// 导购抽奖数
                        LuckyDrawModel *model = [[LuckyDrawModel alloc]init];
                        model.body = GUIDE;
                        [weakSelf.luckyDrawAndJDECardArray addObject:model];
曹云霄's avatar
曹云霄 committed
276
                    }
277
                }
勾芒's avatar
勾芒 committed
278
            }
曹云霄's avatar
曹云霄 committed
279 280 281 282 283 284 285 286 287 288 289
            
        } 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];
        }];
    }
290 291 292 293 294 295 296 297 298
    /// 查询客户订单抽奖状态
    static RsAwardDraw *resultModel = nil;
    dispatch_group_enter(group);
    RsLotteryRequest *queryDrawState = [[RsLotteryRequest alloc]init];
    /// 判断订单是否支付
    if (!self.isShowPayButton) {
       queryDrawState.orderNumberEquals = self.orderCode;
    }
    queryDrawState.winnerIdEquals = [Customermanager manager].model.fid;
曹云霄's avatar
曹云霄 committed
299
    queryDrawState.stateEquals = self.isShowPayButton?ACCOMPLISHED:USED;
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    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];
        }else {
            resultModel = nil;
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        resultModel = nil;
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:NETWORK];
    } WithFailureBlock:^(NSError *error) {
        resultModel = nil;
        dispatch_group_leave(group);
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
    }];
    /// 完成后回调
325
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
326 327 328 329 330 331 332 333 334 335 336
        
        /// 消费者抽奖成功后若没有支付,后面支付时可以继续享受奖品折扣
        if ([resultModel.draw.state isEqualToString:ACCOMPLISHED]) {
            weakSelf.customerDrawModel = [LuckDrawResultModel initializeWith:resultModel];
        }
        /// 支付完成后
        if (self.isShowPrintButton && resultModel.award) {
            weakSelf.customerDrawModel = [LuckDrawResultModel initializeWith:resultModel];
        }
        /// 默认弹出支付框
        if (weakSelf.isShowPayButton && [weakSelf.orderDetails.order.orderState isEqualToString:NOTPAY]) {
曹云霄's avatar
曹云霄 committed
337 338 339 340 341 342 343 344
            /// 找出客户抽奖
            for (int i=0;i<weakSelf.luckyDrawAndJDECardArray.count;i++) {
                id object = weakSelf.luckyDrawAndJDECardArray[i];
                if ([object isKindOfClass:[LuckyDrawModel class]] && !resultModel) {
                    LuckyDrawModel *model = (LuckyDrawModel *)object;
                    if ([model.body isEqualToString:CONSUMER]) {
                        [weakSelf queryConsumerLuckyDrawChance:model];
                        break;
曹云霄's avatar
曹云霄 committed
345 346
                    }
                }
曹云霄's avatar
曹云霄 committed
347 348 349 350 351 352 353
                /// 有促销无抽奖情况
                if (i == weakSelf.luckyDrawAndJDECardArray.count-1) {
                    [weakSelf payButtonClickAction];
                }
            }
            /// 无促销情况
            if (!weakSelf.luckyDrawAndJDECardArray.count) {
曹云霄's avatar
曹云霄 committed
354
                [weakSelf payButtonClickAction];
355
            }
356
        }
357 358 359 360
        if (finish) {
            finish();
        }
        [weakSelf.orderDetailsTableview reloadData];
361 362 363
    });
}

364

曹云霄's avatar
曹云霄 committed
365
#pragma mark - 卡劵领取成功
366
- (void)rebateApplySuccess:(NSString *)message
曹云霄's avatar
曹云霄 committed
367 368
{
    RebateSuccessTableViewController *success = [self.getStoryboardWithName instantiateViewControllerWithIdentifier:@"RebateSuccessTableViewController"];
369
    success.titleArray = @[message,@"查看账户",@"我知道了"];
曹云霄's avatar
曹云霄 committed
370 371 372 373 374
    [success setClickEvent:^(NSIndexPath *indexPath) {
        if (indexPath.row == 1) {
            /// 我知道了
        }else if (indexPath.row == 0)
        {
375
            [[NSNotificationCenter defaultCenter] postNotificationName:OPENCONTROLLER object:@(3)];
曹云霄's avatar
曹云霄 committed
376 377 378 379 380 381 382 383 384 385
        }
    }];
    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
386
#pragma mark - 显示京东E卡
387
- (void)showJDECard
曹云霄's avatar
曹云霄 committed
388
{
曹云霄's avatar
曹云霄 committed
389
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
390
    JDEcardViewController *jdeCard = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"JDEcardViewController"];
曹云霄's avatar
曹云霄 committed
391 392 393 394
    [jdeCard setDismissJDECardBlock:^{
        [weakSelf.settingsPopoverController dismissPopoverAnimated:YES];
    }];
    jdeCard.preferredContentSize = CGSizeMake(400, 247);
曹云霄's avatar
曹云霄 committed
395 396 397 398 399
    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];
400
    self.settingsPopoverController.theme.glossShadowColor = [UIColor clearColor];
曹云霄's avatar
曹云霄 committed
401 402 403
    [self.settingsPopoverController presentPopoverAsDialogAnimated:YES
                                                           options:WYPopoverAnimationOptionFadeWithScale];
}
勾芒's avatar
勾芒 committed
404

405 406 407 408 409 410 411
#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);
412
    [previewButton setTitle:self.isShowPayButton?@"撤销订单":@"预览" forState:UIControlStateNormal];
413 414
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
415
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
416 417 418 419 420
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
421 422
    //显示支付按钮的情况下,不显示打印按钮
    if (!self.isShowPayButton) {
勾芒's avatar
勾芒 committed
423 424 425 426 427 428 429 430 431 432 433 434
     
        //打印
        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];
435 436 437 438 439 440 441 442 443 444 445 446
        
        //分享
        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
447
    }
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
    //横线
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 59, ScreenWidth, 1)];
    lineView.backgroundColor = kTCColor(193, 193, 193);
    [headerView addSubview:lineView];
    self.orderDetailsTableview.tableHeaderView = headerView;
}

#pragma mark -TableviewFooterView------根据不同的订单状态判断支付按钮是否显示
- (void)CreateTableviewFooterView
{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
    //支付
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeSystem];
    payButton.frame = CGRectMake((ScreenWidth-150)/2, 30, 150, 40);
    [payButton setTitle:@"支付" forState:UIControlStateNormal];
    payButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
465
    [payButton addTarget:self action:@selector(payButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
466 467 468 469 470 471 472
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}

473
#pragma mark - 查询客户抽奖机会
474
- (void)queryConsumerLuckyDrawChance:(LuckyDrawModel *)model
475
{
476
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
477 478 479 480 481 482 483 484 485 486 487
    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:nil message:@"恭喜您获得一次大转盘抽奖机会!" preferredStyle:UIAlertControllerStyleAlert];
    [alertControl addAction:[UIAlertAction actionWithTitle:@"马上参与" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf showLuckyDrawControl:model.lottery.uuid andOrderNumber:weakSelf.orderCode luckyDrawFinish:^(NSDictionary *dict) {
            id json = [NSJSONSerialization JSONObjectWithData:[dict[@"body"] dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
            if (json) {
                if ([json isKindOfClass:[NSDictionary class]]) {
                    weakSelf.customerDrawModel = [[LuckDrawResultModel alloc]initWithDictionary:json error:nil];
                    if ([BaseViewController isBlankString:weakSelf.customerDrawModel.awardId]) {
                        [weakSelf SHOWPrompttext:@"未中奖"];
                    }else {
                        [weakSelf SHOWPrompttext:[NSString stringWithFormat:@"恭喜你获得了 %@",weakSelf.customerDrawModel.descriptionString]];
488 489
                    }
                }
曹云霄's avatar
曹云霄 committed
490 491 492 493 494
            }
            return;
        }];
    }]];
    [self presentViewController:alertControl animated:YES completion:nil];
495 496 497 498 499 500 501 502 503 504 505 506
}

#pragma mark - 查询导购抽奖机会
- (void)queryGuideLuckyDrawChanceisTrue:(void(^)())finish
{
    /// 查询是否有导购抽奖机会
    for (id object in self.luckyDrawAndJDECardArray) {
        if ([object isKindOfClass:[LuckyDrawModel class]]) {
            LuckyDrawModel *model = (LuckyDrawModel *)object;
            if ([model.body isEqualToString:GUIDE]) {
                finish();
                break;
507 508 509 510
            }
        }
    }
}
511

512
#pragma mark -调出支付框
513
- (void)payButtonClickAction
514 515
{
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
516 517 518 519 520
    settlement.preferredContentSize = CGSizeMake(380, 500);
    settlement.goodsArray = self.orderDetails.orderdetailList;
    settlement.promotionalArray = self.promotionalArray;
    settlement.luckyDrawAndJDECardArray = self.luckyDrawAndJDECardArray;
    settlement.orderCode = self.orderCode;
521
    settlement.resultModel = self.customerDrawModel;
522 523 524 525 526
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    [self presentViewController:settlement animated:YES completion:nil];
    ///支付成功
527
    WS(weakSelf);
勾芒's avatar
勾芒 committed
528
    [settlement setPaySuccessReturnBlock:^{
529 530 531 532

        if (weakSelf.DelecteAndPayButtonBlock) {
            weakSelf.DelecteAndPayButtonBlock(_cellindex,PAYSUCCESS);
        }
533
        [weakSelf SuccessMBProgressView:@"支付成功"];
534
        weakSelf.isShowPayButton = NO;
535
        weakSelf.isUserInteractionEnabled = NO;
536
        weakSelf.isShowHeaderView = YES;
537
        [weakSelf CreateTableviewHeaderView];
538
        weakSelf.orderDetailsTableview.tableFooterView = nil;
539 540
        __block BOOL isJDEcard;//促销中是否有京东E卡;
        __block BOOL isGuideDraw;//促销中是否有导购抽奖机会
541 542 543
        /// 刷新数据成功
        [weakSelf getOrderDetailsData:^{
            /// 先判断促销中有无E卡,有则认为发放成功
544
            for (id object in weakSelf.luckyDrawAndJDECardArray) {
545 546 547
                if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
                    PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
                    if ([model.body isEqualToString:GUIDE] && [model.type isEqualToString:JDECardAction]) {
548
                        isJDEcard = YES;break;
549 550 551
                    }
                }
            }
552 553 554 555
            /// 查询导购抽奖机会
            [weakSelf queryGuideLuckyDrawChanceisTrue:^{
                isGuideDraw = YES;
            }];
556 557 558 559 560 561 562 563
            /// 弹出框
            if (isJDEcard && isGuideDraw) {
                [weakSelf rebateApplySuccess:@"京东E卡、抽奖机会已放到你的账户"];
            }else if (isJDEcard && !isGuideDraw) {
                [weakSelf rebateApplySuccess:@"京东E卡已放到你的账户"];
            }else if (!isJDEcard && isGuideDraw) {
                [weakSelf rebateApplySuccess:@"抽奖机会已放到你的账户"];
            }
564
        }];
565 566
    }];
}
567

568
#pragma mark - 抽奖界面
569
- (void)showLuckyDrawControl:(NSString *)lotteryId andOrderNumber:(NSString *)orderNumber luckyDrawFinish:(void(^)(NSDictionary *dict))complete
570
{
571
    WS(weakSelf);
572
    CustomWKWebViewController *wkWebView = [[CustomWKWebViewController alloc]init];
573
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(DRAW),lotteryId,@"",orderNumber];
574 575 576 577
     NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
    wkWebView.pdfURLString = newServer;
    [wkWebView setLuckyDrawFinishBlock:^(NSDictionary *result) {
        complete(result);
勾芒's avatar
勾芒 committed
578
    }];
579 580 581
    [wkWebView setDismissLuckyDrawController:^{
        [weakSelf payButtonClickAction];
    }];
582
    [self presentViewController:wkWebView animated:YES completion:nil];
583 584 585
}


586

587 588 589 590 591 592 593
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        case 1:
        case 2:
594
        case 4:
595 596 597 598
            return 1;
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
599
            return self.orderDetails.orderdetailList.count+1;
600 601
        }
            break;
602
        case 5:
603
        {
604
            return self.promotionalArray.count;
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
        }
            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
620
            cell.model = self.orderDetails;
621 622 623 624 625 626
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
627
            cell.model = self.orderDetails.consumer;
628 629 630 631 632 633
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
634
            cell.model = self.orderDetails.order;
635 636 637 638 639
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
640
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
641 642 643
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
644 645
                cell.model = self.customerDrawModel;
                cell.promotionalArray = self.promotionalArray;
勾芒's avatar
勾芒 committed
646
                cell.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
647
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
648 649 650 651 652 653
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
654
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
655 656 657 658 659 660
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
661
            
勾芒's avatar
勾芒 committed
662
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
663
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
664
                return cell;
665 666
        }
            break;
667 668 669 670
        case 5://促销信息
        {
            PromotionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PromotionalTableViewCell" forIndexPath:indexPath];
            NSString *describe = nil;
曹云霄's avatar
曹云霄 committed
671
            cell.userInteractionEnabled = self.isUserInteractionEnabled;
672 673 674 675 676 677 678 679
            id object = self.promotionalArray[indexPath.row];
            if ([object isKindOfClass:[PromotionalGoodsModel class]]) {
                PromotionalGoodsModel *goodsModel = object;
                cell.accessoryType = goodsModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
                describe = [NSString stringWithFormat:@"赠送商品:%@%ld",goodsModel.goods.name,goodsModel.count];
            }else if ([object isKindOfClass:[PromotionalDeductionModel class]]){
                PromotionalDeductionModel *deductionModel = self.promotionalArray[indexPath.row];
                cell.accessoryType = deductionModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
曹云霄's avatar
曹云霄 committed
680
                describe = [NSString stringWithFormat:@"抵扣金额:%ld",deductionModel.total];
681 682 683 684 685 686
            }
            cell.promotionalTitleLabel.text = describe;
            return cell;
        }
            break;
            
687 688 689
        default:
            break;
    }
690
    return [UITableViewCell new];
691 692
}

勾芒's avatar
勾芒 committed
693

694 695 696 697 698 699 700 701 702 703
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
704
            return 110;
705 706 707 708
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
709
            return 90;
710 711 712 713 714
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
715
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
            return 75;
        }
            break;
731 732 733 734 735
        case 5:
        {
            return 44;
        }
            break;
736 737 738 739 740 741 742 743 744
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
745 746 747
    OrderDetailsSectionHeaderView *headerView = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailsSectionHeaderView"];
    headerView.sectionHeaderTitleLabel.text = [self.sectionTitle objectAtIndex_opple:section];
    return headerView;
748 749 750 751 752
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
勾芒's avatar
勾芒 committed
753
    return 60;
754 755
}

756 757
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
758
    if (indexPath.section == 5 && self.isUserInteractionEnabled) {
759 760 761 762 763 764 765 766 767 768
        PromotionalTableViewCell *promotionalCell = [tableView cellForRowAtIndexPath:indexPath];
        id object = self.promotionalArray[indexPath.row];
        if ([object isKindOfClass:[PromotionalGoodsModel class]]) {
            PromotionalGoodsModel *goodsModel = object;
            goodsModel.isSelected = !goodsModel.isSelected;
            promotionalCell.accessoryType = goodsModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
        }else if ([object isKindOfClass:[PromotionalDeductionModel class]]){
            PromotionalDeductionModel *deductionModel = object;
            deductionModel.isSelected = !deductionModel.isSelected;
            promotionalCell.accessoryType = deductionModel.isSelected?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
曹云霄's avatar
曹云霄 committed
769 770
            /// 刷新总金额
            [self.orderDetailsTableview reloadData];
771 772 773
        }
    }
}
774 775 776

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
777
    return self.sectionTitle.count;
778 779
}

曹云霄's avatar
曹云霄 committed
780 781 782
#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
783 784
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(ORDERDETAILSURL),[Shoppersmanager manager].Shoppers.employee.departid,self.orderCode];
    NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
785 786 787 788
    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
789

790 791 792 793 794 795 796 797 798 799 800 801 802
#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:^{
803
        [weakSelf ErrorMBProgressView:@"打印失败"];
勾芒's avatar
勾芒 committed
804
    }];
曹云霄's avatar
曹云霄 committed
805 806
}

807 808 809 810 811 812
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
    [self ErrorMBProgressView:@"操作失败"];
}


勾芒's avatar
勾芒 committed
813
#pragma mark -预览订单、撤销订单
勾芒's avatar
勾芒 committed
814 815
- (void)PreviewButtonClick:(UIButton *)button
{
816
    WS(weakSelf);
勾芒's avatar
勾芒 committed
817
    if ([button.currentTitle isEqualToString:@"预览"]) {
818 819 820 821 822
        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
823
        
勾芒's avatar
勾芒 committed
824 825
    }else if ([button.currentTitle isEqualToString:@"撤销订单"])
    {
勾芒's avatar
勾芒 committed
826 827 828 829 830
        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)
        {
831
            [weakSelf CreateMBProgressHUDLoding];
832
            [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@",SERVERREQUESTURL(RESETORDER),_orderCode,@"001",@"005"] WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
833
                [weakSelf RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
834
                if ([returnValue[@"code"] isEqualToNumber:@0]) {
835 836 837 838 839 840 841 842 843 844 845
                    [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
846
                    }
847
                } else {
848
                    [weakSelf ErrorMBProgressView:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
849 850 851
                }
                
            } WithErrorCodeBlock:^(id errorCodeValue) {
852
                [weakSelf RemoveMBProgressHUDLoding];
853 854 855 856
                [weakSelf ErrorMBProgressView:NETWORK];
            } WithFailureBlock:^(NSError *error) {
                [weakSelf RemoveMBProgressHUDLoding];
                [weakSelf ErrorMBProgressView:error.localizedDescription];
勾芒's avatar
勾芒 committed
857 858 859
            }];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
860
    }
勾芒's avatar
勾芒 committed
861
}
曹云霄's avatar
曹云霄 committed
862

勾芒's avatar
勾芒 committed
863 864 865 866
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
曹云霄's avatar
曹云霄 committed
867

勾芒's avatar
勾芒 committed
868 869 870 871
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return self.PDFpath;
}
曹云霄's avatar
曹云霄 committed
872

勾芒's avatar
勾芒 committed
873 874 875 876
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
877

878 879 880 881 882 883
#pragma mark - 分享订单
- (void)ShareButtonClick:(UIButton *)sender
{
    ShareGoodsViewController *shareController = [[ShareGoodsViewController alloc]init];
    shareController.isShareOrderbill = YES;
    shareController.orderBillNumber = self.orderCode;
曹云霄's avatar
曹云霄 committed
884
    shareController.shareImage = [UIImage imageNamed:@"Icon-83.5"];
885 886 887 888 889 890
    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];
891 892 893
}


894

895
@end