123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- //
- // RQActivateVIPViewController.m
- // SDJK
- //
- // Created by 张嵘 on 2021/9/9.
- //
- #import "RQActivateVIPViewController.h"
- @interface RQActivateVIPViewController ()
- @property (nonatomic, readonly, strong) RQActivateVIPViewModel *viewModel;
- @property (weak, nonatomic) IBOutlet UIView *containerView;
- @property (weak, nonatomic) IBOutlet UIView *myHeaderView;
- @property (nonatomic, readwrite, strong) RQActivateVIPCodeView *activateVIPCodeView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelToTop;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelHeight;
- @property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
- @property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
- @property (weak, nonatomic) IBOutlet UIButton *openBtn;
- @property (weak, nonatomic) IBOutlet UIView *activationCodeView;
- @property (weak, nonatomic) IBOutlet UIView *wechatView;
- @property (weak, nonatomic) IBOutlet UILabel *vipPriceOriginalLabel;
- @property (weak, nonatomic) IBOutlet UILabel *vipPriceLabel;
- @end
- @implementation RQActivateVIPViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 设置
- [self rq_setup];
- /// 设置子控件
- [self rq_setupSubViews];
- /// 初始化部分数据
- [self rq_configureData];
- }
- #pragma mark - Override
- - (void)bindViewModel{
- [super bindViewModel];
-
- @weakify(self);
- /// 激活码
- RAC(self.viewModel , activateVIPCode) = [RACSignal merge:@[RACObserve(self.activateVIPCodeView.activateVIPCodeTextField, text),self.activateVIPCodeView.activateVIPCodeTextField.rac_textSignal]];
- /// 开通按钮有效性
- RAC(self.openBtn , enabled) = self.viewModel.validOpenSignal;
-
- [RACObserve(self.viewModel, vipPrice) subscribeNext:^(id _Nullable x) {
- @strongify(self)
- if (RQStringIsNotEmpty(self.viewModel.vipPrice)) {
- NSMutableAttributedString *vipPriceMutableStr = [[NSMutableAttributedString alloc] initWithString:self.viewModel.vipPrice];
-
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
- [vipPriceMutableStr appendAttributedString:attr];
- self.vipPriceLabel.attributedText = vipPriceMutableStr;
- }
- }];
-
- [RACObserve(self.viewModel, vipPriceOriginal) subscribeNext:^(id _Nullable x) {
- @strongify(self)
- if (RQStringIsNotEmpty(self.viewModel.vipPriceOriginal)) {
- NSMutableAttributedString *vipPriceOriginalMutableStr = [[NSMutableAttributedString alloc] initWithString:self.viewModel.vipPriceOriginal attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
- NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
- [vipPriceOriginalMutableStr appendAttributedString:attr1];
- self.vipPriceOriginalLabel.attributedText = vipPriceOriginalMutableStr;
- }
- }];
-
- /// show HUD
- [[[self.viewModel.openCommand.executing
- skip:1]
- doNext:^(id x) {
- @strongify(self)
- [self.view endEditing:YES];
- }]
- subscribeNext:^(NSNumber * showHud) {
- @strongify(self);
- if (showHud.boolValue) {
- [MBProgressHUD rq_showProgressHUD:@"请稍后..."];
- }else if(!self.viewModel.error){
- [MBProgressHUD rq_hideHUD];
- }
- }];
-
- [self.viewModel.getVipPriceCommand execute:nil];
- // [self.viewModel.getVipPriceOrriginalCommand execute:nil];
- /// show errors
- [self.viewModel.openCommand.errors subscribeNext:^(NSError * error) {
- [MBProgressHUD rq_showErrorTips:error];
- }];
-
- [self.viewModel.getVipPriceCommand.errors subscribeNext:^(NSError * error) {
- [MBProgressHUD rq_showErrorTips:error];
- }];
-
- // [self.viewModel.getVipPriceOrriginalCommand.errors subscribeNext:^(NSError * error) {
- // [MBProgressHUD rq_showErrorTips:error];
- // }];
-
- }
- #pragma mark - PrivateMethods
- - (void)rq_setup {
- @weakify(self)
- /// 设置contentSize
- [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(RQ_SCREEN_WIDTH);
- make.height.mas_equalTo(RQ_SCREEN_HEIGHT);
- }];
- UIScrollView *scrollView = (UIScrollView *)self.view;
- scrollView.alwaysBounceVertical = YES;
- scrollView.showsHorizontalScrollIndicator = NO;
- scrollView.showsVerticalScrollIndicator = NO;
-
- /// 适配 iOS 11
- RQAdjustsScrollViewInsets_Never(scrollView);
-
- _titleLabelToTop.constant = RQ_APPLICATION_STATUS_BAR_HEIGHT;
- _titleLabelHeight.constant = RQ_APPLICATION_NAV_BAR_HEIGHT;
-
- [_openBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_COLOR size:_openBtn.size cornerRadius:20.f] forState:UIControlStateNormal];
- [_openBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_BACKGROUNDCOLOR_2 size:_openBtn.size cornerRadius:20.f] forState:UIControlStateDisabled];
-
- _activationCodeView.layer.borderWidth = 1;
- _activationCodeView.layer.borderColor = RQColorFromHexString(@"#498EF5").CGColor;
- _activationCodeView.layer.shadowColor = [UIColor colorWithHexString:@"#8DABFF" alpha:0.16].CGColor;
-
-
- _wechatView.layer.borderWidth = 1;
- _wechatView.layer.borderColor = RQColorFromHexString(@"#01C18D").CGColor;
- _wechatView.layer.shadowColor = [UIColor colorWithHexString:@"#8DABFF" alpha:0.16].CGColor;
-
-
- NSMutableAttributedString *vipPriceMutableStr = [[NSMutableAttributedString alloc] initWithString:_vipPriceLabel.text];
-
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
- [vipPriceMutableStr appendAttributedString:attr];
- _vipPriceLabel.attributedText = vipPriceMutableStr;
-
- NSMutableAttributedString *vipPriceOriginalMutableStr = [[NSMutableAttributedString alloc] initWithString:_vipPriceOriginalLabel.text attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
- NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
- [vipPriceOriginalMutableStr appendAttributedString:attr1];
- _vipPriceOriginalLabel.attributedText = vipPriceOriginalMutableStr;
-
- [_wechatView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- @strongify(self)
- [self.viewModel.openCommand execute:nil];
- }];
-
- [_activationCodeView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- [RQ_Profile_Module showVIPAlertWithComplete:^(BOOL isSuccess) {
- if (isSuccess) {
- }
- }];
- }];
- }
- - (void)rq_setupSubViews {
- /// 激活码
- RQActivateVIPCodeView *activateVIPCodeView = [RQActivateVIPCodeView activateVIPCodeView];
- self.activateVIPCodeView = activateVIPCodeView;
- // [self.containerView addSubview:activateVIPCodeView];
-
- // [activateVIPCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.mas_equalTo(self.myHeaderView.mas_bottom).mas_offset(8.f);
- // make.left.right.mas_equalTo(self.containerView).mas_offset(0.f);
- // make.height.mas_offset(45.f);
- // }];
- }
- - (void)rq_configureData {
- @weakify(self)
- RAC(_nicknameLabel, text) = RACObserve(RQ_USER_MANAGER, nickName);
-
- [_headerImageView yy_setImageWithURL:[NSURL URLWithString:RQ_USER_MANAGER.headImage] placeholder:RQWebAvatarImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
- @strongify(self)
- if(image) {
- image = [image scaledToSize:CGSizeMake(54, 54)];
- image = [image qmui_imageWithClippedCornerRadius:27];
- self.headerImageView.image = image;
- }
- }];
- }
- - (IBAction)actiVateBtnAction:(id)sender {
- [self.viewModel.openCommand execute:nil];
- }
- - (IBAction)backAction:(id)sender {
- [self.viewModel.closeCommand execute:nil];
- }
- @end
|