// // YOUPAILZVipCoinTransformVC.m // VQU // // Created by CY on 2021/8/26. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZVipCoinTransformVC.h" #import "LZAlertWindow.h" #import "UIViewController+TFPresent.h" @interface YOUPAILZVipCoinTransformVC () @property (nonatomic,weak) UITextField *youpaiptransformTF; @property (nonatomic,weak) UILabel *youpaipbalanceL; @property (nonatomic,weak) UILabel *youpaipdescL; @property (nonatomic,assign) NSInteger youpaipuser_noble_coin; @property (nonatomic,assign) NSInteger youpaiprate; @end @implementation YOUPAILZVipCoinTransformVC - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.youpaipuser_noble_coin = 0; self.youpaiprate = 0; self.title = @"兑换钻石"; [self youpaifinitUI]; [self youpaifrequestVipCoinInfo]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] init]; bgV.backgroundColor = LZF7F8FAColor; bgV.layer.cornerRadius = ScaleSize(8.0f); bgV.clipsToBounds = YES; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(14.0f)); make.top.offset(NavBarHeight + ScaleSize(10.0f)); make.right.offset(ScaleSize(-14.0f)); make.height.offset(ScaleSize(180.0f)); }]; UILabel *descL = [[UILabel alloc] init]; descL.font = LCFont(ScaleSize(14.0f)); descL.textColor = LZ273145Color; descL.text = @"贵族币兑换钻石"; [bgV addSubview:descL]; self.youpaipdescL = descL; [descL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.offset(ScaleSize(14.0f)); make.right.offset(ScaleSize(-14.0f)); }]; UILabel *rmbSymbolL = [[UILabel alloc] init]; rmbSymbolL.text = @"¥"; rmbSymbolL.textColor = LZ273145Color; rmbSymbolL.font = LCFont(ScaleSize(36.0f)); [rmbSymbolL sizeToFit]; rmbSymbolL.frame = CGRectMake(0, 0, rmbSymbolL.mj_w, ScaleSize(62.0f)); UITextField *transformTF = [[UITextField alloc] init]; transformTF.tintColor = LZ7C69FEColor; transformTF.leftView = rmbSymbolL; transformTF.leftViewMode = UITextFieldViewModeAlways; transformTF.text = @"0"; transformTF.textColor = LZ273145Color; transformTF.font = LCFont(ScaleSize(36.0f)); transformTF.keyboardType = UIKeyboardTypeNumberPad; NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入兑换数量"]; [attrStr addAttribute:NSFontAttributeName value:LCFont(ScaleSize(24.0f)) range:NSMakeRange(0, attrStr.length)]; [attrStr addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStr.length)]; transformTF.attributedPlaceholder = attrStr; transformTF.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; [bgV addSubview:transformTF]; self.youpaiptransformTF = transformTF; [transformTF mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(14.0f)); make.top.equalTo(descL.mas_bottom).offset(ScaleSize(26.0f)); make.right.offset(ScaleSize(-14.0f)); make.height.offset(ScaleSize(62.0f)); }]; [transformTF addLineWithColor:LZF7F8FAColor lineRect:CGRectMake(0, ScaleSize(62.0f) - 0.5f, KScreenWidth - ScaleSize(56.0f), 0.5f)]; UILabel *balanceL = [[UILabel alloc] init]; balanceL.font = LCFont(ScaleSize(12.0f)); balanceL.textColor = LZA3AABEColor; balanceL.text = @"可用贵族币 ¥0"; [bgV addSubview:balanceL]; self.youpaipbalanceL = balanceL; [balanceL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(14.0f)); make.top.equalTo(transformTF.mas_bottom).offset(0.0f); make.bottom.offset(0.0f); }]; UIButton *transformAllBtn = [UIButton buttonWithType:UIButtonTypeCustom]; transformAllBtn.layer.cornerRadius = ScaleSize(27.0f) / 2.0f; transformAllBtn.clipsToBounds = YES; [transformAllBtn setTitle:@"全部兑换" forState:UIControlStateNormal]; [transformAllBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; transformAllBtn.titleLabel.font = LCFont(ScaleSize(12.0f)); transformAllBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); [transformAllBtn addTarget:self action:@selector(youpaiftransformAllBtnClick) forControlEvents:UIControlEventTouchUpInside]; [bgV addSubview:transformAllBtn]; [transformAllBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(balanceL); make.right.offset(ScaleSize(-14.0f)); make.size.mas_offset(CGSizeMake(ScaleSize(76.0f), ScaleSize(27.0f))); }]; UIButton *transformBtn = [UIButton buttonWithType:UIButtonTypeCustom]; transformBtn.layer.cornerRadius = 24.0f; transformBtn.clipsToBounds = YES; [transformBtn setTitle:@"兑换" forState:UIControlStateNormal]; [transformBtn setTitleColor:HexColorFromRGB(0x75170A) forState:UIControlStateNormal]; transformBtn.titleLabel.font = LCFont16; [transformBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom] forState:UIControlStateNormal]; [transformBtn addTarget:self action:@selector(youpaiftransformBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:transformBtn]; [transformBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.offset(-30.0f-SafeHeight); make.centerX.equalTo(self.view); make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f)); }]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } - (void)youpaifrequestVipCoinInfo{ @weakify(self); [LCHttpHelper requestWithURLString:GetNobleToCoinRate parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { self.youpaipuser_noble_coin = [[[dict objectForKey:@"data"]objectForKey:@"user_noble_coin"] integerValue]; self.youpaiprate = [[[dict objectForKey:@"data"]objectForKey:@"rate"] integerValue]; self.youpaipbalanceL.text = [NSString stringWithFormat:@"可用贵族币 ¥%@",@(self.youpaipuser_noble_coin)]; self.youpaipdescL.text = [NSString stringWithFormat:@"贵族币兑换钻石(1:%@)",@(self.youpaiprate)];; } } failure:^(NSError *error) { }]; } - (void)youpaiftransformAllBtnClick{ self.youpaiptransformTF.text = [NSString stringWithFormat:@"%@",@(self.youpaipuser_noble_coin)]; } - (void)youpaiftransformBtnClick{ if([self.youpaiptransformTF.text integerValue] > 0 && self.youpaiprate > 0) { @weakify(self); LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.bgColor = LZF5F4F7Color; cancelAction.color = LZ273145Color; LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) { @strongify(self); [LCHttpHelper requestWithURLString:NobleExchange parameters:@{@"num":self.youpaiptransformTF.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper showTitle:@"兑换成功"]; [self youpaifrequestVipCoinInfo]; [[NSNotificationCenter defaultCenter]postNotificationName:@"yqApplePaySuccess" object:nil userInfo:nil]; self.youpaiptransformTF.text = @"0"; } } failure:^(NSError *error) { }]; }]; confimAction.cornerRadius = 24.0f; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom]]; confimAction.color = HexColorFromRGB(0x75170A); NSString *content = [NSString stringWithFormat:@"将消耗%@贵族币\n获得%@钻石",self.youpaiptransformTF.text,@([self.youpaiptransformTF.text integerValue] *self.youpaiprate)]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"兑换提示" content:content action:@[cancelAction,confimAction]]; alert.contentTextAlignment = NSTextAlignmentCenter; [self TFPresentVC:alert completion:^{}]; }else{ [ZCHUDHelper showTitle:@"请输入兑换数量"]; } } @end