BuyerGetMoneyVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // BuyerGetMoneyVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/29.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "BuyerGetMoneyVC.h"
  9. //#import "profitTypeVC.h"
  10. #import "YBGetTypeListVC.h"
  11. #define kMaxLength 10
  12. @interface BuyerGetMoneyVC ()
  13. {
  14. UILabel *nowVotesL;
  15. UITextField *votesT;
  16. UILabel *typeLabel;
  17. int cash_rate;
  18. UIButton *inputBtn;
  19. UILabel *tipsLabel;
  20. NSDictionary *typeDic;
  21. UIImageView *seletTypeImgView;
  22. }
  23. @end
  24. @implementation BuyerGetMoneyVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.view.backgroundColor =UIColor.whiteColor;
  28. [self navtion];
  29. [self creatUI];
  30. }
  31. -(void)navtion{
  32. UIView *navtion = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 64 + statusbarHeight)];
  33. navtion.backgroundColor =UIColor.whiteColor;
  34. UILabel *label = [[UILabel alloc]init];
  35. label.text = YZMsg(@"提取余额");
  36. [label setFont:NaviTitle_Font];
  37. label.textColor = UIColor.blackColor;
  38. label.frame = CGRectMake(0, statusbarHeight,_window_width,84);
  39. label.textAlignment = NSTextAlignmentCenter;
  40. [navtion addSubview:label];
  41. UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  42. UIButton *bigBTN = [[UIButton alloc]initWithFrame:CGRectMake(0, statusbarHeight, _window_width/2, 64)];
  43. [bigBTN addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  44. [navtion addSubview:bigBTN];
  45. returnBtn.frame = CGRectMake(8,24 + statusbarHeight,40,40);
  46. returnBtn.imageEdgeInsets = UIEdgeInsetsMake(12.5, 0, 12.5, 25);
  47. [returnBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:UIControlStateNormal];
  48. [returnBtn addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  49. [navtion addSubview:returnBtn];
  50. UIButton *btnttttt = [UIButton buttonWithType:UIButtonTypeCustom];
  51. btnttttt.backgroundColor = [UIColor clearColor];
  52. [btnttttt addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  53. btnttttt.frame = CGRectMake(0,0,100,64);
  54. [navtion addSubview:btnttttt];
  55. [PublicObj lineViewWithFrame:CGRectMake(0, navtion.height-1, _window_width, 1) andColor:RGB(245, 245, 245) andView:navtion];
  56. [self.view addSubview:navtion];
  57. }
  58. -(void)doReturn{
  59. [self.navigationController popViewControllerAnimated:YES];
  60. [self dismissViewControllerAnimated:YES completion:nil];
  61. }
  62. - (void)tapClick{
  63. [votesT resignFirstResponder];
  64. }
  65. - (void)creatUI{
  66. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
  67. [self.view addGestureRecognizer:tap];
  68. //黄色背景图
  69. UIImageView *backImgView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.04, 64+statusbarHeight+10, _window_width*0.92, _window_width*0.92*24/69)];
  70. backImgView.image = [UIImage imageNamed:@"profitBg"];
  71. [self.view addSubview:backImgView];
  72. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, backImgView.height/4, backImgView.width, backImgView.height/4)];
  73. label.textAlignment = NSTextAlignmentCenter;
  74. label.textColor = [UIColor whiteColor];
  75. label.font = [UIFont systemFontOfSize:15];
  76. label.text = YZMsg(@"可提取金额");
  77. [backImgView addSubview:label];
  78. nowVotesL = [[UILabel alloc]initWithFrame:CGRectMake(0, label.bottom+10, backImgView.width, backImgView.height/4)];
  79. nowVotesL.textAlignment = NSTextAlignmentCenter;
  80. nowVotesL.textColor = [UIColor whiteColor];
  81. nowVotesL.font = [UIFont boldSystemFontOfSize:22];
  82. nowVotesL.text = minstr([self.moneyDic valueForKey:@"balance"]);
  83. [backImgView addSubview:nowVotesL];
  84. //输入提现金额的视图
  85. UIView *textView = [[UIView alloc]initWithFrame:CGRectMake(backImgView.left, backImgView.bottom+10, backImgView.width, backImgView.height/2)];
  86. textView.backgroundColor = RGB(245, 245, 245);
  87. textView.layer.cornerRadius = 5.0;
  88. textView.layer.masksToBounds = YES;
  89. [self.view addSubview:textView];
  90. NSArray *arr = @[YZMsg(@"输入提取金额")];
  91. for (int i = 0; i<1; i++) {
  92. CGFloat labelW = [PublicObj widthOfString:arr[i] andFont:[UIFont systemFontOfSize:15] andHeight:textView.height];
  93. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(textView.width*0.05, textView.height/2*i, labelW+20, textView.height)];
  94. label.textColor = Normal_TextColor;
  95. label.font = [UIFont systemFontOfSize:15];
  96. label.text = arr[i];
  97. [textView addSubview:label];
  98. votesT = [[UITextField alloc]initWithFrame:CGRectMake(label.right, 0, textView.width*0.95-label.right, textView.height)];
  99. votesT.textColor = Pink_Cor;
  100. votesT.font = [UIFont boldSystemFontOfSize:17];
  101. votesT.placeholder = @"0";
  102. votesT.keyboardType = UIKeyboardTypeNumberPad;
  103. [textView addSubview:votesT];
  104. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldEditChanged:)
  105. name:@"UITextFieldTextDidChangeNotification" object:votesT];
  106. }
  107. //选择提现账户
  108. UIView *typeView = [[UIView alloc]initWithFrame:CGRectMake(backImgView.left, textView.bottom+10, backImgView.width, 50)];
  109. typeView.backgroundColor = RGB(245, 245, 245);
  110. typeView.layer.cornerRadius = 5.0;
  111. typeView.layer.masksToBounds = YES;
  112. [self.view addSubview:typeView];
  113. typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(textView.width*0.05, 0, typeView.width*0.95-40, 50)];
  114. typeLabel.textColor = Normal_TextColor;
  115. typeLabel.font = [UIFont systemFontOfSize:15];
  116. typeLabel.text = YZMsg(@"请选择提现账户");
  117. [typeView addSubview:typeLabel];
  118. seletTypeImgView = [[UIImageView alloc]initWithFrame:CGRectMake(typeLabel.left, 15, 20, 20)];
  119. seletTypeImgView.hidden = YES;
  120. [typeView addSubview:seletTypeImgView];
  121. UIImageView *rightImgView = [[UIImageView alloc]initWithFrame:CGRectMake(typeView.width-30, 18, 14, 14)];
  122. rightImgView.image = [UIImage imageNamed:@"person_right"];
  123. rightImgView.userInteractionEnabled = YES;
  124. [typeView addSubview:rightImgView];
  125. UIButton *btn = [UIButton buttonWithType:0];
  126. btn.frame = CGRectMake(0, 0, typeView.width, typeView.height);
  127. [btn addTarget:self action:@selector(selectPayType) forControlEvents:UIControlEventTouchUpInside];
  128. [typeView addSubview:btn];
  129. inputBtn = [UIButton buttonWithType:0];
  130. inputBtn.frame = CGRectMake(15, typeView.bottom + 50, _window_width - 30, 40);
  131. [inputBtn setBackgroundColor:Pink_Cor];
  132. [inputBtn setTitle:YZMsg(@"立即提现") forState:0];
  133. [inputBtn addTarget:self action:@selector(inputBtnClick) forControlEvents:UIControlEventTouchUpInside];
  134. inputBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  135. inputBtn.layer.cornerRadius = 20;
  136. inputBtn.layer.masksToBounds = YES;
  137. [self.view addSubview:inputBtn];
  138. tipsLabel = [[UILabel alloc]initWithFrame:CGRectMake(inputBtn.left+15, inputBtn.bottom + 15, inputBtn.width-30, 100)];
  139. tipsLabel.font = [UIFont systemFontOfSize:11];
  140. tipsLabel.textColor = RGB_COLOR(@"#666666", 1);
  141. tipsLabel.numberOfLines = 0;
  142. [self.view addSubview:tipsLabel];
  143. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeMoenyLabelValue) name:UITextFieldTextDidChangeNotification object:nil];
  144. }
  145. //选择z提现方式
  146. - (void)selectPayType{
  147. YBGetTypeListVC *vc = [[YBGetTypeListVC alloc]init];
  148. if ([typeDic allKeys].count>0) {
  149. vc.selectID = minstr([typeDic valueForKey:@"id"]);
  150. }else{
  151. vc.selectID = YZMsg(@"未选择提现方式");
  152. }
  153. YBWeakSelf;
  154. vc.block = ^(NSDictionary * _Nonnull dic) {
  155. typeDic = dic;
  156. if ([dic allKeys].count>0) {
  157. [Config saveCashAccount:typeDic];
  158. }
  159. [weakSelf updateShowAccount:dic];
  160. };
  161. [self.navigationController pushViewController:vc animated:YES];
  162. }
  163. -(void)updateShowAccount:(NSDictionary *)dic {
  164. seletTypeImgView.hidden = NO;
  165. typeLabel.x = seletTypeImgView.right + 5;
  166. typeLabel.textColor = [UIColor blackColor];
  167. int type = [minstr([dic valueForKey:@"type"]) intValue];
  168. switch (type) {
  169. case 1:
  170. seletTypeImgView.image = [UIImage imageNamed:@"profit_zff"];
  171. typeLabel.text = [NSString stringWithFormat:@"%@(%@)",minstr([dic valueForKey:@"account"]),minstr([dic valueForKey:@"name"])];
  172. break;
  173. case 2:
  174. seletTypeImgView.image = [UIImage imageNamed:@"profit_wx"];
  175. typeLabel.text = [NSString stringWithFormat:@"%@",minstr([dic valueForKey:@"account"])];
  176. break;
  177. case 3:
  178. seletTypeImgView.image = [UIImage imageNamed:@"profit_card"];
  179. typeLabel.text = [NSString stringWithFormat:@"%@(%@)",minstr([dic valueForKey:@"account"]),minstr([dic valueForKey:@"name"])];
  180. break;
  181. default:{
  182. seletTypeImgView.hidden = YES;
  183. typeLabel.x = seletTypeImgView.left;
  184. typeLabel.text = YZMsg(@"请选择提现账户");
  185. typeLabel.textColor = RGB_COLOR(@"#646464", 1);
  186. }break;
  187. }
  188. }
  189. //提交申请
  190. - (void)inputBtnClick{
  191. if(!typeDic){
  192. [MBProgressHUD showError:YZMsg(@"请填写提现账户")];
  193. return;
  194. }
  195. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"accountid":minstr([typeDic valueForKey:@"id"]),@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  196. NSString *sign = [PublicObj sortString:signdic];
  197. NSDictionary *dic = @{
  198. @"uid":[Config getOwnID],
  199. @"token":[Config getOwnToken],
  200. @"accountid":minstr([typeDic valueForKey:@"id"]),
  201. @"money":votesT.text,
  202. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  203. @"sign":sign,
  204. };
  205. [YBNetworking postWithUrl:@"User.setShopCash" Dic:dic Suc:^(int code, id info, NSString *msg) {
  206. if (code == 0) {
  207. [MBProgressHUD showError:msg];
  208. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  209. }else{
  210. [MBProgressHUD showError:msg];
  211. }
  212. } Fail:^(id fail) {
  213. }];
  214. }
  215. - (void)ChangeMoenyLabelValue{
  216. if ([[NSString stringWithFormat:@"%lld",[votesT.text longLongValue]/cash_rate] integerValue] > 0) {
  217. inputBtn.userInteractionEnabled = YES;
  218. [inputBtn setBackgroundColor:Pink_Cor];
  219. }else{
  220. inputBtn.userInteractionEnabled = NO;
  221. [inputBtn setBackgroundColor:RGB_COLOR(@"#dcdcdc", 1)];
  222. }
  223. }
  224. -(void)textFieldEditChanged:(NSNotification *)obj{
  225. UITextField *textField = (UITextField *)obj.object;
  226. NSString *toBeString = textField.text;
  227. NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
  228. if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
  229. UITextRange *selectedRange = [textField markedTextRange]; //获取高亮部分
  230. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  231. // 没有高亮选择的字,则对已输入的文字进行字数统计和限制
  232. if (!position) {
  233. if (toBeString.length > kMaxLength) {
  234. textField.text = [toBeString substringToIndex:kMaxLength];
  235. }
  236. } // 有高亮选择的字符串,则暂不对文字进行统计和限制
  237. else{
  238. }
  239. } // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况 else{
  240. if (toBeString.length > kMaxLength) {
  241. textField.text = [toBeString substringToIndex:kMaxLength];
  242. }
  243. }
  244. @end