123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // RQUpdatePasswordViewModel.m
- // YueXueChe
- //
- // Created by 张嵘 on 2019/1/14.
- // Copyright © 2019 RONG. All rights reserved.
- //
- #import "RQUpdatePasswordViewModel.h"
- #import "RQHTTPService+RQUpdatePassword.h"
- @interface RQUpdatePasswordViewModel ()
- /// closeCommand
- @property (nonatomic, readwrite, strong) RACCommand *closeCommand;
- /// sureCommand
- @property (nonatomic, readwrite, strong) RACCommand *sureCommand;
- /// 确定按钮有效性
- @property (nonatomic, readwrite, strong) RACSignal *validSureSignal;
- /// phone
- @property (nonatomic, readwrite, copy) NSString *phone;
- /// code
- @property (nonatomic, readwrite, copy) NSString *code;
- @end
- @implementation RQUpdatePasswordViewModel
- - (void)initialize {
- [super initialize];
- /// 显示导航栏的细线
- self.prefersNavigationBarBottomLineHidden = NO;
- self.title = @"修改密码";
-
- @weakify(self);
- self.closeCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
- @strongify(self);
- [self.services popToRootViewModelAnimated:YES];
- return [RACSignal empty];
- }];
-
- /// 按钮的有效性
- self.validSureSignal = [[RACSignal
- combineLatest:@[RACObserve(self, freshPassword)]
- reduce:^(NSString *freshPassword) {
- return @(RQStringIsNotEmpty(freshPassword));
- }]
- distinctUntilChanged];
-
- self.sureCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
- @strongify(self);
- [QMUITips showLoading:@"修改中..." inView:DefaultTipsParentView];
- return [self updatePassWorld];
- }];
- }
- - (RACSignal *)updatePassWorld {
- @weakify(self);
- return [[[RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
- [[RQ_HTTP_Service updatePasswordWithLoginCode:RQ_USER_MANAGER.currentUser.loginCode password:self.freshPassword] subscribeNext:^(id _Nullable x) {
- [subscriber sendNext:x];
- } error:^(NSError * _Nullable error) {
- [subscriber sendError:error];
- } completed:^{
- [subscriber sendCompleted];
- }];
- return [RACDisposable disposableWithBlock:^{
- }];
- }] doNext:^(id _Nullable x) {
- @strongify(self);
- [QMUITips hideAllTips];
- [QMUITips showSucceed:@"修改成功"];
- [RQ_USER_MANAGER logoutUser];
- /// 延迟一段时间
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- /// 这里切换 到账号登录的界面
- [RQNotificationCenter postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogout)}];
- });
- }] doError:^(NSError * _Nonnull error) {
- [QMUITips hideAllTips];
- [QMUITips showError:[NSError rq_tipsFromError:error]];
- }];
- }
- @end
|