// // VerificationPhoneViewController.swift // RainbowPlanet // // Created by 南鑫林 on 2019/3/27. // Copyright © 2019 南鑫林. All rights reserved. // import UIKit import RxSwift import RxCocoa class VerificationPhoneViewController: BaseViewController { @IBOutlet weak var phoneAreaCodeButton: UIButton! @IBOutlet weak var smsButton: CountdownButton! @IBOutlet weak var verificationPhoneButton: UIButton! @IBOutlet weak var phoneNumberTextField: UITextField! @IBOutlet weak var smsTextField: UITextField! /// 手机号 var phoneNumber : String = "" /// var sms : String = "" override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) MobClick.beginLogPageView("VerificationPhoneViewController:验证手机页面") } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) MobClick.endLogPageView("VerificationPhoneViewController:验证手机页面") } override func viewDidLoad() { super.viewDidLoad() setupViews() } override func setupViews() { navigationBar.wr_setRightButton(title: "手机密码登录", titleColor: k333333Color) navigationBar.onClickRightButton = {[weak self] in self?.present(PasswordLoginViewController(), animated: true, completion: { }) } smsButton.normalText = " 获取验证码 " smsButton.disabledText = " seconds后重新获取 " smsButton.setTitle(smsButton.normalText, for: UIControl.State.normal) smsButton.setTitle(smsButton.disabledText, for: UIControl.State.disabled) smsButton.setTitleColor(kED3934Color, for: UIControl.State.normal) smsButton.setTitleColor(k333333Color, for: UIControl.State.disabled) smsButton.titleLabel?.font = kRegularFont12 smsButton.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.center smsButton.sizeToFit() smsButton.normalBorderColor = kED3934Color smsButton.normalBorderWidth = 0.5 smsButton.normalCornerRadius = 15 smsButton.normalBackgroundColor = UIColor.white smsButton.disabledBorderColor = ke6e6e6Color smsButton.disabledBorderWidth = 0.5 smsButton.disabledCornerRadius = 15 smsButton.disabledBackgroundColor = ke6e6e6Color smsButton.maxSecond = 60 smsButton.updateNormal() verificationPhoneButton.setTitleColor(kffffffColor, for: UIControl.State.normal) verificationPhoneButton.setTitleColor(k666666Color, for: UIControl.State.disabled) verificationPhoneButton.setBackgroundImage(UIImage.imageWithColor(color: kDisabledButtonColor), for: UIControl.State.disabled) verificationPhoneButton.setBackgroundImage(UIImage.imageWithColor(color: kEnabledButtonColor), for: UIControl.State.normal) verificationPhoneButton.titleLabel?.font = kRegularFont18 verificationPhoneButton.cornerRadius = 22 verificationPhoneButton.masksToBounds = true verificationPhoneButton.isEnabled = false phoneNumberTextField.rx.text.changed.subscribe(onNext: { [weak self] (text) in self?.phoneNumberTextField.text = String(text?.prefix(11) ?? "") as String self?.phoneNumber = self?.phoneNumberTextField.text ?? "" self?.observableString() }).disposed(by: disposeBag) smsTextField.rx.text.changed.subscribe(onNext: { [weak self] (text) in self?.smsTextField.text = String(text?.prefix(6) ?? "") as String self?.sms = self?.smsTextField.text ?? "" self?.observableString() }).disposed(by: disposeBag) } func observableString() { Observable.combineLatest(Observable.just(phoneNumber), Observable.just(sms)) { (textValue1, textValue2) -> Bool in let textValue1 = String(textValue1.prefix(11)) as String let textValue2 = String(textValue2.prefix(6)) as String let isSuccess = (textValue1.count == 11) && (textValue2.count == 6) return isSuccess }.subscribe(onNext: { [weak self] isEmpty in self?.verificationPhoneButton.isEnabled = isEmpty }).disposed(by: self.disposeBag) } @IBAction func phoneAreaCodeAction(_ sender: UIButton) { let vc = PhoneCountryAreaViewController() vc.phoneCountryAreaVCCloSure = { [weak self] (phoneCountryAreaMdoel:PhoneCountryAreaMdoel) in self?.phoneAreaCodeButton.setTitle(phoneCountryAreaMdoel.countryCode, for: UIControl.State.normal) } self.present(vc, animated: true) { } } @IBAction func smsAction(_ sender: CountdownButton) { smsButton.countdown = true } /// 立即验证 @IBAction func verificationPhoneNumberAction() { self.dismissToRootViewController(animated: true) { } } }