//
//  GMFaceInfoShareViewController.m
//  Gengmei
//
//  Created by Locus on 2019/6/5.
//  Copyright © 2019 更美互动信息科技有限公司. All rights reserved.
//

#import "GMFaceInfoShareViewController.h"
#import "ALFaceInfoViewModel.h"
#import "ALShareSheet.h"
#import "GMFaceReplayViewController.h"
#import "GMFaceReplayModel.h"
#import "GMFaceV3Model.h"
#import "GMPhotoPickController.h"
#import "GMFaceV3Util.h"
#import "GMSignTask.h"
#import "Gengmei-Swift.h"

#define isGray GMLaunchManager.shareManager.appConfigObject.aiScanFaceGray

@interface GMFaceInfoShareViewController () <WKWebViewDelegate,WKNavigationDelegate, GMPhotoPickDismissDelegate>

@property (nonatomic, strong) ALShareSheet *shareSheet;
@property (nonatomic, strong) WMShareObject *shareObj;
@property (nonatomic, strong) GMImageView *showImageView; // 分享专用imageView
@property (nonatomic, strong) GMImageView *bgImageView;
@property (nonatomic, strong) GMImageView *bgNograyImageView; // 非灰度背景图片

@property (nonatomic, strong) UIImage *shareImage;  // 带小程序码的图片（默认分享图）
@property (nonatomic, strong) UIImage *ewmImage;  // 带二维码的图片

@property (nonatomic, strong) GMPlayerView *playerView;   //  视频播放器
@property (nonatomic, strong) AVURLAsset *playerURL;      // 视频播放的URL
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, copy) NSString *imUrl;
@property (nonatomic, assign) BOOL webLoadSucceed;

@end

@implementation GMFaceInfoShareViewController

- (void)initController {
    [super initController];
    self.pageName = @"report_result";
    self.navigationBar.backgroundColor = isGray ? RGBCOLOR_HEX(0xE9FCFC) : UIColor.clearColor;
    self.navigationBar.isShowShadow = NO;
    self.navigationBar.title = @"颜值报告";
    self.navigationBar.leftIcon = @"back";
    self.navigationBar.rightIcon = @"face_right_share_image";
    self.navigationBar.rightButton.hidden = YES;
    [self.navigationBar.rightButton setTitleColor: isGray ? UIColor.auxiliaryTextGreen : UIColor.headlineText forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (!self.faceModel) {
        NSDictionary *dict = [GMCache fetchObjectAtDocumentPathWithkey:@"GMFaceV3Model"];
        NSData *imageData = [GMCache fetchObjectAtDocumentPathWithkey:@"GMFaceV3ModelImage"];
        GMFaceV3Model *model = [[GMFaceV3Model alloc] initWithDictionary:dict error:NULL];
        model.image = [UIImage imageWithData:imageData];
        self.faceModel = model;
    }
    self.webCompent.delegate = self;
    self.webCompent.clientH5Object.delegate = nil;
    self.fd_interactivePopDisabled = YES;
    self.webCompent.backgroundColor = [UIColor yellowColor];
    [self.webCompent mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    self.path = isGray ? API_ALPHA_FACE_REPORT : API_ALPHA_FACE_REPORT0;
    [self reloadURL];
    if (isGray) {
        [self.view addSubview: self.bgImageView];
    }else{
        [self.view addSubview: self.bgNograyImageView];
    }
    self.webCompent.webView.scrollView.delegate = self;
    [self addNotification]; // 添加通知
    [self uploadSignTaskComplete];// 上传签到任务完成
}

- (void)addNotification{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(faceReplayResultVCNotification:) name:@"GMFaceReplayResultVC" object:nil];
}

- (NSString *)moreQueryParameters {
    NSString *faceId = [ALFaceInfoViewModel getLocalFaceId];
    return [NSString stringWithFormat:@"&face_id=%@&referrer=%@",faceId,self.pageName];
}

- (void)uploadSignTaskComplete {
    [self.navigationController.childViewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isKindOfClass:[NewFaceShotController class]]) {
            NewFaceShotController *newFace = (NewFaceShotController *)obj;
            if (newFace.haveTask) {
                if (newFace.cameraType == GMScanAnimationTypeScanFace) {
                    [GMSignTask signTaskComplete:GMSignTaskTypeScanFace taskId:@""];
                } else {
                    [GMSignTask signTaskComplete:GMSignTaskTypeTestSkin taskId:@""];
                }
                newFace.haveTask = NO;
                *stop = YES;
            }
        }
    }];
}
#pragma mark - 与前端交互方法

