shouhuView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. //
  2. // shouhuView.m
  3. // yunbaolive
  4. //
  5. // Created by Boom on 2018/8/9.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "shouhuView.h"
  9. #import "grardButton.h"
  10. #import "guardAlertView.h"
  11. @implementation shouhuView{
  12. UIView *whiteView;
  13. NSMutableArray *btnArray;
  14. int selectIndex;
  15. UILabel *coinLabel;
  16. UIButton *buyBtn;
  17. NSDictionary *infoDic;
  18. NSMutableArray *privilegeArray;
  19. NSMutableArray *privilegeTitleArray;
  20. NSMutableArray *privilegeDesArray;
  21. guardAlertView *gAlert;
  22. UIImageView *headerImgView;
  23. UIImageView *moveView;
  24. }
  25. -(instancetype)init{
  26. self = [super init];
  27. if (self) {
  28. self.frame = CGRectMake(0, 0, _window_width, _window_height);
  29. self.backgroundColor = [UIColor clearColor];
  30. privilegeArray = [NSMutableArray array];
  31. privilegeTitleArray = [NSMutableArray array];
  32. privilegeDesArray = [NSMutableArray array];
  33. btnArray = [NSMutableArray array];
  34. selectIndex = 0;
  35. [self requestData];
  36. }
  37. return self;
  38. }
  39. - (void)creatUI:(NSDictionary *)subDic{
  40. UIButton *hidebtn = [UIButton buttonWithType:0];
  41. hidebtn.frame = CGRectMake(0, 0, _window_width, _window_height-360-ShowDiff);
  42. [hidebtn addTarget:self action:@selector(hideBtnClick) forControlEvents:UIControlEventTouchUpInside];
  43. [self addSubview:hidebtn];
  44. whiteView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height, _window_width, 360+ShowDiff)];
  45. whiteView.backgroundColor = [UIColor whiteColor];
  46. whiteView.layer.mask = [PublicObj setViewLeftTop:20 andRightTop:20 andView:whiteView];
  47. whiteView.clipsToBounds = YES;
  48. [self addSubview:whiteView];
  49. headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 80)];
  50. headerImgView.image = [UIImage imageNamed:@"guard_lowwwwwww"];
  51. headerImgView.contentMode = UIViewContentModeScaleToFill;
  52. headerImgView.clipsToBounds = YES;
  53. headerImgView.userInteractionEnabled = YES;
  54. [whiteView addSubview:headerImgView];
  55. NSArray *arr = [subDic valueForKey:@"list"];
  56. for (int i = 0 ; i < arr.count ; i++) {
  57. UIButton *btn = [UIButton buttonWithType:0];
  58. btn.frame = CGRectMake(_window_width/arr.count*i, 0, _window_width/arr.count, headerImgView.height);
  59. [btn setTitle:[NSString stringWithFormat:@"%@\n%@%@",minstr([arr[i] valueForKey:@"name"]),minstr([arr[i] valueForKey:@"coin"]),[common name_coin]] forState:0];
  60. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  61. btn.titleLabel.textAlignment = NSTextAlignmentCenter;
  62. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  63. [btn setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.4] forState:0];
  64. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  65. btn.tag = 201889+i;
  66. btn.titleLabel.numberOfLines = 0;
  67. [btnArray addObject:btn];
  68. [headerImgView addSubview:btn];
  69. if (i==0) {
  70. btn.selected = YES;
  71. moveView = [[UIImageView alloc]initWithFrame:CGRectMake(btn.centerX-7, btn.height-7, 14, 7)];
  72. moveView.image = [UIImage imageNamed:@"guard_sanjiao"];
  73. [headerImgView addSubview:moveView];
  74. }else{
  75. btn.selected = NO;
  76. }
  77. // CGFloat widthhhh = 0;
  78. //
  79. // if (i == arr.count - 1 ) {
  80. // widthhhh = 20;
  81. // }
  82. // grardButton *btn = [[grardButton alloc] initWithFrame:CGRectMake(20+90*i, label1.bottom, 85+widthhhh, 40)];
  83. // btn.tag = 201889+i;
  84. // btn.coinL.text = minstr([arr[i] valueForKey:@"coin"]);
  85. // btn.nameL.text = minstr([arr[i] valueForKey:@"name"]);
  86. //
  87. // if (i==0) {
  88. // btn.selected = YES;
  89. // }else{
  90. // btn.selected = NO;
  91. // }
  92. // if (i == arr.count - 1){
  93. // [btn setBackgroundImage:[UIImage imageNamed:@"guard_select_s_2"] forState:UIControlStateSelected];
  94. // [btn setBackgroundImage:[UIImage imageNamed:@"guard_select_n_2"] forState:UIControlStateNormal];
  95. // }else{
  96. // [btn setBackgroundImage:[UIImage imageNamed:@"guard_select_s"] forState:UIControlStateSelected];
  97. // [btn setBackgroundImage:[UIImage imageNamed:@"guard_select_n"] forState:UIControlStateNormal];
  98. // }
  99. // [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  100. // [btnArray addObject:btn];
  101. // [whiteView addSubview:btn];
  102. }
  103. // UIImageView *lineImgView =[[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.05, whiteView.height*0.25, _window_width*0.9, 1)];
  104. // lineImgView.image = [UIImage imageNamed:@"jimo_shouhu_xuxian"];
  105. // [whiteView addSubview:lineImgView];
  106. //
  107. // UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, lineImgView.bottom, _window_width*0.8, whiteView.height*0.12)];
  108. // label2.text = YZMsg(@"守护特权");
  109. // label2.font = [UIFont systemFontOfSize:15];
  110. // label2.textColor = RGB_COLOR(@"#626364", 1);
  111. //
  112. // [whiteView addSubview:label2];
  113. NSArray *privilege = [subDic valueForKey:@"privilege"];
  114. NSArray *firstArr = [[[subDic valueForKey:@"list"] firstObject] valueForKey:@"privilege"];
  115. for (int i = 0; i < privilege.count; i++) {
  116. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 80+i*57.5, _window_width, 57.5)];
  117. [whiteView addSubview:view];
  118. NSDictionary *itemDic = privilege[i];
  119. UIImageView *imgView = [[UIImageView alloc]init];
  120. imgView.contentMode = UIViewContentModeScaleAspectFit;
  121. [view addSubview:imgView];
  122. [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.left.equalTo(view).offset(10);
  124. make.centerY.equalTo(view);
  125. make.width.height.equalTo(view.mas_height).multipliedBy(0.55);
  126. }];
  127. UILabel *titleLabel = [[UILabel alloc]init];
  128. titleLabel.font = [UIFont systemFontOfSize:13];
  129. titleLabel.text = minstr([itemDic valueForKey:@"title"]);
  130. [view addSubview:titleLabel];
  131. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.left.equalTo(imgView.mas_right).offset(8);
  133. make.top.equalTo(imgView);
  134. }];
  135. UILabel *contentLabel = [[UILabel alloc]init];
  136. contentLabel.font = SYS_Font(12);
  137. contentLabel.textColor = [UIColor grayColor];
  138. contentLabel.text = minstr([itemDic valueForKey:@"des"]);
  139. [view addSubview:contentLabel];
  140. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.left.equalTo(imgView.mas_right).offset(8);
  142. make.bottom.equalTo(imgView);
  143. }];
  144. if (i < firstArr.count) {
  145. if (i == 0) {
  146. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_g"])]];
  147. }else{
  148. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_c"])]];
  149. }
  150. titleLabel.textColor = RGB_COLOR(@"#646464", 1);
  151. contentLabel.textColor = RGB_COLOR(@"#646464", 1);
  152. }else{
  153. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_g"])]];
  154. titleLabel.textColor = RGB_COLOR(@"#c8c8c8", 1);
  155. contentLabel.textColor = RGB_COLOR(@"#c8c8c8", 1);
  156. }
  157. [privilegeArray addObject:imgView];
  158. [privilegeTitleArray addObject:titleLabel];
  159. [privilegeDesArray addObject:contentLabel];
  160. }
  161. UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 310, _window_width, 1)];
  162. lineView.backgroundColor = RGB_COLOR(@"#F0F0F0", 1);
  163. [whiteView addSubview:lineView];
  164. coinLabel = [[UILabel alloc]init];
  165. coinLabel.font = [UIFont systemFontOfSize:14];
  166. coinLabel.textColor = RGB_COLOR(@"#646464", 1);
  167. coinLabel.attributedText = [self coinLabel:minstr([subDic valueForKey:@"coin"])];
  168. [whiteView addSubview:coinLabel];
  169. [coinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.left.equalTo(whiteView).offset(10);
  171. make.bottom.equalTo(whiteView).offset(-ShowDiff);
  172. make.height.mas_equalTo(49);
  173. }];
  174. buyBtn = [UIButton buttonWithType:0];
  175. [buyBtn addTarget:self action:@selector(buyBtnClick) forControlEvents:UIControlEventTouchUpInside];
  176. buyBtn.layer.cornerRadius = 15;
  177. buyBtn.layer.masksToBounds = YES;
  178. [buyBtn setTitle:YZMsg(@"立即开通") forState:0];
  179. buyBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  180. [whiteView addSubview:buyBtn];
  181. [buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.right.equalTo(whiteView).offset(-10);
  183. make.centerY.equalTo(coinLabel);
  184. make.height.mas_equalTo(30);
  185. make.width.mas_equalTo(90);
  186. }];
  187. [buyBtn layoutIfNeeded];
  188. [PublicObj addGradientWithFromColor:RGB_COLOR(@"#872ae7", 1) andEndColor:RGB_COLOR(@"#cb16e1", 1) andView:buyBtn direction:0];
  189. [self show];
  190. }
  191. - (NSMutableAttributedString *)coinLabel:(NSString *)coin{
  192. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]init];
  193. NSAttributedString *str1 = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@:",YZMsg(@"我的"),[common name_coin]]];
  194. [attStr appendAttributedString:str1];
  195. // NSTextAttachment *xoinAttchment = [[NSTextAttachment alloc]init];
  196. // xoinAttchment.bounds = CGRectMake(0, -2, 13, 13);//设置frame
  197. // xoinAttchment.image = [UIImage imageNamed:@"logFirst_钻石"];//设置图片
  198. // NSAttributedString *coinString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(xoinAttchment)];
  199. // [attStr appendAttributedString:coinString];
  200. NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc]initWithString:coin];
  201. [str2 addAttribute:NSForegroundColorAttributeName value:Pink_Cor range:NSMakeRange(0, [coin length])];//RGB_COLOR(@"#6e52f2", 1)-紫色
  202. [attStr appendAttributedString:str2];
  203. return attStr;
  204. }
  205. - (void)hideBtnClick{
  206. [self.delegate removeShouhuView];
  207. }
  208. - (void)btnClick:(grardButton *)sender{
  209. if (sender.selected) {
  210. return;
  211. }
  212. sender.selected = YES;
  213. selectIndex = (int)sender.tag - 201889;
  214. for (grardButton *btn in btnArray) {
  215. if (sender != btn) {
  216. btn.selected = NO;
  217. }
  218. }
  219. moveView.centerX = sender.centerX;
  220. if (sender.tag == 201891) {
  221. headerImgView.image = [UIImage imageNamed:@"guard_height"];
  222. }else{
  223. headerImgView.image = [UIImage imageNamed:@"guard_lowwwwwww"];
  224. }
  225. NSArray *privilege = [infoDic valueForKey:@"privilege"];
  226. NSDictionary *selectDiccc = [infoDic valueForKey:@"list"][selectIndex];
  227. NSArray *firstArr = [selectDiccc valueForKey:@"privilege"];
  228. for (int i = 0; i < privilege.count; i ++) {
  229. NSDictionary *itemDic = privilege[i];
  230. UIImageView *imgView = privilegeArray[i];
  231. UILabel *titleLabel = privilegeTitleArray[i];
  232. UILabel *contentLabel = privilegeDesArray[i];
  233. if (i < firstArr.count) {
  234. if([minstr([selectDiccc valueForKey:@"type"]) isEqual:@"2"]){
  235. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_c"])]];
  236. }else{
  237. if (i == 0) {
  238. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_g"])]];
  239. }else{
  240. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_c"])]];
  241. }
  242. }
  243. titleLabel.textColor = RGB_COLOR(@"#646464", 1);
  244. contentLabel.textColor = RGB_COLOR(@"#646464", 1);
  245. }else{
  246. [imgView sd_setImageWithURL:[NSURL URLWithString:minstr([itemDic valueForKey:@"thumb_g"])]];
  247. titleLabel.textColor = RGB_COLOR(@"#c8c8c8", 1);
  248. contentLabel.textColor = RGB_COLOR(@"#c8c8c8", 1);
  249. }
  250. }
  251. }
  252. - (void)show{
  253. [UIView animateWithDuration:0.3 animations:^{
  254. whiteView.frame = CGRectMake(0, _window_height-360-ShowDiff, _window_width, 360+ShowDiff);
  255. }];
  256. }
  257. - (void)hideAlert{
  258. [gAlert removeFromSuperview];
  259. gAlert = nil;
  260. }
  261. - (void)buyBtnClick{
  262. // if ([_guardType isEqual:@"0"]) {
  263. //
  264. //// [self goBuy];
  265. // }else{
  266. if ([_guardType isEqual:@"1"] && selectIndex == 2) {
  267. gAlert = [[guardAlertView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) andType:1 andMsg:YZMsg(@"您当前为主播的月守护,开通年守护将覆盖您的月守护剩余时长,是否开通?")];
  268. __weak shouhuView *wSelf = self;
  269. gAlert.block = ^(BOOL isSure) {
  270. if (isSure) {
  271. [wSelf goBuy];
  272. }else{
  273. [wSelf hideAlert];
  274. }
  275. };
  276. [self addSubview:gAlert];
  277. }else if ([_guardType isEqual:@"2"] && selectIndex != 2) {
  278. gAlert = [[guardAlertView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) andType:0 andMsg:YZMsg(@"您当前为主播的年守护\n无法开通7天/月守护")];
  279. __weak shouhuView *wSelf = self;
  280. gAlert.block = ^(BOOL isSure) {
  281. if (isSure) {
  282. [wSelf goBuy];
  283. }else{
  284. [wSelf hideAlert];
  285. }
  286. };
  287. [self addSubview:gAlert];
  288. }else{
  289. NSString *msg;
  290. switch (selectIndex) {
  291. case 0:
  292. msg = [NSString stringWithFormat:@"%@%@%@,%@",YZMsg(@"您将花费"),minstr([[infoDic valueForKey:@"list"][selectIndex] valueForKey:@"coin"]),[common name_coin],YZMsg(@"为主播开通7天守护")];
  293. break;
  294. case 1:
  295. msg = [NSString stringWithFormat:@"%@%@%@,%@",YZMsg(@"您将花费"),minstr([[infoDic valueForKey:@"list"][selectIndex] valueForKey:@"coin"]),[common name_coin],YZMsg(@"为主播开通月守护")];
  296. break;
  297. case 2:
  298. msg = [NSString stringWithFormat:@"%@%@%@,%@",YZMsg(@"您将花费"),minstr([[infoDic valueForKey:@"list"][selectIndex] valueForKey:@"coin"]),[common name_coin],YZMsg(@"为主播开通年守护")];
  299. break;
  300. default:
  301. break;
  302. }
  303. gAlert = [[guardAlertView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) andType:1 andMsg:msg];
  304. __weak shouhuView *wSelf = self;
  305. gAlert.block = ^(BOOL isSure) {
  306. if (isSure) {
  307. [wSelf goBuy];
  308. }else{
  309. [wSelf hideAlert];
  310. }
  311. };
  312. [self addSubview:gAlert];
  313. }
  314. // }
  315. }
  316. - (void)goBuy{
  317. NSDictionary *parameterDic = @{
  318. @"liveuid":_liveUid,
  319. @"guardid":minstr([[infoDic valueForKey:@"list"][selectIndex] valueForKey:@"id"]),
  320. @"stream":_stream
  321. };
  322. [YBNetworking postWithUrl:@"Guard.BuyGuard" Dic:parameterDic Suc:^(int code, id info, NSString *msg) {
  323. if (code == 0) {
  324. NSDictionary *infos = [info firstObject];
  325. [self.delegate buyShouhuSuccess:infos];
  326. [self hideBtnClick];
  327. }
  328. [MBProgressHUD showError:msg];
  329. } Fail:^(id fail) {
  330. [MBProgressHUD showError:YZMsg(@"网络错误")];
  331. }];
  332. }
  333. - (void)requestData{
  334. [YBNetworking postWithUrl:@"Guard.GetList" Dic:nil Suc:^(int code, id info, NSString *msg) {
  335. if (code == 0) {
  336. infoDic = [info firstObject];
  337. [self creatUI:infoDic];
  338. }else {
  339. [MBProgressHUD showPop:msg];
  340. }
  341. } Fail:^(id fail) {
  342. }];
  343. }
  344. #pragma mark ================ alertview ===============
  345. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  346. // if (buttonIndex == 1) {
  347. // [self.delegate pushCoinV];
  348. // }
  349. //}
  350. @end