WithdrawalController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. //
  2. // WithdrawalController.m
  3. // model
  4. //
  5. // Created by zuxiukuan on 2018/7/15.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 提现界面
  8. #import "WithdrawalController.h"
  9. #import "BindPhoneController.h"
  10. @interface WithdrawalController () <UITextFieldDelegate> {
  11. NSString *amount;
  12. NSString *useAmount;
  13. NSString *name;
  14. NSString *account;
  15. }
  16. @property(nonatomic, strong) UILabel *moneyLabel;
  17. @property(nonatomic, strong) UILabel *totalMoneyLabel;
  18. @property(nonatomic, strong) UILabel *withdrawalLabel;
  19. @property(nonatomic, strong) UILabel *accountNameLabel;
  20. @property(nonatomic, strong) UILabel *phoneLabel;
  21. @property(nonatomic, strong) UITextField *priceTF; //提现金额
  22. @end
  23. @implementation WithdrawalController
  24. - (void)viewWillAppear:(BOOL)animated {
  25. [super viewWillAppear:animated];
  26. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  27. [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  28. [self.navigationController.navigationBar setShadowImage:[UIImage new]];
  29. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
  30. [self getDataFromNetworking];
  31. }
  32. - (void)viewWillDisappear:(BOOL)animated {
  33. [super viewWillDisappear:animated];
  34. self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
  35. [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
  36. [self.navigationController.navigationBar setShadowImage:nil];
  37. [self.navigationController.navigationBar setTitleTextAttributes:nil];
  38. }
  39. - (void)viewDidLoad {
  40. [super viewDidLoad];
  41. self.view.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  42. //设置导航条
  43. [self creatNavBar];
  44. //设置子试图
  45. [self creatSubViews];
  46. }
  47. - (void)didReceiveMemoryWarning {
  48. [super didReceiveMemoryWarning];
  49. // Dispose of any resources that can be recreated.
  50. }
  51. - (void)creatNavBar {
  52. self.title = @"提现";
  53. //返回
  54. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  55. btn.frame = CGRectMake(0, 0, 40, 40);
  56. [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
  57. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  58. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  59. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  60. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  61. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  62. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  63. }
  64. - (void)backClick {
  65. if (self.passBackAmount) {
  66. self.passBackAmount(amount);
  67. }
  68. [self.navigationController popViewControllerAnimated:YES];
  69. }
  70. - (void)creatSubViews {
  71. CGFloat headerHeight = (HeightStatusBar == 44) ? 277 : 233;
  72. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, headerHeight)];
  73. UIImageView *bgView = [[UIImageView alloc] initWithFrame:headerView.bounds];
  74. [bgView setImage:[UIImage imageNamed:@"jianbianbeijing"]];
  75. [headerView addSubview:bgView];
  76. //
  77. UIImageView *verticalImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth / 2, headerHeight - 125, 1, 75)];
  78. verticalImageView.image = [UIImage imageNamed:@"shufenge"];
  79. [headerView addSubview:verticalImageView];
  80. //
  81. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, Height_NaviBar + 50, ScreenWidth / 2, 14)];
  82. titleLabel.text = @"资产总额";
  83. titleLabel.textAlignment = NSTextAlignmentCenter;
  84. titleLabel.font = [UIFont systemFontOfSize:14];
  85. titleLabel.textColor = RGBValueColor(0xffffff, 1.0);
  86. [headerView addSubview:titleLabel];
  87. //
  88. self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleLabel.frame) + 25, ScreenWidth / 2, 30)];
  89. self.moneyLabel.textAlignment = NSTextAlignmentCenter;
  90. self.moneyLabel.textColor = RGBValueColor(0xffffff, 1.0);
  91. NSString *str = @"0元";
  92. NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:str];
  93. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str.length - 1)];
  94. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str.length - 1, 1)];
  95. self.moneyLabel.attributedText = attrString;
  96. [headerView addSubview:self.moneyLabel];
  97. //
  98. UILabel *moneyTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(verticalImageView.frame), Height_NaviBar + 50, ScreenWidth / 2, 14)];
  99. moneyTitleLabel.text = @"可提现";
  100. moneyTitleLabel.textAlignment = NSTextAlignmentCenter;
  101. moneyTitleLabel.font = [UIFont systemFontOfSize:14];
  102. moneyTitleLabel.textColor = RGBValueColor(0xffffff, 1.0);
  103. [headerView addSubview:moneyTitleLabel];
  104. //
  105. self.totalMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(verticalImageView.frame), CGRectGetMaxY(moneyTitleLabel.frame) + 25, ScreenWidth / 2, 30)];
  106. self.totalMoneyLabel.textAlignment = NSTextAlignmentCenter;
  107. self.totalMoneyLabel.textColor = RGBValueColor(0xffffff, 1.0);
  108. NSString *str1 = @"0元";
  109. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:str1];
  110. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str1.length - 1)];
  111. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str1.length - 1, 1)];
  112. self.totalMoneyLabel.attributedText = attrString1;
  113. [headerView addSubview:self.totalMoneyLabel];
  114. [self.view addSubview:headerView];
  115. // 白色背景 views
  116. UIImageView *whiteImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headerView.frame) + 10, ScreenWidth, 163)];
  117. whiteImageView.userInteractionEnabled = YES;
  118. whiteImageView.image = [UIImage imageNamed:@"beisebeijing"];
  119. [self.view addSubview:whiteImageView];
  120. //我的提现账户
  121. UILabel *accountlabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, ScreenWidth / 2 - 20, 56)];
  122. accountlabel.textAlignment = NSTextAlignmentLeft;
  123. accountlabel.textColor = RGBValueColor(0x333333, 1.0);
  124. accountlabel.text = @"我的提现账户";
  125. accountlabel.font = [UIFont systemFontOfSize:16];
  126. [whiteImageView addSubview:accountlabel];
  127. //管理提现账户
  128. UILabel *managerAccountlabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, 0, ScreenWidth / 2 - 40, 56)];
  129. managerAccountlabel.textAlignment = NSTextAlignmentRight;
  130. managerAccountlabel.textColor = RGBValueColor(0x333333, 1.0);
  131. managerAccountlabel.text = @"管理提现账户";
  132. managerAccountlabel.font = [UIFont systemFontOfSize:16];
  133. [whiteImageView addSubview:managerAccountlabel];
  134. //右箭头
  135. UIImageView *arrowView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 28, 22.5, 8, 14)];
  136. arrowView.image = [UIImage imageNamed:@"youjiantou"];
  137. [whiteImageView addSubview:arrowView];
  138. UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  139. clickBtn.frame = CGRectMake(ScreenWidth / 2, 0, ScreenWidth / 2, 56);
  140. [clickBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
  141. [whiteImageView addSubview:clickBtn];
  142. //分割线
  143. UIImageView *lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 56, ScreenWidth, 1)];
  144. lineView.image = [UIImage imageNamed:@"fengexian"];
  145. [whiteImageView addSubview:lineView];
  146. //提现账户(支付宝
  147. self.withdrawalLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(lineView.frame) + 17, ScreenWidth, 14)];
  148. self.withdrawalLabel.textAlignment = NSTextAlignmentLeft;
  149. self.withdrawalLabel.textColor = RGBValueColor(0x333333, 1.0);
  150. self.withdrawalLabel.font = [UIFont systemFontOfSize:14.0];
  151. self.withdrawalLabel.text = @"提现账户(支付宝)";
  152. [whiteImageView addSubview:self.withdrawalLabel];
  153. //账户姓名(支付宝)
  154. self.accountNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.withdrawalLabel.frame) + 17, ScreenWidth, 14)];
  155. self.accountNameLabel.textAlignment = NSTextAlignmentLeft;
  156. self.accountNameLabel.textColor = RGBValueColor(0x333333, 1.0);
  157. self.accountNameLabel.font = [UIFont systemFontOfSize:14.0];
  158. self.accountNameLabel.text = @"账户姓名(支付宝)";
  159. [whiteImageView addSubview:self.accountNameLabel];
  160. //未绑定手机
  161. self.phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.accountNameLabel.frame) + 17, ScreenWidth, 14)];
  162. self.phoneLabel.textAlignment = NSTextAlignmentLeft;
  163. self.phoneLabel.textColor = RGBValueColor(0x999999, 1.0);
  164. self.phoneLabel.font = [UIFont systemFontOfSize:14.0];
  165. self.phoneLabel.text = @"未绑定支付宝";
  166. [whiteImageView addSubview:self.phoneLabel];
  167. //金额输入框背景
  168. UIImageView *amtBg = [[UIImageView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(whiteImageView.frame) + 55, ScreenWidth - 40, 45)];
  169. amtBg.image = [UIImage imageNamed:@"chakan"];
  170. [self.view addSubview:amtBg];
  171. //金额输入框
  172. UITextField *priceTF = [[UITextField alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(whiteImageView.frame) + 64, ScreenWidth - 40, 30)];
  173. priceTF.textAlignment = NSTextAlignmentCenter;
  174. priceTF.keyboardType = UIKeyboardTypeDecimalPad;
  175. priceTF.font = [UIFont systemFontOfSize:16];
  176. priceTF.textColor = RGBValueColor(0x333333, 1.0);
  177. priceTF.placeholder = @"请输入提现金额";
  178. priceTF.tag = 1000;
  179. priceTF.delegate = self;
  180. [self.view addSubview:priceTF];
  181. self.priceTF = priceTF;
  182. //提现按钮
  183. UIButton *withdrawalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  184. withdrawalBtn.frame = CGRectMake(20, CGRectGetMaxY(priceTF.frame) + 20, ScreenWidth - 40, 45);
  185. [withdrawalBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal];
  186. [withdrawalBtn setTitle:@"提现" forState:UIControlStateNormal];
  187. [withdrawalBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal];
  188. [withdrawalBtn addTarget:self action:@selector(withdrawalBtnAction) forControlEvents:UIControlEventTouchUpInside];
  189. [self.view addSubview:withdrawalBtn];
  190. }
  191. #pragma mark -- 网络请求
  192. - (void)getDataFromNetworking {
  193. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  194. ModelUser *modelUser = [ModelUser user];
  195. NSDictionary *dic = @{@"modelpk": modelUser.modelpk};
  196. [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcashload(PublicUrl)
  197. parameters:dic
  198. finish:^(id dataDic) {
  199. [MBProgressHUD hideHUDForView:self.view animated:YES];
  200. NSString *issuccess = dataDic[@"msg"];
  201. if ([issuccess isEqualToString:@"success"]) {
  202. NSDictionary *data = dataDic[@"data"];
  203. amount = data[@"coin_a"];
  204. useAmount = data[@"coin_use"];
  205. name = data[@"name"];
  206. account = data[@"alipayid"];
  207. [self updateUI];
  208. } else {
  209. [MBProgressHUD showInfo:@"请求失败!"];
  210. }
  211. }
  212. enError:^(NSError *error) {
  213. [MBProgressHUD hideHUDForView:self.view animated:YES];
  214. }];
  215. }
  216. #pragma mark -- 刷新界面
  217. - (void)updateUI {
  218. NSString *str = [NSString stringWithFormat:@"%@元", amount];
  219. NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:str];
  220. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str.length - 1)];
  221. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str.length - 1, 1)];
  222. self.moneyLabel.attributedText = attrString;
  223. NSString *str1 = [NSString stringWithFormat:@"%@元", useAmount];
  224. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:str1];
  225. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str1.length - 1)];
  226. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str1.length - 1, 1)];
  227. self.totalMoneyLabel.attributedText = attrString1;
  228. self.withdrawalLabel.text = [NSString stringWithFormat:@"提现账户(支付宝):%@", account];
  229. self.accountNameLabel.text = [NSString stringWithFormat:@"账户姓名(支付宝):%@", name];
  230. if (account.length > 0 && name.length > 0) {
  231. self.phoneLabel.hidden = YES;
  232. } else {
  233. self.phoneLabel.hidden = NO;
  234. }
  235. }
  236. #pragma mark -- 管理我的账户
  237. - (void)clickBtn {
  238. NSLog(@"管理我的账户");
  239. BindPhoneController *bindPhoneVC = [[BindPhoneController alloc] init];
  240. [self.navigationController pushViewController:bindPhoneVC animated:YES];
  241. }
  242. #pragma mark -- 提现
  243. - (void)withdrawalBtnAction {
  244. if (account.length == 0 || name.length == 0) {
  245. [MBProgressHUD showInfo:@"请先去绑定支付宝"];
  246. return;
  247. }
  248. if (self.priceTF.text.length == 0) {
  249. [MBProgressHUD showInfo:@"请输入提现金额"];
  250. return;
  251. }
  252. if ([self.priceTF.text doubleValue] > [useAmount doubleValue]) {
  253. [MBProgressHUD showInfo:@"提现金额不能大于可提现总额"];
  254. return;
  255. }
  256. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  257. ModelUser *modelUser = [ModelUser user];
  258. NSDictionary *dic = @{@"modelpk": modelUser.modelpk, @"fee": self.priceTF.text};
  259. [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcash(PublicUrl) parameters:dic finish:^(id dataDic) {
  260. [MBProgressHUD hideHUDForView:self.view animated:YES];
  261. NSString *issuccess = dataDic[@"msg"];
  262. if ([issuccess isEqualToString:@"success"]) {
  263. NSDictionary *dic = dataDic[@"data"];
  264. amount = dic[@"coin_a"];
  265. useAmount = dic[@"coin_use"];
  266. name = dic[@"name"];
  267. account = dic[@"alipayid"];
  268. [self updateUI];
  269. self.priceTF.text = @"";
  270. [MBProgressHUD showInfo:@"提现成功"];
  271. } else {
  272. [MBProgressHUD showInfo:@"提现失败!"];
  273. }
  274. }
  275. enError:^(NSError *error) {
  276. [MBProgressHUD hideHUDForView:self.view animated:YES];
  277. }];
  278. }
  279. #pragma mark ----- UITextFieldDelegate
  280. - (void)textFieldDidEndEditing:(UITextField *)textField {
  281. NSLog(@"textField.text = %@", textField.text);
  282. }
  283. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  284. if (textField.tag == 1000) {
  285. if (![self isValidAboutInputText:textField shouldChangeCharactersInRange:range replacementString:string decimalNumber:2]) {
  286. return NO;
  287. }
  288. }
  289. return YES;
  290. }
  291. //输入框中只能输入数字和小数点,且小数点只能输入一位,参数number 可以设置小数的位数,该函数在-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string调用;
  292. - (BOOL)isValidAboutInputText:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string decimalNumber:(NSInteger)number {
  293. NSScanner *scanner = [NSScanner scannerWithString:string];
  294. NSCharacterSet *numbers;
  295. NSRange pointRange = [textField.text rangeOfString:@"."];
  296. if ((pointRange.length > 0) && (pointRange.location < range.location || pointRange.location > range.location + range.length)) {
  297. numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  298. } else {
  299. numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
  300. }
  301. if ([textField.text isEqualToString:@""] && [string isEqualToString:@"."]) {
  302. return NO;
  303. }
  304. short remain = number; //保留 number位小数
  305. NSString *tempStr = [textField.text stringByAppendingString:string];
  306. NSUInteger strlen = [tempStr length];
  307. if (pointRange.length > 0 && pointRange.location > 0) { //判断输入框内是否含有“.”。
  308. if ([string isEqualToString:@"."]) { //当输入框内已经含有“.”时,如果再输入“.”则被视为无效。
  309. return NO;
  310. }
  311. if (strlen > 0 && (strlen - pointRange.location) > remain + 1) { //当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。
  312. return NO;
  313. }
  314. }
  315. NSRange zeroRange = [textField.text rangeOfString:@"0"];
  316. if (zeroRange.length == 1 && zeroRange.location == 0) { //判断输入框第一个字符是否为“0”
  317. if (![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1) { //当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。
  318. textField.text = string;
  319. return NO;
  320. } else {
  321. if (pointRange.length == 0 && pointRange.location > 0) { //当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。
  322. if ([string isEqualToString:@"0"]) {
  323. return NO;
  324. }
  325. }
  326. }
  327. }
  328. NSString *buffer;
  329. if (![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0)) {
  330. return NO;
  331. } else {
  332. return YES;
  333. }
  334. }
  335. @end