RQActivateVIPViewController.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // RQActivateVIPViewController.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/9/9.
  6. //
  7. #import "RQActivateVIPViewController.h"
  8. @interface RQActivateVIPViewController ()
  9. @property (nonatomic, readonly, strong) RQActivateVIPViewModel *viewModel;
  10. @property (weak, nonatomic) IBOutlet UIView *containerView;
  11. @property (weak, nonatomic) IBOutlet UIView *myHeaderView;
  12. @property (nonatomic, readwrite, strong) RQActivateVIPCodeView *activateVIPCodeView;
  13. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelToTop;
  14. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelHeight;
  15. @property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
  16. @property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
  17. @property (weak, nonatomic) IBOutlet UIButton *openBtn;
  18. @property (weak, nonatomic) IBOutlet UIView *activationCodeView;
  19. @property (weak, nonatomic) IBOutlet UIView *wechatView;
  20. @property (weak, nonatomic) IBOutlet UILabel *vipPriceOriginalLabel;
  21. @property (weak, nonatomic) IBOutlet UILabel *vipPriceLabel;
  22. @end
  23. @implementation RQActivateVIPViewController
  24. @dynamic viewModel;
  25. #pragma mark - SystemMethod
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. /// 设置
  29. [self rq_setup];
  30. /// 设置子控件
  31. [self rq_setupSubViews];
  32. /// 初始化部分数据
  33. [self rq_configureData];
  34. }
  35. #pragma mark - Override
  36. - (void)bindViewModel{
  37. [super bindViewModel];
  38. @weakify(self);
  39. /// 激活码
  40. RAC(self.viewModel , activateVIPCode) = [RACSignal merge:@[RACObserve(self.activateVIPCodeView.activateVIPCodeTextField, text),self.activateVIPCodeView.activateVIPCodeTextField.rac_textSignal]];
  41. /// 开通按钮有效性
  42. RAC(self.openBtn , enabled) = self.viewModel.validOpenSignal;
  43. [RACObserve(self.viewModel, vipPrice) subscribeNext:^(id _Nullable x) {
  44. @strongify(self)
  45. if (RQStringIsNotEmpty(self.viewModel.vipPrice)) {
  46. NSMutableAttributedString *vipPriceMutableStr = [[NSMutableAttributedString alloc] initWithString:self.viewModel.vipPrice];
  47. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
  48. [vipPriceMutableStr appendAttributedString:attr];
  49. self.vipPriceLabel.attributedText = vipPriceMutableStr;
  50. }
  51. }];
  52. [RACObserve(self.viewModel, vipPriceOriginal) subscribeNext:^(id _Nullable x) {
  53. @strongify(self)
  54. if (RQStringIsNotEmpty(self.viewModel.vipPriceOriginal)) {
  55. NSMutableAttributedString *vipPriceOriginalMutableStr = [[NSMutableAttributedString alloc] initWithString:self.viewModel.vipPriceOriginal attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  56. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
  57. [vipPriceOriginalMutableStr appendAttributedString:attr1];
  58. self.vipPriceOriginalLabel.attributedText = vipPriceOriginalMutableStr;
  59. }
  60. }];
  61. /// show HUD
  62. [[[self.viewModel.openCommand.executing
  63. skip:1]
  64. doNext:^(id x) {
  65. @strongify(self)
  66. [self.view endEditing:YES];
  67. }]
  68. subscribeNext:^(NSNumber * showHud) {
  69. @strongify(self);
  70. if (showHud.boolValue) {
  71. [MBProgressHUD rq_showProgressHUD:@"请稍后..."];
  72. }else if(!self.viewModel.error){
  73. [MBProgressHUD rq_hideHUD];
  74. }
  75. }];
  76. [self.viewModel.getVipPriceCommand execute:nil];
  77. // [self.viewModel.getVipPriceOrriginalCommand execute:nil];
  78. /// show errors
  79. [self.viewModel.openCommand.errors subscribeNext:^(NSError * error) {
  80. [MBProgressHUD rq_showErrorTips:error];
  81. }];
  82. [self.viewModel.getVipPriceCommand.errors subscribeNext:^(NSError * error) {
  83. [MBProgressHUD rq_showErrorTips:error];
  84. }];
  85. // [self.viewModel.getVipPriceOrriginalCommand.errors subscribeNext:^(NSError * error) {
  86. // [MBProgressHUD rq_showErrorTips:error];
  87. // }];
  88. }
  89. #pragma mark - PrivateMethods
  90. - (void)rq_setup {
  91. @weakify(self)
  92. /// 设置contentSize
  93. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.width.mas_equalTo(RQ_SCREEN_WIDTH);
  95. make.height.mas_equalTo(RQ_SCREEN_HEIGHT);
  96. }];
  97. UIScrollView *scrollView = (UIScrollView *)self.view;
  98. scrollView.alwaysBounceVertical = YES;
  99. scrollView.showsHorizontalScrollIndicator = NO;
  100. scrollView.showsVerticalScrollIndicator = NO;
  101. /// 适配 iOS 11
  102. RQAdjustsScrollViewInsets_Never(scrollView);
  103. _titleLabelToTop.constant = RQ_APPLICATION_STATUS_BAR_HEIGHT;
  104. _titleLabelHeight.constant = RQ_APPLICATION_NAV_BAR_HEIGHT;
  105. [_openBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_COLOR size:_openBtn.size cornerRadius:20.f] forState:UIControlStateNormal];
  106. [_openBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_BACKGROUNDCOLOR_2 size:_openBtn.size cornerRadius:20.f] forState:UIControlStateDisabled];
  107. _activationCodeView.layer.borderWidth = 1;
  108. _activationCodeView.layer.borderColor = RQColorFromHexString(@"#498EF5").CGColor;
  109. _activationCodeView.layer.shadowColor = [UIColor colorWithHexString:@"#8DABFF" alpha:0.16].CGColor;
  110. _wechatView.layer.borderWidth = 1;
  111. _wechatView.layer.borderColor = RQColorFromHexString(@"#01C18D").CGColor;
  112. _wechatView.layer.shadowColor = [UIColor colorWithHexString:@"#8DABFF" alpha:0.16].CGColor;
  113. NSMutableAttributedString *vipPriceMutableStr = [[NSMutableAttributedString alloc] initWithString:_vipPriceLabel.text];
  114. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
  115. [vipPriceMutableStr appendAttributedString:attr];
  116. _vipPriceLabel.attributedText = vipPriceMutableStr;
  117. NSMutableAttributedString *vipPriceOriginalMutableStr = [[NSMutableAttributedString alloc] initWithString:_vipPriceOriginalLabel.text attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  118. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:@"元" attributes:@{NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:RQColorFromHexString(@"#FF4D53"),NSFontAttributeName:[UIFont systemFontOfSize:16.0]}];
  119. [vipPriceOriginalMutableStr appendAttributedString:attr1];
  120. _vipPriceOriginalLabel.attributedText = vipPriceOriginalMutableStr;
  121. [_wechatView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  122. @strongify(self)
  123. [self.viewModel.openCommand execute:nil];
  124. }];
  125. [_activationCodeView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  126. [RQ_Profile_Module showVIPAlertWithComplete:^(BOOL isSuccess) {
  127. if (isSuccess) {
  128. }
  129. }];
  130. }];
  131. }
  132. - (void)rq_setupSubViews {
  133. /// 激活码
  134. RQActivateVIPCodeView *activateVIPCodeView = [RQActivateVIPCodeView activateVIPCodeView];
  135. self.activateVIPCodeView = activateVIPCodeView;
  136. // [self.containerView addSubview:activateVIPCodeView];
  137. // [activateVIPCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
  138. // make.top.mas_equalTo(self.myHeaderView.mas_bottom).mas_offset(8.f);
  139. // make.left.right.mas_equalTo(self.containerView).mas_offset(0.f);
  140. // make.height.mas_offset(45.f);
  141. // }];
  142. }
  143. - (void)rq_configureData {
  144. @weakify(self)
  145. RAC(_nicknameLabel, text) = RACObserve(RQ_USER_MANAGER, nickName);
  146. [_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) {
  147. @strongify(self)
  148. if(image) {
  149. image = [image scaledToSize:CGSizeMake(54, 54)];
  150. image = [image qmui_imageWithClippedCornerRadius:27];
  151. self.headerImageView.image = image;
  152. }
  153. }];
  154. }
  155. - (IBAction)actiVateBtnAction:(id)sender {
  156. [self.viewModel.openCommand execute:nil];
  157. }
  158. - (IBAction)backAction:(id)sender {
  159. [self.viewModel.closeCommand execute:nil];
  160. }
  161. @end