ASVipCenterViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //
  2. // ASVipCenterViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/26.
  6. //
  7. #import "ASVipCenterViewController.h"
  8. #import "ASUserBaseInfoView.h"
  9. #import "ASVipCenterLineItemView.h"
  10. #import "ASVipCenterCollectCell.h"
  11. #import "ASVipCouponsViewController.h"
  12. #import "ASBirthdayTreatViewController.h"
  13. #import "ASInfomationSetController.h"
  14. @interface ASVipCenterViewController () <UICollectionViewDelegate,UICollectionViewDataSource>
  15. @property (nonatomic, strong) UIScrollView *scrollV;
  16. @property (nonatomic, strong) UIView *contentV;
  17. @property (nonatomic, strong) ASUserBaseInfoView *userInfoV;
  18. @property (nonatomic, strong) UICollectionView *collectV;
  19. @property (nonatomic, strong) UIPageControl *control;
  20. @property (nonatomic, strong) NSMutableArray <ASVipCenterLineItemView *>*bottomVArr;
  21. //@property (nonatomic, strong) NSMutableArray *bottomTitleArr;
  22. @property (nonatomic, strong) NSArray *vipImgArr;
  23. @property (nonatomic, strong) UIStackView *bottomStv;
  24. @end
  25. @implementation ASVipCenterViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [UIView viewAddHorColorBg:self.view colorArr:@[
  29. (id)_E0FFF5.CGColor,
  30. (id)Col_FFF.CGColor
  31. ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)];
  32. // self.bottomTitleArr = [NSMutableArray arrayWithObjects:@"EXCLUSIVE $100 COUPON", @"BIRTHDAY TREAT", nil];
  33. self.vipImgArr = @[@"vip_bg1",@"vip_bg2",@"vip_bg3",@"vip_bg4",@"vip_bg5"];
  34. [self loadSubVs];
  35. [self.view bringSubviewToFront:self.customNavBar];
  36. [self configSubVs];
  37. [self setData];
  38. }
  39. - (void)setData {
  40. [self.userInfoV setData];
  41. ASVipModel *curVipM = ASUserInfoManager.shared.curVipInfo;
  42. ASVipModel *nexVipM = ASUserInfoManager.shared.nextVipInfo;
  43. self.userInfoV.usefualLb.text = [NSString stringWithFormat:@"Growth Value %ld/%ld", ASUserInfoManager.shared.pointAmount.integerValue, nexVipM.exppoints.integerValue];
  44. NSArray *arr = ASUserInfoManager.shared.vipInfoArr;
  45. self.control.numberOfPages = arr.count > 0 ? arr.count : 0;
  46. NSInteger curPage = curVipM.level.integerValue-1;
  47. self.control.currentPage = curPage >= 0 ? curPage : 0;
  48. }
  49. - (void)configSubVs {
  50. self.titleStr = @"VIP Center";
  51. [self setNavRightSearch:^{
  52. }];
  53. self.statusBgV.backgroundColor = _E0FFF5;
  54. self.customNavBar.backgroundColor = _F0FFFA;
  55. }
  56. // MARK: - loadSubVs
  57. - (void)loadSubVs {
  58. [self.view addSubview:self.scrollV];
  59. [self.scrollV addSubview:self.contentV];
  60. [self.contentV addSubview:self.userInfoV];
  61. [self.contentV addSubview:self.collectV];
  62. [self.contentV addSubview:self.control];
  63. self.bottomStv = [self getBottomV:ASUserInfoManager.shared.curVipInfo];
  64. [self.contentV addSubview:self.bottomStv];
  65. [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(self.customNavBar.mas_bottom);
  67. make.leading.trailing.bottom.equalTo(self.view);
  68. }];
  69. [self.contentV mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.edges.equalTo(self.scrollV);
  71. make.width.equalTo(self.view);
  72. }];
  73. [self.userInfoV mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(self.contentV).offset(30);
  75. make.leading.equalTo(self.contentV).offset(20);
  76. make.trailing.equalTo(self.contentV).offset(-20);
  77. }];
  78. [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(self.userInfoV.mas_bottom).offset(50);
  80. make.leading.trailing.equalTo(self.contentV);
  81. CGFloat collH = (KScreenWidth-40)/335*256;
  82. make.height.equalTo(@(collH));
  83. }];
  84. [self.control mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.height.equalTo(@10);
  86. make.leading.equalTo(self.contentV).offset(20);
  87. make.trailing.equalTo(self.contentV).offset(-20);
  88. make.top.equalTo(self.collectV.mas_bottom).offset(20);
  89. }];
  90. [self.bottomStv mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.top.equalTo(self.control.mas_bottom).offset(20);
  92. make.leading.trailing.equalTo(self.contentV);
  93. make.bottom.equalTo(self.contentV.mas_bottom).offset(-80);
  94. }];
  95. }
  96. // MARK: - subvs
  97. - (ASUserBaseInfoView *)userInfoV {
  98. if (!_userInfoV) {
  99. ASUserBaseInfoView *v = [[ASUserBaseInfoView alloc] initWithFrame:CGRectZero];
  100. v.backgroundColor = UIColor.clearColor;
  101. v.usefualLb.font = [UIFont fontWithName:Rob_Regular size:14];
  102. v.usefualLb.textColor = Col_666;
  103. v.avaterV.layer.cornerRadius = 8;
  104. v.avaterV.layer.masksToBounds = true;
  105. _userInfoV = v;
  106. }
  107. return _userInfoV;
  108. }
  109. - (UIScrollView *)scrollV {
  110. if (!_scrollV) {
  111. UIScrollView *v = [[UIScrollView alloc] init];
  112. v.backgroundColor = UIColor.clearColor;
  113. v.showsVerticalScrollIndicator = false;
  114. v.alwaysBounceVertical = true;
  115. _scrollV = v;
  116. }
  117. return _scrollV;
  118. }
  119. - (UIView *)contentV {
  120. if (!_contentV) {
  121. UIView *v = [UIView baseV];
  122. v.backgroundColor = UIColor.clearColor;
  123. _contentV = v;
  124. }
  125. return _contentV;
  126. }
  127. - (UICollectionView *)collectV {
  128. if (!_collectV) {
  129. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  130. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  131. layout.minimumInteritemSpacing = 0;
  132. layout.minimumLineSpacing = 0;
  133. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  134. CGFloat collH = (KScreenWidth-40)/335*256;
  135. layout.itemSize = CGSizeMake(KScreenWidth, collH);
  136. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, collH) collectionViewLayout:layout];
  137. collV.backgroundColor = [UIColor clearColor];
  138. collV.alwaysBounceHorizontal = true;
  139. collV.scrollEnabled = true;
  140. collV.pagingEnabled = true;
  141. collV.delegate = self;
  142. collV.dataSource = self;
  143. collV.showsHorizontalScrollIndicator = false;
  144. [collV registerClass:[ASVipCenterCollectCell class] forCellWithReuseIdentifier:@"ASVipCenterCollectCell"];
  145. _collectV = collV;
  146. }
  147. return _collectV;
  148. }
  149. -(UIPageControl *)control {
  150. if (!_control) {
  151. _control = [[UIPageControl alloc] init];
  152. [_control setTintColor:[UIColor colorWithHexString:@"#000000"]];
  153. [_control setPageIndicatorTintColor:[[UIColor colorWithHexString:@"#000000"] colorWithAlphaComponent:0.3] ];
  154. [_control setCurrentPageIndicatorTintColor:[UIColor colorWithHexString:@"#000000"] ];
  155. _control.transform = CGAffineTransformScale(_control.transform, 1.15, 1.15);
  156. _control.userInteractionEnabled = false;
  157. }
  158. return _control;
  159. }
  160. - (UIStackView *)getBottomV:(ASVipModel *)vipM {
  161. UIStackView *stv = [UIStackView baseStackV:true];
  162. stv.spacing = 0;
  163. stv.distribution = UIStackViewDistributionFillEqually;
  164. self.bottomVArr = [NSMutableArray array];
  165. for (int i=0; i<vipM.privilege.count; i++) {
  166. ASVipPriSubModel *tempM = vipM.privilege[i];
  167. NSString *title = [NSString stringWithFormat:@"%@ %@", tempM.title, tempM.desc];
  168. ASVipCenterLineItemView *v = [[ASVipCenterLineItemView alloc] initWithFrame:CGRectZero];
  169. [v setData:title canGoNext:true];
  170. v.tag = 90000+i;
  171. __weak typeof(self) weakSelf = self;
  172. v.selectCallBack = ^{
  173. if (vipM.level.integerValue != ASUserInfoManager.shared.curVipInfo.level.integerValue) {
  174. return;
  175. }
  176. if (tempM.type.integerValue == 1) { // 优惠券
  177. ASVipCouponsViewController *vc = [ASVipCouponsViewController new];
  178. vc.level = vipM.level;
  179. [self.navigationController pushViewController:vc animated:true];
  180. } else if (tempM.type.integerValue == 2) { // 生日
  181. if (ASUserInfoManager.shared.birthStatus.integerValue == -1) {
  182. ASInfomationSetController *vc = [ASInfomationSetController new];
  183. [self.navigationController pushViewController:vc animated:true];
  184. return;
  185. }
  186. ASBirthdayTreatViewController *vc = [ASBirthdayTreatViewController new];
  187. vc.isBirthday = ASUserInfoManager.shared.birthStatus.integerValue == 2;
  188. [self.navigationController pushViewController:vc animated:true];
  189. }
  190. };
  191. [self.bottomVArr addObject:v];
  192. [stv addArrangedSubview:v];
  193. }
  194. return stv;
  195. }
  196. // MARK: - collectV delegate datesource
  197. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  198. return ASUserInfoManager.shared.vipInfoArr.count;
  199. }
  200. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  201. ASVipCenterCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASVipCenterCollectCell" forIndexPath:indexPath];
  202. NSArray *arr = ASUserInfoManager.shared.vipInfoArr;
  203. if (arr.count <= indexPath.row) {
  204. return cell;
  205. }
  206. ASVipModel *model = arr[indexPath.row];
  207. if (model.nextExppoints != nil && model.nextExppoints.integerValue > 0) {
  208. [cell setData:self.vipImgArr[indexPath.row%self.vipImgArr.count] desStr:[NSString stringWithFormat:@"INTEGRAL TO %@-%@", model.exppoints, model.nextExppoints]];
  209. } else {
  210. [cell setData:self.vipImgArr[indexPath.row%self.vipImgArr.count] desStr:[NSString stringWithFormat:@"INTEGRAL TO %ld", model.exppoints.integerValue + 1]];
  211. }
  212. cell.desLb.textColor = Col_000;
  213. if (indexPath.row == arr.count-1) {
  214. cell.desLb.textColor = _FFE797;
  215. }
  216. return cell;
  217. }
  218. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  219. NSInteger page = (NSInteger)scrollView.contentOffset.x/SCREEN_WIDTH;
  220. self.control.currentPage = page;
  221. [self reSetCurrentBottom];
  222. }
  223. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
  224. NSInteger page = (NSInteger)scrollView.contentOffset.x/SCREEN_WIDTH;
  225. self.control.currentPage = page;
  226. [self reSetCurrentBottom];
  227. }
  228. - (void)reSetCurrentBottom {
  229. NSArray *arr = ASUserInfoManager.shared.vipInfoArr;
  230. if (arr.count <= self.control.currentPage) {
  231. return;
  232. }
  233. ASVipModel *model = arr[self.control.currentPage];
  234. if (self.bottomStv && self.bottomStv.superview != nil) {
  235. for (UIView *item in self.bottomStv.arrangedSubviews) {
  236. [self.bottomStv removeArrangedSubview:item];
  237. }
  238. [self.bottomStv removeFromSuperview];
  239. }
  240. self.bottomStv = [self getBottomV:model];
  241. [self.contentV addSubview:self.bottomStv];
  242. [self.bottomStv mas_remakeConstraints:^(MASConstraintMaker *make) {
  243. make.top.equalTo(self.control.mas_bottom).offset(20);
  244. make.leading.trailing.equalTo(self.contentV);
  245. make.bottom.equalTo(self.contentV.mas_bottom).offset(-80);
  246. }];
  247. }
  248. @end