// // YOUPAILZProfitTransformCoinVC.m // MSYOUPAI // // Created by CY on 2022/3/2. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAILZProfitTransformCoinVC.h" #import "IQKeyboardManager.h" #import "LZAlertWindow.h" #import "UIViewController+TFPresent.h" @interface YOUPAILZProfitTransformCoinVC () @property (nonatomic, weak) UILabel *youpaipbalanceL; @property (nonatomic, weak) UITextField *youpaipmoneyTF; @property (nonatomic, weak) UILabel *youpaipcoinL; @property (nonatomic, weak) UIButton *youpaiptransfromBtn; @end @implementation YOUPAILZProfitTransformCoinVC - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[IQKeyboardManager sharedManager] setEnable:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[IQKeyboardManager sharedManager] setEnable:NO]; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条 [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; // [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES; self.title = @"兑换钻石"; [self youpaifinitUI]; [self youpaifrequestWalleetInfo]; } - (void)youpaifinitUI{ UILabel *youpaipbalanceL = [[UILabel alloc] init]; youpaipbalanceL.text = @"收益金额:0 元"; youpaipbalanceL.textColor = LZ273145Color; youpaipbalanceL.font = LCFont(14); [self.view addSubview:youpaipbalanceL]; self.youpaipbalanceL = youpaipbalanceL; [youpaipbalanceL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(24.0f); make.height.offset(48.0f); make.top.offset(NavBarHeight + 20.0f); }]; UIView *moneyV = [[UIView alloc] init]; moneyV.backgroundColor = LZF7F8FAColor; moneyV.layer.cornerRadius = 6; moneyV.layer.masksToBounds = YES; [self.view addSubview:moneyV]; [moneyV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.top.equalTo(youpaipbalanceL.mas_bottom).offset(8.0f); make.width.offset(KScreenWidth - 24.0f); make.height.offset(48.0f); }]; UILabel* moneyTipL = [[UILabel alloc]init]; moneyTipL.text = @"兑换金额:"; moneyTipL.textColor = LZ273145Color; moneyTipL.font = LCFont14; [moneyV addSubview:moneyTipL]; [moneyTipL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.top.bottom.offset(0.0f); make.width.offset(84.0f); }]; UITextField* youpaipmoneyTF = [[UITextField alloc]init]; youpaipmoneyTF.tintColor = LZ7C69FEColor; youpaipmoneyTF.textColor = LZ273145Color; youpaipmoneyTF.clearButtonMode = UITextFieldViewModeWhileEditing; youpaipmoneyTF.keyboardType = UIKeyboardTypeNumberPad; [[youpaipmoneyTF valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal]; [youpaipmoneyTF addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; NSMutableAttributedString* attrStrName = [[NSMutableAttributedString alloc]initWithString:@"请输入要使用的金额"];//@"请输入支付宝认证名字" [attrStrName addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attrStrName.length)]; [attrStrName addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStrName.length)]; youpaipmoneyTF.attributedPlaceholder = attrStrName; [moneyV addSubview:youpaipmoneyTF]; self.youpaipmoneyTF = youpaipmoneyTF; [youpaipmoneyTF mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(moneyTipL.mas_right).offset(0.0f); make.top.bottom.offset(0.0f); make.right.offset(-12.0f); }]; UILabel *youpaipcoinL = [[UILabel alloc] init]; youpaipcoinL.text = @"获得钻石:0"; youpaipcoinL.textColor = LZ273145Color; youpaipcoinL.font = LCFont(14); [self.view addSubview:youpaipcoinL]; self.youpaipcoinL = youpaipcoinL; [youpaipcoinL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(24.0f); make.height.offset(48.0f); make.top.equalTo(moneyV.mas_bottom).offset(8.0f); }]; UIButton *youpaiptransfromBtn = [[UIButton alloc]initWithFrame:CGRectMake(48, 0.0f, KScreenWidth-96, 48)]; youpaiptransfromBtn.uxy_acceptEventInterval = 3.0; youpaiptransfromBtn.userInteractionEnabled = NO; youpaiptransfromBtn.backgroundColor = LZD3D1D7Color; // [withdrawBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 96, 48) FromColors:@[LZFFB5DBColor,LZFE66A4Color] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];; youpaiptransfromBtn.layer.cornerRadius = 24.0; youpaiptransfromBtn.layer.masksToBounds = YES; youpaiptransfromBtn.titleLabel.font = LCFont16; [youpaiptransfromBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [youpaiptransfromBtn setTitle:@"立即兑换" forState:(UIControlStateNormal)];//立即提现 [youpaiptransfromBtn addTarget:self action:@selector(youpaiptransfromBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [self.view addSubview:youpaiptransfromBtn]; [youpaiptransfromBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(48); make.width.offset(KScreenWidth - 96); make.top.equalTo(youpaipcoinL.mas_bottom).offset(30.0f); make.height.offset(48); }]; self.youpaiptransfromBtn = youpaiptransfromBtn; } - (void)textFieldDidEditing:(UITextField *)textField{ NSString *checkedNumString = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]]; if ([self.youpaipmoneyTF.text isEqualToString:@""] || checkedNumString.length > 0){ [self.youpaiptransfromBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaiptransfromBtn.userInteractionEnabled = NO; self.youpaipcoinL.text = @"获得钻石:0"; }else{ [self.youpaiptransfromBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 96, 48) FromColors:@[LZFFB5DBColor,LZFE66A4Color] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; self.youpaiptransfromBtn.userInteractionEnabled = YES; NSInteger count = [textField.text integerValue]; self.youpaipcoinL.text = [NSString stringWithFormat:@"获得钻石:%@",@(count * 100)]; } } - (void)youpaifrequestWalleetInfo{ [LCHttpHelper requestWithURLString:WalletInit parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSString *incomeMoney = [[[dict objectForKey:@"data"]objectForKey:@"account"]objectForKey:@"income_coin_money"]; self.youpaipbalanceL.text = [NSString stringWithFormat:@"收益金额:%@ 元",incomeMoney]; } } failure:^(NSError *error) { }]; } - (void)youpaiptransfromBtnClick{ @weakify(self); LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.color = LZ273145Color; cancelAction.bgColor = LZF5F4F7Color; LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) { @strongify(self); [LCHttpHelper requestWithURLString:WalletChangeCoin parameters:@{@"moneys":self.youpaipmoneyTF.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 youpaifrequestWalleetInfo]; self.youpaipmoneyTF.text = @""; self.youpaipcoinL.text = @"获得钻石:0"; [self.youpaiptransfromBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaiptransfromBtn.userInteractionEnabled = NO; } }failure:^(NSError *error) { }]; }]; 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] contentStyleBlock:^(UILabel *contentL) { NSString *x = self.youpaipmoneyTF.text; NSString *y = [NSString stringWithFormat:@"%@",@([x integerValue] * 100)]; NSString *contentText = [NSString stringWithFormat:@"将消耗 %@ 元,获得 %@ 钻石",x,y]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:contentText]; [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF3B30) range:[contentText rangeOfString:x]]; [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF3B30) range:[contentText rangeOfString:y]]; contentL.attributedText = str; }]; alert.contentTextAlignment = NSTextAlignmentCenter; [self TFPresentVC:alert completion:^{}]; } @end