// // WithdrawalController.m // model // // Created by zuxiukuan on 2018/7/15. // Copyright © 2018年 Mine. All rights reserved. // 提现界面 #import "WithdrawalController.h" #import "BindPhoneController.h" @interface WithdrawalController () { NSString *amount; NSString *useAmount; NSString *name; NSString *account; } @property(nonatomic, strong) UILabel *moneyLabel; @property(nonatomic, strong) UILabel *totalMoneyLabel; @property(nonatomic, strong) UILabel *withdrawalLabel; @property(nonatomic, strong) UILabel *accountNameLabel; @property(nonatomic, strong) UILabel *phoneLabel; @property(nonatomic, strong) UITextField *priceTF; //提现金额 @end @implementation WithdrawalController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBar.barStyle = UIBarStyleBlack; [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:[UIImage new]]; [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]; [self getDataFromNetworking]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.navigationController.navigationBar.barStyle = UIBarStyleDefault; [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:nil]; [self.navigationController.navigationBar setTitleTextAttributes:nil]; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); //设置导航条 [self creatNavBar]; //设置子试图 [self creatSubViews]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)creatNavBar { self.title = @"提现"; //返回 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 40, 40); [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal]; btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整 self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem]; } - (void)backClick { if (self.passBackAmount) { self.passBackAmount(amount); } [self.navigationController popViewControllerAnimated:YES]; } - (void)creatSubViews { CGFloat headerHeight = (HeightStatusBar == 44) ? 277 : 233; UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, headerHeight)]; UIImageView *bgView = [[UIImageView alloc] initWithFrame:headerView.bounds]; [bgView setImage:[UIImage imageNamed:@"jianbianbeijing"]]; [headerView addSubview:bgView]; // UIImageView *verticalImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth / 2, headerHeight - 125, 1, 75)]; verticalImageView.image = [UIImage imageNamed:@"shufenge"]; [headerView addSubview:verticalImageView]; // UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, Height_NaviBar + 50, ScreenWidth / 2, 14)]; titleLabel.text = @"资产总额"; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.font = [UIFont systemFontOfSize:14]; titleLabel.textColor = RGBValueColor(0xffffff, 1.0); [headerView addSubview:titleLabel]; // self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleLabel.frame) + 25, ScreenWidth / 2, 30)]; self.moneyLabel.textAlignment = NSTextAlignmentCenter; self.moneyLabel.textColor = RGBValueColor(0xffffff, 1.0); NSString *str = @"0元"; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:str]; [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str.length - 1)]; [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str.length - 1, 1)]; self.moneyLabel.attributedText = attrString; [headerView addSubview:self.moneyLabel]; // UILabel *moneyTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(verticalImageView.frame), Height_NaviBar + 50, ScreenWidth / 2, 14)]; moneyTitleLabel.text = @"可提现"; moneyTitleLabel.textAlignment = NSTextAlignmentCenter; moneyTitleLabel.font = [UIFont systemFontOfSize:14]; moneyTitleLabel.textColor = RGBValueColor(0xffffff, 1.0); [headerView addSubview:moneyTitleLabel]; // self.totalMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(verticalImageView.frame), CGRectGetMaxY(moneyTitleLabel.frame) + 25, ScreenWidth / 2, 30)]; self.totalMoneyLabel.textAlignment = NSTextAlignmentCenter; self.totalMoneyLabel.textColor = RGBValueColor(0xffffff, 1.0); NSString *str1 = @"0元"; NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:str1]; [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str1.length - 1)]; [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str1.length - 1, 1)]; self.totalMoneyLabel.attributedText = attrString1; [headerView addSubview:self.totalMoneyLabel]; [self.view addSubview:headerView]; // 白色背景 views UIImageView *whiteImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headerView.frame) + 10, ScreenWidth, 163)]; whiteImageView.userInteractionEnabled = YES; whiteImageView.image = [UIImage imageNamed:@"beisebeijing"]; [self.view addSubview:whiteImageView]; //我的提现账户 UILabel *accountlabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, ScreenWidth / 2 - 20, 56)]; accountlabel.textAlignment = NSTextAlignmentLeft; accountlabel.textColor = RGBValueColor(0x333333, 1.0); accountlabel.text = @"我的提现账户"; accountlabel.font = [UIFont systemFontOfSize:16]; [whiteImageView addSubview:accountlabel]; //管理提现账户 UILabel *managerAccountlabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, 0, ScreenWidth / 2 - 40, 56)]; managerAccountlabel.textAlignment = NSTextAlignmentRight; managerAccountlabel.textColor = RGBValueColor(0x333333, 1.0); managerAccountlabel.text = @"管理提现账户"; managerAccountlabel.font = [UIFont systemFontOfSize:16]; [whiteImageView addSubview:managerAccountlabel]; //右箭头 UIImageView *arrowView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 28, 22.5, 8, 14)]; arrowView.image = [UIImage imageNamed:@"youjiantou"]; [whiteImageView addSubview:arrowView]; UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom]; clickBtn.frame = CGRectMake(ScreenWidth / 2, 0, ScreenWidth / 2, 56); [clickBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside]; [whiteImageView addSubview:clickBtn]; //分割线 UIImageView *lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 56, ScreenWidth, 1)]; lineView.image = [UIImage imageNamed:@"fengexian"]; [whiteImageView addSubview:lineView]; //提现账户(支付宝 self.withdrawalLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(lineView.frame) + 17, ScreenWidth, 14)]; self.withdrawalLabel.textAlignment = NSTextAlignmentLeft; self.withdrawalLabel.textColor = RGBValueColor(0x333333, 1.0); self.withdrawalLabel.font = [UIFont systemFontOfSize:14.0]; self.withdrawalLabel.text = @"提现账户(支付宝)"; [whiteImageView addSubview:self.withdrawalLabel]; //账户姓名(支付宝) self.accountNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.withdrawalLabel.frame) + 17, ScreenWidth, 14)]; self.accountNameLabel.textAlignment = NSTextAlignmentLeft; self.accountNameLabel.textColor = RGBValueColor(0x333333, 1.0); self.accountNameLabel.font = [UIFont systemFontOfSize:14.0]; self.accountNameLabel.text = @"账户姓名(支付宝)"; [whiteImageView addSubview:self.accountNameLabel]; //未绑定手机 self.phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.accountNameLabel.frame) + 17, ScreenWidth, 14)]; self.phoneLabel.textAlignment = NSTextAlignmentLeft; self.phoneLabel.textColor = RGBValueColor(0x999999, 1.0); self.phoneLabel.font = [UIFont systemFontOfSize:14.0]; self.phoneLabel.text = @"未绑定支付宝"; [whiteImageView addSubview:self.phoneLabel]; //金额输入框背景 UIImageView *amtBg = [[UIImageView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(whiteImageView.frame) + 55, ScreenWidth - 40, 45)]; amtBg.image = [UIImage imageNamed:@"chakan"]; [self.view addSubview:amtBg]; //金额输入框 UITextField *priceTF = [[UITextField alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(whiteImageView.frame) + 64, ScreenWidth - 40, 30)]; priceTF.textAlignment = NSTextAlignmentCenter; priceTF.keyboardType = UIKeyboardTypeDecimalPad; priceTF.font = [UIFont systemFontOfSize:16]; priceTF.textColor = RGBValueColor(0x333333, 1.0); priceTF.placeholder = @"请输入提现金额"; priceTF.tag = 1000; priceTF.delegate = self; [self.view addSubview:priceTF]; self.priceTF = priceTF; //提现按钮 UIButton *withdrawalBtn = [UIButton buttonWithType:UIButtonTypeCustom]; withdrawalBtn.frame = CGRectMake(20, CGRectGetMaxY(priceTF.frame) + 20, ScreenWidth - 40, 45); [withdrawalBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal]; [withdrawalBtn setTitle:@"提现" forState:UIControlStateNormal]; [withdrawalBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal]; [withdrawalBtn addTarget:self action:@selector(withdrawalBtnAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:withdrawalBtn]; } #pragma mark -- 网络请求 - (void)getDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; ModelUser *modelUser = [ModelUser user]; NSDictionary *dic = @{@"modelpk": modelUser.modelpk}; [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcashload(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { NSDictionary *data = dataDic[@"data"]; amount = data[@"coin_a"]; useAmount = data[@"coin_use"]; name = data[@"name"]; account = data[@"alipayid"]; [self updateUI]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } #pragma mark -- 刷新界面 - (void)updateUI { NSString *str = [NSString stringWithFormat:@"%@元", amount]; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:str]; [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str.length - 1)]; [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str.length - 1, 1)]; self.moneyLabel.attributedText = attrString; NSString *str1 = [NSString stringWithFormat:@"%@元", useAmount]; NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:str1]; [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str1.length - 1)]; [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str1.length - 1, 1)]; self.totalMoneyLabel.attributedText = attrString1; self.withdrawalLabel.text = [NSString stringWithFormat:@"提现账户(支付宝):%@", account]; self.accountNameLabel.text = [NSString stringWithFormat:@"账户姓名(支付宝):%@", name]; if (account.length > 0 && name.length > 0) { self.phoneLabel.hidden = YES; } else { self.phoneLabel.hidden = NO; } } #pragma mark -- 管理我的账户 - (void)clickBtn { NSLog(@"管理我的账户"); BindPhoneController *bindPhoneVC = [[BindPhoneController alloc] init]; [self.navigationController pushViewController:bindPhoneVC animated:YES]; } #pragma mark -- 提现 - (void)withdrawalBtnAction { if (account.length == 0 || name.length == 0) { [MBProgressHUD showInfo:@"请先去绑定支付宝"]; return; } if (self.priceTF.text.length == 0) { [MBProgressHUD showInfo:@"请输入提现金额"]; return; } if ([self.priceTF.text doubleValue] > [useAmount doubleValue]) { [MBProgressHUD showInfo:@"提现金额不能大于可提现总额"]; return; } [MBProgressHUD showHUDAddedTo:self.view animated:YES]; ModelUser *modelUser = [ModelUser user]; NSDictionary *dic = @{@"modelpk": modelUser.modelpk, @"fee": self.priceTF.text}; [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcash(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { NSDictionary *dic = dataDic[@"data"]; amount = dic[@"coin_a"]; useAmount = dic[@"coin_use"]; name = dic[@"name"]; account = dic[@"alipayid"]; [self updateUI]; self.priceTF.text = @""; [MBProgressHUD showInfo:@"提现成功"]; } else { [MBProgressHUD showInfo:@"提现失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } #pragma mark ----- UITextFieldDelegate - (void)textFieldDidEndEditing:(UITextField *)textField { NSLog(@"textField.text = %@", textField.text); } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField.tag == 1000) { if (![self isValidAboutInputText:textField shouldChangeCharactersInRange:range replacementString:string decimalNumber:2]) { return NO; } } return YES; } //输入框中只能输入数字和小数点,且小数点只能输入一位,参数number 可以设置小数的位数,该函数在-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string调用; - (BOOL)isValidAboutInputText:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string decimalNumber:(NSInteger)number { NSScanner *scanner = [NSScanner scannerWithString:string]; NSCharacterSet *numbers; NSRange pointRange = [textField.text rangeOfString:@"."]; if ((pointRange.length > 0) && (pointRange.location < range.location || pointRange.location > range.location + range.length)) { numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; } else { numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."]; } if ([textField.text isEqualToString:@""] && [string isEqualToString:@"."]) { return NO; } short remain = number; //保留 number位小数 NSString *tempStr = [textField.text stringByAppendingString:string]; NSUInteger strlen = [tempStr length]; if (pointRange.length > 0 && pointRange.location > 0) { //判断输入框内是否含有“.”。 if ([string isEqualToString:@"."]) { //当输入框内已经含有“.”时,如果再输入“.”则被视为无效。 return NO; } if (strlen > 0 && (strlen - pointRange.location) > remain + 1) { //当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。 return NO; } } NSRange zeroRange = [textField.text rangeOfString:@"0"]; if (zeroRange.length == 1 && zeroRange.location == 0) { //判断输入框第一个字符是否为“0” if (![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1) { //当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。 textField.text = string; return NO; } else { if (pointRange.length == 0 && pointRange.location > 0) { //当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。 if ([string isEqualToString:@"0"]) { return NO; } } } } NSString *buffer; if (![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0)) { return NO; } else { return YES; } } @end