// // YMImproveInfoViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/8. // Copyright © 2024 MS. All rights reserved. // #import "YMImproveInfoViewController.h" #import "YMImproveInfoViewModel.h" #import "YMImproveInfoAvatarView.h" #import "YMImproveInfoMaleNicknameView.h" #import "YMImproveInfoFemaleNicknameView.h" #import "YMImproveInfoGenderView.h" #import "YMImproveInfoAgeView.h" #import "YMImproveInfoInviteCodeView.h" #import "PGDatePickManager.h" #import @interface YMImproveInfoViewController () /// 完善信息VM @property (nonatomic, strong) YMImproveInfoViewModel *viewModel; /// 容器滚动视图 @property (nonatomic, strong) UIScrollView *contentScrollView; @property (nonatomic, strong) UIImageView *topImgV; /// 容器视图 @property (nonatomic, strong) UIView *contentView; /// 完善信息标签 @property (nonatomic, strong) UILabel *improveInfoLb; @property (nonatomic, strong) UILabel *tipLb; /// 头像视图 @property (nonatomic, strong) YMImproveInfoAvatarView *avatarView; /// 男性昵称视图 @property (nonatomic, strong) YMImproveInfoMaleNicknameView *maleNicknameView; /// 女性昵称视图 @property (nonatomic, strong) YMImproveInfoFemaleNicknameView *femaleNicknameView; /// 性别视图 @property (nonatomic, strong) YMImproveInfoGenderView *genderView; /// 年龄视图 @property (nonatomic, strong) YMImproveInfoAgeView *ageView; /// 邀请码视图 //@property (nonatomic, strong) YMImproveInfoInviteCodeView *inviteCodeView; @property (nonatomic, strong) UILabel *alertLb; /// 开启缘分按钮 @property (nonatomic, strong) UIButton *openOpportunityBtn; @end @implementation YMImproveInfoViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = UIColor.whiteColor; IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; keyboardManager.enable = YES; self.isHideLeftItem = YES; [self setNavHidden:YES]; UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, adapt(438))]; imgV.image = ImageByName(@"ym_improve_info_top_bg"); imgV.userInteractionEnabled = true; [self.view addSubview:imgV]; UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [leftBtn setImage:ImageByName(@"ym_navigation_black_icon") forState:UIControlStateNormal]; [[[leftBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; customView.cancelTitle = @"取消"; customView.confirmTitle = @"放弃"; customView.confirmBgColor = HexColorFromRGB(0x7CF997); customView.confirmTitleColor = HexColorFromRGB(0x000000); [customView configutationWithTips:@"是否放弃完善信息?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { [LCTools changeRootToLogin]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; }]; [self.view addSubview:leftBtn]; [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(kYMNavHeight-adapt(40)); make.left.equalTo(self.view).offset(8); make.width.height.mas_equalTo(adapt(40)); }]; // [self setLeftBarButtonWithImage:@"ym_navigation_black_icon" block:^(id _Nonnull sender) { // YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; // customView.cancelTitle = @"取消"; // customView.confirmTitle = @"放弃"; // customView.confirmBgColor = HexColorFromRGB(0x7CF997); // customView.confirmTitleColor = HexColorFromRGB(0x000000); // [customView configutationWithTips:@"是否放弃完善信息?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES]; // YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; // popupView.priority = 999; // popupView.cornerRadius = adapt(10); // popupView.rectCorners = UIRectCornerAllCorners; // popupView.positionStyle = YMPositionStyleCenter; // popupView.isHideBg = NO; // popupView.bgAlpha = 0.3; // @weakify(popupView) // customView.buttonBlock = ^(BOOL isConfirm) { // @strongify(popupView) // if (isConfirm) { // [LCTools changeRootToLogin]; // } // [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; // }; // [popupView pop]; // // }]; [UMengRecordTool umengEventCountWithId:EnterRegistration]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [UMengRecordTool umengEnterViewWithName:NSStringFromClass(self.class)]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [UMengRecordTool umengOutViewWithName:NSStringFromClass(self.class)]; } - (void)ym_setupViews{ // [self.view addSubview:self.topImgV]; // [self.view addSubview:self.contentScrollView]; [self.view addSubview:self.contentView]; [self.contentView addSubview:self.improveInfoLb]; [self.contentView addSubview:self.tipLb]; [self.contentView addSubview:self.avatarView]; [self.contentView addSubview:self.maleNicknameView]; [self.contentView addSubview:self.femaleNicknameView]; [self.contentView addSubview:self.ageView]; [self.contentView addSubview:self.genderView]; // [self.contentView addSubview:self.inviteCodeView]; [self.view addSubview:self.alertLb]; [self.view addSubview:self.openOpportunityBtn]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ // [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.view).offset(kYMNavHeight); // make.left.equalTo(self.view); // make.right.equalTo(self.view); // }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(kYMNavHeight); make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view); }]; // [self.topImgV mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.view); // make.left.equalTo(self.view); // make.right.equalTo(self.view); // make.height.mas_equalTo(adapt(460)); // }]; [self.improveInfoLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(adapt(10)); make.left.equalTo(self.contentView).offset(adapt(30)); }]; [self.tipLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.improveInfoLb.mas_bottom).offset(adapt(5)); make.left.equalTo(self.improveInfoLb); }]; [self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tipLb.mas_bottom).offset(adapt(18)); make.left.equalTo(self.contentView).offset(adapt(30)); make.width.height.mas_equalTo(adapt(96)); }]; [self.maleNicknameView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.avatarView.mas_bottom).offset(adapt(30)); make.left.equalTo(self.contentView).offset(30); make.right.equalTo(self.contentView).offset(-30); make.height.mas_equalTo(adapt(75)); }]; [self.femaleNicknameView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.avatarView.mas_bottom).offset(adapt(30)); make.left.equalTo(self.contentView).offset(30); make.right.equalTo(self.contentView).offset(-30); make.height.mas_equalTo(adapt(75)); }]; [self.genderView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.maleNicknameView.mas_bottom).offset(adapt(20)); make.left.equalTo(self.contentView).offset(30); make.right.equalTo(self.contentView).offset(-30); make.height.mas_equalTo(adapt(75)); }]; [self.ageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.genderView.mas_bottom).offset(adapt(20)); make.left.equalTo(self.contentView).offset(30); make.right.equalTo(self.contentView).offset(-30); make.height.mas_equalTo(adapt(75)); }]; // [self.inviteCodeView mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.ageView.mas_bottom).offset(adapt(28)); // make.left.equalTo(self.contentView); // make.right.equalTo(self.contentView); // make.bottom.equalTo(self.contentView).offset(adapt(-10)); // }]; [self.openOpportunityBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(adapt(40)); make.right.equalTo(self.view).offset(adapt(-40)); make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12)); make.height.mas_equalTo(adapt(54)); }]; [self.alertLb mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(adapt(20)); make.right.equalTo(self.view).offset(adapt(-20)); make.bottom.equalTo(self.openOpportunityBtn.mas_top).offset(adapt(-10)); make.height.mas_equalTo(adapt(17)); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel{ [self.avatarView ym_bindViewModel:self.viewModel]; [self.maleNicknameView ym_bindViewModel:self.viewModel]; [self.femaleNicknameView ym_bindViewModel:self.viewModel]; [self.genderView ym_bindViewModel:self.viewModel]; [self.ageView ym_bindViewModel:self.viewModel]; // [self.inviteCodeView ym_bindViewModel:self.viewModel]; [self.viewModel getNicknameOrAvatarData]; @weakify(self) [[[[RACObserve(self.viewModel, genderType) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) { @strongify(self) switch ([value intValue]) { case 2: { self.maleNicknameView.hidden = NO; self.femaleNicknameView.hidden = YES; self.openOpportunityBtn.enabled = YES; self.openOpportunityBtn.alpha = 1; } break; case 1: { self.maleNicknameView.hidden = YES; self.femaleNicknameView.hidden = NO; [self.viewModel.validImproveInfoSignal subscribeNext:^(id _Nullable value) { self.openOpportunityBtn.enabled = [value boolValue]; if ([value boolValue]) { self.openOpportunityBtn.alpha = 1; } else { self.openOpportunityBtn.alpha = 0.5; } }]; } break; default: break; } [self.viewModel randomAvatar]; }]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view resignFirstResponder]; } - (UIScrollView *)contentScrollView{ if (!_contentScrollView) { _contentScrollView = [[UIScrollView alloc]init]; _contentScrollView.alwaysBounceVertical = YES; _contentScrollView.showsVerticalScrollIndicator = NO; _contentScrollView.showsHorizontalScrollIndicator = NO; _contentScrollView.backgroundColor = UIColor.whiteColor; _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; } return _contentScrollView; } - (UIView *)contentView{ if (!_contentView) { _contentView = [[UIView alloc]init]; } return _contentView; } - (UIImageView *)topImgV{ if (!_topImgV) { _topImgV = [[UIImageView alloc]init]; _topImgV.image = ImageByName(@"ym_improve_info_top_bg"); _topImgV.userInteractionEnabled = YES; } return _topImgV; } - (UILabel *)improveInfoLb{ if (!_improveInfoLb) { _improveInfoLb = [[UILabel alloc]init]; _improveInfoLb.font = LCBoldFont(22); _improveInfoLb.textColor = HexColorFromRGB(0x1B2739); _improveInfoLb.textAlignment = NSTextAlignmentLeft; _improveInfoLb.text = @"完善资料"; _improveInfoLb.numberOfLines = 0; } return _improveInfoLb; } - (UILabel *)tipLb{ if (!_tipLb) { _tipLb = [[UILabel alloc]init]; _tipLb.font = LCFont(14); _tipLb.textColor = HexColorFromRGBA(0x000000,0.35); _tipLb.textAlignment = NSTextAlignmentLeft; _tipLb.text = @"让大家更好的了解你"; _tipLb.numberOfLines = 0; } return _tipLb; } - (UILabel *)alertLb{ if (!_alertLb) { _alertLb = [[UILabel alloc]init]; _alertLb.font = LCFont(12); _alertLb.textColor = HexColorFromRGBA(0xF04747,1); _alertLb.textAlignment = NSTextAlignmentCenter; _alertLb.text = @"性别填写后不可修改,请准确填写哦!"; _alertLb.numberOfLines = 1; } return _alertLb; } - (YMImproveInfoAvatarView *)avatarView{ if (!_avatarView) { _avatarView = [[YMImproveInfoAvatarView alloc]init]; } return _avatarView; } - (YMImproveInfoMaleNicknameView *)maleNicknameView{ if (!_maleNicknameView) { _maleNicknameView = [[YMImproveInfoMaleNicknameView alloc]init]; _maleNicknameView.hidden = NO; } return _maleNicknameView; } - (YMImproveInfoFemaleNicknameView *)femaleNicknameView{ if (!_femaleNicknameView) { _femaleNicknameView = [[YMImproveInfoFemaleNicknameView alloc]init]; _femaleNicknameView.hidden = YES; } return _femaleNicknameView; } - (YMImproveInfoGenderView *)genderView{ if (!_genderView) { _genderView = [[YMImproveInfoGenderView alloc]init]; } return _genderView; } - (YMImproveInfoAgeView *)ageView{ if (!_ageView) { _ageView = [[YMImproveInfoAgeView alloc]init]; _ageView.userInteractionEnabled = YES; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_ageView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel openAgePickerPopupView]; }]; } return _ageView; } - (UIButton *)openOpportunityBtn{ if (!_openOpportunityBtn) { _openOpportunityBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _openOpportunityBtn.titleLabel.font = LCBoldFont(15); [_openOpportunityBtn setTitle:@"开启缘分" forState:UIControlStateNormal]; [_openOpportunityBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; [_openOpportunityBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; _openOpportunityBtn.layer.cornerRadius = adapt(27); _openOpportunityBtn.layer.masksToBounds = true; WS(weakSelf) [[[_openOpportunityBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; customView.confirmBgColor = kMainGradColor2; customView.confirmTitleColor = HexColorFromRGB(0xFFFFFF); [customView configutationWithTips:@"性别选择后,将无法修改,请确认你的性别" TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { [weakSelf.viewModel submitImproverInfoData]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; }]; } return _openOpportunityBtn; } @end