ForgetPasswordViewController.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 ForgetPasswordViewController: BaseViewController {
  10. @IBOutlet weak var btnLogin: UIButton!
  11. @IBOutlet weak var btnCode: CusButtonGetCode!
  12. @IBOutlet weak var btnView: UIButton!
  13. @IBOutlet weak var btnClose: UIButton!
  14. @IBOutlet weak var txtCode: UITextField!
  15. @IBOutlet weak var txtPassword: UITextField!
  16. @IBOutlet weak var txtPhone: UITextField!
  17. ///0:找回密码 1:修改密码
  18. var type = 0
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. if type == 0 {
  22. self.title = "找回密码"
  23. } else {
  24. self.title = "修改密码"
  25. btnClose.isHidden = true
  26. txtPhone.text = CommonValue.getLoginUserName()
  27. txtPhone.isEnabled = true
  28. }
  29. initNavLeftBackButton()
  30. txtPhone.setContentMarginLeft(leftWidth: 15)
  31. txtPassword.setContentMarginLeft(leftWidth: 15)
  32. txtCode.setContentMarginLeft(leftWidth: 15)
  33. txtPhone.setCornerRadius(size: 4)
  34. txtPassword.setCornerRadius(size: 4)
  35. txtCode.setCornerRadius(size: 4)
  36. }
  37. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  38. txtPhone.resignFirstResponder()
  39. txtPassword.resignFirstResponder()
  40. txtCode.resignFirstResponder()
  41. }
  42. //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
  43. @IBAction func btnMenuClick(_ sender: AnyObject) {
  44. switch (sender as! UIButton).tag {
  45. case 1001: // 清空手机号
  46. txtPhone.text = ""
  47. break
  48. case 1002: // 显示隐藏密码
  49. if btnView.isSelected {
  50. txtPassword.isSecureTextEntry = true
  51. } else {
  52. txtPassword.isSecureTextEntry = false
  53. }
  54. btnView.isSelected = !btnView.isSelected
  55. break
  56. case 1003: // 获取验证码
  57. if txtPhone.text!.length() < 1 {
  58. SVProgressHUD.showError(withStatus: "请输入您的手机号")
  59. return
  60. }
  61. getCode()
  62. break
  63. case 1004: // 确定
  64. if txtPhone.text!.length() < 1 {
  65. SVProgressHUD.showError(withStatus: "请输入您的手机号")
  66. return
  67. }
  68. if txtCode.text!.length() < 1 {
  69. SVProgressHUD.showError(withStatus: "请输入验证码")
  70. return
  71. }
  72. if txtPassword.text!.length() < 1 {
  73. SVProgressHUD.showError(withStatus: "请输入您的密码")
  74. return
  75. }
  76. submitData()
  77. //toViewController(viewController: GuesturePasswordViewController());
  78. break
  79. case 1005: //
  80. break
  81. case 1006: //
  82. break
  83. default:
  84. break
  85. }
  86. }
  87. func submitData() {
  88. var url = RequestURL.findPassword
  89. let params = NSMutableDictionary()
  90. if type == 0 {
  91. url = RequestURL.findPassword
  92. } else {
  93. url = RequestURL.updatePassword
  94. }
  95. params.setValue(txtPhone.text!, forKey: "phone")
  96. params.setValue(txtPassword.text!, forKey: "password")
  97. params.setValue(txtCode.text!, forKey: "code")
  98. submitData(url: url, params: params, tag: 1001)
  99. }
  100. func getCode() {
  101. let url = RequestURL.getCode
  102. let params = NSMutableDictionary()
  103. params.setValue(txtPhone.text!, forKey: "phone")
  104. params.setValue(3, forKey: "type")
  105. submitData(url: url, params: params, tag: 1002)
  106. }
  107. override func returnData(tag: Int) {
  108. if tag == 1001 {
  109. SVProgressHUD.showSuccess(withStatus: "密码修改成功!")
  110. handleBack()
  111. } else if tag == 1002 {
  112. btnCode.startGetCode()
  113. }
  114. }
  115. override func returnError(tag: Int, type: String) {
  116. }
  117. override func viewWillAppear(_ animated: Bool) {
  118. super.viewWillAppear(animated)
  119. }
  120. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  121. super.init(nibName: "ForgetPasswordViewController", bundle: nil)
  122. }
  123. required init?(coder aDecoder: NSCoder) {
  124. fatalError("init(coder:) has not been implemented")
  125. }
  126. }