BalanceAccountViewController.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. //
  2. // BalanceAccountViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/29.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class BalanceAccountViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
  10. var shopOpen: ShopOpenEntity!
  11. @IBOutlet weak var viewType2: UIView!
  12. @IBOutlet weak var viewType1: UIView!
  13. @IBOutlet weak var txtPhone: UITextField!
  14. ///0:对私账户 1:对公账户
  15. var accountType = 0
  16. @IBOutlet weak var lblAccountTitle: UILabel!
  17. @IBOutlet weak var img1: UIImageView!
  18. @IBOutlet weak var txtBankChild: UITextField!
  19. @IBOutlet weak var txtBankAddress: UITextField!
  20. @IBOutlet weak var txtBank: UITextField!
  21. @IBOutlet weak var txtBankNo: UITextField!
  22. // @IBOutlet weak var txtPhone: UITextField!
  23. // @IBOutlet weak var txtCard: UITextField!
  24. @IBOutlet weak var btnAccountType: UIButton!
  25. @IBOutlet weak var lblAccountType: UITextField!
  26. @IBOutlet weak var lblCardTitle: UILabel!
  27. @IBOutlet weak var scrollView: UIScrollView!
  28. @IBOutlet weak var btnFinish: UIButton!
  29. @IBOutlet weak var viewContent: UIView!
  30. @IBOutlet weak var txtName: UITextField!
  31. var addressIds = ["", "", ""]
  32. var addressNames = ["", "", ""]
  33. var imgUrl1 = ""
  34. var zhiHangId = ""
  35. var yinhangId = ""
  36. var zhiHangName = ""
  37. var bankCardCityName = ""
  38. var namem = ""
  39. var arrBank = NSMutableArray()
  40. override func viewDidLoad() {
  41. super.viewDidLoad()
  42. self.title = "结算账户信息"
  43. initNavLeftBackButton()
  44. txtName.delegate = self
  45. txtBank.delegate = self
  46. txtBankNo.delegate = self
  47. loadDefaultData()
  48. let jsonPath = Bundle.main.path(forResource: "bankData", ofType: "json")
  49. do {
  50. let arrTemp = try CommonJSON.jsonToArray(json: String(contentsOfFile: jsonPath!))
  51. if arrTemp != nil {
  52. arrBank.setArray(arrTemp! as! [Any])
  53. }
  54. print(arrBank.count)
  55. } catch {}
  56. txtPhone.delegate = self
  57. txtPhone.tag = 9009
  58. // Do any additional setup after loading the view.
  59. }
  60. func loadDefaultData() {
  61. imgUrl1 = shopOpen.bankCardImage
  62. addressIds[0] = shopOpen.bankAddressId1
  63. addressIds[1] = shopOpen.bankAddressId2
  64. addressIds[2] = shopOpen.bankAddressId3
  65. addressNames[0] = shopOpen.bankAddressName1
  66. addressNames[1] = shopOpen.bankAddressName2
  67. addressNames[2] = shopOpen.bankAddressName3
  68. if shopOpen.bankOpenName != "" {
  69. txtName.text = shopOpen.bankOpenName
  70. } else if shopOpen.name != "" {
  71. txtName.text = shopOpen.name
  72. }
  73. txtBankNo.text = shopOpen.bankCardNo
  74. txtBank.text = shopOpen.bankName
  75. txtBankAddress.text = addressNames.joined(separator: " ")// shopOpen.bankAddress
  76. txtBankChild.text = shopOpen.bankAffiliatedBranchBankCN
  77. txtPhone.text = shopOpen.reservePhone
  78. zhiHangId = shopOpen.bankAffiliatedBranchBank
  79. zhiHangName = shopOpen.bankAffiliatedBranchBankCN
  80. imgLocalPath = shopOpen.bankCardImgLocal
  81. yinhangId = shopOpen.bankAffiliatedBank
  82. accountType = 0
  83. reSetView()
  84. if shopOpen.bankCardImage != "" {
  85. img1.loadImage(imgUrl: shopOpen.bankCardImage, defaultImage: "")
  86. }
  87. // if(shopOpen.bankAccountType == "0")
  88. // {
  89. // accountType = 0
  90. // reSetView();
  91. // if(shopOpen.bankCardImage != "")
  92. // {
  93. // img1.loadImage(imgUrl: shopOpen.bankCardImage, defaultImage: "")
  94. // }
  95. // }
  96. // else if(shopOpen.bankAccountType == "1")
  97. // {
  98. // accountType = 1
  99. // reSetView();
  100. //
  101. // if(shopOpen.openingPermitImage != "")
  102. // {
  103. // img1.loadImage(imgUrl: shopOpen.openingPermitImage, defaultImage: "")
  104. // }
  105. // }
  106. // else
  107. // {
  108. // if(shopOpen.shopType == 0)
  109. // {
  110. // btnAccountType.isEnabled = false;
  111. // accountType = 0
  112. // reSetView();
  113. // }
  114. // else
  115. // {
  116. // btnAccountType.isEnabled = true;
  117. // accountType = 1
  118. // reSetView();
  119. // }
  120. // }
  121. }
  122. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  123. txtName.resignFirstResponder()
  124. txtBankNo.resignFirstResponder()
  125. txtBank.resignFirstResponder()
  126. txtBankChild.resignFirstResponder()
  127. txtBankAddress.resignFirstResponder()
  128. txtPhone.resignFirstResponder()
  129. }
  130. var viewSelectCity: Virgil_SelectCity!
  131. @IBAction func btnMenuClick(_ sender: AnyObject) {
  132. switch (sender as! UIButton).tag {
  133. case 1001: // 上传照片
  134. uploadImage(type: 0)
  135. break
  136. case 1002: // 所属地区
  137. let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
  138. if viewSelectCity == nil {
  139. viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
  140. viewSelectCity.modelType = 2
  141. viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
  142. self!.addressIds[0] = self!.getString(key: "addressId1", dic: dic)
  143. self!.addressIds[1] = self!.getString(key: "addressId2", dic: dic)
  144. self!.addressIds[2] = self!.getString(key: "addressId3", dic: dic)
  145. self!.addressNames[0] = self!.getString(key: "addressName1", dic: dic)
  146. self!.addressNames[1] = self!.getString(key: "addressName2", dic: dic)
  147. self!.addressNames[2] = self!.getString(key: "addressName3", dic: dic)
  148. self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
  149. self!.txtBankAddress.text = self!.getString(key: "address", dic: dic)
  150. }
  151. self.view.addSubview(viewSelectCity)
  152. }
  153. viewSelectCity.showPickerView()
  154. break
  155. case 1003: // 所属支行
  156. // if(addressIds[1] == "")
  157. // {
  158. // SVProgressHUD.showError(withStatus: "请先选择省市区")
  159. // return;
  160. // }
  161. let vc = SelectBankViewController()
  162. vc.shopEntity = shopOpen
  163. vc.provinceId = ""//addressIds[0]
  164. vc.cityId = ""//addressIds[1];
  165. var substr = ""
  166. if self.bankCardCityName.contains("市") {
  167. let arr = self.bankCardCityName.components(separatedBy: "市")
  168. substr = arr[0]
  169. }else {
  170. substr = self.bankCardCityName
  171. }
  172. namem = self.txtBank.text! + substr
  173. vc.bankName = namem //txtBank.text!;
  174. toViewController(viewController: vc)
  175. break
  176. case 1004: // 完成
  177. if shopOpen.shopType == 0 {
  178. if imgUrl1 == "" {
  179. SVProgressHUD.showError(withStatus: "请上传银行卡照片")
  180. return
  181. }
  182. } else {
  183. if imgUrl1 == "" {
  184. SVProgressHUD.showError(withStatus: "请上传银行卡照片")
  185. return
  186. }
  187. }
  188. if txtName.text!.length() < 1 {
  189. SVProgressHUD.showError(withStatus: "请输入姓名")
  190. return
  191. }
  192. if txtBankNo.text!.length() < 1 {
  193. SVProgressHUD.showError(withStatus: "请输入银行卡号")
  194. return
  195. }
  196. // if(txtBank.text!.length() < 1 || txtBank.text! == "未识别银行")
  197. // {
  198. // SVProgressHUD.showError(withStatus: "请正确输入银行卡号");
  199. // return;
  200. // }
  201. if addressIds[1] == "" {
  202. SVProgressHUD.showError(withStatus: "请选择银行所在地区")
  203. return
  204. }
  205. if txtBankChild.text! == "" || zhiHangId == "" {
  206. SVProgressHUD.showError(withStatus: "请选择所属支行")
  207. return
  208. }
  209. if shopOpen.shopType == 0 {
  210. if txtPhone.text! == "" {
  211. SVProgressHUD.showError(withStatus: "请输入预留手机号")
  212. return
  213. }
  214. }
  215. shopOpen.bankAccountType = "\(accountType)"
  216. if shopOpen.shopType == 0 {
  217. shopOpen.bankCardImage = imgUrl1
  218. shopOpen.reservePhone = txtPhone.text!
  219. } else {
  220. shopOpen.openingPermitImage = imgUrl1
  221. }
  222. shopOpen.bankCardImage = imgUrl1
  223. shopOpen.bankOpenName = txtName.text!
  224. shopOpen.bankCardNo = txtBankNo.text!
  225. shopOpen.bankName = txtBank.text!
  226. shopOpen.bankAddress = txtBankAddress.text!
  227. shopOpen.bankAffiliatedBranchBankCN = txtBankChild.text!
  228. shopOpen.bankAddressId1 = addressIds[0]
  229. shopOpen.bankAddressId2 = addressIds[1]
  230. shopOpen.bankAddressId3 = addressIds[2]
  231. shopOpen.bankAddressName1 = addressNames[0]
  232. shopOpen.bankAddressName2 = addressNames[1]
  233. shopOpen.bankAddressName3 = addressNames[2]
  234. shopOpen.bankAffiliatedBranchBank = zhiHangId
  235. shopOpen.bankCardImgLocal = imgLocalPath
  236. shopOpen.bankAffiliatedBranchBankCN = txtBankChild.text!
  237. shopOpen.bankAffiliatedBank = yinhangId
  238. handleBack()
  239. break
  240. case 1005: // 账户类型 0:对私 1:对公
  241. CommonUntils.AlertView(controller: self, title: nil, message: "请选择账户类型", buttons: ["对私账户", "对公账户"], style: .actionSheet) {[weak self] (index, _) in
  242. self!.accountType = index
  243. self!.reSetView()
  244. }
  245. break
  246. case 1006: //
  247. break
  248. default:
  249. break
  250. }
  251. }
  252. func reSetView() {
  253. if accountType == 0 {
  254. lblAccountType.text = "对私账户"
  255. lblCardTitle.text = "银行卡正面"
  256. lblAccountTitle.text = "结算人姓名"
  257. viewContent.setSizeHeight(height: 317)
  258. } else {
  259. lblAccountType.text = "对公账户"
  260. lblCardTitle.text = "开户许可证"
  261. lblAccountTitle.text = "结算账户名称"
  262. viewContent.setSizeHeight(height: 315)
  263. }
  264. btnFinish.marginTop(top: 40, view: viewContent)
  265. scrollView.contentSize.height = btnFinish.bottom() + 60
  266. }
  267. func textFieldDidEndEditing(_ textField: UITextField) {
  268. if textField.tag == 1003 {
  269. let str = textField.text!
  270. if str.length() > 5 {
  271. loadBankName()
  272. }
  273. }
  274. }
  275. func loadBankName() {
  276. var str8 = ""
  277. var str6 = ""
  278. if txtBankNo.text!.length() >= 8 {
  279. str8 = txtBankNo.text!.substringTo(index: 8)
  280. str6 = txtBankNo.text!.substringTo(index: 6)
  281. }
  282. if txtBankNo.text!.length() >= 6 {
  283. str6 = txtBankNo.text!.substringTo(index: 6)
  284. } else {
  285. txtBank.text = "未识别银行"
  286. return
  287. }
  288. if arrBank.count > 0 {
  289. var isFined = false
  290. for dic in arrBank {
  291. let bin = (dic as! NSDictionary).getString(key: "bin")
  292. if bin == str8 || bin == str6 {
  293. isFined = true
  294. txtBank.text = (dic as! NSDictionary).getString(key: "bankName").split(s: "-")[0]
  295. break
  296. }
  297. }
  298. if !isFined {
  299. txtBank.text = "未识别银行"
  300. }
  301. } else {
  302. txtBank.text = "未识别银行"
  303. }
  304. }
  305. // MARK: ============选择头像============
  306. var uploadImageType = 0
  307. func uploadImage(type: Int) {
  308. uploadImageType = type
  309. CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
  310. let ipc = UIImagePickerController()
  311. if index == 0 {
  312. ipc.sourceType = .camera
  313. } else {
  314. ipc.sourceType = .photoLibrary
  315. }
  316. ipc.delegate = self!
  317. ipc.allowsEditing = false
  318. self!.present(ipc, animated: true, completion: nil)
  319. }
  320. }
  321. var imgTemp: UIImage!
  322. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  323. self.dismiss(animated: true) {[weak self] in
  324. var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
  325. if picker.allowsEditing {
  326. imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
  327. }
  328. if imgTemp != nil {
  329. self!.UploadFile(img: imgTemp!)
  330. } else {
  331. SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
  332. }
  333. }
  334. }
  335. func UploadFile(img: UIImage) {
  336. MBProgressHUD.showAdded(to: self.view, animated: true)
  337. let uploadFile = QiNiuUploadFile()
  338. uploadFile.uploadFile(img: img) {[weak self] (type, str) in
  339. if type == 1 {
  340. self!.uploadWeb(img: img)
  341. let userLoginUrl = RequestURL.qiNiuImageUrl + str
  342. self!.imgUrl1 = userLoginUrl
  343. self!.img1.loadImage(imgUrl: self!.imgUrl1, defaultImage: "")
  344. } else {
  345. MBProgressHUD.hide(for: self!.view, animated: true)
  346. SVProgressHUD.showError(withStatus: "上传失败")
  347. }
  348. }
  349. }
  350. var imgLocalPath = ""
  351. func uploadWeb(img: UIImage) {
  352. let manage = AFHTTPSessionManager()
  353. let param = NSMutableDictionary()
  354. param.setValue(8, forKey: "type")
  355. manage.requestSerializer.timeoutInterval = 60.0
  356. manage.post(RequestURL.uploadMerchantFile, parameters: param, constructingBodyWith: { (formDate) in
  357. formDate.appendPart(withFileData: img.jpegData(compressionQuality: 0.4)!, name: "fileInput", fileName: "fileInput", mimeType: "multipart/form-data")
  358. }, progress: nil, success: {[weak self] (op, json1) in
  359. let json = json1 as! NSDictionary
  360. print(json)
  361. let succeed = json.object(forKey: "succeed") as! String
  362. if succeed == "000" {
  363. let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
  364. if status == 200 {
  365. self!.imgLocalPath = (json["dataInfo"] as! NSDictionary).getString(key: "url")
  366. let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
  367. let hkResult = haike["result"] as! NSDictionary
  368. let hkResultData = hkResult["data"] as! NSDictionary
  369. self!.txtBank.text = hkResultData.getString(key: "bankName")
  370. self!.txtBankNo.text = hkResultData.getString(key: "cardNumber")
  371. } else {
  372. SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传或手动输入银行卡号!")
  373. }
  374. } else {
  375. SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
  376. //CommonUntils.alert(message: json.object(forKey: "sucInfo") as! String)
  377. }
  378. MBProgressHUD.hide(for: self!.view, animated: true)
  379. }) { (_, _) in
  380. SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
  381. MBProgressHUD.hide(for: self.view, animated: true)
  382. }
  383. }
  384. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  385. tempTextFeild = textField
  386. return true
  387. }
  388. var tempTextFeild: UITextField!
  389. override func keyboardWasShown(noti: NSNotification) {
  390. if tempTextFeild == nil || tempTextFeild.tag != 9009 {
  391. return
  392. }
  393. DispatchQueue.main.async { [weak self] in
  394. let info = noti.userInfo
  395. let keyHe = (info![UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size.height
  396. //文本框距上的高度
  397. let viewTop = CommonViewUntils.getControlRectForScreen(view: self!.tempTextFeild).origin.y + self!.tempTextFeild.height()
  398. if viewTop + 64 > (ScreenHeight - keyHe) {
  399. self!.scrollView.marginTop(top: -(viewTop - (ScreenHeight - keyHe)))
  400. }
  401. }
  402. }
  403. override func keyboardWasHidden(noti: NSNotification) {
  404. self.scrollView.marginTop(top: 0)
  405. }
  406. override func viewWillAppear(_ animated: Bool) {
  407. super.viewWillAppear(animated)
  408. if mainViewControllerIsGo {
  409. if mainViewControllerIsGoType == 0 {
  410. zhiHangId = mainViewControllerIsGoValue1
  411. zhiHangName = mainViewControllerIsGoValue
  412. yinhangId = mainViewControllerIsGoValue2
  413. txtBankChild.text = zhiHangName
  414. }
  415. }
  416. mainViewControllerIsGo = false
  417. }
  418. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  419. super.init(nibName: "BalanceAccountViewController", bundle: nil)
  420. }
  421. required init?(coder aDecoder: NSCoder) {
  422. fatalError("init(coder:) has not been implemented")
  423. }
  424. }