RegViewController2.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // LoginViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/22.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class RegViewController2: BaseViewController, UITextFieldDelegate {
  10. @IBOutlet weak var viewContent: UIView!
  11. @IBOutlet weak var btnReView: UIButton!
  12. @IBOutlet weak var txtRePassword: UITextField!
  13. @IBOutlet weak var btnAngree: UIButton!
  14. @IBOutlet weak var btnLogin: UIButton!
  15. @IBOutlet weak var btnCode: CusButtonGetCode!
  16. @IBOutlet weak var btnView: UIButton!
  17. @IBOutlet weak var btnClose: UIButton!
  18. @IBOutlet weak var txtCode: UITextField!
  19. @IBOutlet weak var txtPassword: UITextField!
  20. @IBOutlet weak var txtPhone: UITextField!
  21. var recCode = ""
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. self.title = "注册账号"
  25. initNavLeftBackButton()
  26. txtPhone.setContentMarginLeft(leftWidth: 15)
  27. txtPassword.setContentMarginLeft(leftWidth: 15)
  28. txtCode.setContentMarginLeft(leftWidth: 15)
  29. txtRePassword.setContentMarginLeft(leftWidth: 15)
  30. txtPhone.setCornerRadius(size: 4)
  31. txtPassword.setCornerRadius(size: 4)
  32. txtRePassword.setCornerRadius(size: 4)
  33. txtCode.setCornerRadius(size: 4)
  34. txtCode.delegate = self
  35. btnAngree.setAttributedTitle(CommonViewUntils.getAttributedString(str: " 我已阅读并同意《服务协议》", left: [8, 14], color: [CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: 1.0)]), for: .normal)
  36. //37A6FF
  37. }
  38. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  39. txtPhone.resignFirstResponder()
  40. txtPassword.resignFirstResponder()
  41. txtCode.resignFirstResponder()
  42. txtRePassword.resignFirstResponder()
  43. viewContent.marginTop(top: 0)
  44. }
  45. //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
  46. @IBAction func btnMenuClick(_ sender: AnyObject) {
  47. switch (sender as! UIButton).tag {
  48. case 1001: // 清空手机号
  49. txtPhone.text = ""
  50. break
  51. case 1002: // 显示隐藏密码
  52. if btnView.isSelected {
  53. txtPassword.isSecureTextEntry = true
  54. } else {
  55. txtPassword.isSecureTextEntry = false
  56. }
  57. btnView.isSelected = !btnView.isSelected
  58. break
  59. case 1003: // 获取验证码
  60. if txtPhone.text!.length() < 1 {
  61. SVProgressHUD.showError(withStatus: "请输入您的手机号")
  62. return
  63. }
  64. getCode()
  65. break
  66. case 1004: // 登录
  67. if txtPhone.text!.length() < 1 {
  68. SVProgressHUD.showError(withStatus: "请输入您的手机号")
  69. return
  70. }
  71. if txtPassword.text!.length() < 1 {
  72. SVProgressHUD.showError(withStatus: "请输入您的密码")
  73. return
  74. }
  75. if txtRePassword.text!.length() < 1 {
  76. SVProgressHUD.showError(withStatus: "请输入您的确认密码")
  77. return
  78. }
  79. if txtPassword.text! != txtRePassword.text! {
  80. SVProgressHUD.showError(withStatus: "确认密码不一致,请重新输入")
  81. return
  82. }
  83. if txtCode.text!.length() < 1 {
  84. SVProgressHUD.showError(withStatus: "请输入验证码")
  85. return
  86. }
  87. if !btnAngree.isSelected {
  88. SVProgressHUD.showError(withStatus: "请先阅读并同意《服务协议》")
  89. return
  90. }
  91. submitData()
  92. break
  93. case 1005: // 同意协议
  94. btnAngree.isSelected = !btnAngree.isSelected
  95. break
  96. case 1006: // 忘记密码
  97. break
  98. case 1007: // 显示隐藏确认密码
  99. if btnReView.isSelected {
  100. txtRePassword.isSecureTextEntry = true
  101. } else {
  102. txtRePassword.isSecureTextEntry = false
  103. }
  104. btnReView.isSelected = !btnReView.isSelected
  105. break
  106. case 1008: // 服务协议
  107. let vcWeb = CommonWebViewViewController()
  108. vcWeb.strTitle = "服务协议"
  109. vcWeb.url = RequestURL.systemSetting
  110. toViewController(viewController: vcWeb)
  111. break
  112. default:
  113. break
  114. }
  115. }
  116. // MARK: =============加载数据===============
  117. func submitData() {
  118. let url = RequestURL.register
  119. let params = NSMutableDictionary()
  120. params.setValue(txtPhone.text!, forKey: "mobile")
  121. params.setValue(txtPassword.text!, forKey: "password")
  122. params.setValue(txtCode.text!, forKey: "code")
  123. params.setValue(recCode, forKey: "recCode")
  124. submitData(url: url, params: params, tag: 1001)
  125. }
  126. func getCode() {
  127. let url = RequestURL.getCode
  128. let params = NSMutableDictionary()
  129. params.setValue(txtPhone.text!, forKey: "phone")
  130. params.setValue(1, forKey: "type")
  131. submitData(url: url, params: params, tag: 1002)
  132. }
  133. override func returnData(tag: Int) {
  134. if tag == 1001 {
  135. CommonValue.setLoginUserAccountInfo(userName: txtPhone.text!, password: txtPassword.text!, type: "2")
  136. let dic = NSMutableDictionary()
  137. CommonValue.setLoginUserInfo(loginUser: dicBackData)
  138. CommonUntils.AlertView(controller: self, title: "提示", message: "是否进行实名认证", buttons: ["确定"], style: .alert, actionHandler: {[weak self] (_, _) in
  139. let viewWeb = RealNameAuthViewController()
  140. self!.toViewController(viewController: viewWeb)
  141. }) {[weak self] in
  142. self!.navigationController?.popToRootViewController(animated: true)
  143. }
  144. } else if tag == 1002 {
  145. btnCode.startGetCode()
  146. }
  147. }
  148. override func returnError(tag: Int, type: String) {
  149. }
  150. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  151. viewContent.marginTop(top: -30)
  152. return true
  153. }
  154. override func viewWillAppear(_ animated: Bool) {
  155. super.viewWillAppear(animated)
  156. }
  157. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  158. super.init(nibName: "RegViewController2", bundle: nil)
  159. }
  160. required init?(coder aDecoder: NSCoder) {
  161. fatalError("init(coder:) has not been implemented")
  162. }
  163. }