QuickOpenViewController.swift 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // QuickOpenViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/27.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class QuickOpenViewController: BaseViewController {
  10. @IBOutlet weak var btnGetCode: CusButtonGetCode!
  11. @IBOutlet weak var txtCode: UITextField!
  12. @IBOutlet weak var txtPhone: UITextField!
  13. var shopOpen = ShopOpenEntity()
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. self.title = "快速开通"
  17. initNavLeftBackButton()
  18. btnGetCode.setCornerRadius(size: 4)
  19. }
  20. // override func keyboardWasHidden(noti: NSNotification) {
  21. // txtCode.resignFirstResponder()
  22. // txtPhone.resignFirstResponder();
  23. // }
  24. @IBAction func btnGetCodeClick(_ sender: Any) {
  25. if txtPhone.text!.length() < 1 {
  26. SVProgressHUD.showError(withStatus: "请输入手机号")
  27. return
  28. }
  29. if txtPhone.text!.length() < 11 {
  30. SVProgressHUD.showError(withStatus: "请输入正确的手机号")
  31. return
  32. }
  33. getCode()
  34. }
  35. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  36. txtPhone.resignFirstResponder()
  37. txtCode.resignFirstResponder()
  38. }
  39. @IBAction func btnNextClick(_ sender: Any) {
  40. //
  41. // txtPhone.text = "15411111115";
  42. // self.shopOpen.phone = txtPhone.text!;
  43. // saveAppuser();
  44. // return;
  45. //// self.shopOpen.phone = txtPhone.text!;
  46. //// let vc = PersonalBaseViewController()
  47. //// self.shopOpen.phone = "14811122234";
  48. //// vc.shopOpen = self.shopOpen;
  49. //// toViewController(viewController:vc);
  50. // saveAppuser();
  51. // return;
  52. if txtPhone.text!.length() < 1 {
  53. SVProgressHUD.showError(withStatus: "请输入手机号")
  54. return
  55. }
  56. if txtPhone.text!.length() < 11 {
  57. SVProgressHUD.showError(withStatus: "请输入正确的手机号")
  58. return
  59. }
  60. if txtCode.text!.length() < 1 {
  61. SVProgressHUD.showError(withStatus: "请输入验证码")
  62. return
  63. }
  64. if txtCode.text!.length() < 4 {
  65. SVProgressHUD.showError(withStatus: "请输入正确的验证码")
  66. return
  67. }
  68. checkCode()
  69. }
  70. // MARK: =============加载数据===============
  71. func getCode() {
  72. let url = RequestURL.getCode
  73. let params = NSMutableDictionary()
  74. params.setValue(txtPhone.text!, forKey: "phone")
  75. params.setValue("5", forKey: "type")
  76. loadDataInfo(url: url, params: params, tag: 1001)
  77. }
  78. func checkCode() {
  79. let url = RequestURL.verificationCode
  80. let params = NSMutableDictionary()
  81. params.setValue(txtPhone.text!, forKey: "phone")
  82. params.setValue("5", forKey: "type")
  83. params.setValue(txtCode.text!, forKey: "code")
  84. loadDataInfo(url: url, params: params, tag: 1002)
  85. }
  86. let dicHK = NSMutableDictionary()
  87. //上报海科
  88. func saveAppuser() {
  89. let url = RequestURL.saveAppuser
  90. let params = NSMutableDictionary()
  91. params.setValue(txtPhone.text!, forKey: "regAccno")
  92. loadDataInfo(url: url, params: params, tag: 1003, reDic: dicHK)
  93. }
  94. let dicLocalBase = NSMutableDictionary()
  95. func loadLocalBaseInfo() {
  96. let url = RequestURL.hkMerchantInfo
  97. let params = NSMutableDictionary()
  98. params.setValue(txtPhone.text!, forKey: "regAccno")
  99. loadDataInfo(url: url, params: params, tag: 1004, reDic: dicLocalBase)
  100. }
  101. override func returnData(tag: Int) {
  102. if tag == 1001 {
  103. btnGetCode.startGetCode()
  104. } else if tag == 1002 {
  105. let state = dicData.getInt(key: "state")
  106. if state == 1 {
  107. saveAppuser()
  108. } else {
  109. SVProgressHUD.showError(withStatus: "验证码不正确,请重新输入")
  110. }
  111. } else if tag == 1003 {
  112. let dichaike = dicHK["haike"] as? NSDictionary
  113. if dichaike != nil {
  114. let dicMessage = dichaike!["message"] as? NSDictionary
  115. if dicMessage != nil {
  116. if dicMessage!.getString(key: "code") == "success" {
  117. self.shopOpen.phone = txtPhone.text!
  118. let vc = PersonalBaseViewController()
  119. vc.shopOpen = self.shopOpen
  120. toViewController(viewController: vc)
  121. } else if dicMessage!.getString(key: "code") == "1111" {
  122. loadLocalBaseInfo()
  123. } else {
  124. SVProgressHUD.showError(withStatus: dicMessage!.getString(key: "content"))
  125. }
  126. } else {
  127. SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
  128. }
  129. } else {
  130. SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
  131. }
  132. } else if tag == 1004 {
  133. if dicLocalBase.getInt(key: "step") == 0 {
  134. self.shopOpen.phone = txtPhone.text!
  135. let vc = PersonalBaseViewController()
  136. vc.shopOpen = self.shopOpen
  137. toViewController(viewController: vc)
  138. } else {
  139. let dicHkMerchantInfo = dicLocalBase["hkMerchantInfo"] as? NSDictionary
  140. if dicHkMerchantInfo != nil {
  141. self.shopOpen.companyName = dicHkMerchantInfo!.getString(key: "companyName")
  142. self.shopOpen.name = dicHkMerchantInfo!.getString(key: "applicantName")
  143. self.shopOpen.card = dicHkMerchantInfo!.getString(key: "applicantCard")
  144. self.shopOpen.creditCardNum = dicHkMerchantInfo!.getString(key: "creditCardNum")
  145. self.shopOpen.creditCardPhone = dicHkMerchantInfo!.getString(key: "creditCardPhone")
  146. self.shopOpen.shopName = dicHkMerchantInfo!.getString(key: "shopName")
  147. self.shopOpen.addressDetail = dicHkMerchantInfo!.getString(key: "shopAddress")
  148. self.shopOpen.addressId1 = dicHkMerchantInfo!.getString(key: "shopProvinceId")
  149. self.shopOpen.addressName1 = dicHkMerchantInfo!.getString(key: "shopProvinceName")
  150. self.shopOpen.addressName2 = dicHkMerchantInfo!.getString(key: "shopCityName")
  151. self.shopOpen.addressId2 = dicHkMerchantInfo!.getString(key: "shopCityId")
  152. self.shopOpen.addressName3 = dicHkMerchantInfo!.getString(key: "shopAreaName")
  153. self.shopOpen.addressId3 = dicHkMerchantInfo!.getString(key: "shopAreaId")
  154. self.shopOpen.pmmerId = dicHkMerchantInfo!.getString(key: "pmmerId")
  155. self.shopOpen.phone = txtPhone.text!
  156. let vc = PersonalBindCardViewController()
  157. vc.shopOpen = self.shopOpen
  158. toViewController(viewController: vc)
  159. } else {
  160. SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
  161. }
  162. }
  163. }
  164. }
  165. override func returnError(tag: Int, type: String) {
  166. }
  167. override func viewWillAppear(_ animated: Bool) {
  168. super.viewWillAppear(animated)
  169. }
  170. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  171. super.init(nibName: "QuickOpenViewController", bundle: nil)
  172. }
  173. required init?(coder aDecoder: NSCoder) {
  174. fatalError("init(coder:) has not been implemented")
  175. }
  176. }