// // YOUPAIZYBiHuVC.m // VQU // // Created by Elaine on 2020/10/9. // Copyright © 2020 leo. All rights reserved. // #import "YOUPAIZYBiHuVC.h" #import "LZAlertWindow.h" #import "UIViewController+TFPresent.h" #import "YOUPAILZVipVC.h" @interface YOUPAIZYBiHuVC() @property(nonatomic,strong)UIImageView *youpaipbkImgV; @property(nonatomic,strong)NSMutableArray *youpaipbtnArray; @property(nonatomic,strong)NSArray *youpaipnumStrArray; @property(nonatomic,strong)UILabel *youpaiptitleLab,*youpaipnoticeLab; @property(nonatomic,strong)UIButton *youpaipbiHuBtn; @property(nonatomic,strong)UIView *youpaipnumView; @property(nonatomic,assign)CGFloat youpaipleftPadding; @property(nonatomic,assign)NSInteger youpaiptotalNum; @end; @implementation YOUPAIZYBiHuVC -(void)viewDidLoad { [super viewDidLoad]; _youpaipleftPadding = (self.vWidth-290)/2.0; _youpaipnumStrArray = @[@"1天",@"3天",@"7天",@"30天"]; _youpaipbtnArray = [[NSMutableArray alloc]init]; _youpaiptotalNum =1; CAShapeLayer *maskLayer = [CAShapeLayer layer]; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.baseView.bounds cornerRadius:16.0f]; maskLayer.path = path.CGPath; self.baseView.layer.mask = maskLayer; self.baseView = self.baseView; // // [self.view setFrame:CGRectMake(0, 0, self.vWidth, self.vHeight)]; // [self.view setBackgroundColor:[UIColor whiteColor]]; [self.baseView addSubview:self.youpaipbkImgV]; [self.baseView addSubview:self.youpaiptitleLab]; // [self.baseView addSubview:self.noticeLab]; [self.baseView addSubview:self.youpaipnumView]; [self.baseView addSubview:self.youpaipbiHuBtn]; // NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她1个守护符",_infoModel.guard_price]; // [_titleLab setText:@"她将出现在首页“贵族庇护”页面"]; NSString *text = @"她将出现在首页“贵族庇护”页面"; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text]; [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4A4B) range:[text rangeOfString:@"“贵族庇护”"]]; _youpaiptitleLab.attributedText = str; // [_noticeLab setText:[NSString stringWithFormat:@"距离上一名还差%ld个守护符",_infoModel.diff_num]]; [_youpaipbiHuBtn setTitle:@"庇护她" forState:UIControlStateNormal]; [_youpaiptitleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.baseView).with.offset(0); make.right.equalTo(self.baseView).with.offset(0); make.top.equalTo(self->_youpaipbkImgV.mas_bottom).with.offset(19); make.height.mas_equalTo(20); }]; [_youpaipnumView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.baseView).with.offset(self->_youpaipleftPadding); make.right.equalTo(self.baseView).with.offset(-self->_youpaipleftPadding); make.top.equalTo(self->_youpaiptitleLab.mas_bottom).with.offset(17); make.width.mas_equalTo(220); make.height.mas_equalTo(28); }]; // [_noticeLab mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.view).with.offset(0); // make.right.equalTo(self.view).with.offset(0); // make.top.equalTo(self->_numView.mas_bottom).with.offset(6); // make.height.mas_equalTo(15); // }]; // // [_guardHerBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.view).with.offset(_leftPadding); // make.right.equalTo(self.view).with.offset(-_leftPadding); // make.top.equalTo(_noticeLab.mas_bottom).with.offset(10); // make.bottom.equalTo(self.view.mas_bottom).with.offset(-15); // make.height.mas_equalTo(44); // }]; // CAShapeLayer *maskLayer = [CAShapeLayer layer]; // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds cornerRadius:25]; // maskLayer.path = path.CGPath; // self.view.layer.mask = maskLayer; } -(UIImageView *)youpaipbkImgV { if(!_youpaipbkImgV) { _youpaipbkImgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.vWidth, (self.vWidth*165)/320.0)]; [_youpaipbkImgV setImage:[UIImage imageNamed:@"vqu_images_guizhu_prompt"]]; } return _youpaipbkImgV; } -(UIView *)youpaipnumView { if(!_youpaipnumView) { CGFloat btnWidth = 60,btnHeight = 28,orginx= 10,orginy =1,btnspace=10; _youpaipnumView = [[UIView alloc]initWithFrame:CGRectMake(_youpaipleftPadding, 0,290, 28)]; for(int i=0;i<4;i++) { UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*i, orginy, btnWidth, btnHeight)]; btn.tag = i; [btn.titleLabel setFont:[UIFont systemFontOfSize:13]]; btn.layer.cornerRadius =4; btn.layer.borderWidth = 1; [btn setTitle:_youpaipnumStrArray[i] forState:UIControlStateNormal]; if(i==0) { [btn setTitleColor:HexColorFromRGB(0xFF4A4B) forState:UIControlStateNormal]; btn.layer.borderColor = HexColorFromRGB(0xFF4A4B).CGColor; } else { btn.layer.borderColor = HexColorFromRGB(0xCCCCCC).CGColor; [btn setTitleColor:HexColorFromRGB(0xCCCCCC) forState:UIControlStateNormal]; } [btn addTarget:self action:@selector(youpaifupdateNumView:) forControlEvents:UIControlEventTouchUpInside]; [_youpaipbtnArray addObject:btn]; [_youpaipnumView addSubview:btn]; } } return _youpaipnumView; } -(UILabel *)youpaiptitleLab { if(!_youpaiptitleLab) { _youpaiptitleLab = [[UILabel alloc]init]; [_youpaiptitleLab setTextColor:HexColorFromRGB(0x666666)]; [_youpaiptitleLab setFont:[UIFont systemFontOfSize:14]]; [_youpaiptitleLab setTextAlignment:NSTextAlignmentCenter]; } return _youpaiptitleLab; } -(UILabel *)youpaipnoticeLab { if(!_youpaipnoticeLab) { _youpaipnoticeLab = [[UILabel alloc]init]; [_youpaipnoticeLab setTextColor:HexColorFromRGB(0xaaaaaa)]; [_youpaipnoticeLab setFont:[UIFont systemFontOfSize:12]]; [_youpaipnoticeLab setTextAlignment:NSTextAlignmentCenter]; } return _youpaipnoticeLab; } -(UIButton *)youpaipbiHuBtn { if(!_youpaipbiHuBtn) { _youpaipbiHuBtn = [[UIButton alloc]init]; [_youpaipbiHuBtn.titleLabel setFont:[UIFont systemFontOfSize:17]]; _youpaipbiHuBtn.layer.cornerRadius = 24; _youpaipbiHuBtn.layer.masksToBounds = YES; [_youpaipbiHuBtn addTarget:self action:@selector(youpaifaddBiHu) forControlEvents:UIControlEventTouchUpInside]; [_youpaipbiHuBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // [_biHuBtn setBackgroundColor:HexColorFromRGB(0x4D1B1B)]; _youpaipbiHuBtn.frame = CGRectMake(29.0f,self.vHeight-46-44,self.vWidth - 29.0f*2, 48); [_youpaipbiHuBtn setBackgroundImage:[LCTools ColorImage:_youpaipbiHuBtn.frame.size FromColors:@[HexColorFromRGB(0xFF9696),HexColorFromRGB(0xFF4A4B)] ByGradientType:GradientLeftToRight] forState:0]; } return _youpaipbiHuBtn; } -(void)youpaifupdateNumView:(UIButton *)btn { NSInteger tag = btn.tag; NSArray *totalArray =@[@(1),@(3),@(7),@(30)]; for(int i=0;i<4;i++) { UIButton *cacheBtn = [_youpaipbtnArray objectAtIndex:i]; if(tag == i){ [cacheBtn setTitleColor:HexColorFromRGB(0xFF4A4B) forState:UIControlStateNormal]; cacheBtn.layer.borderColor = HexColorFromRGB(0xFF4A4B).CGColor; _youpaiptotalNum = [totalArray[i] integerValue]; // NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她%ld个守护符",_infoModel.guard_price*_totalNum,_totalNum]; // [_titleLab setText:titleStr]; } else { cacheBtn.layer.borderColor = HexColorFromRGB(0xCCCCCC).CGColor; [cacheBtn setTitleColor:HexColorFromRGB(0xCCCCCC) forState:UIControlStateNormal]; } } } -(void)youpaifaddBiHu { _youpaipbiHuBtn.userInteractionEnabled = NO; //add by leo v1.0.8 视频中守护 WeakSelf; [LCHttpHelper requestWithURLString:AddAsylum parameters:@{@"user_id":self.youpaipuser_id,@"day":@(_youpaiptotalNum)} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self dismissViewControllerAnimated:YES completion:nil]; [weakSelf.youpaipdelegate youpaifaddBiHuSuccess]; [ZCHUDHelper showTitle:dict[@"message"] showtime:2]; }else if(code==1005){ [self dismissViewControllerAnimated:YES completion:^{ LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"再想想" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.color = LZ273145Color; cancelAction.bgColor = LZF5F4F7Color; LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"马上开通" handler:^(LZAlertAction *action) { YOUPAILZVipVC* vc = [[YOUPAILZVipVC alloc]init]; [[ZCUtils getCurrentVC].navigationController pushViewController:vc animated:YES]; }]; confimAction.cornerRadius = 24.0f; confimAction.color = [UIColor whiteColor]; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"【伯爵】以上贵族才可以庇护哦" action:@[cancelAction,confimAction]]; alert.contentTextAlignment = NSTextAlignmentCenter; [kAppDelegate.window.rootViewController TFPresentVC:alert completion:^{}]; }]; }else { weakSelf.youpaipbiHuBtn.userInteractionEnabled = YES; [ZCHUDHelper showTitle:dict[@"message"] showtime:5]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.mj_JSONString showtime:5]; [self dismissViewControllerAnimated:YES completion:nil]; }]; } @end