YBRedProfitVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. //
  2. // YBRedProfitVC.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2023/1/10.
  6. // Copyright © 2023 cat. All rights reserved.
  7. //
  8. #import "YBRedProfitVC.h"
  9. #import "YBGetTypeListVC.h"
  10. #import "PubH5.h"
  11. #import "accountDetails.h"
  12. @interface YBRedProfitVC ()<UITextFieldDelegate>{
  13. UILabel *allVotesL;
  14. UILabel *nowVotesL;
  15. MyTextField *votesT;
  16. UILabel *_getL;
  17. UILabel *moneyLabel;
  18. UILabel *typeLabel;
  19. int cash_rate;
  20. UIButton *inputBtn;
  21. UILabel *tipsLabel;
  22. NSDictionary *typeDic;
  23. UIImageView *seletTypeImgView;
  24. CGFloat _ratio;
  25. UILabel *_alertTipsL;
  26. }
  27. @end
  28. @implementation YBRedProfitVC
  29. -(void)navtion{
  30. UIView *navtion = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 64 + statusbarHeight)];
  31. navtion.backgroundColor = Normal_Color;
  32. UILabel *label = [[UILabel alloc]init];
  33. label.text = YZMsg(@"红包收益");
  34. [label setFont:NaviTitle_Font];
  35. label.textColor = [UIColor whiteColor];
  36. label.frame = CGRectMake(0, statusbarHeight,_window_width,84);
  37. label.textAlignment = NSTextAlignmentCenter;
  38. [navtion addSubview:label];
  39. UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. UIButton *bigBTN = [[UIButton alloc]initWithFrame:CGRectMake(0, statusbarHeight, _window_width/2, 64)];
  41. [bigBTN addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  42. [navtion addSubview:bigBTN];
  43. returnBtn.frame = CGRectMake(8,24 + statusbarHeight,40,40);
  44. returnBtn.imageEdgeInsets = UIEdgeInsetsMake(12.5, 0, 12.5, 25);
  45. [returnBtn setImage:[UIImage imageNamed:@"pub_back"] forState:UIControlStateNormal];
  46. [returnBtn addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  47. [navtion addSubview:returnBtn];
  48. UIButton *btnttttt = [UIButton buttonWithType:UIButtonTypeCustom];
  49. btnttttt.backgroundColor = [UIColor clearColor];
  50. [btnttttt addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  51. btnttttt.frame = CGRectMake(0,0,100,64);
  52. [navtion addSubview:btnttttt];
  53. UIButton *historyBtn = [UIButton buttonWithType:0];
  54. historyBtn.frame = CGRectMake(_window_width-75, 24+statusbarHeight, 65, 40);
  55. [historyBtn setTitle:YZMsg(@"明细") forState:0];
  56. [historyBtn setTitleColor:RGB_COLOR(@"#EA377F", 1) forState:0];
  57. historyBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  58. [historyBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  59. [navtion addSubview:historyBtn];
  60. // [PublicObj lineViewWithFrame:CGRectMake(0, navtion.height-1, _window_width, 1) andColor:RGB(244, 245, 246) andView:navtion];
  61. [self.view addSubview:navtion];
  62. }
  63. - (void)addBtnClick:(UIButton *)sender{
  64. accountDetails *web = [[accountDetails alloc]init];
  65. web.fromType = @"red";
  66. [self.navigationController pushViewController:web animated:YES];
  67. }
  68. -(void)doReturn{
  69. [self.navigationController popViewControllerAnimated:YES];
  70. [self dismissViewControllerAnimated:YES completion:nil];
  71. }
  72. - (void)viewDidLoad {
  73. [super viewDidLoad];
  74. self.view.backgroundColor = Normal_Color;
  75. self.naviView.hidden = YES;
  76. [BGSetting getBgSettingUpdate:NO maintain:NO eventBack:nil];
  77. typeDic = [Config getCashAccount];
  78. _ratio = 1;
  79. [self navtion];
  80. [self creatUI];
  81. [self requestData];
  82. }
  83. - (void)requestData{
  84. [YBNetworking postWithUrl:@"Cash.getRedProfit" Dic:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken]} Suc:^(int code, id info, NSString *msg) {
  85. if (code == 0) {
  86. //获取收益
  87. nowVotesL.text = [NSString stringWithFormat:@"%@",[[info firstObject] valueForKey:@"total"]];
  88. allVotesL.text = [NSString stringWithFormat:@"%@",[[info firstObject] valueForKey:@"votes"]];//收益 魅力值
  89. _ratio = [minstr([[info firstObject] valueForKey:@"cash_prop"]) floatValue];
  90. _alertTipsL.text = minstr([[info firstObject] valueForKey:@"tips"]);
  91. NSLog(@"收益数据........%@",info);
  92. }
  93. } Fail:^(id fail) {
  94. }];
  95. }
  96. - (void)tapClick{
  97. [votesT resignFirstResponder];
  98. }
  99. - (void)creatUI{
  100. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
  101. [self.view addGestureRecognizer:tap];
  102. //黄色背景图
  103. UIImageView *backImgView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.04, 64+statusbarHeight+10, _window_width*0.92, _window_width*0.92*24/69)];
  104. backImgView.image = [UIImage imageNamed:@"profitBg"];
  105. [self.view addSubview:backImgView];
  106. for (int i = 0; i < 4; i++) {
  107. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(backImgView.width/2*(i%2), backImgView.height/4*(i/2+1), backImgView.width/2, backImgView.height/4)];
  108. label.textAlignment = NSTextAlignmentCenter;
  109. label.textColor = [UIColor whiteColor];
  110. if (i<2) {
  111. label.font = [UIFont systemFontOfSize:15];
  112. if (i == 0) {
  113. label.text = [NSString stringWithFormat:@"%@%@",YZMsg(@"我的"),[common name_votes]];
  114. }else{
  115. label.text = YZMsg(@"可提取金额");
  116. [PublicObj lineViewWithFrame:CGRectMake(backImgView.width/2-0.5, backImgView.height/4, 1, backImgView.height/2) andColor:[UIColor whiteColor] andView:backImgView];
  117. }
  118. }else{
  119. label.font = [UIFont boldSystemFontOfSize:22];
  120. label.text = @"0";
  121. if (i == 2) {
  122. allVotesL = label;
  123. }else{
  124. nowVotesL = label;
  125. }
  126. }
  127. [backImgView addSubview:label];
  128. }
  129. //输入提现金额的视图
  130. UIView *textView = [[UIView alloc]initWithFrame:CGRectMake(backImgView.left, backImgView.bottom+10, backImgView.width, 50)];
  131. textView.backgroundColor = RGB_COLOR(@"#15102C", 1);
  132. [self.view addSubview:textView];
  133. votesT = [[MyTextField alloc]initWithFrame:CGRectMake(15, 0, textView.width-30, 50)];
  134. votesT.textColor = Pink_Cor;
  135. votesT.font = [UIFont systemFontOfSize:15];
  136. votesT.placeholder = @"0";
  137. votesT.placeCol = RGB_COLOR(@"#646464", 1);
  138. votesT.tintColor = Pink_Cor;
  139. votesT.keyboardType = UIKeyboardTypeNumberPad;
  140. votesT.delegate = self;
  141. [textView addSubview:votesT];
  142. UIButton *leftL = [UIButton buttonWithType:UIButtonTypeCustom];
  143. leftL.frame = CGRectMake(0, 0, 150, 50);
  144. leftL.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  145. [leftL setTitle:YZMsg(@"请输入要提取的金额") forState:0];
  146. leftL.titleLabel.font = SYS_Font(15);
  147. [leftL setTitleColor:RGB_COLOR(@"#646464", 1) forState:0];
  148. //leftL.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
  149. votesT.leftView = leftL;
  150. votesT.leftViewMode = UITextFieldViewModeAlways;
  151. [votesT addTarget:self action:@selector(votesTextFieldChange:) forControlEvents:UIControlEventEditingChanged];
  152. //可到账金额
  153. UIView *getView = [[UIView alloc]initWithFrame:CGRectMake(textView.left, textView.bottom+10, textView.width, 50)];
  154. getView.backgroundColor = textView.backgroundColor;
  155. [self.view addSubview:getView];
  156. UILabel *getDesL = [[UILabel alloc]init];
  157. getDesL.textColor = leftL.titleLabel.textColor;
  158. getDesL.font = leftL.titleLabel.font;
  159. getDesL.text = YZMsg(@"可到账金额");
  160. [getView addSubview:getDesL];
  161. [getDesL mas_makeConstraints:^(MASConstraintMaker *make) {
  162. make.left.equalTo(getView.mas_left).offset(15);
  163. make.centerY.equalTo(getView);
  164. }];
  165. _getL = [[UILabel alloc]init];
  166. _getL.textColor = Pink_Cor;
  167. _getL.font = getDesL.font;
  168. _getL.text = @"¥0";
  169. [getView addSubview:_getL];
  170. [_getL mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.left.equalTo(getDesL.mas_right).offset(15);
  172. make.centerY.equalTo(getDesL);
  173. make.right.lessThanOrEqualTo(getView.mas_right).offset(-10);
  174. }];
  175. //选择提现账户
  176. UIView *typeView = [[UIView alloc]initWithFrame:CGRectMake(backImgView.left, getView.bottom+10, backImgView.width, 50)];
  177. typeView.backgroundColor = RGB_COLOR(@"#15102C", 1);
  178. [self.view addSubview:typeView];
  179. typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, typeView.width - 15-40, 50)];
  180. typeLabel.textColor = RGB_COLOR(@"#646464", 1);
  181. typeLabel.font = [UIFont systemFontOfSize:15];
  182. typeLabel.text = YZMsg(@"请选择提现账户");
  183. [typeView addSubview:typeLabel];
  184. seletTypeImgView = [[UIImageView alloc]initWithFrame:CGRectMake(typeLabel.left, 15, 20, 20)];
  185. seletTypeImgView.hidden = YES;
  186. [typeView addSubview:seletTypeImgView];
  187. UIImageView *rightImgView = [[UIImageView alloc]initWithFrame:CGRectMake(typeView.width-30, (50-12*39/24)/2, 12, 12*39/24)];// 24/39
  188. rightImgView.image = [UIImage imageNamed:@"更多-箭头"];
  189. rightImgView.userInteractionEnabled = YES;
  190. [typeView addSubview:rightImgView];
  191. UIButton *btn = [UIButton buttonWithType:0];
  192. btn.frame = CGRectMake(0, 0, typeView.width, typeView.height);
  193. [btn addTarget:self action:@selector(selectPayType) forControlEvents:UIControlEventTouchUpInside];
  194. [typeView addSubview:btn];
  195. inputBtn = [UIButton buttonWithType:0];
  196. inputBtn.frame = CGRectMake(_window_width*0.15, typeView.bottom + 30, _window_width*0.7, 40);
  197. [inputBtn setBackgroundColor:RGB_COLOR(@"#27223B", 1)];
  198. [inputBtn setTitle:YZMsg(@"去提现") forState:0];
  199. [inputBtn setTitleColor:RGB_COLOR(@"#969696", 1) forState:0];
  200. [inputBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:UIControlStateSelected];
  201. [inputBtn addTarget:self action:@selector(inputBtnClick) forControlEvents:UIControlEventTouchUpInside];
  202. inputBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  203. inputBtn.layer.cornerRadius = 5;
  204. inputBtn.layer.masksToBounds = YES;
  205. inputBtn.userInteractionEnabled = NO;
  206. [self.view addSubview:inputBtn];
  207. _alertTipsL = [[UILabel alloc]init];
  208. _alertTipsL.textColor = RGB_COLOR(@"#ffffff", 0.28);
  209. _alertTipsL.font = SYS_Font(11);
  210. _alertTipsL.numberOfLines = 0;
  211. _alertTipsL.textAlignment = NSTextAlignmentLeft;
  212. [self.view addSubview:_alertTipsL];
  213. [_alertTipsL mas_makeConstraints:^(MASConstraintMaker *make) {
  214. make.width.centerX.equalTo(inputBtn);
  215. make.top.equalTo(inputBtn.mas_bottom).offset(15);
  216. }];
  217. // tipsLabel = [[UILabel alloc]initWithFrame:CGRectMake(inputBtn.left+15, inputBtn.bottom + 15, inputBtn.width-30, 100)];
  218. // tipsLabel.font = [UIFont systemFontOfSize:11];
  219. // tipsLabel.textColor = gray66;
  220. // tipsLabel.numberOfLines = 0;
  221. // [self.view addSubview:tipsLabel];
  222. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeMoenyLabelValue) name:UITextFieldTextDidChangeNotification object:nil];
  223. if ([typeDic allKeys].count>0) {
  224. [self updateShowAccount:typeDic];
  225. }
  226. }
  227. -(void)votesTextFieldChange:(UITextField *)text {
  228. CGFloat realFloat = [votesT.text floatValue]*_ratio;
  229. if (realFloat <= 0) {
  230. _getL.text = @"¥0";
  231. }else{
  232. _getL.text = [NSString stringWithFormat:@"¥%.2f",realFloat];
  233. }
  234. }
  235. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  236. if (textField == votesT) {
  237. //新输入的
  238. if (string.length == 0) {
  239. return YES;
  240. }
  241. NSString *checkStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
  242. //非零的正整数
  243. NSString *regex = @"^[1-9]\\d*$";
  244. return [self isValid:checkStr withRegex:regex];
  245. }
  246. return YES;
  247. }
  248. - (BOOL) isValid:(NSString*)checkStr withRegex:(NSString*)regex {
  249. NSPredicate *predicte = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
  250. return [predicte evaluateWithObject:checkStr];
  251. }
  252. //选择z提现方式
  253. - (void)selectPayType{
  254. YBGetTypeListVC *vc = [[YBGetTypeListVC alloc]init];
  255. if ([typeDic allKeys].count>0) {
  256. vc.selectID = minstr([typeDic valueForKey:@"id"]);
  257. }else{
  258. vc.selectID = YZMsg(@"未选择提现方式");
  259. }
  260. YBWeakSelf;
  261. vc.block = ^(NSDictionary * _Nonnull dic) {
  262. typeDic = dic;
  263. if ([dic allKeys].count>0) {
  264. [Config saveCashAccount:typeDic];
  265. }
  266. [weakSelf updateShowAccount:dic];
  267. };
  268. [self.navigationController pushViewController:vc animated:YES];
  269. }
  270. -(void)updateShowAccount:(NSDictionary *)dic {
  271. seletTypeImgView.hidden = NO;
  272. typeLabel.x = seletTypeImgView.right + 5;
  273. typeLabel.textColor = [UIColor whiteColor];
  274. int type = [minstr([dic valueForKey:@"type"]) intValue];
  275. switch (type) {
  276. case 1:
  277. seletTypeImgView.image = [UIImage imageNamed:@"profit_zff"];
  278. typeLabel.text = [NSString stringWithFormat:@"%@(%@)",minstr([dic valueForKey:@"account"]),minstr([dic valueForKey:@"name"])];
  279. break;
  280. case 2:
  281. seletTypeImgView.image = [UIImage imageNamed:@"profit_wx"];
  282. typeLabel.text = [NSString stringWithFormat:@"%@",minstr([dic valueForKey:@"account"])];
  283. break;
  284. case 3:
  285. seletTypeImgView.image = [UIImage imageNamed:@"profit_card"];
  286. typeLabel.text = [NSString stringWithFormat:@"%@(%@)",minstr([dic valueForKey:@"account"]),minstr([dic valueForKey:@"name"])];
  287. break;
  288. default:{
  289. seletTypeImgView.hidden = YES;
  290. typeLabel.x = seletTypeImgView.left;
  291. typeLabel.text = YZMsg(@"请选择提现账户");
  292. typeLabel.textColor = RGB_COLOR(@"#646464", 1);
  293. }break;
  294. }
  295. }
  296. //提交申请
  297. - (void)inputBtnClick{
  298. if(!typeDic || [typeDic allKeys].count<=0){
  299. [MBProgressHUD showError:YZMsg(@"请选择提现账户")];
  300. return;
  301. }
  302. NSDictionary *dic = @{@"accountid":minstr([typeDic valueForKey:@"id"]),@"money":votesT.text,@"uid":[Config getOwnID],@"token":[Config getOwnToken]};
  303. [YBNetworking postWithUrl:@"Cash.setRedCash" Dic:dic Suc:^(int code, id info, NSString *msg) {
  304. if (code == 0) {
  305. votesT.text = @"";
  306. _getL.text = @"¥0";
  307. [MBProgressHUD showError:msg];
  308. [self requestData];
  309. }else{
  310. [MBProgressHUD showError:msg];
  311. }
  312. } Fail:^(id fail) {
  313. }];
  314. }
  315. - (void)ChangeMoenyLabelValue{
  316. // moneyLabel.text = [NSString stringWithFormat:@"¥%lld",[votesT.text longLongValue]/cash_rate];
  317. //[votesT.text integerValue]
  318. if (votesT.text.length > 0) {
  319. inputBtn.userInteractionEnabled = YES;
  320. [inputBtn setBackgroundColor:RGB_COLOR(@"#EA377F", 1)];
  321. inputBtn.selected = YES;
  322. }else{
  323. inputBtn.userInteractionEnabled = NO;
  324. inputBtn.selected = NO;
  325. [inputBtn setBackgroundColor:RGB_COLOR(@"#27223B", 1)];
  326. }
  327. }
  328. @end