- (NSString *)nativeDataLoaded {
    NSDictionary *para = @{@"title_bar_height" : @(OCNavigationBar.barHeight)};
    NSData *paraData = [NSJSONSerialization dataWithJSONObject:para options:0 error:NULL];
    NSString *paraStr = [[NSString alloc] initWithData:paraData encoding:NSUTF8StringEncoding];
    return paraStr;
}

// 保存视频方法
-(void)saveFaceVideo:(NSString *)jsonStr {
    NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    UIImage *shareImage = [self stringToImageWith:jsonStr imageStr:@"shareImg"];
    if (!shareImage) {return;}
    GMFaceReplayModel *raplayModel = [[GMFaceReplayModel alloc] initWithDictionary:dict error:nil];
    raplayModel.type = dict[@"type"];  // preview'(预览)/wechat(录制朋友圈视频)/douyin(录制抖音视频)
    raplayModel.dataEwm = dict[@"dataEwm"]; // 二维码图片地址
    raplayModel.xcxCode = dict[@"xcxCode"]; // 小程序图片地址
    raplayModel.faceType = dict[@"faceType"]; // 脸型
    raplayModel.starName = dict[@"starName"]; // 明星脸
    raplayModel.paragraph2 = dict[@"paragraph2"]; // 描述内容
    raplayModel.resultImage = shareImage;
    raplayModel.iconImage = [GMCache fetchObjectAtDocumentPathWithkey:@"scanUserImg"]; // 录屏结果页面头像
    GMFaceReplayViewController * vc = [[GMFaceReplayViewController alloc] initWithModel:self.faceModel replayModel:raplayModel];
    [self.navigationController pushViewController:vc animated:YES];
}

// 监听通知，刷新页面
- (void)faceReplayResultVCNotification:(NSNotification *)noti {
    self.playerURL = [noti object];
    // 刷新当前页面
    [self.webCompent.webView evaluateJavaScript:@"window.gm.pack.run('saveVideoSuccess')" completionHandler:nil];
}

// 播放视频方法
- (void)playFaceVideo {
    if (!self.playerURL) {
        [self toast:@"视频无法播放！"];
        return;
    }
    self.playerView = [[GMPlayerView alloc] init];
    _playerView.topicId = @"";
    _playerView.from = @"";
    __weak typeof (self) weakSelf = self;
    [_playerView setCloseBtnClick:^{
        weakSelf.playerView = nil;
    }];
    [_playerView playWithAVURLAsset:self.playerURL withRect:CGRectMake(MAINSCREEN_WIDTH / 2, MAINSCREEN_HEIGHT / 2, 1, 1)];
}

- (void)changeAvatar {
    GMPhotoPickController *controller = [[GMPhotoPickController alloc] initWithMaxImageCount:1 maxVideoCount:0 maxCount:1 photoDisplayType:GMPhotosDisplayImageType];
    controller.dismissDelegate = self;
    controller.root.singleSelection = YES;
    controller.root.showCropFirst = YES;
    [self presentViewController:controller animated:YES completion:NULL];
}

- (void)dismissPhotoPick:(NSArray<GMEditPhotoInfo *> *)infos {
    if (infos.count == 0) { return;}
    GMEditPhotoInfo *model = infos.firstObject;
    UIImage *image = model.finshedImage;
    [GMFaceV3Util uploadImageToQiNiu:image successBlock:^(id responseObject) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSString *urlStr = [NSString stringWithFormat:@"https://pic.igengmei.com/%@-aspectscale800", responseObject];
            NSString *javaScriptStr = [NSString stringWithFormat:@"window.gm.pack.run('qnIconKey','%@')",urlStr];
            [self.webCompent.webView evaluateJavaScript:javaScriptStr completionHandler:nil];
        });
    }];
}

- (void)imButtonClick {
    if (self.imUrl) {
        [Phobos track:@"on_click_button" attributes:@{@"page_name" : self.pageName, @"button_name" : @"im_button" }];
        [[GMRouter sharedInstance] pushScheme:self.imUrl];
    }
}

