// // YMEditProfileViewModel.m // MSYOUPAI // // Created by YoMi on 2024/2/18. // Copyright © 2024 MS. All rights reserved. // #import "YMEditProfileViewModel.h" #import "YMPersonalInfoModel.h" #import "YMSelectDataTypeModel.h" #import "YMEditProfileSelectTagView.h" #import "YMEditInfoTypeViewController.h" @interface YMEditProfileViewModel () /// 用户头像 @property (nonatomic, strong, readwrite) NSString *userAvatar; /// 是否隐藏用户头像审核 @property (nonatomic, assign, readwrite) BOOL isHideUserAvatarUnderReview; /// 是否显示添加Cell @property (nonatomic, assign, readwrite) BOOL isHideAddCell; /// 添加CellViewModel @property (nonatomic, strong, readwrite) YMEditProfileAlbumCellViewModel *addCellViewModel; /// 相册数据 @property (nonatomic, strong, readwrite) NSArray *albumDataArray; /// 用户语音链接 @property (nonatomic, strong, readwrite) NSString *userVoiceUrl; /// 用户语音时长 @property (nonatomic, assign, readwrite) NSInteger userVoiceDuration; /// 是否隐藏用户语音审核 @property (nonatomic, assign, readwrite) BOOL isHideUserVoiceUnderReview; /// 用户昵称 @property (nonatomic, strong, readwrite) NSString *userNickname; /// 信息数据 @property (nonatomic, strong, readwrite) NSArray *infoDataArray; /// 用户简介 @property (nonatomic, strong, readwrite) NSString *userIntro; /// 标签数据 @property (nonatomic, strong, readwrite) NSArray *tagDataArray; /// 添加相册 @property (nonatomic, strong, readwrite) RACSubject *addAlbumSubject; /// 删除相册 @property (nonatomic, strong, readwrite) RACSubject *deleteAlbumSubject; /// 刷新相册排序 @property (nonatomic, strong, readwrite) RACSubject *refreshAlbumSortSubject; /// 编辑资料操作 @property (nonatomic, strong, readwrite) RACSubject *editProfileOperationSubject; /// 年龄数据 @property (nonatomic, strong) NSArray *ageDataArray; /// 星座数据 @property (nonatomic, strong) NSArray *constellationDataArray; /// 家乡数据 @property (nonatomic, strong) NSArray *hometownDataArray; /// 身高数据 @property (nonatomic, strong) NSArray *heightDataArray; /// 体重数据 @property (nonatomic, strong) NSArray *weightDataArray; /// 年收入数据 @property (nonatomic, strong) NSArray *annualIncomeDataArray; /// 婚姻状态数据 @property (nonatomic, strong) NSArray *maritalStatusDataArray; /// 选中资源 @property (nonatomic, strong) NSMutableArray *selectedAssets; /// 用户Id @property (nonatomic, assign) NSInteger userId; /// 相册图片链接 @property (nonatomic, copy) NSString *albumImagesUrl; /// 星座Id @property (nonatomic, assign) NSInteger constellationId; /// 城市Id @property (nonatomic, assign) NSString *cityId; /// 个人信息模组 @property (nonatomic, strong) YMPersonalInfoModel *model; @end @implementation YMEditProfileViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"编辑资料"; self.userId = [self.params integerValueForKey:ParamsId defaultValue:0]; self.isHideUserAvatarUnderReview = YES; self.addCellViewModel = [[YMEditProfileAlbumCellViewModel alloc]initWithParams:@{ @"isAddCell":@(YES), @"isHideDeleteButton":@(YES), }]; self.isHideUserVoiceUnderReview = YES; [self defaultInitializePickerData]; self.infoDataArray = [@[ @{ @"title":@"昵称", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeNickname), }, @{ @"title":@"年龄", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeAge), }, @{ @"title":@"星座", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeConstellation), }, @{ @"title":@"家乡", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeHometown), }, @{ @"title":@"身高", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeHeight), }, @{ @"title":@"体重", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeWeight), }, @{ @"title":@"年收入", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeAnnualIncome), }, @{ @"title":@"婚姻状态", @"content":@"去完善", ParamsCategoryType:@(YMEditProfileTypeMaritalStatus), }, ].rac_sequence map:^(NSDictionary * _Nullable dic) { YMEditProfileInfoCellViewModel *viewModel = [[YMEditProfileInfoCellViewModel alloc]initWithParams:@{ ParamsModel:dic }]; return viewModel; }].array; @weakify(self) [[self.addAlbumSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSArray * _Nullable photos) { NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.albumDataArray]; NSArray *viewModelArr = [photos.rac_sequence map:^id _Nullable(UIImage * _Nullable value) { YMEditProfileAlbumCellViewModel *viewModel = [[YMEditProfileAlbumCellViewModel alloc]initWithParams:@{ @"isAddCell":@(NO), @"localAlbum":value, @"isHideDeleteButton":@(NO) }]; return viewModel; }].array; [tempArr addObjectsFromArray:viewModelArr]; self.albumDataArray = tempArr.mutableCopy; self.isHideAddCell = self.albumDataArray.count < 6 ? NO : YES; NSLog(@"addAlbum:%@",self.albumDataArray); [self.refreshUISubject sendNext:@(YMRefreshUI)]; }]; [[self.deleteAlbumSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * _Nullable index) { @strongify(self) NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.albumDataArray]; YMEditProfileAlbumCellViewModel *cellVM = [tempArr objectAtIndex:[index intValue]]; ///判断当前删除的CellViewModel是网络图片还是本地图片,本地图片则需要删除selectedAssets里面对应本地图片 if (cellVM.localAlbum != nil) { [self.selectedAssets enumerateObjectsUsingBlock:^(PHAsset * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [[TZImageManager manager] getPhotoWithAsset:obj completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { NSData *cellVM_data = UIImagePNGRepresentation(cellVM.localAlbum); NSData *asset_data = UIImagePNGRepresentation(photo); if ([cellVM_data isEqual:asset_data]) { NSLog(@"两个UIImage相同"); [self.selectedAssets removeObjectAtIndex:idx]; *stop = YES; } }]; }]; } [tempArr removeObjectAtIndex:[index intValue]]; self.albumDataArray = tempArr.mutableCopy; self.isHideAddCell = self.albumDataArray.count < 6 ? NO : YES; NSLog(@"deleteAlbumSubject:%@",self.albumDataArray); [self.refreshUISubject sendNext:@(YMRefreshUI)]; }]; [[self.refreshAlbumSortSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSArray * _Nullable albumDataArray) { self.albumDataArray = albumDataArray; NSLog(@"refreshAlbum:%@",self.albumDataArray); [self.refreshUISubject sendNext:@(YMRefreshUI)]; }]; [[self.editProfileOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) { @strongify(self) switch ([value intValue]) { case YMEditProfileTypeNickname: { YMEditInfoTypeViewModel *editInfoTypeVM = [[YMEditInfoTypeViewModel alloc]initWithParams:@{ ParamsCategoryType:@(YMEditInfoTypeNickname), ParamsEditContent:self.userNickname }]; editInfoTypeVM.nicknameBlock = ^(NSString * _Nonnull nickname) { @strongify(self) self.userNickname = nickname; self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeNickname: { viewModel.infoContent = self.userNickname; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; }; [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_EDIT_INFO_TYPE) withUserInfo:@{ RouterViewModel:editInfoTypeVM } completion:nil]; } break; case YMEditProfileTypeAge: { [self openAgePickerPopupView]; } break; case YMEditProfileTypeConstellation: { [self openConstellationPickerPopupView]; } break; case YMEditProfileTypeHometown: { [self openHometownPickerPopupView]; } break; case YMEditProfileTypeHeight: { [self openHeightPickerPopupView]; } break; case YMEditProfileTypeWeight: { [self openWeightPickerPopupView]; } break; case YMEditProfileTypeAnnualIncome: { [self openAnnualIncomePickerPopupView]; } break; case YMEditProfileTypeMaritalStatus: { [self openMaritalStatusPickerPopupView]; } break; case YMEditProfileTypeIntro: { YMEditInfoTypeViewModel *editInfoTypeVM = [[YMEditInfoTypeViewModel alloc]initWithParams:@{ ParamsCategoryType:@(YMEditInfoTypeIntro), ParamsEditContent:self.userIntro }]; editInfoTypeVM.introBlock = ^(NSString * _Nonnull intro) { @strongify(self) self.userIntro = intro; }; [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_EDIT_INFO_TYPE) withUserInfo:@{ RouterViewModel:editInfoTypeVM } completion:nil]; } break; case YMEditProfileTypeTag: { // YMEditInfoTypeViewModel *editInfoTypeVM = [[YMEditInfoTypeViewModel alloc]initWithParams:@{ // ParamsCategoryType:@(YMEditInfoTypeTag), // }]; // editInfoTypeVM.tagBlock = ^(NSArray * _Nonnull selectedTagArray) { // @strongify(self) // self.tagDataArray = [selectedTagArray.rac_sequence map:^(YMEditInfoTypeTagCellViewModel * _Nullable cellVM) { // YMTagModel *model = [[YMTagModel alloc]init]; // model.tag_id = cellVM.tagId; // model.name = cellVM.tagText; // YMEditProfileTagCellViewModel *viewModel = [[YMEditProfileTagCellViewModel alloc]initWithParams:@{ // ParamsModel:model // }]; // return viewModel; // }].array; // [self.refreshUISubject sendNext:@(YMRefreshUI)]; // }; // [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_EDIT_INFO_TYPE) withUserInfo:@{ // RouterViewModel:editInfoTypeVM // } completion:nil]; [self openMyTagPopupView]; } break; default: break; } }]; } - (void)getEditProfileInfoData{ @weakify(self) [ZCHUDHelper showWithStatus:@"加载中..."]; [LCHttpHelper requestWithURLString:GetUserInfo parameters:@{ @"user_id":@(self.userId) } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; self.model = [YMPersonalInfoModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]]; self.userAvatar = OCStringIsEmpty(self.model.avatar_auth) ? self.model.avatar : self.model.avatar_auth; self.isHideUserAvatarUnderReview = self.model.avatar_auth_status == 0 ? NO : YES; self.albumDataArray = [self.model.albums_list.rac_sequence map:^id _Nullable(YMAlbumsListModel * _Nullable value) { YMEditProfileAlbumCellViewModel *viewModel = [[YMEditProfileAlbumCellViewModel alloc]initWithParams:@{ @"isAddCell":@(NO), @"networkAlbum":value.url, @"isHideDeleteButton":@(NO) }]; return viewModel; }].array; self.userVoiceUrl = self.model.voice.voice; self.userVoiceDuration = self.model.voice.voice_time; self.isHideUserVoiceUnderReview = self.model.voice.voice_status == 0 && !OCStringIsEmpty(self.model.voice.voice) ? NO : YES; self.userNickname = self.model.nickname; self.infoDataArray = [self.infoDataArray.rac_sequence map:^(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeNickname: { viewModel.infoContent = self.userNickname; } break; case YMEditProfileTypeAge: { viewModel.infoContent = self.model.basic_info_detail.age; } break; case YMEditProfileTypeConstellation: { NSArray * constellationDataArray = @[ @"保密", @"白羊座", @"金牛座", @"双子座", @"巨蟹座", @"狮子座", @"处女座", @"天秤座", @"天蝎座", @"射手座", @"摩羯座", @"水瓶座", @"双鱼座", ]; viewModel.infoContent = constellationDataArray[self.model.basic_info_detail.signs > 12 ? 0 : self.model.basic_info_detail.signs]; } break; case YMEditProfileTypeHometown: { viewModel.infoContent = self.model.basic_info_detail.city; } break; case YMEditProfileTypeHeight: { NSString *height = [self.model.basic_info_detail.height stringByReplacingOccurrencesOfString:@"cm" withString:@""]; if ([height isEqualToString:@"0"] || OCStringIsEmpty(height)) { viewModel.infoContent = @"请完善"; } else { viewModel.infoContent = self.model.basic_info_detail.height; } } break; case YMEditProfileTypeWeight: { NSString *height = [self.model.basic_info_detail.weight stringByReplacingOccurrencesOfString:@"kg" withString:@""]; if ([height isEqualToString:@"0"] || OCStringIsEmpty(height)) { viewModel.infoContent = @"请完善"; } else { viewModel.infoContent = self.model.basic_info_detail.weight; } } break; case YMEditProfileTypeAnnualIncome: { if (OCStringIsEmpty(self.model.basic_info_detail.annual_income)) { viewModel.infoContent = @"请完善"; } else { viewModel.infoContent = self.model.basic_info_detail.annual_income; } } break; case YMEditProfileTypeMaritalStatus: { if (OCStringIsEmpty(self.model.basic_info_detail.is_marriage)) { viewModel.infoContent = @"请完善"; } else { viewModel.infoContent = self.model.basic_info_detail.is_marriage; } } break; default: break; } if (OCStringIsEmpty(viewModel.infoContent) || [viewModel.infoContent isEqualToString:@"请完善"]) { viewModel.infoContentColor = HexColorFromRGB(0x9c9c9c); } else { viewModel.infoContentColor = HexColorFromRGB(0x333333); } return viewModel; }].array; self.userIntro = [self.model.sign containsString:@"这个人很懒,什么都没有留下"] ? @"" : self.model.sign; self.tagDataArray = [self.model.label.rac_sequence map:^(YMTagModel * _Nullable model) { YMEditProfileTagCellViewModel *viewModel = [[YMEditProfileTagCellViewModel alloc]initWithParams:@{ ParamsModel:model }]; return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; [self.refreshUISubject sendNext:@(YMRefreshUI)]; }]; [LCHttpHelper requestWithURLString:api_getSelectData parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { YMSelectDataTypeModel *model = [YMSelectDataTypeModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)uploadAlbumData{ NSArray *networkAlbumPhotos = [[self.albumDataArray.rac_sequence filter:^BOOL(YMEditProfileAlbumCellViewModel * _Nullable viewModel) { if (!OCStringIsEmpty(viewModel.networkAlbum)) { return YES; } else { return NO; } }] map:^id _Nullable(YMEditProfileAlbumCellViewModel * _Nullable viewModel) { return viewModel.networkAlbum; }].array; NSArray *localAlbumPhotos = [[self.albumDataArray.rac_sequence filter:^BOOL(YMEditProfileAlbumCellViewModel * _Nullable viewModel) { if (viewModel.localAlbum != nil) { return YES; } else { return NO; } }] map:^id _Nullable(YMEditProfileAlbumCellViewModel * _Nullable viewModel) { return viewModel.localAlbum; }].array; if (localAlbumPhotos.count > 0) { [ZCHUDHelper showWithStatus:@"正在上传相册..."]; [LCCommonHttp uploadWithImages:localAlbumPhotos Type:@"album" successBlock:^(NSArray *ossImagePaths) { [ZCHUDHelper dismiss]; NSMutableArray *tempUrlArray = [NSMutableArray array]; [tempUrlArray addObjectsFromArray:networkAlbumPhotos]; [tempUrlArray addObjectsFromArray:ossImagePaths]; self.albumImagesUrl = [tempUrlArray componentsJoinedByString:@","]; [self saveEditProfileInfoData]; }]; }else{ NSArray *networkAlbumPhotos = [[self.albumDataArray.rac_sequence filter:^BOOL(YMEditProfileAlbumCellViewModel * _Nullable viewModel) { if (!OCStringIsEmpty(viewModel.networkAlbum)) { return YES; } else { return NO; } }] map:^id _Nullable(YMEditProfileAlbumCellViewModel * _Nullable viewModel) { return viewModel.networkAlbum; }].array; NSMutableArray *tempUrlArray = [NSMutableArray array]; [tempUrlArray addObjectsFromArray:networkAlbumPhotos]; self.albumImagesUrl = [tempUrlArray componentsJoinedByString:@","]; [self saveEditProfileInfoData]; } } - (void)saveEditProfileInfoData{ @weakify(self) [ZCHUDHelper showWithStatus:@"保存中..."]; NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params setObject:@(self.userId) forKey:@"user_id"]; ///头像 if (![self.userAvatar isEqualToString:self.model.avatar]) { [params setObject:self.userAvatar forKey:@"avatar"]; } ///相册 NSArray *oldAlbumArr = [[self.model.albums_list.rac_sequence filter:^BOOL(YMAlbumsListModel * _Nullable value) { if (value.is_video) { return NO; } else { return YES; } }] map:^id _Nullable(YMAlbumsListModel * _Nullable value) { return value.url; }].array; NSString *oldImageUrl = [oldAlbumArr componentsJoinedByString:@","]; if (![self.albumImagesUrl isEqualToString:oldImageUrl]){ [params setObject:self.albumImagesUrl forKey:@"albums"]; } ///语音 if (![self.userVoiceUrl isEqualToString:self.model.voice.voice]) { [params setObject:self.userVoiceUrl forKey:@"voice"]; [params setObject:@(self.userVoiceDuration) forKey:@"voice_time"]; } [self.infoDataArray enumerateObjectsUsingBlock:^(YMEditProfileInfoCellViewModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { switch (obj.editProfileType) { case YMEditProfileTypeNickname: { ///昵称 if (![obj.infoContent isEqualToString:self.model.nickname] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:obj.infoContent forKey:@"nickname"]; } } break; case YMEditProfileTypeAge: { ///年龄 if (![obj.infoContent isEqualToString:self.model.basic_info_detail.age] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:obj.infoContent forKey:@"age"]; } } break; case YMEditProfileTypeConstellation: { ///星座 if (self.constellationId != self.model.basic_info_detail.signs && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:@(self.constellationId) forKey:@"signs"]; } } break; case YMEditProfileTypeHometown: { ///家乡 if (![self.cityId isEqualToString:self.model.basic_info_detail.city] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:self.cityId forKey:@"cityId"]; } } break; case YMEditProfileTypeHeight: { ///身高 if (![obj.infoContent isEqualToString:self.model.basic_info_detail.height] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:obj.infoContent forKey:@"height"]; } } break; case YMEditProfileTypeWeight: { ///体重 if (![obj.infoContent isEqualToString:self.model.basic_info_detail.weight] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:obj.infoContent forKey:@"weight"]; } } break; case YMEditProfileTypeAnnualIncome: { ///年收入 if (![obj.infoContent isEqualToString:self.model.basic_info_detail.annual_income] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:obj.infoContent forKey:@"annual_income"]; } } break; case YMEditProfileTypeMaritalStatus: { ///婚姻状态 if (![obj.infoContent isEqualToString:self.model.basic_info_detail.is_marriage] && ![obj.infoContent isEqualToString:@"请完善"]) { [params setObject:obj.infoContent forKey:@"is_marriage"]; } } break; default: break; } }]; ///简介 if (![self.userIntro isEqualToString:self.model.sign]) { [params setObject:self.userIntro forKey:@"signature"]; } ///标签 NSArray *newTagArr = [self.tagDataArray.rac_sequence map:^id _Nullable(YMEditProfileTagCellViewModel * _Nullable value) { return @(value.tagId); }].array; NSArray *oldTagArr = [self.model.label.rac_sequence map:^id _Nullable(YMTagModel * _Nullable value) { return @(value.tag_id); }].array; NSString *newTagStr = [newTagArr componentsJoinedByString:@","]; NSString *oldTagStr = [oldTagArr componentsJoinedByString:@","]; if (![newTagStr isEqualToString:oldTagStr]){ [params setObject:newTagStr forKey:@"label"]; } [LCHttpHelper requestWithURLString:api_Improve_data parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)gotoSoundShowcase{ if (self.isHideUserVoiceUnderReview) { YMSoundShowcaseViewModel *soundShowcaseVM = [[YMSoundShowcaseViewModel alloc]initWithParams:@{}]; @weakify(self) soundShowcaseVM.templateVoiceBlock = ^(NSString * _Nonnull voiceUrl, NSInteger voiceDuration) { @strongify(self) self.userVoiceUrl = voiceUrl; self.userVoiceDuration = voiceDuration; }; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_SOUND_SHOWCASE) withUserInfo:@{ RouterViewModel:soundShowcaseVM } completion:nil]; } else { [ZCHUDHelper showTitle:@"正在审核语音中,请耐心等待" showtime:1.5]; } } #pragma mark - 默认初始化选择器数据 - (void)defaultInitializePickerData{ NSMutableArray *ageDataArray = [NSMutableArray array]; for (int i = 18; i<=60; i++) { [ageDataArray addObject:@{ @"rowName":stringFormat(@"%d岁",i) }]; } self.ageDataArray = ageDataArray.mutableCopy; self.constellationDataArray = @[ @{ @"rowName":@"保密" }, @{ @"rowName":@"白羊座(3.21 - 4.19)" }, @{ @"rowName":@"金牛座(4.20 - 5.20)" }, @{ @"rowName":@"双子座(5.21 - 6.21)" }, @{ @"rowName":@"巨蟹座(6.22 - 7.22)" }, @{ @"rowName":@"狮子座(7.23 - 8.22)" }, @{ @"rowName":@"处女座(8.23 - 9.22)" }, @{ @"rowName":@"天秤座(9.23 - 10.23)" }, @{ @"rowName":@"天蝎座(10.24 - 11.22)" }, @{ @"rowName":@"射手座(11.23 - 12.21)" }, @{ @"rowName":@"摩羯座(12.22 - 1.19)" }, @{ @"rowName":@"水瓶座(1.20 - 2.18)" }, @{ @"rowName":@"双鱼座(2.19 - 3.20)" }, ]; NSMutableArray *heightDataArray = [NSMutableArray array]; for (int i = 60; i<=200; i++) { [heightDataArray addObject:@{ @"rowName":stringFormat(@"%dcm",i) }]; } self.heightDataArray = heightDataArray.mutableCopy; NSMutableArray *weightDataArray = [NSMutableArray array]; for (int i = 40; i<=100; i++) { [weightDataArray addObject:@{ @"rowName":stringFormat(@"%dkg",i) }]; } self.weightDataArray = weightDataArray.mutableCopy; self.annualIncomeDataArray = @[ @{ @"rowName":@"保密" }, @{ @"rowName":@"5万以下" }, @{ @"rowName":@"5万 - 10万" }, @{ @"rowName":@"10万 - 20万" }, @{ @"rowName":@"20万 - 30万" }, @{ @"rowName":@"30万 - 50万" }, @{ @"rowName":@"50万以上" }, ]; self.maritalStatusDataArray = @[ @{ @"rowName":@"单身" }, @{ @"rowName":@"寻爱中" }, @{ @"rowName":@"有伴侣" }, @{ @"rowName":@"已婚" }, @{ @"rowName":@"离异" }, ]; } #pragma mark - 头像选择器 - (void)openAvatarPickerPopupView{ if (self.isHideUserAvatarUnderReview) { TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self]; [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVC]; imagePickerVC.allowTakePicture = YES; imagePickerVC.allowPickingVideo = NO; imagePickerVC.allowPickingImage = YES; imagePickerVC.allowPickingOriginalPhoto = NO; imagePickerVC.showSelectBtn = NO; imagePickerVC.allowCrop = YES; imagePickerVC.sortAscendingByModificationDate = YES; [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { //1通过,0待审核,2,未通过 [LCCommonHttp uploadWithImages:photos Type:@"avatar" successBlock:^(NSArray *ossImagePaths) { NSString *uploadImage = ossImagePaths.firstObject; self.userAvatar = uploadImage; }]; }]; imagePickerVC.modalPresentationStyle = UIModalPresentationFullScreen; [[YMGlobalUtils getCurrentVC] presentViewController:imagePickerVC animated:YES completion:nil]; } else { [ZCHUDHelper showTitle:@"正在审核头像中,请耐心等待" showtime:1.5]; } } #pragma mark - 相册选择器 - (void)openAlbumPickerPopupView{ NSLog(@"可选数量:%ld",6 - self.albumDataArray.count); TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:6 columnNumber:4 delegate:self]; [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVC]; imagePickerVC.selectedAssets = self.selectedAssets; imagePickerVC.allowTakePicture = NO; imagePickerVC.allowTakeVideo = NO; imagePickerVC.allowPickingVideo = NO; imagePickerVC.allowPickingImage = YES; imagePickerVC.showSelectBtn = YES; imagePickerVC.allowPickingOriginalPhoto = YES; imagePickerVC.showSelectedIndex = YES; imagePickerVC.sortAscendingByModificationDate = YES; [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { [self.selectedAssets removeAllObjects]; [self.selectedAssets addObjectsFromArray:assets?:@[]]; [self.addAlbumSubject sendNext:photos]; }]; imagePickerVC.modalPresentationStyle = UIModalPresentationFullScreen; [[YMGlobalUtils getCurrentVC] presentViewController:imagePickerVC animated:YES completion:nil]; } #pragma mark - 年龄选择器 - (void)openAgePickerPopupView{ YMPickerViewModel *pickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"年龄", @"rowDataSource":self.ageDataArray?:@[] } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:pickerVM]; customView.titleText = @"请选择年龄"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { NSLog(@"%@",currentSelectedDataArray); self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeAge: { viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 星座选择器 - (void)openConstellationPickerPopupView{ YMPickerViewModel *constellationPickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"星座", @"rowDataSource":self.constellationDataArray?:@[] } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:constellationPickerVM]; customView.titleText = @"请选择星座"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeConstellation: { self.constellationId = [currentSelectedDataArray.firstObject integerValueForKey:@"currentSelectedRowIndex" defaultValue:0]; viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 家乡选择器 - (void)openHometownPickerPopupView{ YMCityPickerPopupView *customView = [[YMCityPickerPopupView alloc]init]; customView.titleText = @"请选择家乡"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSString * _Nonnull provinceId, NSString * _Nonnull provinceName, NSString * _Nonnull cityId, NSString * _Nonnull cityName) { @strongify(popupView) if (isConfirm) { NSLog(@"%@\n%@\n%@\n%@",provinceId,provinceName,cityId,cityName); NSDictionary *cityCodeDic = [OCUserDefaults objectForKey:kCITY_CODE_DIC]; if (!OCDictionaryIsEmpty(cityCodeDic)) { [cityCodeDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { if ([cityName containsString:obj]) { self.cityId = key; NSLog(@"当前城市Code:%@",self.cityId); *stop = YES; }else{ ///如果选择器返回的城市和列表城市对应不上,在遍历查询一直赋予0,让其设置为“保密” self.cityId = @"0"; } }]; } else if (!OCDictionaryIsEmpty([YMGlobalUtils shared].cityCodeDic)) { [[YMGlobalUtils shared].cityCodeDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { if ([cityName containsString:obj]) { self.cityId = key; NSLog(@"当前城市Code:%@",self.cityId); *stop = YES; }else{ ///如果选择器返回的城市和列表城市对应不上,在遍历查询一直赋予0,让其设置为“保密” self.cityId = @"0"; } }]; } else { } self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeHometown: { viewModel.infoContent = cityName; } break; default: break; } if (OCStringIsEmpty(viewModel.infoContent) || [viewModel.infoContent isEqualToString:@"请完善"]) { viewModel.infoContentColor = HexColorFromRGB(0x9c9c9c); } else { viewModel.infoContentColor = HexColorFromRGB(0x333333); } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 身高选择器 - (void)openHeightPickerPopupView{ YMPickerViewModel *heightPickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"身高", @"rowDataSource":self.heightDataArray?:@[] } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:heightPickerVM]; customView.titleText = @"请选择身高"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeHeight: { viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 体重选择器 - (void)openWeightPickerPopupView{ YMPickerViewModel *weightPickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"体重", @"rowDataSource":self.weightDataArray?:@[] } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:weightPickerVM]; customView.titleText = @"请选择体重"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeWeight: { viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 年收入选择器 - (void)openAnnualIncomePickerPopupView{ YMPickerViewModel *annualIncomePickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"年收入", @"rowDataSource":self.annualIncomeDataArray?:@[] } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:annualIncomePickerVM]; customView.titleText = @"请选择年收入"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeAnnualIncome: { viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 婚姻状态选择器 - (void)openMaritalStatusPickerPopupView{ YMPickerViewModel *maritalStatusPickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"婚姻状态", @"rowDataSource":self.maritalStatusDataArray?:@[] } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:maritalStatusPickerVM]; customView.titleText = @"请选择婚姻状态"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { switch (viewModel.editProfileType) { case YMEditProfileTypeMaritalStatus: { viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; } break; default: break; } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } #pragma mark - 我的标签 - (void)openMyTagPopupView { @weakify(self) YMEditInfoTypeViewModel *editInfoTypeVM = [[YMEditInfoTypeViewModel alloc]initWithParams:@{ ParamsCategoryType:@(YMEditInfoTypeTag), }]; // [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_EDIT_INFO_TYPE) withUserInfo:@{ // RouterViewModel:editInfoTypeVM // } completion:nil]; YMEditInfoTypeViewController *vc = [[YMEditInfoTypeViewController alloc] initWithViewModel:editInfoTypeVM]; // YMEditProfileSelectTagView *customView = [[YMEditProfileSelectTagView alloc]init]; // [customView ym_bindViewModel:editInfoTypeVM]; YMPopupView *popupView = [YMPopupView initWithCustomView:vc.view parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; vc.cancelButnBlock = ^{ [popupView dismiss]; }; vc.saveButnBlock = ^{ [editInfoTypeVM saveEditInfo]; [popupView dismiss]; }; editInfoTypeVM.tagBlock = ^(NSArray * _Nonnull selectedTagArray) { @strongify(self) self.tagDataArray = [selectedTagArray.rac_sequence map:^(YMEditInfoTypeTagCellViewModel * _Nullable cellVM) { YMTagModel *model = [[YMTagModel alloc]init]; model.tag_id = cellVM.tagId; model.name = cellVM.tagText; YMEditInfoTypeTagCellViewModel *viewModel = [[YMEditInfoTypeTagCellViewModel alloc] initWithParams:@{ ParamsModel:model }]; return viewModel; }].array; [popupView dismiss]; [self.refreshUISubject sendNext:@(YMRefreshUI)]; }; UIButton *cancelButn = [UIButton buttonWithType:(UIButtonTypeCustom)]; cancelButn.backgroundColor = [UIColor whiteColor]; cancelButn.titleLabel.font = LCFont(13); [cancelButn setTitle:@"取消" forState:UIControlStateNormal]; [cancelButn setTitleColor:LCTextGray forState:UIControlStateNormal]; WS(weakSelf) [[[cancelButn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [popupView dismiss]; }]; UIButton *saveButn = [UIButton buttonWithType:(UIButtonTypeCustom)]; saveButn.titleLabel.font = LCFont(13); [saveButn setTitle:@"保存" forState:UIControlStateNormal]; [saveButn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; [saveButn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; saveButn.layer.cornerRadius = adapt(8); saveButn.layer.masksToBounds = YES; [[[saveButn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { editInfoTypeVM.tagBlock(vc.viewModel.selectedTagArray); }]; vc.ym_customNavView.hidden = YES; [vc.view addSubview:cancelButn]; [vc.view addSubview:saveButn]; [vc.view mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(popupView); make.height.equalTo(popupView).multipliedBy(0.5); }]; [cancelButn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(vc.view).offset(13); make.left.equalTo(vc.view).offset(13); make.width.mas_equalTo(70); make.height.mas_equalTo(44); }]; [saveButn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(vc.view).offset(13); make.right.equalTo(vc.view).offset(-13); make.width.mas_equalTo(70); make.height.mas_equalTo(44); }]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) // customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { // @strongify(popupView) // if (isConfirm) { // self.infoDataArray = [self.infoDataArray.rac_sequence map:^id _Nullable(YMEditProfileInfoCellViewModel * _Nullable viewModel) { // switch (viewModel.editProfileType) { // // case YMEditProfileTypeMaritalStatus: // { // viewModel.infoContent = [currentSelectedDataArray.firstObject stringValueForKey:@"currentSelectedValue" defaultValue:@""]; // } // break; // default: // break; // } // return viewModel; // }].array; // [self.refreshUISubject sendNext:@(YMRefreshUI)]; // } // [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; // }; [popupView pop]; } - (RACSubject *)addAlbumSubject{ if (!_addAlbumSubject) { _addAlbumSubject = [RACSubject subject]; } return _addAlbumSubject; } - (RACSubject *)deleteAlbumSubject{ if (!_deleteAlbumSubject) { _deleteAlbumSubject = [RACSubject subject]; } return _deleteAlbumSubject; } - (RACSubject *)refreshAlbumSortSubject{ if (!_refreshAlbumSortSubject) { _refreshAlbumSortSubject = [RACSubject subject]; } return _refreshAlbumSortSubject; } - (RACSubject *)editProfileOperationSubject{ if (!_editProfileOperationSubject) { _editProfileOperationSubject = [RACSubject subject]; } return _editProfileOperationSubject; } - (NSMutableArray *)selectedAssets{ if (!_selectedAssets) { _selectedAssets = [NSMutableArray array]; } return _selectedAssets; } @end