YOUPAIZYBiHuVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // YOUPAIZYBiHuVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/10/9.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYBiHuVC.h"
  9. #import "LZAlertWindow.h"
  10. #import "UIViewController+TFPresent.h"
  11. #import "YOUPAILZVipVC.h"
  12. @interface YOUPAIZYBiHuVC()
  13. @property(nonatomic,strong)UIImageView *youpaipbkImgV;
  14. @property(nonatomic,strong)NSMutableArray *youpaipbtnArray;
  15. @property(nonatomic,strong)NSArray *youpaipnumStrArray;
  16. @property(nonatomic,strong)UILabel *youpaiptitleLab,*youpaipnoticeLab;
  17. @property(nonatomic,strong)UIButton *youpaipbiHuBtn;
  18. @property(nonatomic,strong)UIView *youpaipnumView;
  19. @property(nonatomic,assign)CGFloat youpaipleftPadding;
  20. @property(nonatomic,assign)NSInteger youpaiptotalNum;
  21. @end;
  22. @implementation YOUPAIZYBiHuVC
  23. -(void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. _youpaipleftPadding = (self.vWidth-290)/2.0;
  27. _youpaipnumStrArray = @[@"1天",@"3天",@"7天",@"30天"];
  28. _youpaipbtnArray = [[NSMutableArray alloc]init];
  29. _youpaiptotalNum =1;
  30. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  31. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.baseView.bounds cornerRadius:16.0f];
  32. maskLayer.path = path.CGPath;
  33. self.baseView.layer.mask = maskLayer;
  34. self.baseView = self.baseView;
  35. //
  36. // [self.view setFrame:CGRectMake(0, 0, self.vWidth, self.vHeight)];
  37. // [self.view setBackgroundColor:[UIColor whiteColor]];
  38. [self.baseView addSubview:self.youpaipbkImgV];
  39. [self.baseView addSubview:self.youpaiptitleLab];
  40. // [self.baseView addSubview:self.noticeLab];
  41. [self.baseView addSubview:self.youpaipnumView];
  42. [self.baseView addSubview:self.youpaipbiHuBtn];
  43. // NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她1个守护符",_infoModel.guard_price];
  44. // [_titleLab setText:@"她将出现在首页“贵族庇护”页面"];
  45. NSString *text = @"她将出现在首页“贵族庇护”页面";
  46. NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text];
  47. [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFF4A4B) range:[text rangeOfString:@"“贵族庇护”"]];
  48. _youpaiptitleLab.attributedText = str;
  49. // [_noticeLab setText:[NSString stringWithFormat:@"距离上一名还差%ld个守护符",_infoModel.diff_num]];
  50. [_youpaipbiHuBtn setTitle:@"庇护她" forState:UIControlStateNormal];
  51. [_youpaiptitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.equalTo(self.baseView).with.offset(0);
  53. make.right.equalTo(self.baseView).with.offset(0);
  54. make.top.equalTo(self->_youpaipbkImgV.mas_bottom).with.offset(19);
  55. make.height.mas_equalTo(20);
  56. }];
  57. [_youpaipnumView mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.equalTo(self.baseView).with.offset(self->_youpaipleftPadding);
  59. make.right.equalTo(self.baseView).with.offset(-self->_youpaipleftPadding);
  60. make.top.equalTo(self->_youpaiptitleLab.mas_bottom).with.offset(17);
  61. make.width.mas_equalTo(220);
  62. make.height.mas_equalTo(28);
  63. }];
  64. // [_noticeLab mas_makeConstraints:^(MASConstraintMaker *make) {
  65. // make.left.equalTo(self.view).with.offset(0);
  66. // make.right.equalTo(self.view).with.offset(0);
  67. // make.top.equalTo(self->_numView.mas_bottom).with.offset(6);
  68. // make.height.mas_equalTo(15);
  69. // }];
  70. //
  71. // [_guardHerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  72. // make.left.equalTo(self.view).with.offset(_leftPadding);
  73. // make.right.equalTo(self.view).with.offset(-_leftPadding);
  74. // make.top.equalTo(_noticeLab.mas_bottom).with.offset(10);
  75. // make.bottom.equalTo(self.view.mas_bottom).with.offset(-15);
  76. // make.height.mas_equalTo(44);
  77. // }];
  78. // CAShapeLayer *maskLayer = [CAShapeLayer layer];
  79. // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds cornerRadius:25];
  80. // maskLayer.path = path.CGPath;
  81. // self.view.layer.mask = maskLayer;
  82. }
  83. -(UIImageView *)youpaipbkImgV
  84. {
  85. if(!_youpaipbkImgV)
  86. {
  87. _youpaipbkImgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.vWidth, (self.vWidth*165)/320.0)];
  88. [_youpaipbkImgV setImage:[UIImage imageNamed:@"vqu_images_guizhu_prompt"]];
  89. }
  90. return _youpaipbkImgV;
  91. }
  92. -(UIView *)youpaipnumView
  93. {
  94. if(!_youpaipnumView)
  95. {
  96. CGFloat btnWidth = 60,btnHeight = 28,orginx= 10,orginy =1,btnspace=10;
  97. _youpaipnumView = [[UIView alloc]initWithFrame:CGRectMake(_youpaipleftPadding, 0,290, 28)];
  98. for(int i=0;i<4;i++)
  99. {
  100. UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*i, orginy, btnWidth, btnHeight)];
  101. btn.tag = i;
  102. [btn.titleLabel setFont:[UIFont systemFontOfSize:13]];
  103. btn.layer.cornerRadius =4;
  104. btn.layer.borderWidth = 1;
  105. [btn setTitle:_youpaipnumStrArray[i] forState:UIControlStateNormal];
  106. if(i==0)
  107. {
  108. [btn setTitleColor:HexColorFromRGB(0xFF4A4B) forState:UIControlStateNormal];
  109. btn.layer.borderColor = HexColorFromRGB(0xFF4A4B).CGColor;
  110. }
  111. else
  112. {
  113. btn.layer.borderColor = HexColorFromRGB(0xCCCCCC).CGColor;
  114. [btn setTitleColor:HexColorFromRGB(0xCCCCCC) forState:UIControlStateNormal];
  115. }
  116. [btn addTarget:self action:@selector(youpaifupdateNumView:) forControlEvents:UIControlEventTouchUpInside];
  117. [_youpaipbtnArray addObject:btn];
  118. [_youpaipnumView addSubview:btn];
  119. }
  120. }
  121. return _youpaipnumView;
  122. }
  123. -(UILabel *)youpaiptitleLab
  124. {
  125. if(!_youpaiptitleLab)
  126. {
  127. _youpaiptitleLab = [[UILabel alloc]init];
  128. [_youpaiptitleLab setTextColor:HexColorFromRGB(0x666666)];
  129. [_youpaiptitleLab setFont:[UIFont systemFontOfSize:14]];
  130. [_youpaiptitleLab setTextAlignment:NSTextAlignmentCenter];
  131. }
  132. return _youpaiptitleLab;
  133. }
  134. -(UILabel *)youpaipnoticeLab
  135. {
  136. if(!_youpaipnoticeLab)
  137. {
  138. _youpaipnoticeLab = [[UILabel alloc]init];
  139. [_youpaipnoticeLab setTextColor:HexColorFromRGB(0xaaaaaa)];
  140. [_youpaipnoticeLab setFont:[UIFont systemFontOfSize:12]];
  141. [_youpaipnoticeLab setTextAlignment:NSTextAlignmentCenter];
  142. }
  143. return _youpaipnoticeLab;
  144. }
  145. -(UIButton *)youpaipbiHuBtn
  146. {
  147. if(!_youpaipbiHuBtn)
  148. {
  149. _youpaipbiHuBtn = [[UIButton alloc]init];
  150. [_youpaipbiHuBtn.titleLabel setFont:[UIFont systemFontOfSize:17]];
  151. _youpaipbiHuBtn.layer.cornerRadius = 24;
  152. _youpaipbiHuBtn.layer.masksToBounds = YES;
  153. [_youpaipbiHuBtn addTarget:self action:@selector(youpaifaddBiHu) forControlEvents:UIControlEventTouchUpInside];
  154. [_youpaipbiHuBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  155. // [_biHuBtn setBackgroundColor:HexColorFromRGB(0x4D1B1B)];
  156. _youpaipbiHuBtn.frame = CGRectMake(29.0f,self.vHeight-46-44,self.vWidth - 29.0f*2, 48);
  157. [_youpaipbiHuBtn setBackgroundImage:[LCTools ColorImage:_youpaipbiHuBtn.frame.size FromColors:@[HexColorFromRGB(0xFF9696),HexColorFromRGB(0xFF4A4B)] ByGradientType:GradientLeftToRight] forState:0];
  158. }
  159. return _youpaipbiHuBtn;
  160. }
  161. -(void)youpaifupdateNumView:(UIButton *)btn
  162. {
  163. NSInteger tag = btn.tag;
  164. NSArray *totalArray =@[@(1),@(3),@(7),@(30)];
  165. for(int i=0;i<4;i++)
  166. {
  167. UIButton *cacheBtn = [_youpaipbtnArray objectAtIndex:i];
  168. if(tag == i){
  169. [cacheBtn setTitleColor:HexColorFromRGB(0xFF4A4B) forState:UIControlStateNormal];
  170. cacheBtn.layer.borderColor = HexColorFromRGB(0xFF4A4B).CGColor;
  171. _youpaiptotalNum = [totalArray[i] integerValue];
  172. // NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她%ld个守护符",_infoModel.guard_price*_totalNum,_totalNum];
  173. // [_titleLab setText:titleStr];
  174. }
  175. else
  176. {
  177. cacheBtn.layer.borderColor = HexColorFromRGB(0xCCCCCC).CGColor;
  178. [cacheBtn setTitleColor:HexColorFromRGB(0xCCCCCC) forState:UIControlStateNormal];
  179. }
  180. }
  181. }
  182. -(void)youpaifaddBiHu
  183. {
  184. _youpaipbiHuBtn.userInteractionEnabled = NO;
  185. //add by leo v1.0.8 视频中守护
  186. WeakSelf;
  187. [LCHttpHelper requestWithURLString:AddAsylum parameters:@{@"user_id":self.youpaipuser_id,@"day":@(_youpaiptotalNum)} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  188. NSDictionary* dict = (NSDictionary*)responseObject;
  189. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  190. if (code==0) {//成功
  191. [self dismissViewControllerAnimated:YES completion:nil];
  192. [weakSelf.youpaipdelegate youpaifaddBiHuSuccess];
  193. [ZCHUDHelper showTitle:dict[@"message"] showtime:2];
  194. }else if(code==1005){
  195. [self dismissViewControllerAnimated:YES completion:^{
  196. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"再想想" handler:^(LZAlertAction *action) {
  197. }];
  198. cancelAction.cornerRadius = 24.0f;
  199. cancelAction.color = LZ273145Color;
  200. cancelAction.bgColor = LZF5F4F7Color;
  201. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"马上开通" handler:^(LZAlertAction *action) {
  202. YOUPAILZVipVC* vc = [[YOUPAILZVipVC alloc]init];
  203. [[ZCUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
  204. }];
  205. confimAction.cornerRadius = 24.0f;
  206. confimAction.color = [UIColor whiteColor];
  207. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  208. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"【伯爵】以上贵族才可以庇护哦" action:@[cancelAction,confimAction]];
  209. alert.contentTextAlignment = NSTextAlignmentCenter;
  210. [kAppDelegate.window.rootViewController TFPresentVC:alert completion:^{}];
  211. }];
  212. }else
  213. {
  214. weakSelf.youpaipbiHuBtn.userInteractionEnabled = YES;
  215. [ZCHUDHelper showTitle:dict[@"message"] showtime:5];
  216. }
  217. } failure:^(NSError *error) {
  218. [ZCHUDHelper showTitle:error.mj_JSONString showtime:5];
  219. [self dismissViewControllerAnimated:YES completion:nil];
  220. }];
  221. }
  222. @end