MOMyBackpackListVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. //
  2. // MOMyBackpackListVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/12/21.
  6. //
  7. #import "MOMyBackpackListVC.h"
  8. #import "MOMyBackpackTableView.h"
  9. #import "MOShopBuyView.h"
  10. @interface MOMyBackpackListVC ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate,UIGestureRecognizerDelegate>
  11. @property (nonatomic, strong) JXCategoryTitleView *titleCategoryView;
  12. @property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
  13. @property (nonatomic, strong) UIView *titleBgView;
  14. @property (nonatomic, strong) MOShopList *selectModel;
  15. @property (strong, nonatomic) UIImageView *bgImgView;
  16. @property (nonatomic, assign) NSInteger selectIndex;
  17. @end
  18. @implementation MOMyBackpackListVC
  19. - (void)viewWillAppear:(BOOL)animated
  20. {
  21. [super viewWillAppear:animated];
  22. [self.navigationController setNavigationBarHidden:NO animated:animated];
  23. [self mo_setNavLeftItemWithImage:[UIImage imageNamed:@"icon_new_left_gray"] andBackgroundImg:[UIImage imageNamed:@"icon_mine_base_bg"]];
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. self.navigationItem.title = NSLocalString(@"mimo_Backpack_Package");
  29. // [self setNavLeftItemWithImage:[UIImage imageNamed:@"icon_nav_back"]];
  30. [self setupUI];
  31. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  32. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  33. }
  34. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  35. return YES;
  36. }
  37. - (void)setupUI{
  38. self.selectIndex = 0;
  39. self.view.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  40. [self.view addSubview:self.bgImgView];
  41. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.edges.equalTo(self.view);
  43. }];
  44. NSArray *colorArr = @[[MOTools colorWithHexString:@"#EEF2FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
  45. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, (SCREENHEIGHT - NAV_BAR_HEIGHT)) Colors:colorArr GradientType:1];
  46. [self.bgImgView setImage:image];
  47. [self.view addSubview:self.titleBgView];
  48. [self.titleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.view).offset(12.0);
  50. make.left.equalTo(self.view).offset(12.0);
  51. make.right.equalTo(self.view).offset(-12.0);
  52. make.height.equalTo(@32.0);
  53. }];
  54. self.titleBgView.layer.cornerRadius = 32.0 / 2.0;
  55. [self.view addSubview:self.titleCategoryView];
  56. [self.titleCategoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. // make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
  58. make.left.equalTo(self.view).offset(0.0);
  59. make.right.equalTo(self.view).offset(0.0);
  60. make.height.equalTo(@70.0);
  61. make.centerY.equalTo(self.titleBgView.mas_centerY);
  62. }];
  63. self.titleCategoryView.titles = @[NSLocalString(@"mimo_Backpack_Cars"),NSLocalString(@"mimo_Backpack_Headwear"),NSLocalString(@"mimo_Backpack_Bubble"),NSLocalString(@"mimo_Backpack_Package")];
  64. CGFloat totalItemWidth = SCREENWIDTH - 12.0 * 2.0;
  65. CGFloat cellWidth = totalItemWidth / self.titleCategoryView.titles.count;
  66. self.titleCategoryView.cellSpacing = 0;
  67. self.titleCategoryView.cellWidth = cellWidth;
  68. self.titleCategoryView.titleColor = [MOTools colorWithHexString:@"#737373" alpha:1.0];
  69. self.titleCategoryView.titleSelectedColor = kBaseBtnBgColor;
  70. self.titleCategoryView.titleLabelMaskEnabled = YES;
  71. self.titleCategoryView.titleFont = [MOTextTools getTheFontWithSize:15.0 AndFontName:kNormalContentFontStr];
  72. self.titleCategoryView.backgroundColor = [UIColor clearColor];
  73. JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
  74. backgroundView.indicatorHeight = 70.0;
  75. backgroundView.indicatorWidth = cellWidth + 20.0;
  76. backgroundView.indicatorWidthIncrement = 0;
  77. backgroundView.indicatorColor = [UIColor clearColor];
  78. backgroundView.verticalMargin = 4.0;
  79. UIImageView *imgBgView = [[UIImageView alloc] init];
  80. imgBgView.contentMode = UIViewContentModeScaleToFill;
  81. [imgBgView setImage:[UIImage imageNamed:@"icon_rank_btn_bg_apple"]];
  82. [backgroundView addSubview:imgBgView];
  83. [imgBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.edges.equalTo(backgroundView);
  85. }];
  86. self.titleCategoryView.indicators = @[backgroundView];
  87. [self.view addSubview:self.listContainerView];
  88. [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.top.equalTo(self.titleCategoryView.mas_bottom).offset(-5.0);
  90. make.bottom.equalTo(self.view);
  91. make.left.equalTo(self.view).offset(0.0);
  92. make.right.equalTo(self.view).offset(0.0);
  93. }];
  94. self.titleCategoryView.listContainer = self.listContainerView;
  95. }
  96. // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
  97. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
  98. MOLogV(@"变换了");
  99. self.selectIndex = index;
  100. }
  101. #pragma mark - JXCategoryListContainerViewDelegate
  102. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView{
  103. return self.titleCategoryView.titles.count;
  104. }
  105. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{
  106. WEAKSELF
  107. MOMyBackpackTableView *view = [[MOMyBackpackTableView alloc] init];
  108. view.category = index + 1;
  109. view.buyShopView = ^(MOShopList * _Nonnull cellModel) {
  110. [weakSelf toShowAlertWith:cellModel];
  111. };
  112. return view;
  113. }
  114. - (void)toShowAlertWith:(MOShopList *)propModel{
  115. WEAKSELF
  116. if(propModel.propInfo.pricesInfo.count > 0){
  117. MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
  118. alertView.titleLabel.text = NSLocalString(@"mimo_alert_normal_tip");
  119. alertView.subTitleLabel.text = NSLocalString(@"mimo_prop_renew_confirm_tip1");
  120. [alertView.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
  121. [alertView.confirmBtn setTitle:NSLocalString(@"mimo_prop_renew") forState:UIControlStateNormal];
  122. alertView.confirmBlock = ^{
  123. [weakSelf toShowBuyPropWith:propModel];
  124. };
  125. [alertView show];
  126. }
  127. else{
  128. MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
  129. alertView.titleLabel.text = NSLocalString(@"mimo_alert_normal_tip");
  130. alertView.subTitleLabel.text = NSLocalString(@"mimo_prop_renew_confirm_tip2");
  131. alertView.isSingleBtn = YES;
  132. [alertView.confirmBtn setTitle:NSLocalString(@"mimo_TipPleaseConfirm") forState:UIControlStateNormal];
  133. [alertView show];
  134. }
  135. }
  136. - (void)toShowBuyPropWith:(MOShopList *)propModel{
  137. MOShopList *copyModel = [propModel copy];
  138. copyModel.id = propModel.propInfo.id;
  139. copyModel.cornerMark = propModel.propInfo.cornerMark;
  140. copyModel.storeInfo = [propModel.propInfo.storeInfo copy];
  141. copyModel.pricesInfo = [propModel.propInfo.pricesInfo copy];
  142. self.selectModel = copyModel;
  143. WEAKSELF
  144. MOShopBuyView *view = [MOShopBuyView moShopBuyView];
  145. view.viewModel = copyModel;
  146. [view showShopBuyView];
  147. view.buyActionBlock = ^(MOPricesInfo * _Nonnull pricesModel) {
  148. [weakSelf toShowSecondAlertViewWith:pricesModel];
  149. };
  150. }
  151. - (void)toShowSecondAlertViewWith:(MOPricesInfo *)model{
  152. WEAKSELF
  153. MOTitleNormalAlertView *view = [[MOTitleNormalAlertView alloc] init];
  154. NSString *contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_prop_buy_confirm_tip"),model.diamond,self.selectModel.storeInfo.name,model.days];
  155. view.subTitleLabel.text = contentStr;
  156. view.subTitleLabel.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];
  157. view.bgImgView.hidden = YES;
  158. view.containerView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  159. [view.cancelBtn setBackgroundColor:[MOTools colorWithHexString:@"#B0B0B0" alpha:1.0]];
  160. [view.cancelBtn setTitle:NSLocalString(@"mimo_common_cancel") forState:UIControlStateNormal];
  161. [view.cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  162. view.cancelBtn.layer.borderWidth = 0.0;
  163. NSArray *colorArr = @[kBaseBtnBgColor,kBaseBtnBgColor];
  164. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, view.twoBtnWidth, 48.0) Colors:colorArr GradientType:0];
  165. [view.confirmBtn setBackgroundImage:image forState:UIControlStateNormal];
  166. [view.confirmBtn setTitle:NSLocalString(@"mimo_common_buy") forState:UIControlStateNormal];
  167. [view.confirmBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0] forState:UIControlStateNormal];
  168. view.confirmBlock = ^{
  169. NSString *idStr = weakSelf.selectModel.id;
  170. if(idStr.length == 0){
  171. return;
  172. }
  173. NSDictionary *dict = @{@"id":idStr,
  174. @"key":@(model.key)};
  175. [kHttpManager toBuyPropWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  176. if(kCode_Success){
  177. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  178. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
  179. [weakSelf toRefreshTheView];
  180. }
  181. else{
  182. kShowNetError(data)
  183. }
  184. }];
  185. };
  186. [view show];
  187. }
  188. - (void)toRefreshTheView{
  189. WEAKSELF
  190. [self.listContainerView.validListDict enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, id<JXCategoryListContentViewDelegate> _Nonnull obj, BOOL * _Nonnull stop) {
  191. if([key integerValue] == weakSelf.selectIndex){
  192. MOMyBackpackTableView *listView = (MOMyBackpackTableView *)obj;
  193. [listView toGetFirstHttpData];
  194. }
  195. }];
  196. }
  197. #pragma mark - Lazy
  198. - (JXCategoryTitleView *)titleCategoryView{
  199. if(!_titleCategoryView){
  200. _titleCategoryView = [[JXCategoryTitleView alloc] init];
  201. _titleCategoryView.delegate = self;
  202. _titleCategoryView.backgroundColor = [UIColor whiteColor];
  203. }
  204. return _titleCategoryView;
  205. }
  206. - (JXCategoryListContainerView *)listContainerView{
  207. if(!_listContainerView){
  208. _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
  209. }
  210. return _listContainerView;
  211. }
  212. - (UIView *)titleBgView{
  213. if(!_titleBgView){
  214. _titleBgView = [[UIView alloc] init];
  215. _titleBgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.05];
  216. }
  217. return _titleBgView;
  218. }
  219. - (UIImageView *)bgImgView{
  220. if(!_bgImgView){
  221. _bgImgView = [[UIImageView alloc] init];
  222. _bgImgView.contentMode = UIViewContentModeScaleToFill;
  223. }
  224. return _bgImgView;
  225. }
  226. @end