123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // YOUPAILZVipPayWindow.m
- // VQU
- //
- // Created by CY on 2021/8/24.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAILZVipPayWindow.h"
- #import "YOUPAILZVipRenewItemCell.h"
- #import "UIViewController+TFPresent.h"
- @interface YOUPAILZVipPayWindow ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic,weak) UILabel *youpaiptitleL;
- @property (nonatomic,weak) UILabel *youpaipreturnCoinL;
- @property (nonatomic,weak) UILabel *youpaipvalidityL;
- @property (nonatomic,weak) UIButton *youpaipconfimBtn;
- @property (nonatomic,weak) UICollectionView *youpaipcollectionView;
- @property (nonatomic,strong) NSArray <YOUPAILZVipRenewModel *> *youpaipdataSource;
- @property (nonatomic,strong) YOUPAILZVipRenewModel *youpaipcurrentModel;
- @end
- @implementation YOUPAILZVipPayWindow
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.baseView.hidden = YES;
-
- [self youpaifrequestListData];
- }
- - (void)youpaifinitUI{
- UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
- [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
- bgV.backgroundColor = HexColorFromRGB(0x2A2935);
- [self.view addSubview:bgV];
- [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.offset(0.0f);
- }];
-
- UILabel *titleL = [[UILabel alloc] init];
- titleL.font = LCFont(17.0f);
- titleL.textColor = HexColorFromRGB(0xFDCC88);
- [bgV addSubview:titleL];
- self.youpaiptitleL = titleL;
- [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(16.0f);
- make.centerX.equalTo(bgV);
- }];
-
- UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [closeBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close"] forState:UIControlStateNormal];
- [closeBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close"] forState:UIControlStateHighlighted];
- [closeBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [bgV addSubview:closeBtn];
- [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.centerY.equalTo(titleL);
- make.size.mas_offset(CGSizeMake(28, 28));
- }];
- UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- flowLayout.minimumInteritemSpacing = 9.0f;
- flowLayout.minimumLineSpacing = 9.0f;
- CGFloat width = (KScreenWidth - 55.0f) / 4.0f;
- CGFloat height = width;
- flowLayout.itemSize = CGSizeMake(width, height);
- flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 14.0f, 0.0f, 14.0f);
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- collectionView.backgroundColor = HexColorFromRGB(0x2A2935);
- collectionView.alwaysBounceVertical = YES;
- collectionView.delegate = self;
- collectionView.dataSource = self;
- [collectionView registerClass:YOUPAILZVipRenewItemCell.class forCellWithReuseIdentifier:@"cell"];
- [self.view addSubview:collectionView];
- self.youpaipcollectionView = collectionView;
- NSInteger rowTotal = (self.youpaipdataSource.count + 3) / 4;
- [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.offset(0.0f);
- make.top.equalTo(titleL.mas_bottom).offset(26.0f);
- make.height.offset(rowTotal * (width + 9.0f));
- }];
-
- UILabel *returnCoinL = [[UILabel alloc] init];
- returnCoinL.font = LCFont(15.0f);
- returnCoinL.textColor = HexColorFromRGB(0xFDCC88);
- [bgV addSubview:returnCoinL];
- self.youpaipreturnCoinL = returnCoinL;
- [returnCoinL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.top.equalTo(collectionView.mas_bottom).offset(20.0f);
- }];
-
- UILabel *validityL = [[UILabel alloc] init];
- validityL.font = LCFont(11.0f);
- validityL.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.45f];
- [bgV addSubview:validityL];
- self.youpaipvalidityL = validityL;
- [validityL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.top.equalTo(returnCoinL.mas_bottom).offset(10.0f);
- }];
-
- UIButton *confimBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- confimBtn.backgroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 120.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom]];
- confimBtn.layer.cornerRadius = 24.0f;
- confimBtn.clipsToBounds = YES;
- [confimBtn setTitleColor:HexColorFromRGB(0x75170A) forState:UIControlStateNormal];
- confimBtn.titleLabel.font = LCFont(17.0f);
-
- [confimBtn addTarget:self action:@selector(youpaifconfimBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [bgV addSubview:confimBtn];
- self.youpaipconfimBtn = confimBtn;
-
- [confimBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(validityL.mas_bottom).offset(20.0f);
- make.centerX.equalTo(bgV);
- make.size.mas_offset(CGSizeMake(KScreenWidth - 120.0f, 48.0f));
- make.bottom.offset(-20.0f-SafeHeight);
- }];
-
- [self youpaifreloadUI];
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.youpaipdataSource.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAILZVipRenewItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAILZVipRenewModel *model = self.youpaipdataSource[indexPath.item];
- if (![model.youpaippay_info.youpaipstatus isEqual:@"forbid"]) {
- self.youpaipcurrentModel.youpaipisSelected = NO;
- self.youpaipcurrentModel = model;
- self.youpaipcurrentModel.youpaipisSelected = YES;
- [self youpaifreloadUI];
- }
- }
- - (void)youpaifcloseBtnClick{
- [self TFDismissViewController];
- }
- - (void)youpaifconfimBtnClick{
- [self dismissViewControllerAnimated:YES completion:^{
- if (self.payBlock != nil) {
- self.payBlock(self.youpaipcurrentModel);
- }
- }];
- }
- - (void)youpaifrequestListData{
- @weakify(self);
- [LCHttpHelper requestWithURLString:VipRechargeIndex parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- self.youpaipdataSource = [YOUPAILZVipRenewModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]].mutableCopy;
- for (YOUPAILZVipRenewModel *model in self.youpaipdataSource) {
- if([model.youpaipid isEqual:self.youpaipvipId]){
- model.youpaipisSelected = YES;
- self.youpaipcurrentModel = model;
- break;
- }
- }
- [self youpaifinitUI];
- }else{
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)youpaifreloadUI{
- [self youpaifsetupReturnCoinAttributedString];
- [self youpaifsetupValidityAttributedString];
- [self youpaifsetupConfimBtnTitle];
- [self.youpaipcollectionView reloadData];
- }
- - (void)youpaifsetupReturnCoinAttributedString{
- NSString *returnCoinText = [NSString stringWithFormat:@"%@立即返还",self.youpaipcurrentModel.youpaippay_info.youpaipbtn];
- NSRange returnCoinRange = NSMakeRange(returnCoinText.length, self.youpaipcurrentModel.youpaippay_info.youpaipreturn_coin.length);
- returnCoinText = [NSString stringWithFormat:@"%@%@钻石",returnCoinText,self.youpaipcurrentModel.youpaippay_info.youpaipreturn_coin];
- NSMutableAttributedString *returnCoinAttrStr = [[NSMutableAttributedString alloc] initWithString:returnCoinText];
- [returnCoinAttrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4848) range:returnCoinRange];
- self.youpaipreturnCoinL.attributedText = returnCoinAttrStr.copy;
- }
- - (void)youpaifsetupValidityAttributedString{
- NSString *validityText = @"贵族有效期30天 (";
- NSRange startRange = NSMakeRange(validityText.length, self.youpaipcurrentModel.youpaippay_info.youpaiptime_start.length);
- validityText = [NSString stringWithFormat:@"%@%@ 至 ",validityText,self.youpaipcurrentModel.youpaippay_info.youpaiptime_start];
- NSRange overRange = NSMakeRange(validityText.length, self.youpaipcurrentModel.youpaippay_info.youpaiptime_over.length);
- validityText = [NSString stringWithFormat:@"%@%@)",validityText,self.youpaipcurrentModel.youpaippay_info.youpaiptime_over];
- NSMutableAttributedString *returnCoinAttrStr = [[NSMutableAttributedString alloc] initWithString:validityText];
- [returnCoinAttrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4848) range:startRange];
- [returnCoinAttrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4848) range:overRange];
- self.youpaipvalidityL.attributedText = returnCoinAttrStr.copy;
- }
- - (void)youpaifsetupConfimBtnTitle{
- self.youpaiptitleL.text = [NSString stringWithFormat:@"%@%@",self.youpaipcurrentModel.youpaippay_info.youpaipbtn,self.youpaipcurrentModel.youpaipname];
- [self.youpaipconfimBtn setTitle:[NSString stringWithFormat:@"%@元 立即%@",self.youpaipcurrentModel.youpaippay_info.youpaipprice,self.youpaipcurrentModel.youpaippay_info.youpaipbtn] forState:UIControlStateNormal];
- }
- @end
|