70 lines
2.2 KiB
Swift
70 lines
2.2 KiB
Swift
//
|
|
// ChangePhoneVC.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/11.
|
|
//
|
|
|
|
import UIKit
|
|
import RxSwift
|
|
import RxCocoa
|
|
|
|
class ChangePhoneVC: BaseViewController {
|
|
|
|
fileprivate var rootView: ChangePhoneView!
|
|
|
|
override func loadView() {
|
|
rootView = ChangePhoneView(frame: UIScreen.main.bounds)
|
|
view = rootView
|
|
}
|
|
|
|
private var timestamp: String = ""
|
|
private var countDownService = CountDownService(countDownTime: 60)
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
reactiveAction()
|
|
}
|
|
|
|
private func reactiveAction() {
|
|
rootView.smsCodeBtn.rx.tap.subscribe(onNext: { _ in
|
|
self.requestSmsCodeAPI()
|
|
}).disposed(by: disposeBag)
|
|
|
|
rootView.confirmBtn.rx.tap.subscribe(onNext: { _ in
|
|
self.requestChangePhone()
|
|
}).disposed(by: disposeBag)
|
|
}
|
|
|
|
// MARK: - API 验证码
|
|
func requestSmsCodeAPI() {
|
|
guard let phone = rootView.phoneTF.text, !phone.isEmpty else {
|
|
DLToast.show(text: "请输入手机号")
|
|
return
|
|
}
|
|
DLToast.showLoading()
|
|
SystemService.sendSmsCode(phone: phone).subscribe(onNext: { [weak self] response in
|
|
DLToast.showSuccess(text: "发送成功")
|
|
guard let self = self, let responseData = response.result as? [String : Any] else { return }
|
|
self.startCountDown(self.rootView.smsCodeBtn, self.countDownService)
|
|
if let timestamp = responseData["timestamp"] as? String {
|
|
self.timestamp = timestamp
|
|
}
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
|
|
// MARK: - API 更换手机号
|
|
private func requestChangePhone() {
|
|
DLToast.showLoading()
|
|
guard let phone = rootView.phoneTF.text, let code = rootView.codeTF.text else { return }
|
|
UserService.changePhone(timestamp: timestamp, phone: phone, code: code).subscribe(onNext: { response in
|
|
DLToast.show(text: "更换成功") {
|
|
AppRouter.shared.popToRoot()
|
|
}
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
}
|