//
//  WebSwiftTwoViewController.swift
//  MobilePortal
//
//  Created by caiyang on 2020/12/17.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

class WebSwiftTwoViewController: BaseViewController {

    var newType:NewType = .OrdinaryNewsType
    var isShowTitleType:IsShowTitleType = .YesShowTitleType
    var isHomePushType:IsHomePushType = .YesIsHomePushType
    var webViewUrl:String?
    var strAction:String = ""
    var appid:String?
    var isEncryptionType:IsEncryptionType = .NoEncryptionType
    ///上个页面是否隐藏导航栏
    var previousPageShowTitleType : IsShowTitleType = .YesShowTitleType
    
    var webView = UIWebView()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initTitleBar()
        self.addWebView()
        // Do any additional setup after loading the view.
    }
    func addWebView(){
        if #available(iOS 11.0, *) {
            webView.frame = CGRect(x:0, y: getStatusBarH(), width:SCREEN_WHIDTH() , height:SCREEN_HEIGHT()+HEIGHT_BOTTOM_MARGIN()-getStatusBarH() )
        }else{
            webView.frame = CGRect(x:0, y: 0, width:SCREEN_WHIDTH() , height:SCREEN_HEIGHT()+HEIGHT_BOTTOM_MARGIN())
        }
        let count = self.getWebCookie(urlStr: self.webViewUrl)
        let url2:NSURL = NSURL.init(string: WebActionOC.share().getUrl(self.webViewUrl))!
        let urlRequest:NSMutableURLRequest = NSMutableURLRequest.init(url: url2 as URL)
//        urlRequest.setValue(WebActionOC.share()?.getCookieValue((WebActionOC.share()?.encryptAES(count, key: self.appid))!, andWebView: webView) as String?, forHTTPHeaderField: "Cookie")
        
        self.view.addSubview(webView)
//        webView.load((urlRequest as NSMutableURLRequest) as URLRequest, mimeType: )
        webView.loadRequest(urlRequest as URLRequest)
        
        
        self.view.addSubview(webView)
    }
    func getStatusBarH() -> CGFloat {
        var h = CGFloat()
        if self.isShowTitleType == .NoShowTitleType {
            h = UIApplication.shared.statusBarFrame.size.height
        } else {
            h = UIApplication.shared.statusBarFrame.size.height+(self.navigationController?.navigationBar.frame.size.height)!
        }
        return h
    }

}
