ASVipCenterViewController.m 11 KB

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