ApplyCardWebViewController.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // IntegralWebViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/5/5.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class ApplyCardWebViewController: BaseViewController, UIScrollViewDelegate {
  10. lazy var wkWebView: WKWebView = {
  11. () -> WKWebView in
  12. let config = WKWebViewConfiguration.init()
  13. let wkWebView = WKWebView.init(frame: CGRect.zero, configuration: config)
  14. return wkWebView
  15. }()
  16. var urlStr = ""
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. initNavLeftBackButton()
  20. wkWebView.frame = self.view.bounds
  21. // self.view.addSubview(wkWebView)
  22. urlStr = "\(RequestURL.cardMain)#/?org_code=\(RequestURL.orgId)&user_code=\(CommonValue.getUserId())&cid=\(CommonUntils.getUUID())"
  23. wkWebView.load(URLRequest(url: URL(string: urlStr)!))
  24. // initNavRightButtonForImage(imgName: "share_common")
  25. // initNavRightButtonForTitle(title: "进度查询")
  26. self.loadData()
  27. }
  28. var dataArray = NSArray.init()
  29. func loadData() {
  30. let http = AFHTTPSessionManager()
  31. http.get(RequestURL.getCreditBankList, parameters: nil, progress: { (_) in
  32. }, success: { (operation, json) in
  33. print(json as Any)
  34. let success = (json as! NSDictionary).object(forKey: "succeed") as! String
  35. if success == "000"{
  36. self.dataArray = (json as! NSDictionary).object(forKey: "dataInfo") as! NSArray
  37. self.creatUI()
  38. }
  39. }) { (_, _) in
  40. }
  41. }
  42. let scrollView = UIScrollView()
  43. func creatUI() {
  44. let allNum = self.dataArray.count
  45. var l = allNum/3
  46. let c = allNum%3
  47. if c == 0 {
  48. l = l+1
  49. }
  50. let width = Int((kScreenWidth-40)/3)
  51. scrollView.delegate = self //设置代理
  52. scrollView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight-45)//设置scrollview的大小
  53. scrollView.backgroundColor = self.view.backgroundColor
  54. scrollView.isPagingEnabled = false //是否支持分页
  55. scrollView.bounces = false //是否支持回弹效果
  56. scrollView.showsVerticalScrollIndicator = false //垂直滑动线隐藏
  57. scrollView.showsHorizontalScrollIndicator = false //水平滑动线隐藏
  58. //scrollView.contentInset = UIEdgeInsetsMake(10, 10, 10, 10) //设置内边距
  59. scrollView.contentSize = CGSize(width: kScreenWidth, height: CGFloat(width*l+20))
  60. self.view.addSubview(scrollView)
  61. var num = 0
  62. for i in 0..<l {
  63. for j in 0..<3 {
  64. if num == allNum {
  65. return
  66. }
  67. let cell = BankCardCel.init()
  68. cell.isUserInteractionEnabled = true
  69. cell.mj_x = CGFloat(j*width+10*j+10)
  70. cell.mj_y = CGFloat(i*width+10*i+10)
  71. cell.setSizeWidth(width: CGFloat(width))
  72. cell.setSizeHeight(height: CGFloat(width))
  73. // cell.frame = CGRect(x: j*40+10, y: i*40+10, width: (kScreenWidth-40)/3, height: (kScreenWidth-40)/3)
  74. scrollView.addSubview(cell)
  75. let dic = self.dataArray[num]as!NSDictionary
  76. cell.titleLabel.text = (dic["name"]as!String)
  77. cell.imageView.sd_setImage(with: NSURL.init(string: "https://img.weimilo.com\(dic["logo"]as!String)") as URL?)
  78. cell.tipLabel.text = (dic["logo_tip"]as!String)
  79. cell.btn.addTarget(self, action: #selector(bankBtnTouch(_:)), for: .touchUpInside)
  80. num+=1
  81. }
  82. }
  83. }
  84. @objc func bankBtnTouch(_ sender: UIButton) {
  85. let dic = self.dataArray[sender.tag]as!NSDictionary
  86. let vc = UpMessageCardViewController()
  87. vc.dic = dic
  88. toViewController(viewController: vc)
  89. }
  90. override func btnRightMenuClick() {
  91. let urlStr = "http://app.xingchuangke.net/jsp/creditBank/bank_list.jsp?userId=\(CommonValue.getUserId())"
  92. CommonUMengShare.showSharedMenu(viewController: self, title: "免费办理信用卡,分享即可拿奖励", desc: "办卡有奖励、手续简、下卡快、额度高", icon: UIImage(named: "icon")!, url: urlStr)
  93. }
  94. override func handleBack() {
  95. if wkWebView.canGoBack {
  96. wkWebView.goBack()
  97. } else {
  98. super.handleBack()
  99. }
  100. }
  101. override func viewWillAppear(_ animated: Bool) {
  102. super.viewWillAppear(animated)
  103. self.tabBarController?.title = self.title
  104. }
  105. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  106. super.init(nibName: "ApplyCardWebViewController", bundle: nil)
  107. }
  108. required init?(coder aDecoder: NSCoder) {
  109. fatalError("init(coder:) has not been implemented")
  110. }
  111. }