BogoWardOpenView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //
  2. // BogoWardOpenView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/10/8.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoWardOpenView.h"
  9. #import "BogoOpenWardCollectionView.h"
  10. #import "BogoWardModel.h"
  11. #import "BogoOpenWardBottomView.h"
  12. @interface BogoWardOpenView()
  13. @property (nonatomic, strong) UIView *shadowView;
  14. @property (nonatomic, strong) UIImageView *topBackView;
  15. @property (nonatomic, strong) UIImageView *iconImageView;
  16. @property (nonatomic, strong) UIImageView *wardImageView;
  17. @property (nonatomic, strong) UILabel *titleL;
  18. @property (nonatomic, strong) UILabel *timeLabel;
  19. @property(nonatomic, strong) QMUIButton *diamondBtn;
  20. @property (nonatomic, copy) clickFAQBtnBlock clickFAQBtnBlock;
  21. @property (nonatomic, copy) clickWardListBtnBlock clickWardListBtnBlock;
  22. @property (nonatomic, copy) clickOpenViewBtnBlock clickOpenViewBtnBlock;
  23. @property (nonatomic, copy) clickPrivilegeBtnBlock clickPrivilegeBtnBlock;
  24. @property (nonatomic, copy) NSString *userId;
  25. @property (nonatomic, copy) NSString *currentId;
  26. @property (nonatomic, strong) NSArray *privilegeArray;
  27. @property(nonatomic, strong) UILabel *timeL;
  28. @property(nonatomic, strong) UILabel *privilegeL;
  29. @property(nonatomic, strong) BogoOpenWardCollectionView *wardCollectionView;//守护时长
  30. @property(nonatomic, strong) BogoOpenWardCollectionView *timeCollectionView;//守护时长
  31. @property(nonatomic, strong) BogoOpenWardCollectionView *privilegeCollectionView;//守护特权
  32. @property(nonatomic, strong) BogoOpenWardBottomView *bottomView;
  33. @property(nonatomic, strong) UIView *backGroundView;
  34. @end
  35. @implementation BogoWardOpenView
  36. -(instancetype)initWithFrame:(CGRect)frame UserId:(nonnull NSString *)userId{
  37. if (self = [super initWithFrame:frame]) {
  38. self.backgroundColor = kWhiteColor;
  39. self.backGroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 50, frame.size.width - 20, frame.size.height)];
  40. [self addSubview:self.backGroundView];
  41. self.backGroundView.backgroundColor = kWhiteColor;
  42. ViewRadius(self.backGroundView, 10);
  43. UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
  44. CAShapeLayer* shape = [[CAShapeLayer alloc] init];
  45. [shape setPath:rounded.CGPath];
  46. self.layer.mask = shape;
  47. self.userId = userId;
  48. CAGradientLayer *gl = [CAGradientLayer layer];
  49. gl.frame = self.bounds;
  50. gl.startPoint = CGPointMake(0, 0);
  51. gl.endPoint = CGPointMake(1, 1);
  52. gl.colors = @[(__bridge id)[UIColor colorWithRed:174/255.0 green:44/255.0 blue:241/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:137/255.0 green:106/255.0 blue:255/255.0 alpha:1.0].CGColor];
  53. gl.locations = @[@(0.0),@(1.0f)];
  54. [self.layer insertSublayer:gl atIndex:0];
  55. self.layer.cornerRadius = 20;
  56. [self initSubview];
  57. [self requestData];
  58. }
  59. return self;
  60. }
  61. - (void)initSubview{
  62. UIImageView *zhuanshi = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, self.width, 90)];
  63. [self addSubview:zhuanshi];
  64. zhuanshi.contentMode = UIViewContentModeScaleAspectFit;
  65. zhuanshi.image = [UIImage imageNamed:@"守护装饰"];
  66. UIButton *faqBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
  67. [faqBtn setBackgroundImage:[UIImage imageNamed:@"lr_btn_ward_faq"] forState:UIControlStateNormal];
  68. // [faqBtn addTarget:self action:@selector(faqBtnAction) forControlEvents:UIControlEventTouchUpInside];
  69. faqBtn.hidden = YES;
  70. [self addSubview:faqBtn];
  71. [self addSubview:self.iconImageView];
  72. [self addSubview:self.wardImageView];
  73. UIButton *closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, kRealValue(25), kRealValue(25))];
  74. closeBtn.right = self.right - kRealValue(10);
  75. closeBtn.hidden = YES;
  76. [closeBtn setImage:[UIImage imageNamed:@"lr_btn_ward_close"] forState:UIControlStateNormal];
  77. [closeBtn addTarget:self action:@selector(closeBtn:) forControlEvents:UIControlEventTouchUpInside];
  78. [self addSubview:closeBtn];
  79. CGSize wardListBtnSize = [ASLocalizedString(@"TA的守护")textSizeIn:CGSizeMake(MAXFLOAT, MAXFLOAT) font:[UIFont systemFontOfSize:15]];
  80. UIButton *wardListBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, wardListBtnSize.width, 20)];
  81. wardListBtn.right = self.right - kRealValue(10);
  82. [wardListBtn setTitle:ASLocalizedString(@"TA的守护")forState:UIControlStateNormal];
  83. [wardListBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  84. [wardListBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
  85. [wardListBtn addTarget:self action:@selector(wardListBtnAction) forControlEvents:UIControlEventTouchUpInside];
  86. [self addSubview:wardListBtn];
  87. self.titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 2, kRealValue(50))];
  88. self.titleL.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
  89. self.titleL.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
  90. self.titleL.textAlignment = NSTextAlignmentCenter;
  91. self.titleL.text = ASLocalizedString(@"开通守护");
  92. self.titleL.centerX = kScreenW / 2;
  93. [self addSubview:self.titleL];
  94. [self setUpCollectionView];
  95. closeBtn.centerY = wardListBtn.centerY = self.titleL.centerY;
  96. }
  97. -(void)setUpCollectionView{
  98. [self addSubview:self.timeL];
  99. [self addSubview:self.privilegeL];
  100. [self addSubview:self.wardCollectionView];
  101. [self addSubview:self.timeCollectionView];
  102. [self addSubview:self.privilegeCollectionView];
  103. [self addSubview:self.bottomView];
  104. self.wardCollectionView.frame = CGRectMake(10, self.titleL.bottom + 10, kScreenW - 20, kRealValue(80));
  105. self.timeL.top = self.wardCollectionView.bottom;
  106. self.timeCollectionView.frame = CGRectMake(10, self.timeL.bottom, kScreenW -20, kRealValue(40));
  107. self.privilegeL.top = self.timeCollectionView.bottom;
  108. self.privilegeCollectionView.frame = CGRectMake(10, self.privilegeL.bottom, kScreenW -20, kRealValue(160));
  109. self.backGroundView.qmui_extendToBottom = self.privilegeCollectionView.bottom + 5;
  110. }
  111. - (void)requestData{
  112. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  113. [dict setValue:@"guardians" forKey:@"ctl"];
  114. [dict setValue:@"duardian_index" forKey:@"act"];
  115. [dict setValue:self.userId forKey:@"host_id"];
  116. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  117. if ([responseJson toInt:@"status"] == 1) {
  118. [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:responseJson[@"head_image"]] placeholderImage:kDefaultPreloadHeadImg];
  119. NSString *is_guaritian = responseJson[@"is_guartian"];
  120. NSString *diamond = responseJson[@"diamonds"];
  121. NSString *guartian_time = responseJson[@"guartian_time"];
  122. NSString *guartian_icon = responseJson[@"guartian_icon"];
  123. NSArray *guardianTypeArr = [NSArray modelArrayWithClass:[BogoWardModel class] json:responseJson[@"list"]];
  124. NSArray *priviteArr = [NSArray modelArrayWithClass:[BogoWardModel class] json:responseJson[@"guardian_effects"]];
  125. //
  126. [self.wardCollectionView refreshType:BOGO_OPENWARD_Collection_TYPE_GUARDIANS array:guardianTypeArr];
  127. [self.privilegeCollectionView refreshType:BOGO_OPENWARD_Collection_TYPE_PRIVITE array:priviteArr];
  128. self.bottomView.is_guartian = is_guaritian;
  129. self.bottomView.diamondStr = diamond;
  130. self.bottomView.guartian_icon = guartian_icon;
  131. self.bottomView.guartian_time = guartian_time;
  132. BogoWardModel *model = guardianTypeArr.firstObject;
  133. [self.timeCollectionView refreshType:BOGO_OPENWARD_Collection_TYPE_TIME array:model.guardian_pay];
  134. BogoWardPayTimeModel *timeModel = model.guardian_pay.firstObject;
  135. if ([timeModel isKindOfClass:[NSDictionary class]]) {
  136. timeModel = [BogoWardPayTimeModel modelWithDictionary:timeModel];
  137. }
  138. self.currentId = timeModel.id;
  139. }else{
  140. NSLog(ASLocalizedString(@"守护类型接口请求失败responseJson:%@"),responseJson);
  141. }
  142. } FailureBlock:^(NSError *error) {
  143. NSLog(ASLocalizedString(@"守护类型接口请求失败error:%@"),error);
  144. }];
  145. }
  146. -(void)closeBtn:(UIButton *)sender{
  147. [self hide];
  148. }
  149. - (void)wardListBtnAction{
  150. [self hide];
  151. if (self.clickWardListBtnBlock) {
  152. self.clickWardListBtnBlock();
  153. }
  154. }
  155. - (void)openBtnAction{
  156. NSLog(ASLocalizedString(@"点击了开通守护按钮"));
  157. [self hide];
  158. if (self.clickOpenViewBtnBlock) {
  159. self.clickOpenViewBtnBlock(self.currentId);
  160. }
  161. }
  162. -(BogoOpenWardCollectionView *)wardCollectionView{
  163. if (!_wardCollectionView) {
  164. _wardCollectionView = [[BogoOpenWardCollectionView alloc]initWithFrame:CGRectMake(20, kRealValue(30), kScreenW - 20, kRealValue(78))];
  165. _wardCollectionView.selectRowBlock = ^(BogoWardModel * _Nonnull model) {
  166. [self.timeCollectionView refreshType:BOGO_OPENWARD_Collection_TYPE_TIME array:model.guardian_pay];
  167. [self.privilegeCollectionView refreshTypeNameWithArray:model.type_name];
  168. BogoWardPayTimeModel *timeModel = model.guardian_pay.firstObject;
  169. if ([timeModel isKindOfClass:[NSDictionary class]]) {
  170. timeModel = [BogoWardPayTimeModel modelWithDictionary:timeModel];
  171. }
  172. self.currentId = timeModel.id;
  173. };
  174. }
  175. return _wardCollectionView;
  176. }
  177. -(BogoOpenWardCollectionView *)timeCollectionView{
  178. if (!_timeCollectionView) {
  179. _timeCollectionView = [[BogoOpenWardCollectionView alloc]initWithFrame:CGRectMake(10, kRealValue(30), kScreenW - 20, kRealValue(40))];
  180. _timeCollectionView.selectTimeCollectionViewRowBlock = ^(BogoWardPayTimeModel * _Nonnull timeModel) {
  181. if ([timeModel isKindOfClass:[NSDictionary class]]) {
  182. timeModel = [BogoWardPayTimeModel modelWithDictionary:timeModel];
  183. }
  184. self.currentId = timeModel.id;
  185. };
  186. }
  187. return _timeCollectionView;
  188. }
  189. -(BogoOpenWardCollectionView *)privilegeCollectionView{
  190. if (!_privilegeCollectionView) {
  191. _privilegeCollectionView = [[BogoOpenWardCollectionView alloc]initWithFrame:CGRectMake(10, kRealValue(30), kScreenW - 20, kRealValue(150))];
  192. }
  193. return _privilegeCollectionView;
  194. }
  195. -(UILabel *)timeL{
  196. if (!_timeL) {
  197. _timeL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(12), 0, kScreenW / 2, kRealValue(30))];
  198. _timeL.font = [UIFont systemFontOfSize:14];
  199. _timeL.textColor = [UIColor colorWithHexString:@"#333333"];
  200. _timeL.text = ASLocalizedString(@"守护时长");
  201. }
  202. return _timeL;
  203. }
  204. -(UILabel *)privilegeL{
  205. if (!_privilegeL) {
  206. _privilegeL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(12), 0, kScreenW / 2, kRealValue(30))];
  207. _privilegeL.font = [UIFont systemFontOfSize:14];
  208. _privilegeL.textColor = [UIColor colorWithHexString:@"#333333"];
  209. _privilegeL.text = ASLocalizedString(@"守护特权");
  210. }
  211. return _privilegeL;
  212. }
  213. -(BogoOpenWardBottomView *)bottomView{
  214. if (!_bottomView) {
  215. _bottomView = [[BogoOpenWardBottomView alloc]initWithFrame:CGRectMake(0, self.height - kRealValue(60) - MG_BOTTOM_MARGIN, kScreenW, kRealValue(60))];
  216. _bottomView.clickOpenBtnBlock = ^(BOOL isClick) {
  217. [self openBtnAction];
  218. };
  219. }
  220. return _bottomView;
  221. }
  222. @end