123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // YMRegisterViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/5.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMRegisterViewModel.h"
- @interface YMRegisterViewModel ()
- /// 注册按钮有效性
- @property (nonatomic, strong, readwrite) RACSignal *validRegisterSignal;
- @end
- @implementation YMRegisterViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- /// 注册按钮有效性
- self.validRegisterSignal = [[[RACSignal combineLatest:@[
- RACObserve(self, mobile),
- RACObserve(self, verifyCode),
- RACObserve(self, password)
- ] reduce:^(NSString *mobile, NSString *verifyCode, NSString *password ) {
- //是否不为空
- return @(!OCStringIsEmpty(mobile) && !OCStringIsEmpty(verifyCode) &&!OCStringIsEmpty(password));
- }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
- }
- /// 获取验证码
- - (void)getVerifyCodeWithCaptcha:(id)captcha handler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler {
- NSMutableDictionary *dictm = [NSMutableDictionary dictionary];
- dictm[@"mobile"] = self.mobile;
- dictm[@"type"] = @"register";
- if ([captcha isKindOfClass:[NSString class]]) {
- dictm[@"captcha"] = captcha;
- }
- if ([captcha isKindOfClass:[NSDictionary class]]) {
- [dictm addEntriesFromDictionary:captcha];
- }
-
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"获取验证码中"];
- [LCHttpHelper requestWithURLString:PhoneCode parameters:dictm needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper showTitle:@"验证码已发送"];
- handler(dict?:@{},nil);
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)registerRequest{
-
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- [params setObject:self.mobile?:@"" forKey:@"mobile"];
- [params setObject:self.verifyCode?:@"" forKey:@"phone_code"];
- [params setObject:self.password?:@"" forKey:@"password"];
- [params setObject:@"1" forKey:@"agreement"];
-
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"注册中"];
- [LCHttpHelper requestWithURLString:PhoneRegister parameters:params needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
- YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- [LCSaveModel saveUserModel:userModel];
- [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
- [LCSaveData saveLoginMark:YES];
-
- [LCHttpHelper requestWithURLString:GiftConfig parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSLog(@"GiftConfig == %@",dict);
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSMutableArray *giftArray = [NSMutableArray array];
- giftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
- for (int i = 0; i<giftArray.count; i++) {
- YOUPAILCGiftModel *model = giftArray[i];
- if (model.youpaipsvga.length > 0 ) {
- [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
- }
- }
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
-
- if (userModel.youpaipuserinfo.youpaiptype == 2) {
- //是特殊用户
- [LCSaveData saveIsspecial:YES];
- }
- //未完善资料,进入完善资料页面
- if (userModel.youpaipuserinfo.youpaipfinish_status == 0) {
-
- YMImproveInfoViewModel *improveInfoVM = [[YMImproveInfoViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_IMPROVE_INFO) withUserInfo:@{
- RouterViewModel:improveInfoVM
- } completion:nil];
-
- }else{
- //已经完善资料
- [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
- [LCTools changeRootToTabbar];
- }
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- @end
|