- (void)shareFaceInfoImageMethod:(NSString *)imageDataStr {
    _shareImage = [self stringToImageWith:imageDataStr imageStr:@"xcxImageString"];// 默认展示带有“小程序码”的海报
    _ewmImage = [self stringToImageWith:imageDataStr imageStr:@"imageString"];// 二维码
    if (!_shareImage) {
        [self toast:@"糟糕，生成失败了，再试一次吧"];
        return;
    }
    [self shareFaceInfo];   // 展示分享框
    // 保存图片到相册
    UIImageWriteToSavedPhotosAlbum(_shareImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    [self toast:@"图片已存至相册，快分享给朋友炫耀一下"];
}

- (NSInteger)stringToImage:(NSString *)imageData name:(NSString *)name{
    NSData *jsonData = [imageData dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
     NSString *imageString = dict[name] ? : @"0";
    return [imageString integerValue];
}

- (UIImage *)stringToImageWith:(NSString *)imageData imageStr:(NSString *)imageStr {
    NSData *jsonData = [imageData dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    NSString *imageString = dict[imageStr] ?: @"";
    UIImage *image = [UIImage imageWithData:[[NSData alloc] initWithBase64EncodedString:imageString options:NSDataBase64DecodingIgnoreUnknownCharacters]];
    return image;
}

- (void)shareFaceInfo {
    CGFloat scale1 = _shareImage.size.height / _shareImage.size.width;
    CGFloat width1 = ShareImageHeight / scale1;
    self.showImageView.image = self.shareImage;
    self.showImageView.frame = CGRectMake((MAINSCREEN_WIDTH - width1)/2, OCNavigationBar.barHeight + 10, width1, ShareImageHeight);
    [self.shareSheet addSubview:self.showImageView];
    [self.shareSheet show];
    [UIView animateWithDuration:0.5 animations:^{
        _showImageView.alpha = 1.0;
    }];
}

- (GMButton *)creatBtnWithImageName:(NSString *)imageStr title:(NSString *)title titleColor:(UIColor *)titleColor selector:(SEL)sel{
    GMButton *btn = [[GMButton alloc] init];
    btn.adjustsImageWhenHighlighted = NO;
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    [btn setBackgroundImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [btn addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    return btn;
}

- (void)addSuspendBottomView {
    CGFloat margin = (MAINSCREEN_WIDTH - 103 * 3) / 4;
    // 专家咨询
    GMButton *consultBtn = [self creatBtnWithImageName:@"face_photo_bgImage" title:@"专家咨询" titleColor:RGBCOLOR_HEX(0xFF5963) selector:@selector(imButtonClick)];
    [consultBtn setImage:[UIImage imageNamed:@"face_test_consultIcon"] forState:UIControlStateNormal];
    [self.bottomView addSubview:consultBtn];
    [consultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(38);
        make.width.mas_equalTo(103);
        make.right.mas_equalTo(self.view.mas_right).offset(-margin);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(btnBottomMargin);
    }];
    // 肤质分析
    GMButton *skinAnalyseBtn = [self creatBtnWithImageName:@"face_analyse_bgImage" title:@"肤质分析" titleColor:UIColor.auxiliaryTextGreen selector:@selector(popViewToScanSkin)];
    [skinAnalyseBtn setImage:[UIImage imageNamed:@"face_test_analyse"] forState:UIControlStateNormal];
    [self.bottomView addSubview:skinAnalyseBtn];
    [skinAnalyseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(38);
        make.width.mas_equalTo(103);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(btnBottomMargin);
    }];
    // 再测一次
    GMButton *againBtn = [self creatBtnWithImageName:@"face_analyse_bgImage" title:@"再测一次" titleColor:UIColor.auxiliaryTextGreen selector:@selector(againBtnClick)];
    [againBtn setImage:[UIImage imageNamed:@"face_test_photoIcon"] forState:UIControlStateNormal];
    [self.bottomView addSubview:againBtn];
    [againBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(38);
        make.width.mas_equalTo(103);
        make.left.mas_equalTo(self.view.mas_left).offset(margin);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(btnBottomMargin);
    }];
}


-(UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor clearColor];
        [self.view insertSubview:_bottomView belowSubview:self.bgImageView];
        [_bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(84 + UIView.safeAreaInsetsBottom);
            make.left.right.mas_equalTo(0);
            make.bottom.mas_equalTo(self.view.mas_bottom);
        }];
        // 添加背景颜色
        GMImageView *bgImgView = [[GMImageView alloc] initWithImage:[UIImage imageNamed:@"face_bottomView_bgImage"]];
        [_bottomView addSubview:bgImgView];
        [bgImgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(0);
            make.height.mas_equalTo(84);
        }];
        // 安全区域防止透明
        UIView *safeAreaView = [[UIView alloc] init];
        safeAreaView.backgroundColor = [UIColor whiteColor];
        [_bottomView addSubview:safeAreaView];
        [safeAreaView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.height.mas_equalTo(UIView.safeAreaInsetsBottom);
        }];
    }
    return _bottomView;
}

