123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // ApplyCardExtensionViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/7/16.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class ApplyCardExtensionViewController: BaseViewController {
- @IBOutlet weak var imgView: UIImageView!
- /// 0办卡 1:积分
- var type = 0
- var wkWebView: WKWebView!
- var wkBridge: WKWebViewJavascriptBridge!
- override func viewDidLoad() {
- super.viewDidLoad()
- let config = WKWebViewConfiguration.init()
- wkWebView = WKWebView.init(frame: self.view.bounds, configuration: config)
- self.view.addSubview(wkWebView)
- // let htmlPath = "\(RequestURL.hostMainH5)tuiguang.html?type=\(type)"
- let htmlPath = "http://106.xingchuangke.net:8889/H5/tuiguang.html?type=0"
- wkWebView.loadDataForUrl(url: htmlPath)
- wkBridge = WKWebViewJavascriptBridge(for: wkWebView)
- wkBridge.setWebViewDelegate(self)
- // 接收js调用方法
- wkBridge.registerHandler("btnTest") { [weak self](data, _) in
- let dic = data as? NSDictionary
- if dic != nil {
- if dic!.getString(key: "funName") == "saveImage" {
- let param = CommonJSON.jsonToDic(json: dic!.getString(key: "param"))
- if param != nil {
- let index = param!.getInt(key: "index")
- if self!.arrData.count > index {
- let imgUrl = self!.getString(current: index, key: "image")
- SVProgressHUD.show()
- self!.imgView.sd_setImage(with: URL(string: imgUrl), completed: { (_, error, _, _) in
- if error == nil {
- self!.saveImage()
- } else {
- SVProgressHUD.dismiss()
- }
- })
- }
- }
- }
- }
- }
- WKWebViewJavascriptBridge.enableLogging()
- loadData()
- }
- func btnRightClick() {
- wkBridge.callHandler("getSelectIndex", data: nil) {[weak self] (content) in
- let param = content as? NSDictionary
- if param != nil {
- print(param!)
- let index = param!.getInt(key: "index")
- if self!.arrData.count > index {
- let imgUrl = self!.getString(current: index, key: "image")
- SVProgressHUD.show()
- self!.imgView.sd_setImage(with: URL(string: imgUrl), completed: { (img, error, _, url) in
- SVProgressHUD.dismiss()
- if error == nil {
- if self!.type == 0 {
- let urlStr = "http://app.xingchuangke.net/jsp/creditBank/bank_list.jsp?userId=\(CommonValue.getUserId())"
- CommonUMengShare.showSharedMenuCus(viewController: self!, title: "免费办理信用卡,分享即可拿奖励", desc: "办卡有奖励、手续简、下卡快、额度高", icon: UIImage(named: "icon")!, url: urlStr, img: self!.imgView.image!)
- } else {
- CommonUMengShare.showSharedMenuCus(viewController: self!, title: "立即注册,开启您的财富之旅", desc: "POS机办理,信用卡申请,积分换钱......", icon: UIImage(named: "icon")!, url: "\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())", img: self!.imgView.image!)
- }
- }
- })
- }
- }
- }
- }
- func saveImage() {
- if imgView.image != nil {
- let image = imgView.image!
- var urlStr = ""
- if type == 0 {
- urlStr = "http://app.xingchuangke.net/jsp/creditBank/bank_list.jsp?userId=\(CommonValue.getUserId())"
- } else {
- urlStr = "\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())"
- }
- let image2 = CommonBarCodeTools.setupQRCodeImage(urlStr, image: UIImage(named: "icon"))
- let img = drawImages(imageArray: [image, image2])
- UIImageWriteToSavedPhotosAlbum(img, self, #selector(saveImageResult), nil)
- } else {
- SVProgressHUD.dismiss()
- }
- }
- func drawImages(imageArray: [UIImage]) -> UIImage {
- // 1.1.图片的宽度
- let width: CGFloat = imageArray[0].size.width
- // 1.2.图片的高度
- let height: CGFloat = imageArray[0].size.height
- // 1.4.开始绘制图片的大小
- UIGraphicsBeginImageContext(CGSize(width: width, height: height))
- imageArray[0].draw(at: CGPoint(x: 0, y: 0))
- let codeSize = imageArray[0].size.width / 5
- imageArray[1].draw(in: CGRect(x: (imageArray[0].size.width - codeSize) / 2, y: imageArray[0].size.height - codeSize - 15, width: codeSize, height: codeSize))
- // // 1.5.设置一个变量用来获取UIImage的Y值
- // var imageY: CGFloat = 0
- // // 1.6.遍历图片的数组
- // for image in imageArray {
- // // 1.6.1.开始绘画图片
- // image.draw(at: CGPoint(x: 0, y: imageY))
- // // 1.6.2.自增每张图片的Y轴
- // imageY += image.size.height
- //
- // }
- // 1.7.获取已经绘制好的图片
- let drawImage = UIGraphicsGetImageFromCurrentImageContext()!
- // 1.8.结束绘制图片
- UIGraphicsEndImageContext()
- // 1.9.返回已经绘制的图片
- return drawImage
- }
- @objc func saveImageResult(image: UIImage, didFinishSavingWithError error: NSError?, contentInfo: AnyObject) {
- SVProgressHUD.dismiss()
- if error != nil {
- SVProgressHUD.showSuccess(withStatus: "保存失败")
- } else {
- SVProgressHUD.showSuccess(withStatus: "保存成功")
- }
- }
- // MARK: =============加载数据===============
- func loadData() {
- let url = RequestURL.extensionImageList
- let params = NSMutableDictionary()
- params.setValue(type, forKey: "type")
- loadDataList(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- self.tabBarController?.title = self.title
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "ApplyCardExtensionViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|