YOUPAILZProfitTransformCoinVC.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // YOUPAILZProfitTransformCoinVC.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/3/2.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZProfitTransformCoinVC.h"
  9. #import "IQKeyboardManager.h"
  10. #import "LZAlertWindow.h"
  11. #import "UIViewController+TFPresent.h"
  12. @interface YOUPAILZProfitTransformCoinVC ()
  13. @property (nonatomic, weak) UILabel *youpaipbalanceL;
  14. @property (nonatomic, weak) UITextField *youpaipmoneyTF;
  15. @property (nonatomic, weak) UILabel *youpaipcoinL;
  16. @property (nonatomic, weak) UIButton *youpaiptransfromBtn;
  17. @end
  18. @implementation YOUPAILZProfitTransformCoinVC
  19. - (void)viewWillAppear:(BOOL)animated {
  20. [super viewWillAppear:animated];
  21. [[IQKeyboardManager sharedManager] setEnable:YES];
  22. }
  23. - (void)viewWillDisappear:(BOOL)animated {
  24. [super viewWillDisappear:animated];
  25. [[IQKeyboardManager sharedManager] setEnable:NO];
  26. }
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.view.backgroundColor = [UIColor whiteColor];
  30. [IQKeyboardManager sharedManager].enableAutoToolbar = NO; // 控制是否显示键盘上的工具条
  31. [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = NavBarHeight; //
  32. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  33. self.title = @"兑换钻石";
  34. [self youpaifinitUI];
  35. [self youpaifrequestWalleetInfo];
  36. }
  37. - (void)youpaifinitUI{
  38. UILabel *youpaipbalanceL = [[UILabel alloc] init];
  39. youpaipbalanceL.text = @"收益金额:0 元";
  40. youpaipbalanceL.textColor = LZ273145Color;
  41. youpaipbalanceL.font = LCFont(14);
  42. [self.view addSubview:youpaipbalanceL];
  43. self.youpaipbalanceL = youpaipbalanceL;
  44. [youpaipbalanceL mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.offset(24.0f);
  46. make.height.offset(48.0f);
  47. make.top.offset(NavBarHeight + 20.0f);
  48. }];
  49. UIView *moneyV = [[UIView alloc] init];
  50. moneyV.backgroundColor = LZF7F8FAColor;
  51. moneyV.layer.cornerRadius = 6;
  52. moneyV.layer.masksToBounds = YES;
  53. [self.view addSubview:moneyV];
  54. [moneyV mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.offset(12.0f);
  56. make.top.equalTo(youpaipbalanceL.mas_bottom).offset(8.0f);
  57. make.width.offset(KScreenWidth - 24.0f);
  58. make.height.offset(48.0f);
  59. }];
  60. UILabel* moneyTipL = [[UILabel alloc]init];
  61. moneyTipL.text = @"兑换金额:";
  62. moneyTipL.textColor = LZ273145Color;
  63. moneyTipL.font = LCFont14;
  64. [moneyV addSubview:moneyTipL];
  65. [moneyTipL mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.offset(12.0f);
  67. make.top.bottom.offset(0.0f);
  68. make.width.offset(84.0f);
  69. }];
  70. UITextField* youpaipmoneyTF = [[UITextField alloc]init];
  71. youpaipmoneyTF.tintColor = LZ7C69FEColor;
  72. youpaipmoneyTF.textColor = LZ273145Color;
  73. youpaipmoneyTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  74. youpaipmoneyTF.keyboardType = UIKeyboardTypeNumberPad;
  75. [[youpaipmoneyTF valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal];
  76. [youpaipmoneyTF addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
  77. NSMutableAttributedString* attrStrName = [[NSMutableAttributedString alloc]initWithString:@"请输入要使用的金额"];//@"请输入支付宝认证名字"
  78. [attrStrName addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attrStrName.length)];
  79. [attrStrName addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStrName.length)];
  80. youpaipmoneyTF.attributedPlaceholder = attrStrName;
  81. [moneyV addSubview:youpaipmoneyTF];
  82. self.youpaipmoneyTF = youpaipmoneyTF;
  83. [youpaipmoneyTF mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(moneyTipL.mas_right).offset(0.0f);
  85. make.top.bottom.offset(0.0f);
  86. make.right.offset(-12.0f);
  87. }];
  88. UILabel *youpaipcoinL = [[UILabel alloc] init];
  89. youpaipcoinL.text = @"获得钻石:0";
  90. youpaipcoinL.textColor = LZ273145Color;
  91. youpaipcoinL.font = LCFont(14);
  92. [self.view addSubview:youpaipcoinL];
  93. self.youpaipcoinL = youpaipcoinL;
  94. [youpaipcoinL mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.offset(24.0f);
  96. make.height.offset(48.0f);
  97. make.top.equalTo(moneyV.mas_bottom).offset(8.0f);
  98. }];
  99. UIButton *youpaiptransfromBtn = [[UIButton alloc]initWithFrame:CGRectMake(48, 0.0f, KScreenWidth-96, 48)];
  100. youpaiptransfromBtn.uxy_acceptEventInterval = 3.0;
  101. youpaiptransfromBtn.userInteractionEnabled = NO;
  102. youpaiptransfromBtn.backgroundColor = LZD3D1D7Color;
  103. // [withdrawBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 96, 48) FromColors:@[LZFFB5DBColor,LZFE66A4Color] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];;
  104. youpaiptransfromBtn.layer.cornerRadius = 24.0;
  105. youpaiptransfromBtn.layer.masksToBounds = YES;
  106. youpaiptransfromBtn.titleLabel.font = LCFont16;
  107. [youpaiptransfromBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  108. [youpaiptransfromBtn setTitle:@"立即兑换" forState:(UIControlStateNormal)];//立即提现
  109. [youpaiptransfromBtn addTarget:self action:@selector(youpaiptransfromBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  110. [self.view addSubview:youpaiptransfromBtn];
  111. [youpaiptransfromBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.offset(48);
  113. make.width.offset(KScreenWidth - 96);
  114. make.top.equalTo(youpaipcoinL.mas_bottom).offset(30.0f);
  115. make.height.offset(48);
  116. }];
  117. self.youpaiptransfromBtn = youpaiptransfromBtn;
  118. }
  119. - (void)textFieldDidEditing:(UITextField *)textField{
  120. NSString *checkedNumString = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
  121. if ([self.youpaipmoneyTF.text isEqualToString:@""] || checkedNumString.length > 0){
  122. [self.youpaiptransfromBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  123. self.youpaiptransfromBtn.userInteractionEnabled = NO;
  124. self.youpaipcoinL.text = @"获得钻石:0";
  125. }else{
  126. [self.youpaiptransfromBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 96, 48) FromColors:@[LZFFB5DBColor,LZFE66A4Color] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  127. self.youpaiptransfromBtn.userInteractionEnabled = YES;
  128. NSInteger count = [textField.text integerValue];
  129. self.youpaipcoinL.text = [NSString stringWithFormat:@"获得钻石:%@",@(count * 100)];
  130. }
  131. }
  132. - (void)youpaifrequestWalleetInfo{
  133. [LCHttpHelper requestWithURLString:WalletInit parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  134. NSDictionary* dict = (NSDictionary*)responseObject;
  135. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  136. if (code==0) {//成功
  137. NSString *incomeMoney = [[[dict objectForKey:@"data"]objectForKey:@"account"]objectForKey:@"income_coin_money"];
  138. self.youpaipbalanceL.text = [NSString stringWithFormat:@"收益金额:%@ 元",incomeMoney];
  139. }
  140. } failure:^(NSError *error) {
  141. }];
  142. }
  143. - (void)youpaiptransfromBtnClick{
  144. @weakify(self);
  145. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  146. }];
  147. cancelAction.cornerRadius = 24.0f;
  148. cancelAction.color = LZ273145Color;
  149. cancelAction.bgColor = LZF5F4F7Color;
  150. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  151. @strongify(self);
  152. [LCHttpHelper requestWithURLString:WalletChangeCoin parameters:@{@"moneys":self.youpaipmoneyTF.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  153. @strongify(self);
  154. NSDictionary* dict = (NSDictionary*)responseObject;
  155. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  156. if (code==0) {//成功
  157. [ZCHUDHelper showTitle:@"兑换成功"];
  158. [self youpaifrequestWalleetInfo];
  159. self.youpaipmoneyTF.text = @"";
  160. self.youpaipcoinL.text = @"获得钻石:0";
  161. [self.youpaiptransfromBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  162. self.youpaiptransfromBtn.userInteractionEnabled = NO;
  163. }
  164. }failure:^(NSError *error) {
  165. }];
  166. }];
  167. confimAction.cornerRadius = 24.0f;
  168. confimAction.color = [UIColor whiteColor];
  169. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  170. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"兑换钻石" content:@"" action:@[cancelAction,confimAction] contentStyleBlock:^(UILabel *contentL) {
  171. NSString *x = self.youpaipmoneyTF.text;
  172. NSString *y = [NSString stringWithFormat:@"%@",@([x integerValue] * 100)];
  173. NSString *contentText = [NSString stringWithFormat:@"将消耗 %@ 元,获得 %@ 钻石",x,y];
  174. NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:contentText];
  175. [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF3B30) range:[contentText rangeOfString:x]];
  176. [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF3B30) range:[contentText rangeOfString:y]];
  177. contentL.attributedText = str;
  178. }];
  179. alert.contentTextAlignment = NSTextAlignmentCenter;
  180. [self TFPresentVC:alert completion:^{}];
  181. }
  182. @end