YOUPAILPGuardHerVC.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. //
  2. // YOUPAILPGuardHerVC.m
  3. // livePro
  4. //
  5. // Created by leo on 2019/12/23.
  6. // Copyright © 2019 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAILPGuardHerVC.h"
  9. #import "YOUPAIXRWalletVC.h"
  10. #import "LZAlertWindow.h"
  11. #import "UIViewController+TFPresent.h"
  12. @interface YOUPAILPGuardHerVC()
  13. @property(nonatomic,strong)UIView *youpaipbkImgV;
  14. @property(nonatomic,strong)NSMutableArray *youpaipbtnArray;
  15. @property(nonatomic,strong)NSMutableArray *youpaipImageArray;
  16. @property(nonatomic,strong)NSArray *youpaipnumStrArray;
  17. @property(nonatomic,strong)UILabel *youpaiptitleLab,*youpaipnoticeLab;
  18. @property(nonatomic,strong)UIButton *youpaipguardHerBtn;
  19. @property(nonatomic,strong)UIView *youpaipnumView;
  20. @property(nonatomic,assign)CGFloat youpaipleftPadding;
  21. @property(nonatomic,assign)NSInteger youpaiptotalNum;
  22. @property(nonatomic,assign)NSInteger youpaiptotalNum1;
  23. @property(nonatomic,strong)UIButton *youpaipshowZuanbtn;
  24. @end;
  25. @implementation YOUPAILPGuardHerVC
  26. -(void)viewDidLoad
  27. {
  28. [super viewDidLoad];
  29. _youpaipleftPadding = 12;
  30. _youpaipnumStrArray = @[@"1个",@"5个",@"10个",@"50个",@"100个",@"520个"];
  31. _youpaipbtnArray = [[NSMutableArray alloc]init];
  32. _youpaipImageArray = [[NSMutableArray alloc]init];
  33. _youpaiptotalNum =1;
  34. _youpaiptotalNum1 = 1;
  35. self.baseView.backgroundColor = [UIColor clearColor];
  36. UIImageView *bgImageView = [UIImageView new];
  37. [self.baseView addSubview:bgImageView];
  38. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.edges.mas_equalTo(0);
  40. }];
  41. bgImageView.userInteractionEnabled = YES;
  42. bgImageView.image = [UIImage imageNamed:@"vqu_images_guard_bg"];
  43. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  44. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.baseView.bounds cornerRadius:16.0f];
  45. maskLayer.path = path.CGPath;
  46. //
  47. // [self.view setFrame:CGRectMake(0, 0, self.vWidth, self.vHeight)];
  48. // [self.view setBackgroundColor:[UIColor whiteColor]];
  49. [bgImageView addSubview:self.youpaipbkImgV];
  50. [self.youpaipbkImgV addSubview:self.youpaiptitleLab];
  51. [self.youpaipbkImgV addSubview:self.youpaipnoticeLab];
  52. [self.youpaipbkImgV addSubview:self.youpaipnumView];
  53. [self.youpaipbkImgV addSubview:self.youpaipguardHerBtn];
  54. // NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她1个",_youpaipinfoModel.youpaipguard_price];
  55. // _youpaiptitleLab.attributedText = [LCTools setRichTextWithTitle:titleStr subTitle:@"守护符" titleColor:HexColorFromRGB(0x666666) subTitleColor:HexColorFromRGB(0xAE5DE0) titleFontSize:14.0f subTitleFontSize:14.0f];
  56. // [_titleLab setText:titleStr];
  57. [_youpaiptitleLab setText:[NSString stringWithFormat:@"Ta距离上一名还差%ld个守护符",_youpaipinfoModel.youpaipdiff_num]];
  58. [_youpaipguardHerBtn setTitle:@"守护Ta" forState:UIControlStateNormal];
  59. [_youpaipbkImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(15);
  61. make.right.mas_equalTo(-15);
  62. make.bottom.mas_equalTo(-15);
  63. make.height.mas_equalTo(276);
  64. }];
  65. [_youpaiptitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.equalTo(bgImageView).with.offset(0);
  67. make.right.equalTo(bgImageView).with.offset(0);
  68. make.top.equalTo(22);
  69. make.height.mas_equalTo(20);
  70. }];
  71. [_youpaipnumView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.equalTo(bgImageView).with.offset(self->_youpaipleftPadding);
  73. make.right.equalTo(bgImageView).with.offset(-self->_youpaipleftPadding);
  74. make.top.equalTo(self->_youpaiptitleLab.mas_bottom).with.offset(17);
  75. make.width.mas_equalTo(ScaleSize(220));
  76. make.height.mas_equalTo((28+15+28)*2);
  77. }];
  78. [_youpaipnoticeLab mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.equalTo(bgImageView).with.offset(0);
  80. make.right.equalTo(bgImageView).with.offset(0);
  81. make.top.equalTo(self->_youpaipnumView.mas_bottom).with.offset(9);
  82. make.height.mas_equalTo(15);
  83. }];
  84. [_youpaipguardHerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.centerX.mas_equalTo(0);
  86. make.size.mas_equalTo(CGSizeMake(self.vWidth - 29.0f*2, 48));
  87. make.bottom.mas_equalTo(-30);
  88. }];
  89. [_youpaipguardHerBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(self.vWidth - 29.0f*2, 48) FromColors:@[HexColorFromRGB(0xFFD845),HexColorFromRGB(0xFFBD45)] ByGradientType:(GradientTopToBottom)] forState:(UIControlStateNormal)];
  90. //vqu_images_guard_select_new
  91. // [_guardHerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  92. // make.left.equalTo(self.view).with.offset(_leftPadding);
  93. // make.right.equalTo(self.view).with.offset(-_leftPadding);
  94. // make.top.equalTo(_noticeLab.mas_bottom).with.offset(10);
  95. // make.bottom.equalTo(self.view.mas_bottom).with.offset(-15);
  96. // make.height.mas_equalTo(44);
  97. // }];
  98. //
  99. // CAShapeLayer *maskLayer = [CAShapeLayer layer];
  100. // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds cornerRadius:25];
  101. // maskLayer.path = path.CGPath;
  102. // self.view.layer.mask = maskLayer;
  103. }
  104. -(UIView *)youpaipbkImgV
  105. {
  106. if(!_youpaipbkImgV)
  107. {
  108. _youpaipbkImgV = [[UIView alloc]init];
  109. _youpaipbkImgV.layer.cornerRadius = 9;
  110. _youpaipbkImgV.layer.masksToBounds = YES;
  111. _youpaipbkImgV.backgroundColor = [UIColor whiteColor];
  112. }
  113. return _youpaipbkImgV;
  114. }
  115. //-(UIImageView *)youpaipSelectImage
  116. //{
  117. // if(!_youpaipSelectImage)
  118. // {
  119. // _youpaipSelectImage = [[UIImageView alloc]init];
  120. // _youpaipSelectImage.image = [UIImage imageNamed:@"vqu_images_guard_select_new"];
  121. // }
  122. // return _youpaipSelectImage;
  123. //}
  124. -(UIView *)youpaipnumView
  125. {
  126. if(!_youpaipnumView)
  127. {
  128. CGFloat btnWidth = ScaleSize(85),btnHeight = 54,orginx=ScaleSize(15),orginy = 0,btnspace= ScaleSize(8);
  129. _youpaipnumView = [[UIView alloc]initWithFrame:CGRectMake(_youpaipleftPadding, 0,ScaleSize(220),28+15+28)];
  130. for(int i=0;i<6;i++)
  131. {
  132. UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*(i%3),orginy+(btnspace+btnHeight)*(i/3), btnWidth, btnHeight)];
  133. btn.tag = i;
  134. [btn.titleLabel setFont:[UIFont systemFontOfSize:13]];
  135. btn.layer.cornerRadius =6;
  136. btn.layer.borderWidth = 1;
  137. [btn setTitle:_youpaipnumStrArray[i] forState:UIControlStateNormal];
  138. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*(i%3)+btn.frame.size.width-23, orginy+(btnspace+btnHeight)*(i/3), 23, 23)];
  139. image.image = [UIImage imageNamed:@"vqu_images_guard_select_new"];
  140. UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(orginx+(btnWidth+btnspace)*(i%3),orginy+(btnspace+btnHeight)*(i/3)+32, btnWidth, 15)];
  141. btn1.titleLabel.textAlignment = NSTextAlignmentCenter;
  142. self.youpaipshowZuanbtn = btn1;
  143. NSArray *totalArray =@[@(1),@(5),@(10),@(50),@(100),@(520)];
  144. _youpaiptotalNum1 = [totalArray[i] integerValue];
  145. switch (i) {
  146. case 0:
  147. {
  148. [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*1] forState:UIControlStateNormal];
  149. }
  150. break;
  151. case 1:
  152. {
  153. [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*5] forState:UIControlStateNormal];
  154. }
  155. break;
  156. case 2:
  157. {
  158. [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*10] forState:UIControlStateNormal];
  159. }
  160. break;
  161. case 3:
  162. {
  163. [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*50] forState:UIControlStateNormal];
  164. }
  165. break;
  166. case 4:
  167. {
  168. [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*100] forState:UIControlStateNormal];
  169. }
  170. break;
  171. case 5:
  172. {
  173. [btn1 setTitle:[NSString stringWithFormat:@"%ld",_youpaipinfoModel.youpaipguard_price*520] forState:UIControlStateNormal];
  174. }
  175. break;
  176. default:
  177. break;
  178. }
  179. [btn1 setImage:[UIImage imageNamed:@"vqu_images_guard_zuanshi"] forState:UIControlStateNormal];
  180. btn1.titleLabel.font = [UIFont systemFontOfSize:12];
  181. [btn1 setTitleColor:LZA3AABEColor forState:UIControlStateNormal];
  182. [btn1 setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  183. if(i==0)
  184. {
  185. [btn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal];
  186. btn.layer.borderColor = HexColorFromRGB(0xFFD845).CGColor;
  187. btn.backgroundColor = HexColorFromRGBA(0xFFD845, 0.1);
  188. image.hidden = NO;
  189. }
  190. else
  191. {
  192. [btn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal];
  193. btn.backgroundColor = HexColorFromRGBA(0xFAFAFC, 1);
  194. btn.layer.borderColor = HexColorFromRGB(0xFAFAFC).CGColor;
  195. image.hidden = YES;
  196. }
  197. [btn addTarget:self action:@selector(youpaifupdateNumView:) forControlEvents:UIControlEventTouchUpInside];
  198. [_youpaipbtnArray addObject:btn];
  199. [_youpaipnumView addSubview:btn];
  200. [_youpaipnumView addSubview:image];
  201. [_youpaipImageArray addObject:image];
  202. [_youpaipnumView addSubview:btn1];
  203. }
  204. }
  205. return _youpaipnumView;
  206. }
  207. -(UILabel *)youpaiptitleLab
  208. {
  209. if(!_youpaiptitleLab)
  210. {
  211. _youpaiptitleLab = [[UILabel alloc]init];
  212. [_youpaiptitleLab setTextColor:HexColorFromRGB(0x475A7D)];
  213. [_youpaiptitleLab setFont:[UIFont systemFontOfSize:12]];
  214. [_youpaiptitleLab setTextAlignment:NSTextAlignmentCenter];
  215. }
  216. return _youpaiptitleLab;
  217. }
  218. -(UILabel *)youpaipnoticeLab
  219. {
  220. if(!_youpaipnoticeLab)
  221. {
  222. _youpaipnoticeLab = [[UILabel alloc]init];
  223. [_youpaipnoticeLab setTextColor:HexColorFromRGB(0xaaaaaa)];
  224. [_youpaipnoticeLab setFont:[UIFont systemFontOfSize:12]];
  225. [_youpaipnoticeLab setTextAlignment:NSTextAlignmentCenter];
  226. }
  227. return _youpaipnoticeLab;
  228. }
  229. -(UIButton *)youpaipguardHerBtn
  230. {
  231. if(!_youpaipguardHerBtn)
  232. {
  233. _youpaipguardHerBtn = [[UIButton alloc]init];
  234. [_youpaipguardHerBtn.titleLabel setFont:[UIFont systemFontOfSize:17]];
  235. _youpaipguardHerBtn.layer.cornerRadius = 24;
  236. _youpaipguardHerBtn.layer.masksToBounds = YES;
  237. [_youpaipguardHerBtn addTarget:self action:@selector(youpaifaddGuard) forControlEvents:UIControlEventTouchUpInside];
  238. [_youpaipguardHerBtn setTitleColor:HexColorFromRGB(0x9C6600) forState:UIControlStateNormal];
  239. // [_guardHerBtn setBackgroundColor:LCYellowColor];
  240. //
  241. //
  242. }
  243. return _youpaipguardHerBtn;
  244. }
  245. -(void)youpaifupdateNumView:(UIButton *)btn
  246. {
  247. NSInteger tag = btn.tag;
  248. NSArray *totalArray =@[@(1),@(5),@(10),@(50),@(100),@(520)];
  249. for(int i=0;i<6;i++)
  250. {
  251. UIButton *cacheBtn = [_youpaipbtnArray objectAtIndex:i];
  252. UIImageView *selectImage = [_youpaipImageArray objectAtIndex:i];
  253. if(tag == i)
  254. {
  255. cacheBtn.layer.borderWidth = 1;
  256. selectImage.hidden = NO;
  257. [cacheBtn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal];
  258. cacheBtn.layer.borderColor = HexColorFromRGB(0xFFD845).CGColor;
  259. cacheBtn.backgroundColor = HexColorFromRGBA(0xFFD845, 0.1);
  260. _youpaiptotalNum = [totalArray[i] integerValue];
  261. NSString *titleStr = [NSString stringWithFormat:@"花费%ld个钻石给她%ld个",_youpaipinfoModel.youpaipguard_price*_youpaiptotalNum,_youpaiptotalNum];
  262. _youpaiptitleLab.attributedText = [LCTools setRichTextWithTitle:titleStr subTitle:@"守护符" titleColor:HexColorFromRGB(0x666666) subTitleColor:HexColorFromRGB(0xAE5DE0) titleFontSize:14.0f subTitleFontSize:14.0f];
  263. // [_titleLab setText:titleStr];
  264. }
  265. else
  266. {
  267. selectImage.hidden = YES;
  268. cacheBtn.layer.borderColor = HexColorFromRGB(0xFAFAFC).CGColor;
  269. [cacheBtn setTitleColor:HexColorFromRGB(0x475A7D) forState:UIControlStateNormal];
  270. cacheBtn.backgroundColor = HexColorFromRGBA(0xFAFAFC, 1);
  271. }
  272. }
  273. }
  274. -(void)youpaifaddGuard
  275. {
  276. _youpaipguardHerBtn.userInteractionEnabled = NO;
  277. WeakSelf;
  278. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  279. NSString *api = @"";
  280. if (self.youpaipisChatRoom) {
  281. params = @{@"to_uid":self.youpaipuser_id,@"guard_num":@(_youpaiptotalNum),@"guard_price":@(_youpaipinfoModel.youpaipguard_price)}.mutableCopy;
  282. if (_youpaiproomid.length != 0) {
  283. [params setValue:_youpaiproomid forKey:@"room_id"];
  284. }
  285. api = TalkSendGuard;
  286. }else{
  287. params = @{@"user_id":self.youpaipuser_id,@"guard_num":@(_youpaiptotalNum),@"guard_price":@(_youpaipinfoModel.youpaipguard_price)}.mutableCopy;
  288. if (_youpaiproomid.length != 0) {
  289. [params setValue:_youpaiproomid forKey:@"room_id"];
  290. }
  291. if (_youpaipliveid.length != 0) {
  292. [params setValue:_youpaipliveid forKey:@"live_id"];
  293. }
  294. api = AddGuard;
  295. }
  296. [LCHttpHelper requestWithURLString:api parameters:params.copy needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  297. NSDictionary* dict = (NSDictionary*)responseObject;
  298. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  299. if (code==0) {//成功
  300. [ZCHUDHelper showTitle:dict[@"message"] showtime:1];
  301. [self dismissViewControllerAnimated:YES completion:nil];
  302. [weakSelf.youpaipdelegate youpaifaddGuardSuccess];
  303. }else if(code==1003){
  304. [self dismissViewControllerAnimated:YES completion:^{
  305. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"舍不得" handler:^(LZAlertAction *action) {
  306. }];
  307. cancelAction.cornerRadius = 24.0f;
  308. cancelAction.color = LZ273145Color;
  309. cancelAction.bgColor = LZF5F4F7Color;
  310. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"去充值" handler:^(LZAlertAction *action) {
  311. [[NSNotificationCenter defaultCenter] postNotificationName:@"InsufficientBalanceNotice" object:nil userInfo:nil];
  312. YOUPAIXRWalletVC* coinRecharge = [[YOUPAIXRWalletVC alloc]init];
  313. [[ZCUtils getCurrentVC].navigationController pushViewController:coinRecharge animated:YES];
  314. }];
  315. confimAction.cornerRadius = 24.0f;
  316. confimAction.color = [UIColor whiteColor];
  317. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  318. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"您的钻石数量不足,去购买" action:@[cancelAction,confimAction]];
  319. alert.contentTextAlignment = NSTextAlignmentCenter;
  320. [kAppDelegate.window.rootViewController TFPresentVC:alert completion:^{}];
  321. }];
  322. }
  323. else
  324. {
  325. weakSelf.youpaipguardHerBtn.userInteractionEnabled = YES;
  326. [ZCHUDHelper showTitle:dict[@"message"] showtime:1];
  327. }
  328. } failure:^(NSError *error) {
  329. [ZCHUDHelper showTitle:error.mj_JSONString showtime:1];
  330. [self dismissViewControllerAnimated:YES completion:nil];
  331. }];
  332. }
  333. /*
  334. // Only override drawRect: if you perform custom drawing.
  335. // An empty implementation adversely affects performance during animation.
  336. - (void)drawRect:(CGRect)rect {
  337. // Drawing code
  338. }
  339. */
  340. @end