123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- //
- // YMMemberPayMethodPopupView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/28.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMMemberPayMethodPopupView.h"
- #import "YMMemberCenterViewModel.h"
- @interface YMMemberPayMethodPopupView ()<UITableViewDataSource, UITableViewDelegate>
- /// 会员中心VM
- @property (nonatomic, strong) YMMemberCenterViewModel *viewModel;
- /// 支付标题标签
- @property (nonatomic, strong) UILabel *payTitleLb;
- /// 支付内容标签
- @property (nonatomic, strong) UILabel *payContentLb;
- /// 关闭按钮
- @property (nonatomic, strong) UIButton *closeBtn;
- /// 支付方式提示标签
- @property (nonatomic, strong) UILabel *payMethodTipsLb;
- /// 容器列表
- @property (nonatomic, strong) UITableView *contentTableView;
- /// 确认按钮
- @property (nonatomic, strong) UIButton *confirmBtn;
- /// 提示标签
- @property (nonatomic, strong) YYLabel *payTipsLb;
- /// 选中支付代码
- @property (nonatomic, copy) NSString *selectedPayCode;
- @end
- @implementation YMMemberPayMethodPopupView
- - (void)ym_setupViews{
- self.backgroundColor = UIColor.whiteColor;
- [self addSubview:self.payTitleLb];
- [self addSubview:self.payContentLb];
- [self addSubview:self.closeBtn];
- [self addSubview:self.payMethodTipsLb];
- [self addSubview:self.contentTableView];
- [self addSubview:self.confirmBtn];
- [self addSubview:self.payTipsLb];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
- [self.payTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(20));
- make.left.equalTo(self).offset(adapt(20));
- make.right.equalTo(self).offset(adapt(-20));
- }];
-
- [self.payContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.payTitleLb.mas_bottom).offset(adapt(20));
- make.left.equalTo(self).offset(adapt(20));
- make.right.equalTo(self).offset(adapt(-20));
- }];
-
- [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.payTitleLb.mas_centerY);
- make.right.equalTo(self).offset(adapt(-20));
- make.width.height.mas_equalTo(adapt(30));
- }];
-
- [self.payMethodTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.payContentLb.mas_bottom).offset(adapt(20));
- make.left.equalTo(self).offset(adapt(10));
- }];
-
- [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.payMethodTipsLb.mas_bottom).offset(adapt(10));
- make.left.equalTo(self);
- make.right.equalTo(self);
- }];
-
- [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentTableView.mas_bottom).offset(adapt(20));
- make.left.equalTo(self).offset(adapt(30));
- make.right.equalTo(self).offset(adapt(-30));
- make.height.mas_equalTo(adapt(45));
- }];
-
- [self.payTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.confirmBtn.mas_centerX);
- make.top.equalTo(self.confirmBtn.mas_bottom).offset(adapt(20));
- make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-35) : adapt(-20));
- make.height.mas_equalTo(adapt(15));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMMemberCenterViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
-
- NSString *payContentStr = stringFormat(@"¥%ld",self.viewModel.payAmount);
- NSMutableAttributedString *payContentAttributed = [[NSMutableAttributedString alloc]initWithString:payContentStr];
- payContentAttributed.yy_font = LCBoldFont(30);
- payContentAttributed.yy_color = HexColorFromRGB(0x37184D);
- payContentAttributed.yy_alignment = NSTextAlignmentCenter;
- [payContentAttributed yy_setFont:LCBoldFont(20) range:[payContentStr rangeOfString:@"¥"]];
- self.payContentLb.attributedText = payContentAttributed;
-
- [self.contentTableView reloadData];
- [self.contentTableView layoutIfNeeded];
- //刷新高度
- CGFloat contentTableViewHeight = self.contentTableView.contentSize.height;
- [self.contentTableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(contentTableViewHeight);
- }];
-
- ///默认选中
- if ([YMGlobalUtils shared].payMethodDataArray.count > 0) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- [self.contentTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
- [self tableView:self.contentTableView didSelectRowAtIndexPath:indexPath];
- }
-
- NSString *payTipsTitle = @"开通即同意";
- NSString *payTipsContent = stringFormat(@"《%@会员协议》",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]);
- NSString *payTipsStr = stringFormat(@"%@%@",payTipsTitle,payTipsContent);
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:payTipsStr];
- attributedString.yy_font = LCFont(12);
- attributedString.yy_color = HexColorFromRGB(0x979797);
- //设置高亮色和点击事件
- [attributedString yy_setTextHighlightRange:[payTipsStr rangeOfString:payTipsContent] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
- if (self.dismissBlock) {
- self.dismissBlock();
- }
- YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
- ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,MemberProtocolH5]
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
- RouterViewModel:webArticleVM
- } completion:nil];
- }];
-
- self.payTipsLb.attributedText = attributedString;
-
- CGFloat payTitleLbHeight = [self.payTitleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat payContentLbHeight = [self.payContentLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat payMethodTipsLbHeight = [self.payMethodTipsLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat confirmBtnHeight = [self.confirmBtn systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat payTipsLbHeight = [self.payTipsLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- self.frame = CGRectMake(0, 0, kFrameWidth, adapt(20) + payTitleLbHeight + adapt(20) + payContentLbHeight + adapt(20) + payMethodTipsLbHeight + adapt(10) + contentTableViewHeight + adapt(20) + confirmBtnHeight + adapt(20) + payTipsLbHeight + (Is_iPhoneX ? adapt(35) : adapt(20)));
-
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [YMGlobalUtils shared].payMethodDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- YMMemberPayMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMMemberPayMethodCell class])];
- if (!cell) {
- cell = [[YMMemberPayMethodCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMMemberPayMethodCell class])];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell ym_bindViewModel:[YMGlobalUtils shared].payMethodDataArray[indexPath.item]];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return adapt(70);
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- self.selectedPayCode = [YMGlobalUtils shared].payMethodDataArray[indexPath.item].payCode;
- }
- - (UILabel *)payTitleLb{
- if (!_payTitleLb) {
- _payTitleLb = [[UILabel alloc]init];
- _payTitleLb.font = LCFont(14);
- _payTitleLb.textColor = HexColorFromRGB(0x333333);
- _payTitleLb.textAlignment = NSTextAlignmentCenter;
- _payTitleLb.text = @"支付方式";
- }
- return _payTitleLb;
- }
- - (UILabel *)payContentLb{
- if (!_payContentLb) {
- _payContentLb = [[UILabel alloc]init];
- _payContentLb.font = LCBoldFont(30);
- _payContentLb.textColor = HexColorFromRGB(0x333333);
- _payContentLb.textAlignment = NSTextAlignmentCenter;
- _payContentLb.text = @"¥*****";
- }
- return _payContentLb;
- }
- - (UIButton *)closeBtn{
- if (!_closeBtn) {
- _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeBtn setBackgroundImage:ImageByName(@"ym_common_close_icon") forState:UIControlStateNormal];
- WS(weakSelf)
- [[[_closeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(NO, @"");
- }
- }];
- }
- return _closeBtn;
- }
- - (UILabel *)payMethodTipsLb{
- if (!_payMethodTipsLb) {
- _payMethodTipsLb = [[UILabel alloc]init];
- _payMethodTipsLb.font = LCFont(11);
- _payMethodTipsLb.textColor = HexColorFromRGB(0x9b9b9b);
- _payMethodTipsLb.textAlignment = NSTextAlignmentLeft;
- _payMethodTipsLb.text = @"请选择支付方式";
- }
- return _payMethodTipsLb;
- }
- - (UITableView *)contentTableView{
- if (!_contentTableView) {
- _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _contentTableView.delegate = self;
- _contentTableView.dataSource = self;
- _contentTableView.estimatedRowHeight = 0;
- _contentTableView.estimatedSectionHeaderHeight = 0;
- _contentTableView.estimatedSectionFooterHeight = 0;
- _contentTableView.showsVerticalScrollIndicator = NO;
- _contentTableView.showsHorizontalScrollIndicator = NO;
- _contentTableView.separatorColor = UIColor.clearColor;
- _contentTableView.backgroundColor = UIColor.whiteColor;
- _contentTableView.scrollEnabled = NO;
- [_contentTableView registerClass:[YMMemberPayMethodCell class] forCellReuseIdentifier:NSStringFromClass([YMMemberPayMethodCell class])];
- }
- return _contentTableView;
- }
- - (UIButton *)confirmBtn {
- if(!_confirmBtn){
- _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _confirmBtn.titleLabel.font = LCFont(15);
- [_confirmBtn setTitle:@"确认支付" forState:UIControlStateNormal];
- [_confirmBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
- _confirmBtn.layer.cornerRadius = adapt(10);
- [_confirmBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
- WS(weakSelf)
- [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(YES,weakSelf.selectedPayCode);
- }
- }];
- }
- return _confirmBtn;
- }
- - (YYLabel *)payTipsLb{
- if (!_payTipsLb) {
- _payTipsLb = [[YYLabel alloc]init];
-
- }
- return _payTipsLb;
- }
- @end
- @interface YMMemberPayMethodCell()
- /// ViewModel
- @property (nonatomic, strong) YMPayMethodCellViewModel *viewModel;
- /// 基础视图
- @property (nonatomic, strong) UIView *baseView;
- /// 支付方式图标
- @property (nonatomic, strong) UIImageView *payMethodIcon;
- /// 支付方式标题标签
- @property (nonatomic, strong) UILabel *payMethodTitleLb;
- /// 选中图标
- @property (nonatomic, strong) UIImageView *selectedIcon;
- @end
- @implementation YMMemberPayMethodCell
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- if (selected) {
- self.selectedIcon.image = ImageByName(@"ym_member_center_pay_selected_icon");
- } else {
- self.selectedIcon.image = ImageByName(@"ym_member_center_pay_normal_icon");
- }
- }
- - (void)ym_setupViews{
- self.contentView.backgroundColor = UIColor.clearColor;
- self.backgroundColor = UIColor.clearColor;
-
- [self.contentView addSubview:self.baseView];
- [self.baseView addSubview:self.payMethodIcon];
- [self.baseView addSubview:self.payMethodTitleLb];
- [self.baseView addSubview:self.selectedIcon];
-
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints {
- [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(adapt(10));
- make.left.equalTo(self.contentView).offset(adapt(10));
- make.right.equalTo(self.contentView).offset(adapt(-10));
- make.bottom.equalTo(self.contentView);
- }];
-
- [self.payMethodIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.baseView.mas_centerY);
- make.left.equalTo(self.baseView).offset(adapt(15));
- make.width.height.mas_equalTo(adapt(18));
- }];
-
- [self.payMethodTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.baseView.mas_centerY);
- make.left.equalTo(self.payMethodIcon.mas_right).offset(adapt(10));
- }];
- [self.selectedIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.baseView.mas_centerY);
- make.right.equalTo(self.baseView).offset(adapt(-15));
- make.width.height.mas_equalTo(adapt(20));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMPayMethodCellViewModel*)viewModel{
- if (!viewModel) {
- return;
- }
- _viewModel = viewModel;
-
- self.payMethodIcon.image = ImageByName(self.viewModel.payIcon);
- self.payMethodTitleLb.text = self.viewModel.payTitle;
-
- }
- - (UIView *)baseView{
- if (!_baseView) {
- _baseView = [[UIView alloc]init];
- _baseView.backgroundColor = HexColorFromRGB(0xf6f6f6);
- _baseView.layer.cornerRadius = adapt(8);
- _baseView.layer.masksToBounds = YES;
- }
- return _baseView;
- }
- - (UIImageView *)payMethodIcon{
- if (!_payMethodIcon) {
- _payMethodIcon = [[UIImageView alloc]init];
- }
- return _payMethodIcon;
- }
- - (UILabel *)payMethodTitleLb{
- if (!_payMethodTitleLb) {
- _payMethodTitleLb = [[UILabel alloc]init];
- _payMethodTitleLb.font = LCFont(14);
- _payMethodTitleLb.textColor = HexColorFromRGB(0x333333);
- _payMethodTitleLb.textAlignment = NSTextAlignmentLeft;
- _payMethodTitleLb.text = @"******";
- }
- return _payMethodTitleLb;
- }
- - (UIImageView *)selectedIcon{
- if (!_selectedIcon) {
- _selectedIcon = [[UIImageView alloc]init];
- _selectedIcon.image = ImageByName(@"ym_member_center_pay_normal_icon");
- }
- return _selectedIcon;
- }
- @end
|