ModBankCardViewController.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 ModBankCardViewController: BaseViewController, UITextFieldDelegate {
  10. @IBOutlet weak var txtType: UITextField!
  11. @IBOutlet weak var txtName: UITextField!
  12. @IBOutlet weak var txtBankChild: UITextField!
  13. @IBOutlet weak var txtBankAddress: UITextField!
  14. @IBOutlet weak var txtBank: UITextField!
  15. @IBOutlet weak var txtBankNo: UITextField!
  16. @IBOutlet weak var txtPhone: UITextField!
  17. @IBOutlet weak var btnFinish: UIButton!
  18. @IBOutlet weak var viewContent2: UIView!
  19. @IBOutlet weak var scrollView: UIScrollView!
  20. var addressIds = ["", "", ""]
  21. var addressNames = ["", "", ""]
  22. var zhiHangId = ""
  23. var zhiHangName = ""
  24. var bankCardCityName = ""
  25. var namem = ""
  26. var type = 0
  27. var arrBank = NSMutableArray()
  28. override func viewDidLoad() {
  29. super.viewDidLoad()
  30. self.title = "修改结算卡"
  31. initNavLeftBackButton()
  32. scrollView.setSizeWidth(width: ScreenWidth)
  33. // Do any additional setup after loading the view.
  34. scrollView.contentSize.height = btnFinish.bottom() + 80
  35. txtBank.delegate = self
  36. txtBankNo.delegate = self
  37. txtPhone.delegate = self
  38. scrollView.keyboardDismissMode = .onDrag
  39. let jsonPath = Bundle.main.path(forResource: "bankData", ofType: "json")
  40. do {
  41. let arrTemp = try CommonJSON.jsonToArray(json: String(contentsOfFile: jsonPath!))
  42. if arrTemp != nil {
  43. arrBank.setArray(arrTemp! as! [Any])
  44. }
  45. print(arrBank.count)
  46. } catch {}
  47. txtName.text = CommonValue.getUserRealName()
  48. }
  49. func initData() {
  50. let dicTemp = dicData["cardInfo"] as! NSDictionary
  51. txtBankAddress.text = "\(dicTemp.getString(key: "provincecn")) \(dicTemp.getString(key: "citycn")) \(dicTemp.getString(key: "areacn"))"
  52. txtBankNo.text = dicTemp.getString(key: "card_number")
  53. txtBankChild.text = dicTemp.getString(key: "affiliated_branch_bank")
  54. txtBank.text = dicTemp.getString(key: "affiliated_bank")
  55. txtPhone.text = dicTemp.getString(key: "reserve_phone")
  56. addressIds[0] = dicTemp.getString(key: "provinceid")
  57. addressIds[1] = dicTemp.getString(key: "cityid")
  58. addressIds[2] = dicTemp.getString(key: "areaid")
  59. zhiHangName = dicTemp.getString(key: "affiliated_branch_bank")
  60. addressNames[0] = dicTemp.getString(key: "provincecn")
  61. addressNames[1] = dicTemp.getString(key: "citycn")
  62. addressNames[2] = dicTemp.getString(key: "areacn")
  63. txtName.text = dicTemp.getString(key: "bank_account_name")
  64. self.bankCardCityName = dicTemp.getString(key: "citycn")
  65. type = dicTemp.getInt(key: "type")
  66. if type == 0 {
  67. txtName.isEnabled = false
  68. }
  69. }
  70. var viewSelectCity: Virgil_SelectCity!
  71. @IBAction func btnMenuClick(_ sender: AnyObject) {
  72. KeyboardHidden(gestureRecognizer: UIGestureRecognizer())
  73. switch (sender as! UIButton).tag {
  74. case 1001: // 身份证正面
  75. break
  76. case 1002: // 身份证背面
  77. break
  78. case 1003: // 手持身份证证件照
  79. break
  80. case 1004: // 辅助证明材料
  81. break
  82. case 1005: // 完成
  83. if txtName.text!.length() < 1 {
  84. SVProgressHUD.showError(withStatus: "请输入开户名")
  85. return
  86. }
  87. if txtBankNo.text!.length() < 1 {
  88. SVProgressHUD.showError(withStatus: "请输入银行卡号")
  89. return
  90. }
  91. // if(txtBank.text!.length() < 1 || txtBank.text! == "未识别银行")
  92. // {
  93. // SVProgressHUD.showError(withStatus: "请正确输入银行卡号");
  94. // return;
  95. // }
  96. if addressIds[1] == "" {
  97. SVProgressHUD.showError(withStatus: "请选择银行所在地区")
  98. return
  99. }
  100. if zhiHangName == "" {
  101. SVProgressHUD.showError(withStatus: "请选择所属支行")
  102. return
  103. }
  104. if txtPhone.text!.length() < 1 && type == 0 {
  105. SVProgressHUD.showError(withStatus: "请输入预留手机号")
  106. return
  107. }
  108. submitData()
  109. break
  110. case 1006: // 所属地区
  111. let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
  112. if viewSelectCity == nil {
  113. viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
  114. viewSelectCity.modelType = 2
  115. viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
  116. self!.addressIds[0] = self!.getString(key: "addressId1", dic: dic)
  117. self!.addressIds[1] = self!.getString(key: "addressId2", dic: dic)
  118. self!.addressIds[2] = self!.getString(key: "addressId3", dic: dic)
  119. self!.addressNames[0] = self!.getString(key: "addressName1", dic: dic)
  120. self!.addressNames[1] = self!.getString(key: "addressName2", dic: dic)
  121. self!.addressNames[2] = self!.getString(key: "addressName3", dic: dic)
  122. self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
  123. self!.txtBankAddress.text = self!.getString(key: "address", dic: dic)
  124. }
  125. self.view.addSubview(viewSelectCity)
  126. }
  127. viewSelectCity.showPickerView()
  128. break
  129. case 1007: // 所属支行
  130. if addressIds[1] == "" {
  131. SVProgressHUD.showError(withStatus: "请先选择省市区")
  132. return
  133. }
  134. let vc = SelectBankViewController()
  135. vc.provinceId = addressIds[0]
  136. vc.cityId = addressIds[1]
  137. var substr = ""
  138. if self.bankCardCityName.contains("市") {
  139. let arr = self.bankCardCityName.components(separatedBy: "市")
  140. substr = arr[0]
  141. }else {
  142. substr = self.bankCardCityName
  143. }
  144. namem = self.txtBank.text! + substr
  145. vc.bankName = namem //txtBank.text!;
  146. toViewController(viewController: vc)
  147. break
  148. case 1008: // 账户类型
  149. CommonUntils.AlertView(controller: self, title: nil, message: "请选择账户类型", buttons: ["个人账户", "对公账户"], style: .actionSheet) {[weak self] (index, _) in
  150. self!.type = index
  151. self!.txtType.text = ["个人账户", "对公账户"][index]
  152. if index == 1 {
  153. self!.viewContent2.setSizeHeight(height: 211)
  154. self!.txtName.isEnabled = true
  155. self!.txtName.text = ""
  156. } else {
  157. self!.txtName.isEnabled = false
  158. self!.txtName.text = CommonValue.getUserRealName()
  159. self!.viewContent2.setSizeHeight(height: 265)
  160. }
  161. }
  162. break
  163. default:
  164. break
  165. }
  166. }
  167. // MARK: =============加载数据===============
  168. func submitData() {
  169. let url = RequestURL.settlementCardUpdate
  170. let params = NSMutableDictionary()
  171. let dicTemp = dicData["cardInfo"] as? NSDictionary
  172. if dicTemp != nil {
  173. params.setValue(dicTemp!.getString(key: "id"), forKey: "id")
  174. }
  175. params.setValue(txtBankNo.text!, forKey: "cardNumber")
  176. params.setValue(txtBank.text!, forKey: "affiliatedBank")
  177. params.setValue(addressIds[0], forKey: "provinceId")
  178. params.setValue(addressIds[1], forKey: "cityId")
  179. params.setValue(addressIds[2], forKey: "areaId")
  180. params.setValue(addressNames[0], forKey: "provincecn")
  181. params.setValue(addressNames[1], forKey: "citycn")
  182. params.setValue(addressNames[2], forKey: "areacn")
  183. params.setValue(zhiHangName, forKey: "affiliatedBranchBank")
  184. params.setValue(txtPhone.text!, forKey: "reservePhone")
  185. params.setValue(type, forKey: "type")
  186. params.setValue(txtName.text!, forKey: "bankAccountName")
  187. submitData(url: url, params: params, tag: 1001)
  188. }
  189. func loadData() {
  190. let url = RequestURL.mySettlementCard
  191. let params = NSMutableDictionary()
  192. loadDataInfo(url: url, params: params, tag: 1002)
  193. }
  194. override func returnData(tag: Int) {
  195. if tag == 1001 {
  196. appDelegate.reloadUserInfo()
  197. SVProgressHUD.showSuccess(withStatus: "修改成功")
  198. handleBack()
  199. } else if tag == 1002 {
  200. if dicData["cardInfo"] as? NSDictionary != nil {
  201. initData()
  202. }
  203. }
  204. }
  205. override func returnError(tag: Int, type: String) {
  206. }
  207. override func handleBack() {
  208. self.navigationController?.popViewController(animated: true)
  209. }
  210. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  211. txtBankNo.resignFirstResponder()
  212. txtBank.resignFirstResponder()
  213. txtBankChild.resignFirstResponder()
  214. txtBankAddress.resignFirstResponder()
  215. txtPhone.resignFirstResponder()
  216. txtName.resignFirstResponder()
  217. }
  218. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  219. tempTextFeild = textField
  220. return true
  221. }
  222. func textFieldDidEndEditing(_ textField: UITextField) {
  223. if textField.tag == 1003 {
  224. let str = textField.text!
  225. if str.length() > 5 {
  226. loadBankName()
  227. }
  228. }
  229. }
  230. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  231. return true
  232. }
  233. func loadBankName() {
  234. var str8 = ""
  235. var str6 = ""
  236. if txtBankNo.text!.length() >= 8 {
  237. str8 = txtBankNo.text!.substringTo(index: 8)
  238. str6 = txtBankNo.text!.substringTo(index: 6)
  239. }
  240. if txtBankNo.text!.length() >= 6 {
  241. str6 = txtBankNo.text!.substringTo(index: 6)
  242. } else {
  243. txtBank.text = "未识别银行"
  244. return
  245. }
  246. if arrBank.count > 0 {
  247. var isFined = false
  248. for dic in arrBank {
  249. let bin = (dic as! NSDictionary).getString(key: "bin")
  250. if bin == str8 || bin == str6 {
  251. isFined = true
  252. txtBank.text = (dic as! NSDictionary).getString(key: "bankName").split(s: "-")[0]
  253. break
  254. }
  255. }
  256. if !isFined {
  257. txtBank.text = "未识别银行"
  258. }
  259. } else {
  260. txtBank.text = "未识别银行"
  261. }
  262. }
  263. var tempTextFeild: UITextField!
  264. override func keyboardWasShown(noti: NSNotification) {
  265. DispatchQueue.main.async { [weak self] in
  266. if self!.tempTextFeild == nil {
  267. return
  268. }
  269. let info = noti.userInfo
  270. let keyHe = (info![UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size.height
  271. //文本框距上的高度
  272. let viewTop = CommonViewUntils.getControlRectForScreen(view: self!.tempTextFeild).origin.y + self!.tempTextFeild.height()
  273. if viewTop + 64 > (ScreenHeight - keyHe) {
  274. self!.scrollView.marginTop(top: -(viewTop - (self!.viewHeight - keyHe)) - 64)
  275. }
  276. }
  277. }
  278. override func keyboardWasHidden(noti: NSNotification) {
  279. DispatchQueue.main.async { [weak self] in
  280. UIView.animate(withDuration: 0.3, animations: {
  281. self!.scrollView.marginTop(top: 0)
  282. })
  283. }
  284. }
  285. override func viewWillAppear(_ animated: Bool) {
  286. super.viewWillAppear(animated)
  287. if mainViewControllerIsGo {
  288. if mainViewControllerIsGoType == 0 {
  289. zhiHangId = mainViewControllerIsGoValue1
  290. zhiHangName = mainViewControllerIsGoValue
  291. txtBankChild.text = zhiHangName
  292. }
  293. }
  294. mainViewControllerIsGo = false
  295. if !isLoad {
  296. loadData()
  297. isLoad = true
  298. }
  299. }
  300. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  301. super.init(nibName: "ModBankCardViewController", bundle: nil)
  302. }
  303. required init?(coder aDecoder: NSCoder) {
  304. fatalError("init(coder:) has not been implemented")
  305. }
  306. }