- (ALShareSheet *)shareSheet {
    if (!_shareSheet) {
        __weak typeof(self) weakSelf = self;
        _shareSheet = [[ALShareSheet alloc] init];
        _shareSheet.bgAlphaColor = RGBCOLOR_HEX(0xF4F3F8);
        _shareSheet.hiddenBlock = ^{  // 隐藏
            [UIView animateWithDuration:0.25 animations:^{
                weakSelf.showImageView.alpha = 0.0;
            } completion:^(BOOL finished) {
                [weakSelf.showImageView removeFromSuperview];
                weakSelf.showImageView = nil;
            }];
        };
        _shareSheet.shareTypeBlock = ^(GMSharePlatform platform) {  // 分享
            UIImage *image;
            if (platform == GMSharePlatformWechatTimeline) {
                image = weakSelf.shareImage;
            }else{
                image = weakSelf.ewmImage;
            }
            [[GMShareSDK shareInstance] shareImage:image platform:platform];
            [Phobos track:@"page_click_share_channel" attributes:@{@"page_name":SafeString(weakSelf.pageName),
                                                                   @"share_channel":SafeString([GMShareSDK shareChannel:platform])}];
        };
    }
    return _shareSheet;
}

-(GMImageView *)showImageView{
    if (!_showImageView) {
        _showImageView = [[GMImageView alloc] init];
        _showImageView.backgroundColor = UIColor.clearColor;
        _showImageView.contentMode = UIViewContentModeScaleAspectFit;
        _showImageView.layer.cornerRadius = 10;
        _showImageView.layer.masksToBounds = YES;
    }
    return _showImageView;
}

#pragma mark -其它逻辑处理

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {}

// 返回按钮点击事件
-(void)backBtnClick {
    BOOL isPop = YES;
    for (UIViewController *vc in AppDelegate.navigation.childViewControllers) {
        if ([vc isKindOfClass:[NewFaceShotController class]]){
            isPop = NO;
            [AppDelegate.navigation popToViewController:vc animated:YES];
            return;
        }
    }
    if (isPop) {
        [AppDelegate.navigation popToRootViewControllerAnimated:YES];
    }
}

#pragma mark -添加背景imageView

-(GMImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[GMImageView alloc] initWithImage:[UIImage imageNamed:@"facev5_scan_share_bgImage"]];
        _bgImageView.frame = CGRectMake(0, 0, MAINSCREEN_WIDTH, MAINSCREEN_HEIGHT);
        _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        UIImageView *imageV = [[GMImageView alloc] initWithImage:[UIImage imageNamed:@"facev5_scan_share_image"]];
        imageV.userInteractionEnabled = NO;
        CGFloat w = MAINSCREEN_WIDTH - 25;
        CGFloat h = 479 * w / 350;
        imageV.frame = CGRectMake(0, 0, w, h);
        imageV.center = _bgImageView.center;
        [_bgImageView addSubview:imageV];
    }
    return _bgImageView;
}

-(GMImageView *)bgNograyImageView {
    if (!_bgNograyImageView) {
           _bgNograyImageView = [[GMImageView alloc] initWithImage:[UIImage imageNamed:@"fave4_share_bgImage"]];
           _bgNograyImageView.frame = CGRectMake(0, 0, MAINSCREEN_WIDTH, MAINSCREEN_HEIGHT);
           _bgNograyImageView.contentMode = UIViewContentModeScaleAspectFill;
       }
       return _bgNograyImageView;
}

// 右侧按钮点击事件
- (void)rightButtonClicked:(OCNavigationBarButton *)button {
    [self shareFriend];
}

// 返回到首页
-(void)goHomeBtnClick {
    [Phobos track:@"on_click_button" attributes:@{@"page_name" :SafeString(self.pageName), @"button_name" : @"back_home"}];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

// 再测一次
-(void)againBtnClick {
    [Phobos track:@"on_click_button" attributes:@{@"page_name":SafeString(self.pageName),
                                                  @"button_name":@"scan_again"}];
    [self backBtnClick];
}

// 返回到测肤页面
-(void)popViewToScanSkin{
    [Phobos track:@"on_click_button" attributes:@{@"page_name" :SafeString(self.pageName), @"button_name" : @"goto_face_detect"}];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"GMFaceInfoSharePopToFaceSkin" object:nil];
    [self backBtnClick];
}

