YOUPAILZVipPayWindow.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // YOUPAILZVipPayWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/24.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZVipPayWindow.h"
  9. #import "YOUPAILZVipRenewItemCell.h"
  10. #import "UIViewController+TFPresent.h"
  11. @interface YOUPAILZVipPayWindow ()<UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (nonatomic,weak) UILabel *youpaiptitleL;
  13. @property (nonatomic,weak) UILabel *youpaipreturnCoinL;
  14. @property (nonatomic,weak) UILabel *youpaipvalidityL;
  15. @property (nonatomic,weak) UIButton *youpaipconfimBtn;
  16. @property (nonatomic,weak) UICollectionView *youpaipcollectionView;
  17. @property (nonatomic,strong) NSArray <YOUPAILZVipRenewModel *> *youpaipdataSource;
  18. @property (nonatomic,strong) YOUPAILZVipRenewModel *youpaipcurrentModel;
  19. @end
  20. @implementation YOUPAILZVipPayWindow
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. self.baseView.hidden = YES;
  25. [self youpaifrequestListData];
  26. }
  27. - (void)youpaifinitUI{
  28. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  29. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  30. bgV.backgroundColor = HexColorFromRGB(0x2A2935);
  31. [self.view addSubview:bgV];
  32. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.bottom.right.offset(0.0f);
  34. }];
  35. UILabel *titleL = [[UILabel alloc] init];
  36. titleL.font = LCFont(17.0f);
  37. titleL.textColor = HexColorFromRGB(0xFDCC88);
  38. [bgV addSubview:titleL];
  39. self.youpaiptitleL = titleL;
  40. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.offset(16.0f);
  42. make.centerX.equalTo(bgV);
  43. }];
  44. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  45. [closeBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close"] forState:UIControlStateNormal];
  46. [closeBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close"] forState:UIControlStateHighlighted];
  47. [closeBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
  48. [bgV addSubview:closeBtn];
  49. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.offset(12.0f);
  51. make.centerY.equalTo(titleL);
  52. make.size.mas_offset(CGSizeMake(28, 28));
  53. }];
  54. UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
  55. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  56. flowLayout.minimumInteritemSpacing = 9.0f;
  57. flowLayout.minimumLineSpacing = 9.0f;
  58. CGFloat width = (KScreenWidth - 55.0f) / 4.0f;
  59. CGFloat height = width;
  60. flowLayout.itemSize = CGSizeMake(width, height);
  61. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 14.0f, 0.0f, 14.0f);
  62. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  63. collectionView.backgroundColor = HexColorFromRGB(0x2A2935);
  64. collectionView.alwaysBounceVertical = YES;
  65. collectionView.delegate = self;
  66. collectionView.dataSource = self;
  67. [collectionView registerClass:YOUPAILZVipRenewItemCell.class forCellWithReuseIdentifier:@"cell"];
  68. [self.view addSubview:collectionView];
  69. self.youpaipcollectionView = collectionView;
  70. NSInteger rowTotal = (self.youpaipdataSource.count + 3) / 4;
  71. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.right.offset(0.0f);
  73. make.top.equalTo(titleL.mas_bottom).offset(26.0f);
  74. make.height.offset(rowTotal * (width + 9.0f));
  75. }];
  76. UILabel *returnCoinL = [[UILabel alloc] init];
  77. returnCoinL.font = LCFont(15.0f);
  78. returnCoinL.textColor = HexColorFromRGB(0xFDCC88);
  79. [bgV addSubview:returnCoinL];
  80. self.youpaipreturnCoinL = returnCoinL;
  81. [returnCoinL mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.offset(14.0f);
  83. make.top.equalTo(collectionView.mas_bottom).offset(20.0f);
  84. }];
  85. UILabel *validityL = [[UILabel alloc] init];
  86. validityL.font = LCFont(11.0f);
  87. validityL.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.45f];
  88. [bgV addSubview:validityL];
  89. self.youpaipvalidityL = validityL;
  90. [validityL mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.offset(14.0f);
  92. make.top.equalTo(returnCoinL.mas_bottom).offset(10.0f);
  93. }];
  94. UIButton *confimBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  95. confimBtn.backgroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 120.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom]];
  96. confimBtn.layer.cornerRadius = 24.0f;
  97. confimBtn.clipsToBounds = YES;
  98. [confimBtn setTitleColor:HexColorFromRGB(0x75170A) forState:UIControlStateNormal];
  99. confimBtn.titleLabel.font = LCFont(17.0f);
  100. [confimBtn addTarget:self action:@selector(youpaifconfimBtnClick) forControlEvents:UIControlEventTouchUpInside];
  101. [bgV addSubview:confimBtn];
  102. self.youpaipconfimBtn = confimBtn;
  103. [confimBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.top.equalTo(validityL.mas_bottom).offset(20.0f);
  105. make.centerX.equalTo(bgV);
  106. make.size.mas_offset(CGSizeMake(KScreenWidth - 120.0f, 48.0f));
  107. make.bottom.offset(-20.0f-SafeHeight);
  108. }];
  109. [self youpaifreloadUI];
  110. }
  111. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  112. return 1;
  113. }
  114. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  115. return self.youpaipdataSource.count;
  116. }
  117. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  118. YOUPAILZVipRenewItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  119. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
  120. return cell;
  121. }
  122. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  123. YOUPAILZVipRenewModel *model = self.youpaipdataSource[indexPath.item];
  124. if (![model.youpaippay_info.youpaipstatus isEqual:@"forbid"]) {
  125. self.youpaipcurrentModel.youpaipisSelected = NO;
  126. self.youpaipcurrentModel = model;
  127. self.youpaipcurrentModel.youpaipisSelected = YES;
  128. [self youpaifreloadUI];
  129. }
  130. }
  131. - (void)youpaifcloseBtnClick{
  132. [self TFDismissViewController];
  133. }
  134. - (void)youpaifconfimBtnClick{
  135. [self dismissViewControllerAnimated:YES completion:^{
  136. if (self.payBlock != nil) {
  137. self.payBlock(self.youpaipcurrentModel);
  138. }
  139. }];
  140. }
  141. - (void)youpaifrequestListData{
  142. @weakify(self);
  143. [LCHttpHelper requestWithURLString:VipRechargeIndex parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  144. @strongify(self);
  145. NSDictionary* dict = (NSDictionary*)responseObject;
  146. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  147. if (code == 0) {
  148. self.youpaipdataSource = [YOUPAILZVipRenewModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]].mutableCopy;
  149. for (YOUPAILZVipRenewModel *model in self.youpaipdataSource) {
  150. if([model.youpaipid isEqual:self.youpaipvipId]){
  151. model.youpaipisSelected = YES;
  152. self.youpaipcurrentModel = model;
  153. break;
  154. }
  155. }
  156. [self youpaifinitUI];
  157. }else{
  158. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  159. }
  160. } failure:^(NSError *error) {
  161. [ZCHUDHelper showTitle:error.localizedDescription];
  162. }];
  163. }
  164. - (void)youpaifreloadUI{
  165. [self youpaifsetupReturnCoinAttributedString];
  166. [self youpaifsetupValidityAttributedString];
  167. [self youpaifsetupConfimBtnTitle];
  168. [self.youpaipcollectionView reloadData];
  169. }
  170. - (void)youpaifsetupReturnCoinAttributedString{
  171. NSString *returnCoinText = [NSString stringWithFormat:@"%@立即返还",self.youpaipcurrentModel.youpaippay_info.youpaipbtn];
  172. NSRange returnCoinRange = NSMakeRange(returnCoinText.length, self.youpaipcurrentModel.youpaippay_info.youpaipreturn_coin.length);
  173. returnCoinText = [NSString stringWithFormat:@"%@%@钻石",returnCoinText,self.youpaipcurrentModel.youpaippay_info.youpaipreturn_coin];
  174. NSMutableAttributedString *returnCoinAttrStr = [[NSMutableAttributedString alloc] initWithString:returnCoinText];
  175. [returnCoinAttrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4848) range:returnCoinRange];
  176. self.youpaipreturnCoinL.attributedText = returnCoinAttrStr.copy;
  177. }
  178. - (void)youpaifsetupValidityAttributedString{
  179. NSString *validityText = @"贵族有效期30天 (";
  180. NSRange startRange = NSMakeRange(validityText.length, self.youpaipcurrentModel.youpaippay_info.youpaiptime_start.length);
  181. validityText = [NSString stringWithFormat:@"%@%@ 至 ",validityText,self.youpaipcurrentModel.youpaippay_info.youpaiptime_start];
  182. NSRange overRange = NSMakeRange(validityText.length, self.youpaipcurrentModel.youpaippay_info.youpaiptime_over.length);
  183. validityText = [NSString stringWithFormat:@"%@%@)",validityText,self.youpaipcurrentModel.youpaippay_info.youpaiptime_over];
  184. NSMutableAttributedString *returnCoinAttrStr = [[NSMutableAttributedString alloc] initWithString:validityText];
  185. [returnCoinAttrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4848) range:startRange];
  186. [returnCoinAttrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4848) range:overRange];
  187. self.youpaipvalidityL.attributedText = returnCoinAttrStr.copy;
  188. }
  189. - (void)youpaifsetupConfimBtnTitle{
  190. self.youpaiptitleL.text = [NSString stringWithFormat:@"%@%@",self.youpaipcurrentModel.youpaippay_info.youpaipbtn,self.youpaipcurrentModel.youpaipname];
  191. [self.youpaipconfimBtn setTitle:[NSString stringWithFormat:@"%@元 立即%@",self.youpaipcurrentModel.youpaippay_info.youpaipprice,self.youpaipcurrentModel.youpaippay_info.youpaipbtn] forState:UIControlStateNormal];
  192. }
  193. @end