//
//  InvitePartnerViewController.m
//  ALand
//
//  Created by Z on 16/4/21.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "InvitePartnerViewController.h"
#import "SeeMoreViewController.h"
#import <WebKit/WebKit.h>

@interface InvitePartnerViewController ()<WKNavigationDelegate>
@property (weak, nonatomic) IBOutlet UIButton *btnInvite;

@end

@implementation InvitePartnerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpWebView];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"更多" style:UIBarButtonItemStyleDone target:self action:@selector(actionSeeMore)];
    rightBtn.tintColor = kTextColorDarkGray;
    self.navigationItem.rightBarButtonItem = rightBtn;
    
}

- (void)setUpWebView {
    NSString *inviteWebUrl = [NSString stringWithFormat:@"%@Wap/visit.html", [UserInfo shareInstance].webShopBaseUrl];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:inviteWebUrl] cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:10];
    WKWebView *webView = [WKWebView new];
    webView.navigationDelegate = self;
    webView.backgroundColor = kBacroundColor;
    [webView loadRequest:request];
    [self.view addSubview:webView];
    webView.sd_layout.topSpaceToView(self.view, 0).leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).bottomSpaceToView(self.btnInvite, 0);
}

#pragma mark - wkwebview delegate

// 页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}

// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    [MBProgressHUD hideHUDForView:self.view];
}

//查看更多
- (void)actionSeeMore {
    SeeMoreViewController *seeMoreVC = [[SeeMoreViewController alloc] init];
    seeMoreVC.isShowNavigationBar = YES;
    [self.navigationController pushViewController:seeMoreVC animated:YES];
}


- (IBAction)invitePartner:(id)sender {
    
    [[ShareInstance shareInstace] invitePartner];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"invitePartner"];//("PageOne"为页面名称，可自定义)
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"invitePartner"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
