RealNameAuthViewController.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. //
  2. // ApplyerViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/28.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class RealNameAuthViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
  10. @IBOutlet weak var btnMenu1: UIButton!
  11. @IBOutlet weak var btnMenu2: UIButton!
  12. @IBOutlet weak var btnMenu3: UIButton!
  13. @IBOutlet weak var btnMenu4: UIButton!
  14. @IBOutlet weak var viewMenu1: UIView!
  15. @IBOutlet weak var viewMenu2: UIView!
  16. @IBOutlet weak var viewMenu3: UIView!
  17. @IBOutlet weak var viewMenu4: UIView!
  18. @IBOutlet weak var img1: UIImageView!
  19. @IBOutlet weak var img2: UIImageView!
  20. @IBOutlet weak var img3: UIImageView!
  21. @IBOutlet weak var img4: UIImageView!
  22. @IBOutlet weak var viewContent: UIView!
  23. @IBOutlet weak var txtBankChild: UITextField!
  24. @IBOutlet weak var txtBankAddress: UITextField!
  25. @IBOutlet weak var txtBank: UITextField!
  26. @IBOutlet weak var txtBankNo: UITextField!
  27. @IBOutlet weak var txtPhone: UITextField!
  28. @IBOutlet weak var txtCard: UITextField!
  29. @IBOutlet weak var btnFinish: UIButton!
  30. @IBOutlet weak var txtName: UITextField!
  31. @IBOutlet weak var txtErrorInfo: UITextView!
  32. @IBOutlet weak var viewContent2: UIView!
  33. @IBOutlet weak var scrollView: UIScrollView!
  34. var arrImages = ["", "", "", ""]
  35. var addressIds = ["", "", ""]
  36. var addressNames = ["", "", ""]
  37. var zhiHangId = ""
  38. var zhiHangName = ""
  39. var arrBank = NSMutableArray()
  40. var bankCardCityName = ""
  41. var namem = ""
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. self.title = "实名认证"
  45. initNavLeftBackButton()
  46. scrollView.setSizeWidth(width: ScreenWidth)
  47. CommonViewUntils.setViewAverage(arrView: [viewMenu1, viewMenu2])
  48. CommonViewUntils.setViewAverage(arrView: [viewMenu3, viewMenu4])
  49. // Do any additional setup after loading the view.
  50. scrollView.contentSize.height = btnFinish.bottom() + 80
  51. txtName.delegate = self
  52. txtCard.delegate = self
  53. txtBank.delegate = self
  54. txtBankNo.delegate = self
  55. txtPhone.delegate = self
  56. scrollView.keyboardDismissMode = .onDrag
  57. let jsonPath = Bundle.main.path(forResource: "bankData", ofType: "json")
  58. do {
  59. let arrTemp = try CommonJSON.jsonToArray(json: String(contentsOfFile: jsonPath!))
  60. if arrTemp != nil {
  61. arrBank.setArray(arrTemp! as! [Any])
  62. }
  63. print(arrBank.count)
  64. } catch {}
  65. loadJSData()
  66. scrollView.setSizeHeight(height: ScreenHeight - common_nav_status_height - common_bottom_height)
  67. }
  68. var viewSelectCity: Virgil_SelectCity!
  69. //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
  70. @IBAction func btnMenuClick(_ sender: AnyObject) {
  71. KeyboardHidden(gestureRecognizer: UIGestureRecognizer())
  72. switch (sender as! UIButton).tag {
  73. case 1001: // 身份证正面
  74. uploadImage(type: 0)
  75. break
  76. case 1002: // 身份证背面
  77. uploadImage(type: 1)
  78. break
  79. case 1003: // 手持身份证证件照
  80. uploadImage(type: 2)
  81. break
  82. case 1004: // 辅助证明材料
  83. uploadImage(type: 3)
  84. break
  85. case 1005: // 完成
  86. if !btnMenu1.isSelected {
  87. SVProgressHUD.showError(withStatus: "请上传身份证正面")
  88. return
  89. }
  90. if !btnMenu2.isSelected {
  91. SVProgressHUD.showError(withStatus: "请上传身份证背面")
  92. return
  93. }
  94. if !btnMenu3.isSelected {
  95. SVProgressHUD.showError(withStatus: "请上传手持身份证照")
  96. return
  97. }
  98. if !btnMenu4.isSelected {
  99. SVProgressHUD.showError(withStatus: "请上传银行卡正面照")
  100. return
  101. }
  102. if txtName.text!.length() < 1 {
  103. SVProgressHUD.showError(withStatus: "请输入姓名")
  104. return
  105. }
  106. if txtCard.text!.length() < 1 {
  107. SVProgressHUD.showError(withStatus: "请输入身份证号")
  108. return
  109. }
  110. if txtBankNo.text!.length() < 1 {
  111. SVProgressHUD.showError(withStatus: "请输入银行卡号")
  112. return
  113. }
  114. if addressIds[1] == "" {
  115. SVProgressHUD.showError(withStatus: "请选择银行所在地区")
  116. return
  117. }
  118. if zhiHangName == "" {
  119. SVProgressHUD.showError(withStatus: "请选择所属支行")
  120. return
  121. }
  122. if txtPhone.text!.length() < 1 {
  123. SVProgressHUD.showError(withStatus: "请输入预留手机号")
  124. return
  125. }
  126. submitData()
  127. break
  128. case 1006: // 所属地区
  129. let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
  130. if viewSelectCity == nil {
  131. viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
  132. viewSelectCity.modelType = 2
  133. viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
  134. self!.addressIds[0] = self!.getString(key: "addressId1", dic: dic)
  135. self!.addressIds[1] = self!.getString(key: "addressId2", dic: dic)
  136. self!.addressIds[2] = self!.getString(key: "addressId3", dic: dic)
  137. self!.addressNames[0] = self!.getString(key: "addressName1", dic: dic)
  138. self!.addressNames[1] = self!.getString(key: "addressName2", dic: dic)
  139. self!.addressNames[2] = self!.getString(key: "addressName3", dic: dic)
  140. self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
  141. self!.txtBankAddress.text = self!.getString(key: "address", dic: dic)
  142. }
  143. self.view.addSubview(viewSelectCity)
  144. }
  145. viewSelectCity.showPickerView()
  146. break
  147. case 1007: // 所属支行
  148. if addressIds[1] == "" {
  149. SVProgressHUD.showError(withStatus: "请先选择省市区")
  150. return
  151. }
  152. let vc = SelectBankViewController()
  153. var substr = ""
  154. if self.bankCardCityName.contains("市") {
  155. let arr = self.bankCardCityName.components(separatedBy: "市")
  156. substr = arr[0]
  157. }else {
  158. substr = self.bankCardCityName
  159. }
  160. namem = self.txtBank.text! + substr
  161. vc.bankName = namem //txtBank.text!;
  162. toViewController(viewController: vc)
  163. break
  164. default:
  165. break
  166. }
  167. }
  168. // MARK: =============加载数据===============
  169. func submitData() {
  170. let url = RequestURL.editUser
  171. let params = NSMutableDictionary()
  172. params.setValue(CommonValue.getUserId(), forKey: "userId")
  173. params.setValue("1", forKey: "isAuthentication")
  174. params.setValue(txtName.text!, forKey: "realName")
  175. params.setValue(txtCard.text!, forKey: "cardNo")
  176. params.setValue(arrImages[0], forKey: "cardFront")
  177. params.setValue(arrImages[1], forKey: "cardReverse")
  178. params.setValue(arrImages[2], forKey: "cardHoldFront")
  179. params.setValue(arrImages[3], forKey: "cardHoldReverse")
  180. params.setValue(txtBankNo.text!, forKey: "cardNumber")
  181. params.setValue(txtBank.text!, forKey: "affiliatedBank")
  182. params.setValue(addressIds[0], forKey: "provinceId")
  183. params.setValue(addressIds[1], forKey: "cityId")
  184. params.setValue(addressIds[2], forKey: "areaId")
  185. params.setValue(addressNames[0], forKey: "provincecn")
  186. params.setValue(addressNames[1], forKey: "citycn")
  187. params.setValue(addressNames[2], forKey: "areacn")
  188. params.setValue(zhiHangName, forKey: "affiliatedBranchBank")
  189. params.setValue(zhiHangName, forKey: "affiliated_branch_bank")
  190. params.setValue(txtPhone.text!, forKey: "reservePhone")
  191. submitData(url: url, params: params, tag: 1001)
  192. }
  193. let dicJS = NSMutableDictionary()
  194. func loadJSData() {
  195. let url = RequestURL.mySettlementCard
  196. let params = NSMutableDictionary()
  197. loadDataInfo(url: url, params: params, tag: 1002, reDic: dicJS)
  198. }
  199. override func returnData(tag: Int) {
  200. if tag == 1001 {
  201. appDelegate.reloadUserInfo()
  202. SVProgressHUD.showSuccess(withStatus: "实名认证信息提交成功,")
  203. handleBack()
  204. } else if tag == 1002 {
  205. let cardInfo = dicJS["cardInfo"] as? NSDictionary
  206. if cardInfo != nil {
  207. txtBankNo.text = cardInfo!.getString(key: "card_number")
  208. txtBank.text = cardInfo!.getString(key: "affiliated_bank")
  209. addressIds[0] = cardInfo!.getString(key: "provinceid")
  210. addressIds[1] = cardInfo!.getString(key: "cityid")
  211. addressIds[2] = cardInfo!.getString(key: "areaid")
  212. addressNames[0] = cardInfo!.getString(key: "provincecn")
  213. addressNames[1] = cardInfo!.getString(key: "citycn")
  214. addressNames[2] = cardInfo!.getString(key: "areacn")
  215. txtBankAddress.text = addressNames.joined(separator: "")
  216. zhiHangName = cardInfo!.getString(key: "affiliated_branch_bank")
  217. txtBankChild.text = zhiHangName
  218. txtPhone.text = cardInfo!.getString(key: "reserve_phone")
  219. if txtBankNo.text!.length() > 1 {
  220. appDelegate.reloadUserInfo()
  221. }
  222. }
  223. }
  224. }
  225. override func returnError(tag: Int, type: String) {
  226. if tag == 1002 {
  227. self.isAlertError = false
  228. }
  229. }
  230. override func handleBack() {
  231. self.navigationController?.popToRootViewController(animated: true)
  232. }
  233. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  234. txtName.resignFirstResponder()
  235. txtCard.resignFirstResponder()
  236. txtBankNo.resignFirstResponder()
  237. txtBank.resignFirstResponder()
  238. txtBankChild.resignFirstResponder()
  239. txtBankAddress.resignFirstResponder()
  240. txtPhone.resignFirstResponder()
  241. }
  242. // MARK: ============选择头像============
  243. var uploadImageType = 0
  244. func uploadImage(type: Int) {
  245. if self.isUpload {
  246. return
  247. }
  248. CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
  249. self!.isUpload = true
  250. self!.uploadImageType = type
  251. let ipc = UIImagePickerController()
  252. if index == 0 {
  253. ipc.sourceType = .camera
  254. } else {
  255. ipc.sourceType = .photoLibrary
  256. }
  257. ipc.delegate = self!
  258. ipc.allowsEditing = false
  259. self!.present(ipc, animated: true, completion: nil)
  260. }
  261. }
  262. var isUpload = false
  263. var imgTemp: UIImage!
  264. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  265. self.dismiss(animated: true) {[weak self] in
  266. var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
  267. if picker.allowsEditing {
  268. imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
  269. }
  270. if imgTemp != nil {
  271. self!.UploadFile(img: imgTemp!)
  272. } else {
  273. self!.isUpload = false
  274. SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
  275. }
  276. }
  277. }
  278. func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
  279. self.isUpload = false
  280. self.dismiss(animated: true) {
  281. }
  282. }
  283. func UploadFile(img: UIImage) {
  284. SVProgressHUD.show()
  285. let uploadFile = QiNiuUploadFile()
  286. uploadFile.uploadFile(img: img) {[weak self] (type, str) in
  287. if type == 1 {
  288. let userLoginUrl = RequestURL.qiNiuImageUrl + str
  289. self!.arrImages[self!.uploadImageType] = userLoginUrl
  290. if self!.uploadImageType == 0 {
  291. self!.uploadWeb(img: img)
  292. } else if self!.uploadImageType == 1 {
  293. self!.isUpload = false
  294. SVProgressHUD.dismiss()
  295. self!.btnMenu2.isSelected = true
  296. self!.img2.loadImage(imgUrl: userLoginUrl, defaultImage: "")
  297. } else if self!.uploadImageType == 2 {
  298. self!.isUpload = false
  299. SVProgressHUD.dismiss()
  300. self!.btnMenu3.isSelected = true
  301. self!.img3.loadImage(imgUrl: userLoginUrl, defaultImage: "")
  302. } else if self!.uploadImageType == 3 {
  303. self!.uploadWeb(img: img)
  304. }
  305. } else {
  306. self!.isUpload = false
  307. SVProgressHUD.showError(withStatus: "上传失败")
  308. }
  309. }
  310. }
  311. func uploadWeb(img: UIImage) {
  312. let manage = CommonValue.getHttp()
  313. let param = NSMutableDictionary()
  314. var url = RequestURL.uploadMerchantFile
  315. if self.uploadImageType == 0 {
  316. url = RequestURL.uploadMerchantFile
  317. param.setValue("2", forKey: "type")
  318. } else if self.uploadImageType == 3 {
  319. param.setValue("8", forKey: "type")
  320. }
  321. manage.requestSerializer.timeoutInterval = 60.0
  322. manage.post(url, parameters: param, constructingBodyWith: { (formDate) in
  323. formDate.appendPart(withFileData: img.jpegData(compressionQuality: 0.4)!, name: "fileInput", fileName: "fileInput", mimeType: "multipart/form-data")
  324. }, progress: nil, success: {[weak self] (op, json1) in
  325. SVProgressHUD.dismiss()
  326. self!.isUpload = false
  327. let json = json1 as! NSDictionary
  328. print(json)
  329. let succeed = json.object(forKey: "succeed") as! String
  330. if succeed == "000" {
  331. if self!.uploadImageType == 0 {
  332. let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
  333. if status == 200 {
  334. self!.img1.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
  335. self!.btnMenu1.isSelected = true
  336. let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
  337. let hkResult = haike["result"] as! NSDictionary
  338. let hkResultData = hkResult["data"] as! NSDictionary
  339. self!.txtName.text = hkResultData.getString(key: "name")
  340. self!.txtCard.text = hkResultData.getString(key: "idNumber")
  341. } else {
  342. SVProgressHUD.showError(withStatus: "身份证识别失败,请重新上传!")
  343. }
  344. } else if self!.uploadImageType == 3 {
  345. let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
  346. if status == 200 {
  347. let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
  348. let hkResult = haike["result"] as! NSDictionary
  349. let hkResultData = hkResult["data"] as! NSDictionary
  350. self!.txtBank.text = hkResultData.getString(key: "bankName")
  351. self!.txtBankNo.text = hkResultData.getString(key: "cardNumber")
  352. self!.btnMenu4.isSelected = true
  353. self!.img4.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
  354. } else {
  355. SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传!")
  356. }
  357. }
  358. } else {
  359. SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
  360. //CommonUntils.alert(message: json.object(forKey: "sucInfo") as! String)
  361. }
  362. }) {[weak self] (_, _) in
  363. self!.isUpload = false
  364. SVProgressHUD.dismiss()
  365. SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
  366. }
  367. }
  368. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  369. tempTextFeild = textField
  370. return true
  371. }
  372. func textFieldDidEndEditing(_ textField: UITextField) {
  373. if textField.tag == 1003 {
  374. let str = textField.text!
  375. if str.length() > 5 {
  376. loadBankName()
  377. }
  378. }
  379. }
  380. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  381. return true
  382. }
  383. func loadBankName() {
  384. var str8 = ""
  385. var str6 = ""
  386. if txtBankNo.text!.length() >= 8 {
  387. str8 = txtBankNo.text!.substringTo(index: 8)
  388. str6 = txtBankNo.text!.substringTo(index: 6)
  389. }
  390. if txtBankNo.text!.length() >= 6 {
  391. str6 = txtBankNo.text!.substringTo(index: 6)
  392. } else {
  393. txtBank.text = "未识别银行"
  394. return
  395. }
  396. if arrBank.count > 0 {
  397. var isFined = false
  398. for dic in arrBank {
  399. let bin = (dic as! NSDictionary).getString(key: "bin")
  400. if bin == str8 || bin == str6 {
  401. isFined = true
  402. txtBank.text = (dic as! NSDictionary).getString(key: "bankName").split(s: "-")[0]
  403. break
  404. }
  405. }
  406. if !isFined {
  407. txtBank.text = "未识别银行"
  408. }
  409. } else {
  410. txtBank.text = "未识别银行"
  411. }
  412. }
  413. var tempTextFeild: UITextField!
  414. override func keyboardWasShown(noti: NSNotification) {
  415. DispatchQueue.main.async { [weak self] in
  416. if self!.tempTextFeild == nil {
  417. return
  418. }
  419. let info = noti.userInfo
  420. let keyHe = (info![UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size.height
  421. //文本框距上的高度
  422. let viewTop = CommonViewUntils.getControlRectForScreen(view: self!.tempTextFeild).origin.y + self!.tempTextFeild.height()
  423. if viewTop + 64 > (ScreenHeight - keyHe) {
  424. self!.scrollView.marginTop(top: -(viewTop - (self!.viewHeight - keyHe)) - 64)
  425. }
  426. }
  427. }
  428. override func keyboardWasHidden(noti: NSNotification) {
  429. DispatchQueue.main.async { [weak self] in
  430. UIView.animate(withDuration: 0.3, animations: {
  431. self!.scrollView.marginTop(top: 0)
  432. })
  433. }
  434. }
  435. override func notiReloadUser(noti: NSNotification) {
  436. let dicUser = CommonValue.getLoginUserInfo()
  437. if dicUser != nil {
  438. var remark = dicUser!.getString(key: "remark")
  439. if remark != "" {
  440. txtErrorInfo.isHidden = false
  441. txtErrorInfo.text = "审核拒绝原因:\(remark)"
  442. txtErrorInfo.sizeToFit()
  443. txtErrorInfo.setSizeHeight(height: txtErrorInfo.height() + 10)
  444. scrollView.marginTop(top: 0, view: txtErrorInfo)
  445. scrollView.setSizeHeight(height: ScreenHeight - common_nav_status_height - common_bottom_height - (txtErrorInfo.height() + 10))
  446. }
  447. if dicUser!.getString(key: "cardFront") != "" {
  448. arrImages[0] = dicUser!.getString(key: "cardFront")
  449. arrImages[1] = dicUser!.getString(key: "cardReverse")
  450. arrImages[2] = dicUser!.getString(key: "cardHoldFront")
  451. arrImages[3] = dicUser!.getString(key: "cardHoldReverse")
  452. if arrImages[0].length() > 10 {
  453. btnMenu1.isSelected = true
  454. }
  455. if arrImages[1].length() > 10 {
  456. btnMenu2.isSelected = true
  457. }
  458. if arrImages[2].length() > 10 {
  459. btnMenu3.isSelected = true
  460. }
  461. if arrImages[3].length() > 10 {
  462. btnMenu4.isSelected = true
  463. }
  464. img1.loadImage(imgUrl: arrImages[0], defaultImage: "")
  465. img2.loadImage(imgUrl: arrImages[1], defaultImage: "")
  466. img3.loadImage(imgUrl: arrImages[2], defaultImage: "")
  467. img4.loadImage(imgUrl: arrImages[3], defaultImage: "")
  468. self.txtName.text = dicUser!.getString(key: "realName")
  469. self.txtCard.text = dicUser!.getString(key: "cardNo")
  470. }
  471. }
  472. }
  473. override func viewWillAppear(_ animated: Bool) {
  474. super.viewWillAppear(animated)
  475. if mainViewControllerIsGo {
  476. if mainViewControllerIsGoType == 0 {
  477. zhiHangId = mainViewControllerIsGoValue1
  478. zhiHangName = mainViewControllerIsGoValue
  479. txtBankChild.text = zhiHangName
  480. }
  481. }
  482. mainViewControllerIsGo = false
  483. }
  484. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  485. super.init(nibName: "RealNameAuthViewController", bundle: nil)
  486. }
  487. required init?(coder aDecoder: NSCoder) {
  488. fatalError("init(coder:) has not been implemented")
  489. }
  490. }