YMMemberPayMethodPopupView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. //
  2. // YMMemberPayMethodPopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/28.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMMemberPayMethodPopupView.h"
  9. #import "YMMemberCenterViewModel.h"
  10. @interface YMMemberPayMethodPopupView ()<UITableViewDataSource, UITableViewDelegate>
  11. /// 会员中心VM
  12. @property (nonatomic, strong) YMMemberCenterViewModel *viewModel;
  13. /// 支付标题标签
  14. @property (nonatomic, strong) UILabel *payTitleLb;
  15. /// 支付内容标签
  16. @property (nonatomic, strong) UILabel *payContentLb;
  17. /// 关闭按钮
  18. @property (nonatomic, strong) UIButton *closeBtn;
  19. /// 支付方式提示标签
  20. @property (nonatomic, strong) UILabel *payMethodTipsLb;
  21. /// 容器列表
  22. @property (nonatomic, strong) UITableView *contentTableView;
  23. /// 确认按钮
  24. @property (nonatomic, strong) UIButton *confirmBtn;
  25. /// 提示标签
  26. @property (nonatomic, strong) YYLabel *payTipsLb;
  27. /// 选中支付代码
  28. @property (nonatomic, copy) NSString *selectedPayCode;
  29. @end
  30. @implementation YMMemberPayMethodPopupView
  31. - (void)ym_setupViews{
  32. self.backgroundColor = UIColor.whiteColor;
  33. [self addSubview:self.payTitleLb];
  34. [self addSubview:self.payContentLb];
  35. [self addSubview:self.closeBtn];
  36. [self addSubview:self.payMethodTipsLb];
  37. [self addSubview:self.contentTableView];
  38. [self addSubview:self.confirmBtn];
  39. [self addSubview:self.payTipsLb];
  40. [self setNeedsUpdateConstraints];
  41. [self updateConstraintsIfNeeded];
  42. }
  43. - (void)updateConstraints{
  44. [self.payTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.equalTo(self).offset(adapt(20));
  46. make.left.equalTo(self).offset(adapt(20));
  47. make.right.equalTo(self).offset(adapt(-20));
  48. }];
  49. [self.payContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(self.payTitleLb.mas_bottom).offset(adapt(20));
  51. make.left.equalTo(self).offset(adapt(20));
  52. make.right.equalTo(self).offset(adapt(-20));
  53. }];
  54. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.centerY.equalTo(self.payTitleLb.mas_centerY);
  56. make.right.equalTo(self).offset(adapt(-20));
  57. make.width.height.mas_equalTo(adapt(30));
  58. }];
  59. [self.payMethodTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.payContentLb.mas_bottom).offset(adapt(20));
  61. make.left.equalTo(self).offset(adapt(10));
  62. }];
  63. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(self.payMethodTipsLb.mas_bottom).offset(adapt(10));
  65. make.left.equalTo(self);
  66. make.right.equalTo(self);
  67. }];
  68. [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.equalTo(self.contentTableView.mas_bottom).offset(adapt(20));
  70. make.left.equalTo(self).offset(adapt(30));
  71. make.right.equalTo(self).offset(adapt(-30));
  72. make.height.mas_equalTo(adapt(45));
  73. }];
  74. [self.payTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.centerX.equalTo(self.confirmBtn.mas_centerX);
  76. make.top.equalTo(self.confirmBtn.mas_bottom).offset(adapt(20));
  77. make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-35) : adapt(-20));
  78. make.height.mas_equalTo(adapt(15));
  79. }];
  80. [super updateConstraints];
  81. }
  82. - (void)ym_bindViewModel:(YMMemberCenterViewModel *)viewModel{
  83. if (!viewModel) {
  84. return;
  85. }
  86. _viewModel = viewModel;
  87. NSString *payContentStr = stringFormat(@"¥%ld",self.viewModel.payAmount);
  88. NSMutableAttributedString *payContentAttributed = [[NSMutableAttributedString alloc]initWithString:payContentStr];
  89. payContentAttributed.yy_font = LCBoldFont(30);
  90. payContentAttributed.yy_color = HexColorFromRGB(0x37184D);
  91. payContentAttributed.yy_alignment = NSTextAlignmentCenter;
  92. [payContentAttributed yy_setFont:LCBoldFont(20) range:[payContentStr rangeOfString:@"¥"]];
  93. self.payContentLb.attributedText = payContentAttributed;
  94. [self.contentTableView reloadData];
  95. [self.contentTableView layoutIfNeeded];
  96. //刷新高度
  97. CGFloat contentTableViewHeight = self.contentTableView.contentSize.height;
  98. [self.contentTableView mas_updateConstraints:^(MASConstraintMaker *make) {
  99. make.height.mas_equalTo(contentTableViewHeight);
  100. }];
  101. ///默认选中
  102. if ([YMGlobalUtils shared].payMethodDataArray.count > 0) {
  103. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  104. [self.contentTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
  105. [self tableView:self.contentTableView didSelectRowAtIndexPath:indexPath];
  106. }
  107. NSString *payTipsTitle = @"开通即同意";
  108. NSString *payTipsContent = stringFormat(@"《%@会员协议》",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]);
  109. NSString *payTipsStr = stringFormat(@"%@%@",payTipsTitle,payTipsContent);
  110. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:payTipsStr];
  111. attributedString.yy_font = LCFont(12);
  112. attributedString.yy_color = HexColorFromRGB(0x979797);
  113. //设置高亮色和点击事件
  114. [attributedString yy_setTextHighlightRange:[payTipsStr rangeOfString:payTipsContent] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  115. if (self.dismissBlock) {
  116. self.dismissBlock();
  117. }
  118. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  119. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,MemberProtocolH5]
  120. }];
  121. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  122. RouterViewModel:webArticleVM
  123. } completion:nil];
  124. }];
  125. self.payTipsLb.attributedText = attributedString;
  126. CGFloat payTitleLbHeight = [self.payTitleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  127. CGFloat payContentLbHeight = [self.payContentLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  128. CGFloat payMethodTipsLbHeight = [self.payMethodTipsLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  129. CGFloat confirmBtnHeight = [self.confirmBtn systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  130. CGFloat payTipsLbHeight = [self.payTipsLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  131. 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)));
  132. }
  133. #pragma mark - UITableViewDataSource
  134. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  135. return 1;
  136. }
  137. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  138. return [YMGlobalUtils shared].payMethodDataArray.count;
  139. }
  140. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  141. YMMemberPayMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMMemberPayMethodCell class])];
  142. if (!cell) {
  143. cell = [[YMMemberPayMethodCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMMemberPayMethodCell class])];
  144. }
  145. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  146. [cell ym_bindViewModel:[YMGlobalUtils shared].payMethodDataArray[indexPath.item]];
  147. return cell;
  148. }
  149. #pragma mark - UITableViewDelegate
  150. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  151. return adapt(70);
  152. }
  153. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  154. return nil;
  155. }
  156. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  157. return CGFLOAT_MIN;
  158. }
  159. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  160. return nil;
  161. }
  162. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  163. return CGFLOAT_MIN;
  164. }
  165. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  166. self.selectedPayCode = [YMGlobalUtils shared].payMethodDataArray[indexPath.item].payCode;
  167. }
  168. - (UILabel *)payTitleLb{
  169. if (!_payTitleLb) {
  170. _payTitleLb = [[UILabel alloc]init];
  171. _payTitleLb.font = LCFont(14);
  172. _payTitleLb.textColor = HexColorFromRGB(0x333333);
  173. _payTitleLb.textAlignment = NSTextAlignmentCenter;
  174. _payTitleLb.text = @"支付方式";
  175. }
  176. return _payTitleLb;
  177. }
  178. - (UILabel *)payContentLb{
  179. if (!_payContentLb) {
  180. _payContentLb = [[UILabel alloc]init];
  181. _payContentLb.font = LCBoldFont(30);
  182. _payContentLb.textColor = HexColorFromRGB(0x333333);
  183. _payContentLb.textAlignment = NSTextAlignmentCenter;
  184. _payContentLb.text = @"¥*****";
  185. }
  186. return _payContentLb;
  187. }
  188. - (UIButton *)closeBtn{
  189. if (!_closeBtn) {
  190. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  191. [_closeBtn setBackgroundImage:ImageByName(@"ym_common_close_icon") forState:UIControlStateNormal];
  192. WS(weakSelf)
  193. [[[_closeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  194. if (weakSelf.buttonBlock) {
  195. weakSelf.buttonBlock(NO, @"");
  196. }
  197. }];
  198. }
  199. return _closeBtn;
  200. }
  201. - (UILabel *)payMethodTipsLb{
  202. if (!_payMethodTipsLb) {
  203. _payMethodTipsLb = [[UILabel alloc]init];
  204. _payMethodTipsLb.font = LCFont(11);
  205. _payMethodTipsLb.textColor = HexColorFromRGB(0x9b9b9b);
  206. _payMethodTipsLb.textAlignment = NSTextAlignmentLeft;
  207. _payMethodTipsLb.text = @"请选择支付方式";
  208. }
  209. return _payMethodTipsLb;
  210. }
  211. - (UITableView *)contentTableView{
  212. if (!_contentTableView) {
  213. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  214. _contentTableView.delegate = self;
  215. _contentTableView.dataSource = self;
  216. _contentTableView.estimatedRowHeight = 0;
  217. _contentTableView.estimatedSectionHeaderHeight = 0;
  218. _contentTableView.estimatedSectionFooterHeight = 0;
  219. _contentTableView.showsVerticalScrollIndicator = NO;
  220. _contentTableView.showsHorizontalScrollIndicator = NO;
  221. _contentTableView.separatorColor = UIColor.clearColor;
  222. _contentTableView.backgroundColor = UIColor.whiteColor;
  223. _contentTableView.scrollEnabled = NO;
  224. [_contentTableView registerClass:[YMMemberPayMethodCell class] forCellReuseIdentifier:NSStringFromClass([YMMemberPayMethodCell class])];
  225. }
  226. return _contentTableView;
  227. }
  228. - (UIButton *)confirmBtn {
  229. if(!_confirmBtn){
  230. _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  231. _confirmBtn.titleLabel.font = LCFont(15);
  232. [_confirmBtn setTitle:@"确认支付" forState:UIControlStateNormal];
  233. [_confirmBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  234. _confirmBtn.layer.cornerRadius = adapt(10);
  235. [_confirmBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  236. WS(weakSelf)
  237. [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  238. if (weakSelf.buttonBlock) {
  239. weakSelf.buttonBlock(YES,weakSelf.selectedPayCode);
  240. }
  241. }];
  242. }
  243. return _confirmBtn;
  244. }
  245. - (YYLabel *)payTipsLb{
  246. if (!_payTipsLb) {
  247. _payTipsLb = [[YYLabel alloc]init];
  248. }
  249. return _payTipsLb;
  250. }
  251. @end
  252. @interface YMMemberPayMethodCell()
  253. /// ViewModel
  254. @property (nonatomic, strong) YMPayMethodCellViewModel *viewModel;
  255. /// 基础视图
  256. @property (nonatomic, strong) UIView *baseView;
  257. /// 支付方式图标
  258. @property (nonatomic, strong) UIImageView *payMethodIcon;
  259. /// 支付方式标题标签
  260. @property (nonatomic, strong) UILabel *payMethodTitleLb;
  261. /// 选中图标
  262. @property (nonatomic, strong) UIImageView *selectedIcon;
  263. @end
  264. @implementation YMMemberPayMethodCell
  265. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  266. [super setSelected:selected animated:animated];
  267. if (selected) {
  268. self.selectedIcon.image = ImageByName(@"ym_member_center_pay_selected_icon");
  269. } else {
  270. self.selectedIcon.image = ImageByName(@"ym_member_center_pay_normal_icon");
  271. }
  272. }
  273. - (void)ym_setupViews{
  274. self.contentView.backgroundColor = UIColor.clearColor;
  275. self.backgroundColor = UIColor.clearColor;
  276. [self.contentView addSubview:self.baseView];
  277. [self.baseView addSubview:self.payMethodIcon];
  278. [self.baseView addSubview:self.payMethodTitleLb];
  279. [self.baseView addSubview:self.selectedIcon];
  280. [self setNeedsUpdateConstraints];
  281. [self updateConstraintsIfNeeded];
  282. }
  283. - (void)updateConstraints {
  284. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  285. make.top.equalTo(self.contentView).offset(adapt(10));
  286. make.left.equalTo(self.contentView).offset(adapt(10));
  287. make.right.equalTo(self.contentView).offset(adapt(-10));
  288. make.bottom.equalTo(self.contentView);
  289. }];
  290. [self.payMethodIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  291. make.centerY.equalTo(self.baseView.mas_centerY);
  292. make.left.equalTo(self.baseView).offset(adapt(15));
  293. make.width.height.mas_equalTo(adapt(18));
  294. }];
  295. [self.payMethodTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  296. make.centerY.equalTo(self.baseView.mas_centerY);
  297. make.left.equalTo(self.payMethodIcon.mas_right).offset(adapt(10));
  298. }];
  299. [self.selectedIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  300. make.centerY.equalTo(self.baseView.mas_centerY);
  301. make.right.equalTo(self.baseView).offset(adapt(-15));
  302. make.width.height.mas_equalTo(adapt(20));
  303. }];
  304. [super updateConstraints];
  305. }
  306. - (void)ym_bindViewModel:(YMPayMethodCellViewModel*)viewModel{
  307. if (!viewModel) {
  308. return;
  309. }
  310. _viewModel = viewModel;
  311. self.payMethodIcon.image = ImageByName(self.viewModel.payIcon);
  312. self.payMethodTitleLb.text = self.viewModel.payTitle;
  313. }
  314. - (UIView *)baseView{
  315. if (!_baseView) {
  316. _baseView = [[UIView alloc]init];
  317. _baseView.backgroundColor = HexColorFromRGB(0xf6f6f6);
  318. _baseView.layer.cornerRadius = adapt(8);
  319. _baseView.layer.masksToBounds = YES;
  320. }
  321. return _baseView;
  322. }
  323. - (UIImageView *)payMethodIcon{
  324. if (!_payMethodIcon) {
  325. _payMethodIcon = [[UIImageView alloc]init];
  326. }
  327. return _payMethodIcon;
  328. }
  329. - (UILabel *)payMethodTitleLb{
  330. if (!_payMethodTitleLb) {
  331. _payMethodTitleLb = [[UILabel alloc]init];
  332. _payMethodTitleLb.font = LCFont(14);
  333. _payMethodTitleLb.textColor = HexColorFromRGB(0x333333);
  334. _payMethodTitleLb.textAlignment = NSTextAlignmentLeft;
  335. _payMethodTitleLb.text = @"******";
  336. }
  337. return _payMethodTitleLb;
  338. }
  339. - (UIImageView *)selectedIcon{
  340. if (!_selectedIcon) {
  341. _selectedIcon = [[UIImageView alloc]init];
  342. _selectedIcon.image = ImageByName(@"ym_member_center_pay_normal_icon");
  343. }
  344. return _selectedIcon;
  345. }
  346. @end