// 分享给朋友
-(void)shareFriend {
    [Phobos track:@"page_click_share" attributes:@{@"page_name" : SafeString(self.pageName)}];
    [self.webCompent.webView evaluateJavaScript:@"window.gm.pack.run('share')" completionHandler:nil];
}

// leftButton点击事件
-(void)backAction:(OCNavigationBarButton *)button{
    if (self.webLoadSucceed){
        [self.webCompent.webView evaluateJavaScript:@"window.gm.pack.run('signBack')" completionHandler:nil];
    }else{
        [self backBtnClick];
    }
}

#pragma mark WKWebView 代理方法

-(void)jsControlBackToMethod:(NSString *)str{
    if([str isEqualToString:@"pop"]){  // 返回测肤页面
        [self backBtnClick];
    }else if([str isEqualToString:@"skin"]){ //  返回测脸页面
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GMFaceInfoSharePopToFaceSkin" object:nil];
        [self backBtnClick];
    }
}

// 代理方法回掉， 删掉的话， 进入落地页会闪退
-(void)globalDataLoaded:(NSDictionary *)data{
    self.webLoadSucceed = YES;
}

// 判断按钮滑动的位置
-(void)jsPageReachBottom:(BOOL)isScrollbottom{}

- (void)consultationUrl:(NSDictionary *)data {
    if ([data[@"url"] isNonEmpty]) {
        self.imUrl = data[@"url"];
    }
}

-(void)closeFaceLoading {
    self.bgImageView.hidden = YES;
    self.navigationBar.rightButton.hidden = NO;
    if (isGray) {  // 灰度
        self.bgImageView.hidden = YES;
        self.navigationBar.backgroundColor = UIColor.whiteColor;
    }else {   // 非灰度
        self.bgNograyImageView.hidden = YES;
    }
    [self addSuspendBottomView];   // 添加悬浮按钮
}

-(void)controlTitleBarVisible:(BOOL)show{
    if (isGray) {return;}
    if (show) {
        self.navigationBar.backgroundColor = RGBCOLOR_HEX(0xF5B5E3);
    }else{
        self.navigationBar.backgroundColor = UIColor.clearColor;
    }
}

#pragma mark 暂时不知道这几个方法的作用

- (void)WKWebViewScroll:(WKWebView *)webView CaptureCompletionHandler:(void(^)(UIImage *capturedImage))completionHandler {
    
    // 制作了一个UIView的副本
    UIView *snapShotView = [webView snapshotViewAfterScreenUpdates:YES];
    
    snapShotView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y, snapShotView.frame.size.width, snapShotView.frame.size.height);
    
    [webView.superview addSubview:snapShotView];
    
    // 获取当前UIView可滚动的内容长度
    CGPoint scrollOffset = webView.scrollView.contentOffset;
    
    // 向上取整数 － 可滚动长度与UIView本身屏幕边界坐标相差倍数
    float maxIndex = ceilf(webView.scrollView.contentSize.height/webView.bounds.size.height);
    
    // 保持清晰度
    UIGraphicsBeginImageContextWithOptions(webView.scrollView.contentSize, false, [UIScreen mainScreen].scale);
    
    // 滚动截图
    [self ZTContentScroll:webView PageDraw:0 maxIndex:(int)maxIndex drawCallback:^{
        UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        // 恢复原UIView
        [webView.scrollView setContentOffset:scrollOffset animated:NO];
        [snapShotView removeFromSuperview];
        //        UIImage *resultImg = [UIImage imageWithData:UIImageJPEGRepresentation(capturedImage, 0.5)];
        completionHandler(capturedImage);
        
    }];
}

// 滚动截图
- (void)ZTContentScroll:(WKWebView *)webView PageDraw:(int)index maxIndex:(int)maxIndex drawCallback:(void(^)(void))drawCallback{
    [webView.scrollView setContentOffset:CGPointMake(0, (float)index * webView.frame.size.height)];
    CGRect splitFrame = CGRectMake(0, (float)index * webView.frame.size.height, webView.bounds.size.width, webView.bounds.size.height);
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [webView drawViewHierarchyInRect:splitFrame afterScreenUpdates:YES];
        if(index < maxIndex){
            [self ZTContentScroll:webView PageDraw: index + 1 maxIndex:maxIndex drawCallback:drawCallback];
        }else{
            drawCallback();
        }
    });
}

- (void)showNativeEmptyView {
    [self showEmptyView:GMEmptyViewTypeException];
}

- (void)emptyViewDidClickReload {
    [self hideEmptyView];
    [self.webCompent reload];
}

@end
