YOUPAILZVipCoinTransformVC.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // YOUPAILZVipCoinTransformVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/26.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZVipCoinTransformVC.h"
  9. #import "LZAlertWindow.h"
  10. #import "UIViewController+TFPresent.h"
  11. @interface YOUPAILZVipCoinTransformVC ()
  12. @property (nonatomic,weak) UITextField *youpaiptransformTF;
  13. @property (nonatomic,weak) UILabel *youpaipbalanceL;
  14. @property (nonatomic,weak) UILabel *youpaipdescL;
  15. @property (nonatomic,assign) NSInteger youpaipuser_noble_coin;
  16. @property (nonatomic,assign) NSInteger youpaiprate;
  17. @end
  18. @implementation YOUPAILZVipCoinTransformVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.view.backgroundColor = [UIColor whiteColor];
  22. self.youpaipuser_noble_coin = 0;
  23. self.youpaiprate = 0;
  24. self.title = @"兑换钻石";
  25. [self youpaifinitUI];
  26. [self youpaifrequestVipCoinInfo];
  27. }
  28. - (void)youpaifinitUI{
  29. UIView *bgV = [[UIView alloc] init];
  30. bgV.backgroundColor = LZF7F8FAColor;
  31. bgV.layer.cornerRadius = ScaleSize(8.0f);
  32. bgV.clipsToBounds = YES;
  33. [self.view addSubview:bgV];
  34. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.offset(ScaleSize(14.0f));
  36. make.top.offset(NavBarHeight + ScaleSize(10.0f));
  37. make.right.offset(ScaleSize(-14.0f));
  38. make.height.offset(ScaleSize(180.0f));
  39. }];
  40. UILabel *descL = [[UILabel alloc] init];
  41. descL.font = LCFont(ScaleSize(14.0f));
  42. descL.textColor = LZ273145Color;
  43. descL.text = @"贵族币兑换钻石";
  44. [bgV addSubview:descL];
  45. self.youpaipdescL = descL;
  46. [descL mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.top.offset(ScaleSize(14.0f));
  48. make.right.offset(ScaleSize(-14.0f));
  49. }];
  50. UILabel *rmbSymbolL = [[UILabel alloc] init];
  51. rmbSymbolL.text = @"¥";
  52. rmbSymbolL.textColor = LZ273145Color;
  53. rmbSymbolL.font = LCFont(ScaleSize(36.0f));
  54. [rmbSymbolL sizeToFit];
  55. rmbSymbolL.frame = CGRectMake(0, 0, rmbSymbolL.mj_w, ScaleSize(62.0f));
  56. UITextField *transformTF = [[UITextField alloc] init];
  57. transformTF.tintColor = LZ7C69FEColor;
  58. transformTF.leftView = rmbSymbolL;
  59. transformTF.leftViewMode = UITextFieldViewModeAlways;
  60. transformTF.text = @"0";
  61. transformTF.textColor = LZ273145Color;
  62. transformTF.font = LCFont(ScaleSize(36.0f));
  63. transformTF.keyboardType = UIKeyboardTypeNumberPad;
  64. NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入兑换数量"];
  65. [attrStr addAttribute:NSFontAttributeName value:LCFont(ScaleSize(24.0f)) range:NSMakeRange(0, attrStr.length)];
  66. [attrStr addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStr.length)];
  67. transformTF.attributedPlaceholder = attrStr;
  68. transformTF.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
  69. [bgV addSubview:transformTF];
  70. self.youpaiptransformTF = transformTF;
  71. [transformTF mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.offset(ScaleSize(14.0f));
  73. make.top.equalTo(descL.mas_bottom).offset(ScaleSize(26.0f));
  74. make.right.offset(ScaleSize(-14.0f));
  75. make.height.offset(ScaleSize(62.0f));
  76. }];
  77. [transformTF addLineWithColor:LZF7F8FAColor lineRect:CGRectMake(0, ScaleSize(62.0f) - 0.5f, KScreenWidth - ScaleSize(56.0f), 0.5f)];
  78. UILabel *balanceL = [[UILabel alloc] init];
  79. balanceL.font = LCFont(ScaleSize(12.0f));
  80. balanceL.textColor = LZA3AABEColor;
  81. balanceL.text = @"可用贵族币 ¥0";
  82. [bgV addSubview:balanceL];
  83. self.youpaipbalanceL = balanceL;
  84. [balanceL mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.offset(ScaleSize(14.0f));
  86. make.top.equalTo(transformTF.mas_bottom).offset(0.0f);
  87. make.bottom.offset(0.0f);
  88. }];
  89. UIButton *transformAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  90. transformAllBtn.layer.cornerRadius = ScaleSize(27.0f) / 2.0f;
  91. transformAllBtn.clipsToBounds = YES;
  92. [transformAllBtn setTitle:@"全部兑换" forState:UIControlStateNormal];
  93. [transformAllBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  94. transformAllBtn.titleLabel.font = LCFont(ScaleSize(12.0f));
  95. transformAllBtn.backgroundColor = HexColorFromRGB(0x4F4B5B);
  96. [transformAllBtn addTarget:self action:@selector(youpaiftransformAllBtnClick) forControlEvents:UIControlEventTouchUpInside];
  97. [bgV addSubview:transformAllBtn];
  98. [transformAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.centerY.equalTo(balanceL);
  100. make.right.offset(ScaleSize(-14.0f));
  101. make.size.mas_offset(CGSizeMake(ScaleSize(76.0f), ScaleSize(27.0f)));
  102. }];
  103. UIButton *transformBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. transformBtn.layer.cornerRadius = 24.0f;
  105. transformBtn.clipsToBounds = YES;
  106. [transformBtn setTitle:@"兑换" forState:UIControlStateNormal];
  107. [transformBtn setTitleColor:HexColorFromRGB(0x75170A) forState:UIControlStateNormal];
  108. transformBtn.titleLabel.font = LCFont16;
  109. [transformBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom] forState:UIControlStateNormal];
  110. [transformBtn addTarget:self action:@selector(youpaiftransformBtnClick) forControlEvents:UIControlEventTouchUpInside];
  111. [self.view addSubview:transformBtn];
  112. [transformBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.bottom.offset(-30.0f-SafeHeight);
  114. make.centerX.equalTo(self.view);
  115. make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f));
  116. }];
  117. }
  118. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  119. [self.view endEditing:YES];
  120. }
  121. - (void)youpaifrequestVipCoinInfo{
  122. @weakify(self);
  123. [LCHttpHelper requestWithURLString:GetNobleToCoinRate parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  124. @strongify(self);
  125. NSDictionary* dict = (NSDictionary*)responseObject;
  126. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  127. if (code == 0) {
  128. self.youpaipuser_noble_coin = [[[dict objectForKey:@"data"]objectForKey:@"user_noble_coin"] integerValue];
  129. self.youpaiprate = [[[dict objectForKey:@"data"]objectForKey:@"rate"] integerValue];
  130. self.youpaipbalanceL.text = [NSString stringWithFormat:@"可用贵族币 ¥%@",@(self.youpaipuser_noble_coin)];
  131. self.youpaipdescL.text = [NSString stringWithFormat:@"贵族币兑换钻石(1:%@)",@(self.youpaiprate)];;
  132. }
  133. } failure:^(NSError *error) {
  134. }];
  135. }
  136. - (void)youpaiftransformAllBtnClick{
  137. self.youpaiptransformTF.text = [NSString stringWithFormat:@"%@",@(self.youpaipuser_noble_coin)];
  138. }
  139. - (void)youpaiftransformBtnClick{
  140. if([self.youpaiptransformTF.text integerValue] > 0 && self.youpaiprate > 0) {
  141. @weakify(self);
  142. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  143. }];
  144. cancelAction.cornerRadius = 24.0f;
  145. cancelAction.bgColor = LZF5F4F7Color;
  146. cancelAction.color = LZ273145Color;
  147. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  148. @strongify(self);
  149. [LCHttpHelper requestWithURLString:NobleExchange parameters:@{@"num":self.youpaiptransformTF.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  150. @strongify(self);
  151. NSDictionary* dict = (NSDictionary*)responseObject;
  152. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  153. if (code == 0) {
  154. [ZCHUDHelper showTitle:@"兑换成功"];
  155. [self youpaifrequestVipCoinInfo];
  156. [[NSNotificationCenter defaultCenter]postNotificationName:@"yqApplePaySuccess" object:nil userInfo:nil];
  157. self.youpaiptransformTF.text = @"0";
  158. }
  159. } failure:^(NSError *error) {
  160. }];
  161. }];
  162. confimAction.cornerRadius = 24.0f;
  163. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom]];
  164. confimAction.color = HexColorFromRGB(0x75170A);
  165. NSString *content = [NSString stringWithFormat:@"将消耗%@贵族币\n获得%@钻石",self.youpaiptransformTF.text,@([self.youpaiptransformTF.text integerValue] *self.youpaiprate)];
  166. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"兑换提示" content:content action:@[cancelAction,confimAction]];
  167. alert.contentTextAlignment = NSTextAlignmentCenter;
  168. [self TFPresentVC:alert completion:^{}];
  169. }else{
  170. [ZCHUDHelper showTitle:@"请输入兑换数量"];
  171. }
  172. }
  173. @end