// // YOUPAILPGuardHerVC.m // livePro // // Created by leo on 2019/12/23. // Copyright © 2019 caiPro. All rights reserved. // #import "YOUPAILPGuardHerVC.h" #import "YOUPAIXRWalletVC.h" #import "LZAlertWindow.h" #import "UIViewController+TFPresent.h" @interface YOUPAILPGuardHerVC() @property(nonatomic,strong)UIView *youpaipbkImgV; @property(nonatomic,strong)NSMutableArray *youpaipbtnArray; @property(nonatomic,strong)NSMutableArray *youpaipImageArray; @property(nonatomic,strong)NSArray *youpaipnumStrArray; @property(nonatomic,strong)UILabel *youpaiptitleLab,*youpaipnoticeLab; @property(nonatomic,strong)UIButton *youpaipguardHerBtn; @property(nonatomic,strong)UIView *youpaipnumView; @property(nonatomic,assign)CGFloat youpaipleftPadding; @property(nonatomic,assign)NSInteger youpaiptotalNum; @property(nonatomic,assign)NSInteger youpaiptotalNum1; @property(nonatomic,strong)UIButton *youpaipshowZuanbtn; @end; @implementation YOUPAILPGuardHerVC -(void)viewDidLoad { [super viewDidLoad]; _youpaipleftPadding = 12; _youpaipnumStrArray = @[@"1个",@"5个",@"10个",@"50个",@"100个",@"520个"]; _youpaipbtnArray = [[NSMutableArray alloc]init]; _youpaipImageArray = [[NSMutableArray alloc]init]; _youpaiptotalNum =1; _youpaiptotalNum1 = 1; self.baseView.backgroundColor = [UIColor clearColor]; UIImageView *bgImageView = [UIImageView new]; [self.baseView addSubview:bgImageView]; [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(0); }]; bgImageView.userInteractionEnabled = YES; bgImageView.image = [UIImage imageNamed:@"vqu_images_guard_bg"]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.baseView.bounds cornerRadius:16.0f]; maskLayer.path = path.CGPath; // // [self.view setFrame:CGRectMake(0, 0, self.vWidth, self.vHeight)]; // [self.view setBackgroundColor:[UIColor whiteColor]]; [bgImageView addSubview:self.youpaipbkImgV]; [self.youpaipbkImgV addSubview:self.youpaiptitleLab]; [self.youpaipbkImgV addSubview:self.youpaipnoticeLab]; [self.youpaipbkImgV addSubview:self.youpaipnumView]; [self.youpaipbkImgV addSubview:self.youpaipguardHerBtn]; // NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她1个",_youpaipinfoModel.youpaipguard_price]; // _youpaiptitleLab.attributedText = [LCTools setRichTextWithTitle:titleStr subTitle:@"守护符" titleColor:HexColorFromRGB(0x666666) subTitleColor:HexColorFromRGB(0xAE5DE0) titleFontSize:14.0f subTitleFontSize:14.0f]; // [_titleLab setText:titleStr]; [_youpaiptitleLab setText:[NSString stringWithFormat:@"Ta距离上一名还差%ld个守护符",_youpaipinfoModel.youpaipdiff_num]]; [_youpaipguardHerBtn setTitle:@"守护Ta" forState:UIControlStateNormal]; [_youpaipbkImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.bottom.mas_equalTo(-15); make.height.mas_equalTo(276); }]; [_youpaiptitleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgImageView).with.offset(0); make.right.equalTo(bgImageView).with.offset(0); make.top.equalTo(22); make.height.mas_equalTo(20); }]; [_youpaipnumView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgImageView).with.offset(self->_youpaipleftPadding); make.right.equalTo(bgImageView).with.offset(-self->_youpaipleftPadding); make.top.equalTo(self->_youpaiptitleLab.mas_bottom).with.offset(17); make.width.mas_equalTo(ScaleSize(220)); make.height.mas_equalTo((28+15+28)*2); }]; [_youpaipnoticeLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgImageView).with.offset(0); make.right.equalTo(bgImageView).with.offset(0); make.top.equalTo(self->_youpaipnumView.mas_bottom).with.offset(9); make.height.mas_equalTo(15); }]; [_youpaipguardHerBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(0); make.size.mas_equalTo(CGSizeMake(self.vWidth - 29.0f*2, 48)); make.bottom.mas_equalTo(-30); }]; [_youpaipguardHerBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(self.vWidth - 29.0f*2, 48) FromColors:@[HexColorFromRGB(0xFFD845),HexColorFromRGB(0xFFBD45)] ByGradientType:(GradientTopToBottom)] forState:(UIControlStateNormal)]; //vqu_images_guard_select_new // [_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; } -(UIView *)youpaipbkImgV { if(!_youpaipbkImgV) { _youpaipbkImgV = [[UIView alloc]init]; _youpaipbkImgV.layer.cornerRadius = 9; _youpaipbkImgV.layer.masksToBounds = YES; _youpaipbkImgV.backgroundColor = [UIColor whiteColor]; } return _youpaipbkImgV; } //-(UIImageView *)youpaipSelectImage //{ // if(!_youpaipSelectImage) // { // _youpaipSelectImage = [[UIImageView alloc]init]; // _youpaipSelectImage.image = [UIImage imageNamed:@"vqu_images_guard_select_new"]; // } // return _youpaipSelectImage; //} -(UIView *)youpaipnumView { if(!_youpaipnumView) { CGFloat btnWidth = ScaleSize(85),btnHeight = 54,orginx=ScaleSize(15),orginy = 0,btnspace= ScaleSize(8); _youpaipnumView = [[UIView alloc]initWithFrame:CGRectMake(_youpaipleftPadding, 0,ScaleSize(220),28+15+28)]; for(int i=0;i<6;i++) { UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*(i%3),orginy+(btnspace+btnHeight)*(i/3), btnWidth, btnHeight)]; btn.tag = i; [btn.titleLabel setFont:[UIFont systemFontOfSize:13]]; btn.layer.cornerRadius =6; btn.layer.borderWidth = 1; [btn setTitle:_youpaipnumStrArray[i] forState:UIControlStateNormal]; UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*(i%3)+btn.frame.size.width-23, orginy+(btnspace+btnHeight)*(i/3), 23, 23)]; image.image = [UIImage imageNamed:@"vqu_images_guard_select_new"]; UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*(i%3),orginy+(btnspace+btnHeight)*(i/3)+32, btnWidth, 15)]; btn1.titleLabel.textAlignment = NSTextAlignmentCenter; self.youpaipshowZuanbtn = btn1; NSArray *totalArray =@[@(1),@(5),@(10),@(50),@(100),@(520)]; _youpaiptotalNum1 = [totalArray[i] integerValue]; switch (i) { case 0: { [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*1] forState:UIControlStateNormal]; } break; case 1: { [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*5] forState:UIControlStateNormal]; } break; case 2: { [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*10] forState:UIControlStateNormal]; } break; case 3: { [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*50] forState:UIControlStateNormal]; } break; case 4: { [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*100] forState:UIControlStateNormal]; } break; case 5: { [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*520] forState:UIControlStateNormal]; } break; default: break; } [btn1 setImage:[UIImage imageNamed:@"vqu_images_guard_zuanshi"] forState:UIControlStateNormal]; btn1.titleLabel.font = [UIFont systemFontOfSize:12]; [btn1 setTitleColor:LZA3AABEColor forState:UIControlStateNormal]; [btn1 setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft]; if(i==0) { [btn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal]; btn.layer.borderColor = HexColorFromRGB(0xFFD845).CGColor; btn.backgroundColor = HexColorFromRGBA(0xFFD845, 0.1); image.hidden = NO; } else { [btn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal]; btn.backgroundColor = HexColorFromRGBA(0xFAFAFC, 1); btn.layer.borderColor = HexColorFromRGB(0xFAFAFC).CGColor; image.hidden = YES; } [btn addTarget:self action:@selector(youpaifupdateNumView:) forControlEvents:UIControlEventTouchUpInside]; [_youpaipbtnArray addObject:btn]; [_youpaipnumView addSubview:btn]; [_youpaipnumView addSubview:image]; [_youpaipImageArray addObject:image]; [_youpaipnumView addSubview:btn1]; } } return _youpaipnumView; } -(UILabel *)youpaiptitleLab { if(!_youpaiptitleLab) { _youpaiptitleLab = [[UILabel alloc]init]; [_youpaiptitleLab setTextColor:HexColorFromRGB(0x475A7D)]; [_youpaiptitleLab setFont:[UIFont systemFontOfSize:12]]; [_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 *)youpaipguardHerBtn { if(!_youpaipguardHerBtn) { _youpaipguardHerBtn = [[UIButton alloc]init]; [_youpaipguardHerBtn.titleLabel setFont:[UIFont systemFontOfSize:17]]; _youpaipguardHerBtn.layer.cornerRadius = 24; _youpaipguardHerBtn.layer.masksToBounds = YES; [_youpaipguardHerBtn addTarget:self action:@selector(youpaifaddGuard) forControlEvents:UIControlEventTouchUpInside]; [_youpaipguardHerBtn setTitleColor:HexColorFromRGB(0x9C6600) forState:UIControlStateNormal]; // [_guardHerBtn setBackgroundColor:LCYellowColor]; // // } return _youpaipguardHerBtn; } -(void)youpaifupdateNumView:(UIButton *)btn { NSInteger tag = btn.tag; NSArray *totalArray =@[@(1),@(5),@(10),@(50),@(100),@(520)]; for(int i=0;i<6;i++) { UIButton *cacheBtn = [_youpaipbtnArray objectAtIndex:i]; UIImageView *selectImage = [_youpaipImageArray objectAtIndex:i]; if(tag == i) { cacheBtn.layer.borderWidth = 1; selectImage.hidden = NO; [cacheBtn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal]; cacheBtn.layer.borderColor = HexColorFromRGB(0xFFD845).CGColor; cacheBtn.backgroundColor = HexColorFromRGBA(0xFFD845, 0.1); _youpaiptotalNum = [totalArray[i] integerValue]; NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她%ld个",_youpaipinfoModel.youpaipguard_price*_youpaiptotalNum,_youpaiptotalNum]; _youpaiptitleLab.attributedText = [LCTools setRichTextWithTitle:titleStr subTitle:@"守护符" titleColor:HexColorFromRGB(0x666666) subTitleColor:HexColorFromRGB(0xAE5DE0) titleFontSize:14.0f subTitleFontSize:14.0f]; // [_titleLab setText:titleStr]; } else { selectImage.hidden = YES; cacheBtn.layer.borderColor = HexColorFromRGB(0xFAFAFC).CGColor; [cacheBtn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal]; cacheBtn.backgroundColor = HexColorFromRGBA(0xFAFAFC, 1); } } } -(void)youpaifaddGuard { _youpaipguardHerBtn.userInteractionEnabled = NO; WeakSelf; NSMutableDictionary *params = [NSMutableDictionary dictionary]; NSString *api = @""; if (self.youpaipisChatRoom) { params = @{@"to_uid":self.youpaipuser_id,@"guard_num":@(_youpaiptotalNum),@"guard_price":@(_youpaipinfoModel.youpaipguard_price)}.mutableCopy; if (_youpaiproomid.length != 0) { [params setValue:_youpaiproomid forKey:@"room_id"]; } api = TalkSendGuard; }else{ params = @{@"user_id":self.youpaipuser_id,@"guard_num":@(_youpaiptotalNum),@"guard_price":@(_youpaipinfoModel.youpaipguard_price)}.mutableCopy; if (_youpaiproomid.length != 0) { [params setValue:_youpaiproomid forKey:@"room_id"]; } if (_youpaipliveid.length != 0) { [params setValue:_youpaipliveid forKey:@"live_id"]; } api = AddGuard; } [LCHttpHelper requestWithURLString:api parameters:params.copy needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:dict[@"message"] showtime:1]; [self dismissViewControllerAnimated:YES completion:nil]; [weakSelf.youpaipdelegate youpaifaddGuardSuccess]; }else if(code==1003){ [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) { [[NSNotificationCenter defaultCenter] postNotificationName:@"InsufficientBalanceNotice" object:nil userInfo:nil]; YOUPAIXRWalletVC* coinRecharge = [[YOUPAIXRWalletVC alloc]init]; [[ZCUtils getCurrentVC].navigationController pushViewController:coinRecharge 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.youpaipguardHerBtn.userInteractionEnabled = YES; [ZCHUDHelper showTitle:dict[@"message"] showtime:1]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.mj_JSONString showtime:1]; [self dismissViewControllerAnimated:YES completion:nil]; }]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end