// // ApplyCardTabBarViewController.swift // xingchuangke // // Created by Virgil on 2019/7/16. // Copyright © 2019 Virgil. All rights reserved. // import UIKit @objcMembers class ApplyCardTabBarViewController: UITabBarController { /// 0办卡 1:积分 var type = 0 var arrBtnText = [["进度查询", "马上推广", "马上推广", "收益查询"], ["马上推广", "马上推广", "马上推广", "收益查询"]] var tab11: IntegralWebViewController! var tab41: IntegralBillViewController! var tab1: ApplyCardWebViewController! var tab2: ApplyCardAgentViewController! var tab3: ApplyCardExtensionViewController! var tab4: ApplyCardBillViewController! override func viewDidLoad() { super.viewDidLoad() initNavLeftBackButton() self.initBar() } func initBar() { initNavRightButtonForTitle(title: arrBtnText[type][0], color: UIColor.white) tab2 = ApplyCardAgentViewController() tab2.type = type tab2.tabBarItem.tag = 1002 tab2.tabBarItem.image = UIImage.init(named: "ico_02") tab2.tabBarItem.selectedImage = UIImage.init(named: "ico_02_s") tab2.title = "代理" tab3 = ApplyCardExtensionViewController() tab3.type = type tab3.tabBarItem.tag = 1003 tab3.tabBarItem.image = UIImage.init(named: "ico_05") tab3.tabBarItem.selectedImage = UIImage.init(named: "ico_05_s") tab3.title = "推广" if type == 0 { tab1 = ApplyCardWebViewController() tab1.tabBarItem.tag = 1001 tab1.tabBarItem.image = UIImage.init(named: "ico_01") tab1.tabBarItem.selectedImage = UIImage.init(named: "ico_01_s") tab1.title = "推荐办卡" tab4 = ApplyCardBillViewController() tab4.tabBarItem.tag = 1004 tab4.tabBarItem.image = UIImage.init(named: "ico_04") tab4.tabBarItem.selectedImage = UIImage.init(named: "ico_04_s") tab4.title = "账单" self.viewControllers = [tab1, tab2, tab3, tab4] } else { tab11 = IntegralWebViewController() tab11.tabBarItem.tag = 1001 tab11.tabBarItem.image = UIImage.init(named: "ico_03") tab11.tabBarItem.selectedImage = UIImage.init(named: "ico_03_s") tab11.title = "积分兑换" tab41 = IntegralBillViewController() tab41.tabBarItem.tag = 1004 tab41.tabBarItem.image = UIImage.init(named: "ico_04") tab41.tabBarItem.selectedImage = UIImage.init(named: "ico_04_s") tab41.title = "账单" self.viewControllers = [tab11, tab2, tab3, tab41] } } override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { rbtnMenu.setTitle(arrBtnText[type][item.tag - 1001], for: .normal) } func setTitle(title: String) { self.title = title } func initNavLeftBackButton() { let backBtn = UIButton(type: UIButton.ButtonType.custom) backBtn.frame = CGRect(x: 0, y: 0, width: 80, height: 44) backBtn.contentHorizontalAlignment = .left backBtn.setImage(UIImage(named: "ion_return-arrow"), for: .normal) backBtn.addTarget(self, action: #selector(self.handleBack), for: UIControl.Event.touchUpInside) let backBarBtnItem=UIBarButtonItem(customView: backBtn) self.navigationItem.leftBarButtonItem = backBarBtnItem } var rbtnMenu: UIButton! func initNavRightButtonForTitle(title: String, color: UIColor) { rbtnMenu = UIButton(type: .custom) rbtnMenu.frame = CGRect(x: 0, y: 0, width: 80, height: 14) rbtnMenu.setTitle(title, for: .normal) rbtnMenu.titleLabel?.font = UIFont.systemFont(ofSize: 15) rbtnMenu.setTitleColor(color, for: .normal) rbtnMenu.sizeToFit() let barItem = UIBarButtonItem(customView: rbtnMenu) self.navigationItem.rightBarButtonItem = barItem rbtnMenu.addTarget(self, action: #selector(self.btnRightMenuClick), for: UIControl.Event.touchUpInside) } @objc func handleBack() { if selectedIndex == 0 { if type == 0 { let vc = viewControllers![0] as! ApplyCardWebViewController if vc.wkWebView.canGoBack { vc.wkWebView.goBack() } else { self.navigationController?.popViewController(animated: true) } } else { let vc = viewControllers![0] as! IntegralWebViewController if vc.wkWebView.canGoBack { vc.wkWebView.goBack() } else { self.navigationController?.popViewController(animated: true) } } } else { self.navigationController?.popViewController(animated: true) } } @objc func btnRightMenuClick() { if self.selectedIndex == 2 { tab3.btnRightClick() } else if self.selectedIndex == 1 { if type == 0 { let urlStr = "http://app.xingchuangke.net/jsp/creditBank/bank_list.jsp?userId=\(CommonValue.getUserId())" CommonUMengShare.showSharedMenu(viewController: self, title: "免费办理信用卡,分享即可拿奖励", desc: "办卡有奖励、手续简、下卡快、额度高", icon: UIImage(named: "icon")!, url: urlStr) } else { CommonUMengShare.showSharedMenu(viewController: self, title: "立即注册,开启您的财富之旅", desc: "POS机办理,信用卡申请,积分换钱......", icon: UIImage(named: "icon")!, url: "\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())") } } else if self.selectedIndex == 0 { if type == 0 { let vc = SpeedViewController() self.navigationController?.pushViewController(vc, animated: true) // UIApplication.shared.openURL(URL(string:"http://card-dev.qdrsd.top/#/progress")!); } else { CommonUMengShare.showSharedMenu(viewController: self, title: "立即注册,开启您的财富之旅", desc: "POS机办理,信用卡申请,积分换钱......", icon: UIImage(named: "icon")!, url: "\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())") } } //http://card-dev.qdrsd.top/#/progress else { let vc = ProfitListViewController() vc.type = type self.navigationController?.pushViewController(vc, animated: true) } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }