//
//  DeviceIntroducedVC.m
//  gaotingshan
//
//  Created by MacBook Dq01 on 16/3/30.
//  Copyright © 2016年 Mac Book DQ02. All rights reserved.
//

#import "DeviceIntroducedVC.h"

@interface DeviceIntroducedVC () <UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation DeviceIntroducedVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"登山设备介绍";
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrics:(UIBarMetricsDefault)];
//    //改变字体颜色
//    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
//    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
//    self.navigationController.navigationBar.titleTextAttributes = textAttrs;
    
    
    [Manager setNavi:self.navigationController.navigationBar];
    
    
#pragma - 设置导航栏左边的按钮

 //   self.navigationItem.leftBarButtonItem = [Manager rightItemTarget:self img:@"nav_back" tag:1000000 action:@selector(leftBarButtonItemIsClicked:)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_back"] landscapeImagePhone:nil style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemIsClicked:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    //以下是对webView的一些处理。
//    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)];
//    [_webView setUserInteractionEnabled:YES];
//    _webView.delegate = self;
//    [_webView setOpaque:NO]; //设置是否透明。
//    [_webView setScalesPageToFit:YES]; //自动缩放以适应屏幕。
//    _webView.scrollView.bounces = NO;
//    _webView.scrollView.showsVerticalScrollIndicator = NO;
    
    _webView = [Manager screenFrameWebview];
    _webView.delegate = self;
    //加载网页
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/terminal/deviceshow",localRequestUrl]];
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];
    [self.view addSubview:_webView];
    
    
}

#pragma mark - 导航栏左边按钮被点击
- (void)leftBarButtonItemIsClicked:(UIBarButtonItem *)sender {
    
    [self dismissViewControllerAnimated:NO completion:nil];
    
}

#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"登山设备介绍页url=%@",request.URL.absoluteString);
    if ([request.URL.absoluteString containsString:@"deviceshow?type=purchase"]) {
        ConfirmOrderVC *vc = [[ConfirmOrderVC alloc]init];
        UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:vc];
        na.navigationBar.translucent =YES;
        [self presentViewController:na animated:NO completion:nil];
    }
    
    return YES;
}




/////////////////////////////////////////
- (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
