123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- //
- // ApplyerViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/28.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class RealNameAuthViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
- @IBOutlet weak var btnMenu1: UIButton!
- @IBOutlet weak var btnMenu2: UIButton!
- @IBOutlet weak var btnMenu3: UIButton!
- @IBOutlet weak var btnMenu4: UIButton!
- @IBOutlet weak var viewMenu1: UIView!
- @IBOutlet weak var viewMenu2: UIView!
- @IBOutlet weak var viewMenu3: UIView!
- @IBOutlet weak var viewMenu4: UIView!
- @IBOutlet weak var img1: UIImageView!
- @IBOutlet weak var img2: UIImageView!
- @IBOutlet weak var img3: UIImageView!
- @IBOutlet weak var img4: UIImageView!
- @IBOutlet weak var viewContent: UIView!
- @IBOutlet weak var txtBankChild: UITextField!
- @IBOutlet weak var txtBankAddress: UITextField!
- @IBOutlet weak var txtBank: UITextField!
- @IBOutlet weak var txtBankNo: UITextField!
- @IBOutlet weak var txtPhone: UITextField!
- @IBOutlet weak var txtCard: UITextField!
- @IBOutlet weak var btnFinish: UIButton!
- @IBOutlet weak var txtName: UITextField!
- @IBOutlet weak var txtErrorInfo: UITextView!
- @IBOutlet weak var viewContent2: UIView!
- @IBOutlet weak var scrollView: UIScrollView!
- var arrImages = ["", "", "", ""]
- var addressIds = ["", "", ""]
- var addressNames = ["", "", ""]
- var zhiHangId = ""
- var zhiHangName = ""
- var arrBank = NSMutableArray()
- var bankCardCityName = ""
- var namem = ""
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "实名认证"
- initNavLeftBackButton()
- scrollView.setSizeWidth(width: ScreenWidth)
- CommonViewUntils.setViewAverage(arrView: [viewMenu1, viewMenu2])
- CommonViewUntils.setViewAverage(arrView: [viewMenu3, viewMenu4])
- // Do any additional setup after loading the view.
- scrollView.contentSize.height = btnFinish.bottom() + 80
- txtName.delegate = self
- txtCard.delegate = self
- txtBank.delegate = self
- txtBankNo.delegate = self
- txtPhone.delegate = self
- scrollView.keyboardDismissMode = .onDrag
- let jsonPath = Bundle.main.path(forResource: "bankData", ofType: "json")
- do {
- let arrTemp = try CommonJSON.jsonToArray(json: String(contentsOfFile: jsonPath!))
- if arrTemp != nil {
- arrBank.setArray(arrTemp! as! [Any])
- }
- print(arrBank.count)
- } catch {}
- loadJSData()
- scrollView.setSizeHeight(height: ScreenHeight - common_nav_status_height - common_bottom_height)
- }
- var viewSelectCity: Virgil_SelectCity!
- //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- KeyboardHidden(gestureRecognizer: UIGestureRecognizer())
- switch (sender as! UIButton).tag {
- case 1001: // 身份证正面
- uploadImage(type: 0)
- break
- case 1002: // 身份证背面
- uploadImage(type: 1)
- break
- case 1003: // 手持身份证证件照
- uploadImage(type: 2)
- break
- case 1004: // 辅助证明材料
- uploadImage(type: 3)
- break
- case 1005: // 完成
- if !btnMenu1.isSelected {
- SVProgressHUD.showError(withStatus: "请上传身份证正面")
- return
- }
- if !btnMenu2.isSelected {
- SVProgressHUD.showError(withStatus: "请上传身份证背面")
- return
- }
- if !btnMenu3.isSelected {
- SVProgressHUD.showError(withStatus: "请上传手持身份证照")
- return
- }
- if !btnMenu4.isSelected {
- SVProgressHUD.showError(withStatus: "请上传银行卡正面照")
- return
- }
- if txtName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入姓名")
- return
- }
- if txtCard.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入身份证号")
- return
- }
- if txtBankNo.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入银行卡号")
- return
- }
- if addressIds[1] == "" {
- SVProgressHUD.showError(withStatus: "请选择银行所在地区")
- return
- }
- if zhiHangName == "" {
- SVProgressHUD.showError(withStatus: "请选择所属支行")
- return
- }
- if txtPhone.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入预留手机号")
- return
- }
- submitData()
- break
- case 1006: // 所属地区
- let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
- if viewSelectCity == nil {
- viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
- viewSelectCity.modelType = 2
- viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
- self!.addressIds[0] = self!.getString(key: "addressId1", dic: dic)
- self!.addressIds[1] = self!.getString(key: "addressId2", dic: dic)
- self!.addressIds[2] = self!.getString(key: "addressId3", dic: dic)
- self!.addressNames[0] = self!.getString(key: "addressName1", dic: dic)
- self!.addressNames[1] = self!.getString(key: "addressName2", dic: dic)
- self!.addressNames[2] = self!.getString(key: "addressName3", dic: dic)
- self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
- self!.txtBankAddress.text = self!.getString(key: "address", dic: dic)
- }
- self.view.addSubview(viewSelectCity)
- }
- viewSelectCity.showPickerView()
- break
- case 1007: // 所属支行
- if addressIds[1] == "" {
- SVProgressHUD.showError(withStatus: "请先选择省市区")
- return
- }
- let vc = SelectBankViewController()
- var substr = ""
- if self.bankCardCityName.contains("市") {
- let arr = self.bankCardCityName.components(separatedBy: "市")
- substr = arr[0]
- }else {
- substr = self.bankCardCityName
- }
- namem = self.txtBank.text! + substr
- vc.bankName = namem //txtBank.text!;
- toViewController(viewController: vc)
- break
- default:
- break
- }
- }
- // MARK: =============加载数据===============
- func submitData() {
- let url = RequestURL.editUser
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue("1", forKey: "isAuthentication")
- params.setValue(txtName.text!, forKey: "realName")
- params.setValue(txtCard.text!, forKey: "cardNo")
- params.setValue(arrImages[0], forKey: "cardFront")
- params.setValue(arrImages[1], forKey: "cardReverse")
- params.setValue(arrImages[2], forKey: "cardHoldFront")
- params.setValue(arrImages[3], forKey: "cardHoldReverse")
- params.setValue(txtBankNo.text!, forKey: "cardNumber")
- params.setValue(txtBank.text!, forKey: "affiliatedBank")
- params.setValue(addressIds[0], forKey: "provinceId")
- params.setValue(addressIds[1], forKey: "cityId")
- params.setValue(addressIds[2], forKey: "areaId")
- params.setValue(addressNames[0], forKey: "provincecn")
- params.setValue(addressNames[1], forKey: "citycn")
- params.setValue(addressNames[2], forKey: "areacn")
- params.setValue(zhiHangName, forKey: "affiliatedBranchBank")
- params.setValue(zhiHangName, forKey: "affiliated_branch_bank")
- params.setValue(txtPhone.text!, forKey: "reservePhone")
- submitData(url: url, params: params, tag: 1001)
- }
- let dicJS = NSMutableDictionary()
- func loadJSData() {
- let url = RequestURL.mySettlementCard
- let params = NSMutableDictionary()
- loadDataInfo(url: url, params: params, tag: 1002, reDic: dicJS)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- appDelegate.reloadUserInfo()
- SVProgressHUD.showSuccess(withStatus: "实名认证信息提交成功,")
- handleBack()
- } else if tag == 1002 {
- let cardInfo = dicJS["cardInfo"] as? NSDictionary
- if cardInfo != nil {
- txtBankNo.text = cardInfo!.getString(key: "card_number")
- txtBank.text = cardInfo!.getString(key: "affiliated_bank")
- addressIds[0] = cardInfo!.getString(key: "provinceid")
- addressIds[1] = cardInfo!.getString(key: "cityid")
- addressIds[2] = cardInfo!.getString(key: "areaid")
- addressNames[0] = cardInfo!.getString(key: "provincecn")
- addressNames[1] = cardInfo!.getString(key: "citycn")
- addressNames[2] = cardInfo!.getString(key: "areacn")
- txtBankAddress.text = addressNames.joined(separator: "")
- zhiHangName = cardInfo!.getString(key: "affiliated_branch_bank")
- txtBankChild.text = zhiHangName
- txtPhone.text = cardInfo!.getString(key: "reserve_phone")
- if txtBankNo.text!.length() > 1 {
- appDelegate.reloadUserInfo()
- }
- }
- }
- }
- override func returnError(tag: Int, type: String) {
- if tag == 1002 {
- self.isAlertError = false
- }
- }
- override func handleBack() {
- self.navigationController?.popToRootViewController(animated: true)
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtName.resignFirstResponder()
- txtCard.resignFirstResponder()
- txtBankNo.resignFirstResponder()
- txtBank.resignFirstResponder()
- txtBankChild.resignFirstResponder()
- txtBankAddress.resignFirstResponder()
- txtPhone.resignFirstResponder()
- }
- // MARK: ============选择头像============
- var uploadImageType = 0
- func uploadImage(type: Int) {
- if self.isUpload {
- return
- }
- CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
- self!.isUpload = true
- self!.uploadImageType = type
- let ipc = UIImagePickerController()
- if index == 0 {
- ipc.sourceType = .camera
- } else {
- ipc.sourceType = .photoLibrary
- }
- ipc.delegate = self!
- ipc.allowsEditing = false
- self!.present(ipc, animated: true, completion: nil)
- }
- }
- var isUpload = false
- var imgTemp: UIImage!
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
- self.dismiss(animated: true) {[weak self] in
- var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
- if picker.allowsEditing {
- imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
- }
- if imgTemp != nil {
- self!.UploadFile(img: imgTemp!)
- } else {
- self!.isUpload = false
- SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
- }
- }
- }
- func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
- self.isUpload = false
- self.dismiss(animated: true) {
- }
- }
- func UploadFile(img: UIImage) {
- SVProgressHUD.show()
- let uploadFile = QiNiuUploadFile()
- uploadFile.uploadFile(img: img) {[weak self] (type, str) in
- if type == 1 {
- let userLoginUrl = RequestURL.qiNiuImageUrl + str
- self!.arrImages[self!.uploadImageType] = userLoginUrl
- if self!.uploadImageType == 0 {
- self!.uploadWeb(img: img)
- } else if self!.uploadImageType == 1 {
- self!.isUpload = false
- SVProgressHUD.dismiss()
- self!.btnMenu2.isSelected = true
- self!.img2.loadImage(imgUrl: userLoginUrl, defaultImage: "")
- } else if self!.uploadImageType == 2 {
- self!.isUpload = false
- SVProgressHUD.dismiss()
- self!.btnMenu3.isSelected = true
- self!.img3.loadImage(imgUrl: userLoginUrl, defaultImage: "")
- } else if self!.uploadImageType == 3 {
- self!.uploadWeb(img: img)
- }
- } else {
- self!.isUpload = false
- SVProgressHUD.showError(withStatus: "上传失败")
- }
- }
- }
- func uploadWeb(img: UIImage) {
- let manage = CommonValue.getHttp()
- let param = NSMutableDictionary()
- var url = RequestURL.uploadMerchantFile
- if self.uploadImageType == 0 {
- url = RequestURL.uploadMerchantFile
- param.setValue("2", forKey: "type")
- } else if self.uploadImageType == 3 {
- param.setValue("8", forKey: "type")
- }
- manage.requestSerializer.timeoutInterval = 60.0
- manage.post(url, parameters: param, constructingBodyWith: { (formDate) in
- formDate.appendPart(withFileData: img.jpegData(compressionQuality: 0.4)!, name: "fileInput", fileName: "fileInput", mimeType: "multipart/form-data")
- }, progress: nil, success: {[weak self] (op, json1) in
- SVProgressHUD.dismiss()
- self!.isUpload = false
- let json = json1 as! NSDictionary
- print(json)
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- if self!.uploadImageType == 0 {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- self!.img1.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
- self!.btnMenu1.isSelected = true
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- self!.txtName.text = hkResultData.getString(key: "name")
- self!.txtCard.text = hkResultData.getString(key: "idNumber")
- } else {
- SVProgressHUD.showError(withStatus: "身份证识别失败,请重新上传!")
- }
- } else if self!.uploadImageType == 3 {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- self!.txtBank.text = hkResultData.getString(key: "bankName")
- self!.txtBankNo.text = hkResultData.getString(key: "cardNumber")
- self!.btnMenu4.isSelected = true
- self!.img4.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
- } else {
- SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传!")
- }
- }
- } else {
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- //CommonUntils.alert(message: json.object(forKey: "sucInfo") as! String)
- }
- }) {[weak self] (_, _) in
- self!.isUpload = false
- SVProgressHUD.dismiss()
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- }
- }
- func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
- tempTextFeild = textField
- return true
- }
- func textFieldDidEndEditing(_ textField: UITextField) {
- if textField.tag == 1003 {
- let str = textField.text!
- if str.length() > 5 {
- loadBankName()
- }
- }
- }
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
- return true
- }
- func loadBankName() {
- var str8 = ""
- var str6 = ""
- if txtBankNo.text!.length() >= 8 {
- str8 = txtBankNo.text!.substringTo(index: 8)
- str6 = txtBankNo.text!.substringTo(index: 6)
- }
- if txtBankNo.text!.length() >= 6 {
- str6 = txtBankNo.text!.substringTo(index: 6)
- } else {
- txtBank.text = "未识别银行"
- return
- }
- if arrBank.count > 0 {
- var isFined = false
- for dic in arrBank {
- let bin = (dic as! NSDictionary).getString(key: "bin")
- if bin == str8 || bin == str6 {
- isFined = true
- txtBank.text = (dic as! NSDictionary).getString(key: "bankName").split(s: "-")[0]
- break
- }
- }
- if !isFined {
- txtBank.text = "未识别银行"
- }
- } else {
- txtBank.text = "未识别银行"
- }
- }
- var tempTextFeild: UITextField!
- override func keyboardWasShown(noti: NSNotification) {
- DispatchQueue.main.async { [weak self] in
- if self!.tempTextFeild == nil {
- return
- }
- let info = noti.userInfo
- let keyHe = (info![UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size.height
- //文本框距上的高度
- let viewTop = CommonViewUntils.getControlRectForScreen(view: self!.tempTextFeild).origin.y + self!.tempTextFeild.height()
- if viewTop + 64 > (ScreenHeight - keyHe) {
- self!.scrollView.marginTop(top: -(viewTop - (self!.viewHeight - keyHe)) - 64)
- }
- }
- }
- override func keyboardWasHidden(noti: NSNotification) {
- DispatchQueue.main.async { [weak self] in
- UIView.animate(withDuration: 0.3, animations: {
- self!.scrollView.marginTop(top: 0)
- })
- }
- }
- override func notiReloadUser(noti: NSNotification) {
- let dicUser = CommonValue.getLoginUserInfo()
- if dicUser != nil {
- var remark = dicUser!.getString(key: "remark")
- if remark != "" {
- txtErrorInfo.isHidden = false
- txtErrorInfo.text = "审核拒绝原因:\(remark)"
- txtErrorInfo.sizeToFit()
- txtErrorInfo.setSizeHeight(height: txtErrorInfo.height() + 10)
- scrollView.marginTop(top: 0, view: txtErrorInfo)
- scrollView.setSizeHeight(height: ScreenHeight - common_nav_status_height - common_bottom_height - (txtErrorInfo.height() + 10))
- }
- if dicUser!.getString(key: "cardFront") != "" {
- arrImages[0] = dicUser!.getString(key: "cardFront")
- arrImages[1] = dicUser!.getString(key: "cardReverse")
- arrImages[2] = dicUser!.getString(key: "cardHoldFront")
- arrImages[3] = dicUser!.getString(key: "cardHoldReverse")
- if arrImages[0].length() > 10 {
- btnMenu1.isSelected = true
- }
- if arrImages[1].length() > 10 {
- btnMenu2.isSelected = true
- }
- if arrImages[2].length() > 10 {
- btnMenu3.isSelected = true
- }
- if arrImages[3].length() > 10 {
- btnMenu4.isSelected = true
- }
- img1.loadImage(imgUrl: arrImages[0], defaultImage: "")
- img2.loadImage(imgUrl: arrImages[1], defaultImage: "")
- img3.loadImage(imgUrl: arrImages[2], defaultImage: "")
- img4.loadImage(imgUrl: arrImages[3], defaultImage: "")
- self.txtName.text = dicUser!.getString(key: "realName")
- self.txtCard.text = dicUser!.getString(key: "cardNo")
- }
- }
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if mainViewControllerIsGo {
- if mainViewControllerIsGoType == 0 {
- zhiHangId = mainViewControllerIsGoValue1
- zhiHangName = mainViewControllerIsGoValue
- txtBankChild.text = zhiHangName
- }
- }
- mainViewControllerIsGo = false
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "RealNameAuthViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|