//
//  UpMessageCardViewController.swift
//  xingchuangke
//
//  Created by Apple on 2020/10/23.
//  Copyright © 2020 Virgil. All rights reserved.
//

import UIKit

class UpMessageCardViewController: BaseViewController, AVCaptureViewControllerDelegate {

    @IBOutlet weak var nameTextField: UITextField!

    @IBOutlet weak var nextBtn: UIButton!
    @IBOutlet weak var idCardTextField: UITextField!

    @IBOutlet weak var phoneTextField: UITextField!
    @IBOutlet weak var touchbtn: UIButton!
    var dic = NSDictionary.init()
    override func viewDidLoad() {
        super.viewDidLoad()
        initNavLeftBackButton()
        self.title = (dic["name"]as!String)
        nextBtn.layer.cornerRadius = 5
        // Do any additional setup after loading the view.
    }

    @IBAction func touchbtnact(_ sender: Any) {

        let vc = AVCaptureViewController()
                   vc.delegate = self
                   vc.cardType = 0
                   self.present(vc, animated: true) {

                   }

    }

    func avCaptureViewReData(_ iDInfo: IDInfo!, img: UIImage!) {
        print(iDInfo.num as Any)
        nameTextField.text = iDInfo.name
        idCardTextField.text = iDInfo.num
         //txtIDCard.text = iDInfo.num!
         //imgShow.image = img;
     }

    @IBAction func nextBtnAct(_ sender: Any) {
        if CommonValidate.isPhoneNumber(num: phoneTextField!.text! as NSString) {

        } else {
            SVProgressHUD.showError(withStatus: "请输入正确的手机号")
            return
        }
        if CommonValidate.checkIdentityCardNumber(idCardTextField.text!) {

        } else {
           SVProgressHUD.showError(withStatus: "请输入正确的身份证号")
            return
        }

        let params = NSMutableDictionary()
        params.setValue(dic["code"]as!String, forKey: "bankCode")
        params.setValue(nameTextField.text!, forKey: "acount")
        params.setValue(idCardTextField.text!, forKey: "accountNo")
        params.setValue(phoneTextField.text!, forKey: "phoneNum")
              print(params)
                       let http = AFHTTPSessionManager()

                            http.post(RequestURL.submitApplication, parameters: params, progress: { (_) in

                            }, success: { (operation, json) in

                                print(json as Any)
                                let success = (json as! NSDictionary).object(forKey: "succeed") as! String

                                if success == "000"{
                                  let vc  = ApplyCardebViewTViewController()
                                    vc.urlStr = (json as! NSDictionary).object(forKey: "url") as! String
                                    vc.titlet = (self.dic["name"]as!String)
                                  self.toViewController(viewController: vc)
                                } else {
                                    SVProgressHUD.showError(withStatus: ((json as! NSDictionary).object(forKey: "sucInfo") as! String))
                                }

                            }) { (_, _) in

                            }

    }

    /*
    // 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.
    }
    */
    override func viewWillAppear(_ animated: Bool) {
           super.viewWillAppear(animated)

       }
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
           super.init(nibName: "UpMessageCardViewController", bundle: nil)
       }

       required init?(coder aDecoder: NSCoder) {
           fatalError("init(coder:) has not been implemented")
       }
}