BogoNobleViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. //
  2. // BogoNobleViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/4/22.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoNobleViewController.h"
  9. #import "BogoNobleTitleCell.h"
  10. #import "BogoNoblePrivilegeCell.h"
  11. #import "BogoNobleListModel.h"
  12. #import "BogoNobleBottomView.h"//底部视图
  13. #import "BogoNobleAlertView.h"//弹窗view
  14. #import "BogoNoblePayView.h" //支付view
  15. @interface BogoNobleViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,BogoNobleBottomDelegate,BogoNoblePayDelegate>
  16. @property(nonatomic, strong) UICollectionView *titleCollectionView;
  17. @property(nonatomic, strong) UICollectionView *contentCollectionView;
  18. @property(nonatomic, strong) NSMutableArray *titleListArr;
  19. @property(nonatomic, strong) NSMutableArray *contentListArr;
  20. @property(nonatomic, strong) BogoNobleListModel *model;
  21. @property(nonatomic, strong) BogoNobleListTypeModel *typeModel;
  22. @property(nonatomic, strong) BogoNobleListSubTypeModel *selectModel;
  23. @property(nonatomic, strong) UIView *bgTopView;
  24. @property(nonatomic, strong) UIImageView *bgTopImgView;
  25. @property(nonatomic, strong) BogoNobleBottomView *bottomView;
  26. @property(nonatomic, strong) BogoNobleAlertView *alertView;
  27. @property(nonatomic, strong) BogoNoblePayView *payView;
  28. @property(nonatomic, strong) UIView *lineView;//滑动line
  29. @end
  30. @implementation BogoNobleViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. // Do any additional setup after loading the view.
  34. self.view.backgroundColor = kWhiteColor;
  35. UIImageView * bgimgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  36. bgimgV.image = [UIImage imageNamed:@"mine_noblebg"];
  37. [self.view addSubview:bgimgV];
  38. [self setNavView];
  39. [self setUpView];
  40. }
  41. - (void)viewWillAppear:(BOOL)animated {
  42. [super viewWillAppear:animated];
  43. self.navigationController.navigationBarHidden = YES;
  44. [self setModel];
  45. }
  46. -(void)setNavView{
  47. UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, kStatusBarHeight, kScreenW * 0.5, kRealValue(40))];
  48. titleL.text = ASLocalizedString(@"贵族列表");
  49. titleL.font = [UIFont systemFontOfSize:16];
  50. titleL.textAlignment = NSTextAlignmentCenter;
  51. titleL.textColor = UIColor.whiteColor;
  52. [self.view addSubview:titleL];
  53. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  54. [backBtn setImage:[UIImage imageNamed:@"back_w"] forState:UIControlStateNormal];
  55. [backBtn addTarget:self action:@selector(clickBackBtn:) forControlEvents:UIControlEventTouchUpInside];
  56. [self.view addSubview:backBtn];
  57. titleL.centerX = kScreenW / 2;
  58. backBtn.frame = CGRectMake(kRealValue(10), kStatusBarHeight, kRealValue(40), kRealValue(40));
  59. }
  60. -(void)clickBackBtn:(UIButton *)sender{
  61. [self.navigationController popViewControllerAnimated:YES];
  62. }
  63. -(void)setUpView{
  64. UICollectionViewFlowLayout *titleLayout = [[UICollectionViewFlowLayout alloc] init];
  65. titleLayout.itemSize = CGSizeMake(kScreenW / 5, kRealValue(70));
  66. titleLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
  67. titleLayout.minimumInteritemSpacing = 10;
  68. titleLayout.minimumLineSpacing = 10;
  69. titleLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  70. self.titleCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, kTopHeight, kScreenW, kRealValue(48)) collectionViewLayout:titleLayout];
  71. self.titleCollectionView.delegate = self;
  72. self.titleCollectionView.dataSource = self;
  73. self.titleCollectionView.backgroundColor = UIColor.clearColor;
  74. self.titleCollectionView.showsHorizontalScrollIndicator = NO;
  75. [self.titleCollectionView registerNib:[UINib nibWithNibName:@"BogoNobleTitleCell" bundle:nil] forCellWithReuseIdentifier:@"BogoNobleTitleCell"];
  76. [self.titleCollectionView addSubview:self.lineView];
  77. UIImageView *contentImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kRealValue(6), self.titleCollectionView.bottom + kRealValue(117), kScreenW - kRealValue(6 * 2), kScreenH - self.titleCollectionView.bottom - kRealValue(117) - self.bottomView.height)];
  78. contentImgView.image = [UIImage imageNamed:@"bogo_noble_contentBgImg"];
  79. contentImgView.userInteractionEnabled = YES;
  80. UICollectionViewFlowLayout *contentLayout = [[UICollectionViewFlowLayout alloc] init];
  81. contentLayout.itemSize = CGSizeMake((contentImgView.width - kRealValue(10 * 2 + 10 * 5)) / 4, kScreenW / 4);
  82. contentLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
  83. contentLayout.minimumInteritemSpacing = 10;
  84. contentLayout.minimumLineSpacing = 10;
  85. self.contentCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(kRealValue(10), contentImgView.top + kRealValue(5), contentImgView.width - kRealValue(10 * 2),contentImgView.height - kRealValue(10)) collectionViewLayout:contentLayout];
  86. self.contentCollectionView.delegate = self;
  87. self.contentCollectionView.dataSource = self;
  88. self.contentCollectionView.showsVerticalScrollIndicator = NO;
  89. self.contentCollectionView.backgroundColor = kClearColor;
  90. [self.contentCollectionView registerNib:[UINib nibWithNibName:@"BogoNoblePrivilegeCell" bundle:nil] forCellWithReuseIdentifier:@"BogoNoblePrivilegeCell"];
  91. [self.view addSubview:self.titleCollectionView];
  92. [self.view addSubview:self.bgTopView];
  93. [self.view addSubview:contentImgView];
  94. [self.view addSubview:self.contentCollectionView];
  95. [self.view addSubview:self.bottomView];
  96. }
  97. -(void)setModel{
  98. self.titleListArr = [NSMutableArray array];
  99. self.contentListArr = [NSMutableArray array];
  100. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  101. [parmDict setObject:@"Aristocratic" forKey:@"ctl"];
  102. [parmDict setObject:@"index" forKey:@"act"];
  103. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  104. if ([[responseJson valueForKey:@"status"] integerValue] == 1) {
  105. BogoNobleListModel *model = [BogoNobleListModel mj_objectWithKeyValues:responseJson];
  106. self.model = model;
  107. NSLog(@"%@",model);
  108. for (BogoNobleListTypeModel *model in self.model.list) {
  109. [self.titleListArr addObject:model];
  110. if (model == self.titleListArr.firstObject) {
  111. [self.bgTopImgView sd_setImageWithURL:[NSURL URLWithString:model.shop_icon] completed:nil];
  112. model.noble_recharge.name = model.name;
  113. self.bottomView.model = model.noble_recharge;
  114. }
  115. }
  116. // self.bottomView.
  117. NSInteger scrollIndex = 0;
  118. BogoNobleListTypeModel *firstModel = self.model.list.firstObject;
  119. self.typeModel = self.model.list.firstObject;
  120. [self.titleCollectionView reloadData];
  121. [self.contentCollectionView reloadData];
  122. for (int i = 0; i < self.model.list.count; i ++) {
  123. BogoNobleListTypeModel *typeModel = self.model.list[i];
  124. if ([self.model.user_info.nobleid isEqualToString:typeModel.id]) {
  125. self.typeModel = typeModel;
  126. self.bottomView.isOpen = YES;
  127. scrollIndex = i;
  128. }
  129. }
  130. [self collectionView:self.titleCollectionView didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:scrollIndex inSection:0]];
  131. if (scrollIndex > self.titleListArr.count / 2) {
  132. [self.titleCollectionView setContentOffset:CGPointMake(kScreenW / 2, 0)];
  133. }
  134. NSLog(@"%@",self.titleListArr);
  135. }else{
  136. }
  137. } FailureBlock:^(NSError *error) {
  138. }];
  139. }
  140. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  141. return 1;
  142. }
  143. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  144. if (collectionView == self.titleCollectionView) {
  145. return self.titleListArr.count;
  146. }
  147. return self.typeModel.noble_type.count;
  148. // self.contentListArr.count;
  149. }
  150. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  151. if (collectionView == self.titleCollectionView) {
  152. BogoNobleTitleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BogoNobleTitleCell" forIndexPath:indexPath];
  153. BogoNobleListTypeModel *model = self.titleListArr[indexPath.row];
  154. cell.titleLabel.text = model.name;
  155. if ([model.id isEqualToString:self.typeModel.id]) {
  156. cell.titleLabel.textColor = [UIColor colorWithHexString:@"#FCCB9D"];
  157. UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
  158. CGPoint cellCenter = attributes.center;
  159. CGPoint anchorPoint = [collectionView convertPoint:cellCenter toView:self.view];
  160. [UIView animateWithDuration:0.3 animations:^{
  161. self.lineView.centerX = anchorPoint.x + self.titleCollectionView.contentOffset.x;
  162. }];
  163. }else{
  164. cell.titleLabel.textColor = UIColor.whiteColor;
  165. }
  166. return cell;
  167. }
  168. BogoNoblePrivilegeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BogoNoblePrivilegeCell" forIndexPath:indexPath];
  169. BogoNobleListSubTypeModel *model = self.typeModel.noble_type[indexPath.row];
  170. if ([model.is_type isEqualToString:@"1"]) {
  171. [cell.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.icon]];
  172. cell.privilegeLabel.textColor = [UIColor colorWithHexString:@"#BE9854"];
  173. }else{
  174. [cell.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.noicon]];
  175. cell.privilegeLabel.textColor = [UIColor colorWithHexString:@"#777777"];
  176. }
  177. cell.privilegeLabel.text = model.title;
  178. return cell;
  179. }
  180. //- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  181. // if (scrollView == self.titleCollectionView) {
  182. // if (self.typeModel.id) {
  183. // <#statements#>
  184. // }
  185. // [self.titleCollectionView scrollToRight];
  186. // }
  187. //
  188. // NSLog(@"contentOffset.x%f",scrollView.contentOffset.x);
  189. //
  190. //}
  191. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  192. if (collectionView == self.titleCollectionView) {
  193. BogoNobleListTypeModel *model = self.titleListArr[indexPath.row];
  194. // self.typeModel.isSelect = YES;
  195. self.typeModel = model;
  196. [self.bgTopImgView sd_setImageWithURL:[NSURL URLWithString:model.shop_icon] completed:nil];
  197. [self.titleCollectionView reloadData];
  198. [self.contentCollectionView reloadData];
  199. if ([self.model.user_info.nobleid isEqualToString:self.typeModel.id]) {
  200. self.bottomView.isOpen = YES;
  201. }else{
  202. self.bottomView.isOpen = NO;
  203. }
  204. self.bottomView.model = model.noble_recharge;
  205. }else{
  206. BogoNobleListSubTypeModel *model = self.typeModel.noble_type[indexPath.row];
  207. self.selectModel = model;
  208. self.alertView.selectModel = model;
  209. [self.alertView show:self.view];
  210. }
  211. }
  212. #pragma mark - 协议代理
  213. -(void)protocolClickOpenBtn{
  214. self.payView.model = self.typeModel;
  215. [self.payView show:self.view];
  216. }
  217. -(void)protocolBuySuccessWithModel:(BogoNobleListTypeModel *)payModel{
  218. [self.payView hide];
  219. self.model.user_info.nobleid = payModel.id;
  220. // if ([self.model.user_info.nobleid isEqualToString:payModel.id]) {
  221. self.bottomView.isOpen = YES;
  222. // }
  223. }
  224. -(UIView *)bgTopView{
  225. if (!_bgTopView) {
  226. _bgTopView = [[UIView alloc]initWithFrame:CGRectMake(0, self.titleCollectionView.bottom, kScreenW, kRealValue(160))];
  227. _bgTopView.backgroundColor = UIColor.clearColor;
  228. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, kRealValue(15), kRealValue(103), kRealValue(80))];
  229. imgView.centerX = kScreenW / 2;
  230. imgView.image = [UIImage imageNamed:@""];
  231. imgView.contentMode = UIViewContentModeScaleAspectFit;
  232. // imgView.contentMode = UIViewContentModeScaleAspectFill;
  233. // imgView.clipsToBounds = YES;
  234. _bgTopImgView = imgView;
  235. [_bgTopView addSubview:imgView];
  236. }
  237. return _bgTopView;
  238. }
  239. -(BogoNobleBottomView *)bottomView{
  240. if (!_bottomView) {
  241. _bottomView = [[BogoNobleBottomView alloc]initWithFrame:CGRectMake(0, kScreenH - SafeAreaBottomHeight - kRealValue(68), kScreenW, kRealValue(68))];
  242. _bottomView.delegate = self;
  243. }
  244. return _bottomView;
  245. }
  246. -(BogoNobleAlertView *)alertView{
  247. if (!_alertView) {
  248. _alertView = [[NSBundle mainBundle]loadNibNamed:@"BogoNobleAlertView" owner:self options:nil].lastObject;
  249. _alertView.frame = CGRectMake((kScreenW - kRealValue(290) / 2), (kScreenH - kRealValue(341) / 2), kRealValue(290), kRealValue(341));
  250. // _alertView.centerX = kScreenW / 2;
  251. // _alertView.centerY = kScreenH / 2;
  252. }
  253. return _alertView;
  254. }
  255. -(BogoNoblePayView *)payView{
  256. if (!_payView) {
  257. _payView = [[NSBundle mainBundle]loadNibNamed:@"BogoNoblePayView" owner:self options:nil].lastObject;
  258. _payView.delegate = self;
  259. _payView.frame = CGRectMake(0, kScreenH - MG_BOTTOM_MARGIN - kRealValue(285), kScreenW, kRealValue(285));
  260. }
  261. return _payView;
  262. }
  263. -(UIView *)lineView{
  264. if (!_lineView) {
  265. _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, self.titleCollectionView.height - kRealValue(5), kRealValue(16), kRealValue(2))];
  266. _lineView.backgroundColor = [UIColor colorWithHexString:@"#D19E3D"];
  267. _lineView.layer.cornerRadius = kRealValue(2) / 2;
  268. _lineView.layer.masksToBounds = YES;
  269. }
  270. return _lineView;
  271. }
  272. /*
  273. #pragma mark - Navigation
  274. // In a storyboard-based application, you will often want to do a little preparation before navigation
  275. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  276. // Get the new view controller using [segue destinationViewController].
  277. // Pass the selected object to the new view controller.
  278. }
  279. */
  280. @end