VerificationPhoneViewController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // VerificationPhoneViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/3/27.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. class VerificationPhoneViewController: BaseViewController {
  12. @IBOutlet weak var phoneAreaCodeButton: UIButton!
  13. @IBOutlet weak var smsButton: CountdownButton!
  14. @IBOutlet weak var verificationPhoneButton: UIButton!
  15. @IBOutlet weak var phoneNumberTextField: UITextField!
  16. @IBOutlet weak var smsTextField: UITextField!
  17. /// 手机号
  18. var phoneNumber : String = ""
  19. ///
  20. var sms : String = ""
  21. override func viewWillAppear(_ animated: Bool) {
  22. super.viewWillAppear(animated)
  23. MobClick.beginLogPageView("VerificationPhoneViewController:验证手机页面")
  24. }
  25. override func viewWillDisappear(_ animated: Bool) {
  26. super.viewWillDisappear(animated)
  27. MobClick.endLogPageView("VerificationPhoneViewController:验证手机页面")
  28. }
  29. override func viewDidLoad() {
  30. super.viewDidLoad()
  31. setupViews()
  32. }
  33. override func setupViews() {
  34. navigationBar.wr_setRightButton(title: "手机密码登录", titleColor: k333333Color)
  35. navigationBar.onClickRightButton = {[weak self] in
  36. self?.present(PasswordLoginViewController(), animated: true, completion: {
  37. })
  38. }
  39. smsButton.normalText = " 获取验证码 "
  40. smsButton.disabledText = " seconds后重新获取 "
  41. smsButton.setTitle(smsButton.normalText, for: UIControl.State.normal)
  42. smsButton.setTitle(smsButton.disabledText, for: UIControl.State.disabled)
  43. smsButton.setTitleColor(kED3934Color, for: UIControl.State.normal)
  44. smsButton.setTitleColor(k333333Color, for: UIControl.State.disabled)
  45. smsButton.titleLabel?.font = kRegularFont12
  46. smsButton.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.center
  47. smsButton.sizeToFit()
  48. smsButton.normalBorderColor = kED3934Color
  49. smsButton.normalBorderWidth = 0.5
  50. smsButton.normalCornerRadius = 15
  51. smsButton.normalBackgroundColor = UIColor.white
  52. smsButton.disabledBorderColor = ke6e6e6Color
  53. smsButton.disabledBorderWidth = 0.5
  54. smsButton.disabledCornerRadius = 15
  55. smsButton.disabledBackgroundColor = ke6e6e6Color
  56. smsButton.maxSecond = 60
  57. smsButton.updateNormal()
  58. verificationPhoneButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
  59. verificationPhoneButton.setTitleColor(k666666Color, for: UIControl.State.disabled)
  60. verificationPhoneButton.setBackgroundImage(UIImage.imageWithColor(color: kDisabledButtonColor), for: UIControl.State.disabled)
  61. verificationPhoneButton.setBackgroundImage(UIImage.imageWithColor(color: kEnabledButtonColor), for: UIControl.State.normal)
  62. verificationPhoneButton.titleLabel?.font = kRegularFont18
  63. verificationPhoneButton.cornerRadius = 22
  64. verificationPhoneButton.masksToBounds = true
  65. verificationPhoneButton.isEnabled = false
  66. phoneNumberTextField.rx.text.changed.subscribe(onNext: { [weak self] (text) in
  67. self?.phoneNumberTextField.text = String(text?.prefix(11) ?? "") as String
  68. self?.phoneNumber = self?.phoneNumberTextField.text ?? ""
  69. self?.observableString()
  70. }).disposed(by: disposeBag)
  71. smsTextField.rx.text.changed.subscribe(onNext: { [weak self] (text) in
  72. self?.smsTextField.text = String(text?.prefix(6) ?? "") as String
  73. self?.sms = self?.smsTextField.text ?? ""
  74. self?.observableString()
  75. }).disposed(by: disposeBag)
  76. }
  77. func observableString() {
  78. Observable.combineLatest(Observable.just(phoneNumber), Observable.just(sms)) { (textValue1, textValue2) -> Bool in
  79. let textValue1 = String(textValue1.prefix(11)) as String
  80. let textValue2 = String(textValue2.prefix(6)) as String
  81. let isSuccess = (textValue1.count == 11) && (textValue2.count == 6)
  82. return isSuccess
  83. }.subscribe(onNext: {
  84. [weak self] isEmpty in
  85. self?.verificationPhoneButton.isEnabled = isEmpty
  86. }).disposed(by: self.disposeBag)
  87. }
  88. @IBAction func phoneAreaCodeAction(_ sender: UIButton) {
  89. let vc = PhoneCountryAreaViewController()
  90. vc.phoneCountryAreaVCCloSure = { [weak self] (phoneCountryAreaMdoel:PhoneCountryAreaMdoel) in
  91. self?.phoneAreaCodeButton.setTitle(phoneCountryAreaMdoel.countryCode, for: UIControl.State.normal)
  92. }
  93. self.present(vc, animated: true) {
  94. }
  95. }
  96. @IBAction func smsAction(_ sender: CountdownButton) {
  97. smsButton.countdown = true
  98. }
  99. /// 立即验证
  100. @IBAction func verificationPhoneNumberAction() {
  101. self.dismissToRootViewController(animated: true) {
  102. }
  103. }
  104. }