// // YZMAWithdrawViewController.m // YouHuiProject // // Created by jcymac on 2018/5/23. // Copyright © 2018年 kuxuan. All rights reserved. // #import "YZMAWithdrawViewController.h" #import "YZMAWithdrawNextViewController.h" @interface YZMAWithdrawViewController () < UITextFieldDelegate > @property (nonatomic,strong)UILabel *top1Label; @property (nonatomic,strong)UILabel *top2Label; @property (nonatomic,strong)UIView *centerBtns; @property (nonatomic,strong)UIButton *withdrawBtn; @property (nonatomic,strong)UILabel *leftLabel; @property (nonatomic,strong)UIButton *rightBtn; @property (nonatomic,strong)UIView *lineView; @property (nonatomic,strong)UITextField *textField; @property (nonatomic,strong)NSArray *moneyArr; @property (nonatomic,strong)UIButton *currentBtn; @property (nonatomic,strong)NSNumber *infoNum; @end @implementation YZMAWithdrawViewController - (void)viewDidLoad { [super viewDidLoad]; self.infoNum=@(1); [self addUI]; [self adjustUI]; [self configNavigationBar]; [self request]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"提现"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } -(void)request{ NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/priceList",BaseURL]; [YZMAHttp post:url params:nil success:^(id json) { if (json[@"data"]&&json[@"data"][@"data"]) { NSArray *arr=json[@"data"][@"data"]; if(arr.count==3){ self.moneyArr=arr; for (UIButton *btn in self.centerBtns.subviews) { NSInteger index=btn.tag-10000; [btn setTitle:[NSString stringWithFormat:@"%@元",arr[index]] forState:UIControlStateNormal]; } } NSNumber *flag=json[@"data"][@"flag"]; self.infoNum=flag; if ([flag integerValue]==2) { //前往微信绑定 // if (json[@"data"][@"info"]) { // [SVProgressHUD showErrorWithStatus:json[@"data"][@"info"]]; // [SVProgressHUD dismissWithDelay:1.0f]; // } [self.withdrawBtn setTitle:@"绑定微信并提现" forState:UIControlStateNormal]; }else{ [self.withdrawBtn setTitle:@"申请提现" forState:UIControlStateNormal]; } } } failure:^(NSError *error) { }]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } -(void)addUI{ [self.view addSubview:self.top1Label]; [self.view addSubview:self.top2Label]; [self.view addSubview:self.centerBtns]; [self.view addSubview:self.withdrawBtn]; [self.view addSubview:self.leftLabel]; [self.view addSubview:self.rightBtn]; [self.view addSubview:self.lineView]; [self.view addSubview:self.textField]; } -(void)adjustUI{ [self.top1Label mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(20)); make.top.mas_equalTo(98); }]; [self.top2Label mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.top1Label.mas_left); make.top.equalTo(self.top1Label.mas_bottom).offset(4); }]; [self.centerBtns mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.top.equalTo(self.top2Label.mas_bottom).offset(35); make.height.mas_equalTo(40); }]; [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(27)); make.top.equalTo(self.centerBtns.mas_bottom).offset(15); }]; [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(FITSIZE(-27)); make.centerY.equalTo(self.leftLabel.mas_centerY); }]; [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.leftLabel.mas_left); make.right.equalTo(self.rightBtn.mas_right); make.top.equalTo(self.leftLabel.mas_bottom); make.height.mas_equalTo(0.5); }]; [self.withdrawBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view.mas_centerX); make.top.equalTo(self.lineView.mas_bottom).offset(126); make.width.mas_equalTo(FITSIZE(250)); make.height.mas_equalTo(42); }]; [self.textField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.leftLabel.mas_right).offset(FITSIZE(5)); make.right.equalTo(self.rightBtn.mas_left).offset(FITSIZE(5)); make.height.equalTo(self.rightBtn.mas_height); // make.centerY.equalTo(self.leftLabel.mas_centerY); make.bottom.equalTo(self.lineView.mas_top).offset(-2); }]; } #pragma mark -点击事件 -(void)changeMoney:(UIButton *)btn{ if (self.currentBtn) {//把当前的边框和字体颜色变成 self.currentBtn.layer.borderColor=[UIColor YHColorWithHex:0xCCCCCC].CGColor; [self.currentBtn setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal]; } switch (btn.tag) { case 20001: { self.textField.text=self.moneyStr; } break; case 10000: case 10001: case 10002: self.currentBtn=btn; [self.currentBtn setTitleColor:[UIColor YHColorWithHex:0xFF5200] forState:UIControlStateNormal]; self.currentBtn.layer.borderColor=[UIColor YHColorWithHex:0xFF5200].CGColor; if (self.moneyArr &&self.moneyArr.count==3) { if ([self.moneyArr[btn.tag-10000] integerValue]!=0) { self.textField.text=[NSString stringWithFormat:@"%@",self.moneyArr[btn.tag-10000]]; } } break; default: break; } } -(void)withdrawAction{ float money=[self.textField.text floatValue]; float maxMoney=[self.moneyStr floatValue]; if (money>=10) { if (money<=maxMoney) { if ([self.infoNum integerValue]==2) { [[YZMAUMbindWeChat sharedInstance] bindWeChatSuccess:^(UMSocialUserInfoResponse *response) { self.infoNum=@(1); [self.withdrawBtn setTitle:@"申请提现" forState:UIControlStateNormal]; YZMAWithdrawNextViewController *vc=[[YZMAWithdrawNextViewController alloc]init]; vc.moneyStr=self.textField.text; [self.navigationController pushViewController:vc animated:YES]; } fail:^(NSError *error) { }]; }else{ YZMAWithdrawNextViewController *vc=[[YZMAWithdrawNextViewController alloc]init]; vc.moneyStr=self.textField.text; [self.navigationController pushViewController:vc animated:YES]; } }else{ [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"余额不足,请再接再厉哦"]; } }else{ [MBProgressHUD showMessage:@"提现金额不能少于10元哦"]; [SVProgressHUD dismiss]; } } #pragma mark -代理 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ if ([@"" isEqualToString:string]) { return YES; } if ([@"0123456789" rangeOfString:string].location!= NSNotFound) { return YES; } if ([@"." isEqualToString:string]) { if ([textField.text rangeOfString:@"."].location==NSNotFound) { return YES; } } return NO; } #pragma mark -懒加载 -(UILabel *)top1Label{ if (!_top1Label) { _top1Label=[[UILabel alloc]init];//NSForegroundColorAttributeName NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"当前可提现金额:%@元",self.moneyStr]]; [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0f] range:NSMakeRange(0, 8)]; [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:26.0f] range:NSMakeRange(8,self.moneyStr.length)]; [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0f] range:NSMakeRange(self.moneyStr.length+8,1)]; [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor YHColorWithHex:0x333333] range:NSMakeRange(0, 8)]; [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor YHColorWithHex:0xFF1E00] range:NSMakeRange(8,self.moneyStr.length)]; [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor YHColorWithHex:0x333333] range:NSMakeRange(self.moneyStr.length+8,1)]; _top1Label.attributedText = AttributedStr; } return _top1Label; } -(UILabel *)top2Label{ if (!_top2Label) { _top2Label=[[UILabel alloc]init]; _top2Label.font=[UIFont systemFontOfSize:16]; _top2Label.textColor=[UIColor YHColorWithHex:0x333333]; _top2Label.text=@""; } return _top2Label; } -(UIView *)centerBtns{ if (!_centerBtns) { _centerBtns=[[UIView alloc]init]; NSInteger btnSun=3; float btnWidth=FITSIZE(100); float interval=(SCREEN_WIDTH-btnSun*btnWidth)/4.0f; for (int i=0; i