YMHomePageViewController.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. //
  2. // YMHomePageViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/4.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMHomePageViewController.h"
  9. #import "YMHomePageViewModel.h"
  10. #import "YMGroupGreetingPopupView.h"
  11. #import "JXCategoryView.h"
  12. #import "JXPagerView.h"
  13. #import "YMHomePageBannerView.h"
  14. #import "YMHomePageListViewController.h"
  15. #import "YMHomePageListViewControllerOnline.h"
  16. #import "YMSheetPopupView.h" // 添加底部弹窗组件导入
  17. #import "YMPopupView.h" // 添加弹窗管理器导入
  18. #import "YMGroupGreetingViewModel.h"
  19. #import "YOUPAILCBannerModel.h"
  20. #import "YOUPAILZHomeBannerCell.h"
  21. #import "LCHttpHelper.h"
  22. #import "YMAdvertModel.h"
  23. #import "YOUPAIZYFirstRechargeWindow.h"
  24. #import "LCTools.h"
  25. #import "UIViewController+TFPresent.h"
  26. #define LZCategoryViewHeight 40.0f
  27. @interface YMHomePageViewController ()<JXCategoryViewDelegate, JXPagerViewDelegate,JXPagerMainTableViewGestureDelegate,TYCyclePagerViewDataSource, TYCyclePagerViewDelegate>
  28. {
  29. dispatch_source_t _timer;
  30. }
  31. /// 首页VM
  32. @property (nonatomic, strong) YMHomePageViewModel *viewModel;
  33. @property (nonatomic, strong) YMGroupGreetingViewModel *groupGreetingViewModel;
  34. @property (nonatomic, strong) YMGroupGreetingPopupView *greetingView;
  35. @property (nonatomic, strong) YMPopupView *greetingPopupView;
  36. /// 首页Banner视图
  37. @property (nonatomic, strong) YMHomePageBannerView *bannerView;
  38. @property (nonatomic, weak) TYCyclePagerView *youpaipbannerView;
  39. @property (strong, nonatomic) TYPageControl *youpaippageControl;
  40. @property (strong, nonatomic) NSMutableArray *youpaipimageURLStringsGroup;
  41. @property (nonatomic, strong) NSArray <YOUPAILCBannerModel *> *youpaipbannerArray;
  42. @property (nonatomic, strong) UIView *headerV;
  43. /// 分类标题视图
  44. @property (nonatomic, strong) JXCategoryTitleView *categoryView;
  45. /// 分类分页视图
  46. @property (nonatomic, strong) JXPagerView *pagerView;
  47. /// 搜索按钮
  48. @property (nonatomic, strong) UILabel *searchLabel;
  49. /// 搜索按钮
  50. @property (nonatomic, strong) UIButton *searchBtn;
  51. @property (nonatomic, strong) UIButton *zhidingBtn;
  52. /// banner视图高度
  53. @property (nonatomic, assign) CGFloat bannerViewHeight;
  54. @property (nonatomic, assign) NSInteger count;
  55. @end
  56. @implementation YMHomePageViewController
  57. @dynamic viewModel;
  58. - (void)viewDidLoad {
  59. [super viewDidLoad];
  60. [self setNavHidden:YES];
  61. [[YMGlobalUtils shared] getConfig];
  62. [OCNotificationCenter addObserver:self selector:@selector(updateOnline) name:@"youpaifuserOnlineUpdate" object:nil];
  63. self.groupGreetingViewModel = [[YMGroupGreetingViewModel alloc] initWithParams:@{}];
  64. // 设置背景图
  65. UIImageView *topBgImgv = [[UIImageView alloc] init];
  66. topBgImgv.image = ImageByName(@"ym_home_page_top_bg");
  67. topBgImgv.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  68. [self.view insertSubview:topBgImgv atIndex:0];
  69. NSLog(@"输出🍀\nYMHomePageViewController viewDidLoad");
  70. }
  71. - (void)viewDidAppear:(BOOL)animated {
  72. [super viewDidAppear:animated];
  73. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  74. NSLog(@"输出🍀\nYMHomePageViewController viewDidAppear");
  75. // [self getAdvertCompletion:^{
  76. //
  77. // NSLog(@"输出🍀\n%@",YMGlobalUtils.shared.advModels);
  78. // [self showAdvert];
  79. // }];
  80. // [self youpaifloadAdvert1];
  81. }
  82. - (void)viewWillAppear:(BOOL)animated{
  83. [super viewWillAppear:animated];
  84. [self.viewModel judgementsIsOpenAdolescentModel];
  85. [self youpaifrequestBannerData];
  86. }
  87. - (void)viewWillDisappear:(BOOL)animated{
  88. [super viewWillDisappear:animated];
  89. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  90. }
  91. - (void)ym_setupViews{
  92. [self.view addSubview:self.pagerView];
  93. [self.view setNeedsUpdateConstraints];
  94. [self.view updateConstraintsIfNeeded];
  95. }
  96. - (void)updateViewConstraints{
  97. [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.top.equalTo(self.view).offset(0);
  99. make.left.equalTo(self.view);
  100. make.right.equalTo(self.view);
  101. make.bottom.equalTo(self.view);
  102. }];
  103. [super updateViewConstraints];
  104. }
  105. - (void)ym_bindViewModel{
  106. [self.bannerView ym_bindViewModel:self.viewModel.bannerVM];
  107. [[YMGlobalUtils shared] getConfig];
  108. if ([self.viewModel isFemaleGender]) {
  109. self.zhidingBtn.hidden = false;
  110. } else {
  111. self.zhidingBtn.hidden = true;
  112. }
  113. [self headerRefreshing];
  114. }
  115. /// 更新在线状态
  116. - (void)updateOnline{
  117. NSLog(@"updateOnline 更新在线状态");
  118. if (self->_timer) {
  119. dispatch_source_cancel(self->_timer);
  120. }
  121. if ([LCSaveData getTokenString] == nil) {
  122. return;
  123. }
  124. [LCHttpHelper requestWithURLString:onlineUpdate parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  125. NSDictionary* dict = (NSDictionary*)responseObject;
  126. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  127. if (code==0) {//成功
  128. NSInteger user_online_open = [[[dict objectForKey:@"data"]objectForKey:@"user_online_open"] integerValue];
  129. int user_online_time = [[[dict objectForKey:@"data"]objectForKey:@"user_online_time"] intValue];
  130. if (user_online_open == 1) {
  131. __block int timeout= user_online_time;
  132. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  133. self->_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  134. dispatch_source_set_timer(self->_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  135. dispatch_source_set_event_handler(self->_timer, ^{
  136. if(timeout<=0){
  137. dispatch_source_cancel(self->_timer);
  138. dispatch_async(dispatch_get_main_queue(), ^{
  139. [self updateOnline];
  140. });
  141. }else{
  142. // NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout];
  143. dispatch_async(dispatch_get_main_queue(), ^{
  144. //设置界面的按钮显示 根据自己需求设置
  145. //NSLog(@"strTime strTime %@",strTime);
  146. //NSLog(@"当前时间挫%lld",[[LCTools getCurrentTimestamp] longLongValue]);
  147. });
  148. timeout--;
  149. }});
  150. dispatch_resume(self->_timer);
  151. }
  152. }
  153. } failure:^(NSError *error) {
  154. }];
  155. }
  156. - (void)headerRefreshing{
  157. [self.viewModel getAdvertData];
  158. // [self.viewModel getLevelIconData];
  159. [self.viewModel getBadgesAndNobilityIconData];
  160. [self.viewModel.bannerVM getOnTvData];
  161. [OCNotificationCenter postNotificationName:REFRESH_HOME_NOTIFICATION object:nil userInfo:@{}];
  162. }
  163. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  164. //return kYMStatusBarHeight + adapt(70);
  165. CGFloat bannerViewHeight = kYMStatusBarHeight + 18.0f + ScaleSize(82.0f);
  166. self.bannerViewHeight = bannerViewHeight;
  167. return bannerViewHeight;
  168. //return 0.1;
  169. //return self.bannerViewHeight;
  170. }
  171. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  172. return self.headerV;
  173. //return self.bannerView;
  174. //return [[UIView alloc] init];
  175. }
  176. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  177. return 20 + LZCategoryViewHeight;
  178. }
  179. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  180. UIView *sectionView = [[UIView alloc]init];
  181. [sectionView addSubview:self.categoryView];
  182. [sectionView addSubview:self.zhidingBtn];
  183. [sectionView addSubview:self.searchBtn];
  184. [sectionView addSubview:self.searchLabel];
  185. [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  186. //make.top.equalTo(sectionView).offset(kYMStatusBarHeight);
  187. make.centerY.equalTo(sectionView);
  188. make.left.equalTo(sectionView).offset(10);
  189. //make.bottom.equalTo(sectionView).offset(-10);
  190. make.height.equalTo(LZCategoryViewHeight);
  191. }];
  192. [self.zhidingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  193. make.centerY.equalTo(sectionView);
  194. make.left.equalTo(self.categoryView.mas_right).offset(adapt(10));
  195. make.width.equalTo(44);
  196. make.height.equalTo(44);
  197. }];
  198. [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  199. //make.top.equalTo(sectionView).offset(adapt(10));
  200. make.left.equalTo(self.zhidingBtn.mas_right).offset(adapt(10));
  201. make.right.equalTo(sectionView).offset(adapt(-10));
  202. //make.bottom.equalTo(sectionView).offset(adapt(-10));
  203. make.centerY.equalTo(sectionView);
  204. make.width.equalTo(44);
  205. make.height.equalTo(44);
  206. }];
  207. [self.searchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.left.equalTo(self.searchBtn).offset(8);
  209. make.centerY.equalTo(self.searchBtn).offset(3);
  210. }];
  211. return sectionView;
  212. }
  213. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  214. return self.categoryView.titles.count;
  215. }
  216. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index{
  217. // if (index != 0) {
  218. // YMHomePageListViewControllerOnline *childVC = [[YMHomePageListViewControllerOnline alloc] initWithViewModel:self.viewModel.homePageVMListDataArray[index]];
  219. // childVC.jxCategoryPageIndex = index;
  220. // childVC.jxPageTitle = self.categoryView.titles[index];
  221. // return childVC;
  222. // }
  223. YMHomePageListViewController *listVC = [[YMHomePageListViewController alloc] initWithViewModel:self.viewModel.homePageVMListDataArray[index]];
  224. listVC.pageIndex = index;
  225. listVC.jxPageTitle = self.categoryView.titles[index];
  226. @weakify(self)
  227. listVC.refreshBlock = ^{
  228. @strongify(self)
  229. [self.pagerView.mainTableView.mj_header endRefreshing];
  230. };
  231. return listVC;
  232. }
  233. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  234. //NSLog(@"%f",scrollView.contentOffset.y);
  235. //NSLog(@"%f",self.bannerViewHeight - kYMStatusBarHeight);
  236. if ((scrollView.contentOffset.y + 1) >= (self.bannerViewHeight - kYMStatusBarHeight)) {
  237. //self.bannerView.hidden = true;
  238. self.headerV.hidden = true;
  239. } else {
  240. //self.bannerView.hidden = false;
  241. self.headerV.hidden = false;
  242. }
  243. }
  244. #pragma mark - JXCategoryViewDelegate
  245. //滑动table获得的数组
  246. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  247. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  248. }
  249. #pragma mark - JXPagerMainTableViewGestureDelegate
  250. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  251. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  252. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  253. return NO;
  254. }
  255. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  256. }
  257. - (UIView *)headerV{
  258. if (!_headerV) {
  259. _headerV = [[UIView alloc]init];
  260. UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 18.0f + ScaleSize(82.0f))];
  261. //headerV.frame = CGRectMake(0, 0, kScreenWidth, 0.1);
  262. headerV.hidden = NO;
  263. [self.view addSubview:headerV];
  264. _headerV = headerV;
  265. TYCyclePagerView *bannerView = [[TYCyclePagerView alloc]initWithFrame:CGRectMake(10, kYMStatusBarHeight + 9.0f, KScreenWidth - 20,ScaleSize(82.0f))];
  266. [headerV addSubview:bannerView];
  267. bannerView.isInfiniteLoop = YES;
  268. bannerView.autoScrollInterval = 4.0;
  269. bannerView.layer.cornerRadius = ScaleSize(10.0f);
  270. bannerView.clipsToBounds = YES;
  271. bannerView.dataSource = self;
  272. bannerView.delegate = self;
  273. [bannerView registerClass:[YOUPAILZHomeBannerCell class] forCellWithReuseIdentifier:@"cellId"];
  274. self.youpaipbannerView = bannerView;
  275. bannerView.backgroundColor = [UIColor clearColor];
  276. TYPageControl *pageControl = [[TYPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(_youpaipbannerView.frame) - 26, CGRectGetWidth(_youpaipbannerView.frame), 26)];
  277. //pageControl.numberOfPages = _datas.count;
  278. pageControl.currentPageIndicatorSize = CGSizeMake(6, 6);
  279. pageControl.pageIndicatorSize = CGSizeMake(6, 6);
  280. //pageControl.currentPageIndicatorTintColor = [UIColor redColor];
  281. //pageControl.pageIndicatorTintColor = [UIColor grayColor];
  282. pageControl.pageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_n"];
  283. pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_s"];
  284. pageControl.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  285. pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  286. pageControl.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  287. pageControl.pageIndicatorSpaing = 1;
  288. [bannerView addSubview:pageControl];
  289. self.youpaippageControl = pageControl;
  290. }
  291. return _headerV;
  292. }
  293. - (YMHomePageBannerView *)bannerView{
  294. if (!_bannerView) {
  295. _bannerView = [[YMHomePageBannerView alloc]init];
  296. @weakify(self)
  297. _bannerView.bannerViewHeightBlock = ^(CGFloat bannerViewHeight) {
  298. @strongify(self)
  299. self.bannerViewHeight = bannerViewHeight;
  300. [self.pagerView resizeTableHeaderViewHeightWithAnimatable:NO duration:0 curve:0];
  301. };
  302. }
  303. return _bannerView;
  304. }
  305. - (JXCategoryTitleView *)categoryView{
  306. if (!_categoryView) {
  307. _categoryView = [[JXCategoryTitleView alloc]initWithFrame:CGRectMake(0, 0,kFrameWidth, adapt(50))];
  308. _categoryView.delegate = self;
  309. if (self.viewModel.isFemaleGender) {
  310. _categoryView.titles = @[@"推荐", @"高颜值女神", @"活跃", @"男神"];
  311. } else {
  312. _categoryView.titles = @[@"推荐", @"高颜值女神", @"活跃"];
  313. }
  314. _categoryView.titleLabelZoomEnabled = NO;
  315. _categoryView.titleColorGradientEnabled = YES;
  316. _categoryView.titleColor = HexColorFromRGB(0xC6C6C6);
  317. _categoryView.titleSelectedColor = HexColorFromRGB(0x0A0A0A);
  318. _categoryView.titleFont = LCFont(17);
  319. _categoryView.titleSelectedFont = LCBoldFont(18);
  320. _categoryView.averageCellSpacingEnabled = NO;
  321. _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
  322. _categoryView.backgroundColor = [UIColor clearColor];
  323. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc]init];
  324. lineView.indicatorColor = UIColor.clearColor;
  325. lineView.verticalMargin = adapt(8);
  326. lineView.indicatorWidth = JXCategoryViewAutomaticDimension;
  327. lineView.indicatorHeight = adapt(5);
  328. lineView.indicatorCornerRadius = 0;
  329. _categoryView.indicators = @[lineView];
  330. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  331. JXCategoryIndicatorImageView *indicatorImageView = [[JXCategoryIndicatorImageView alloc] init];
  332. indicatorImageView.indicatorImageViewSize = CGSizeMake(adapt(68), 44);
  333. UIImageView *indicatorImgv = [[UIImageView alloc] init];
  334. indicatorImgv.image = [UIImage imageWithColor:HexColorFromRGB(0xFC8997) size:CGSizeMake(adapt(40), adapt(8))];
  335. indicatorImgv.layer.cornerRadius = adapt(4);
  336. indicatorImgv.layer.masksToBounds = YES;
  337. //indicatorImgv.contentMode = UIViewContentModeScaleAspectFit;
  338. [indicatorImageView addSubview:indicatorImgv];
  339. [indicatorImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  340. make.centerX.equalTo(indicatorImageView);
  341. make.bottom.equalTo(indicatorImageView).offset(adapt(0));
  342. make.width.mas_equalTo(adapt(40));
  343. make.height.mas_equalTo(adapt(8));
  344. }];
  345. _categoryView.indicators = @[indicatorImageView];
  346. }
  347. return _categoryView;
  348. }
  349. - (JXPagerView*)pagerView{
  350. if (!_pagerView) {
  351. //需要下拉刷新则要这个代理给设置出来
  352. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  353. _pagerView.mainTableView.backgroundColor = UIColor.clearColor;
  354. _pagerView.mainTableView.gestureDelegate = self;
  355. _pagerView.mainTableView.mj_header = self.refreshHeader;
  356. _pagerView.mainTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  357. //当有头部视图的时候设置固定高度
  358. // _pagerView.pinSectionHeaderVerticalOffset = 50;
  359. //关闭弹簧效果
  360. // _pagerView.mainTableView.bounces = NO;
  361. }
  362. return _pagerView;
  363. }
  364. - (UILabel *)searchLabel {
  365. if (!_searchLabel) {
  366. _searchLabel = [[UILabel alloc] init];
  367. _searchLabel.hidden = YES;
  368. _searchLabel.text = @"寻找";
  369. _searchLabel.textColor = UIColor.whiteColor;
  370. _searchLabel.font = LCFont(11);
  371. }
  372. return _searchLabel;
  373. }
  374. - (UIButton *)searchBtn {
  375. if (!_searchBtn) {
  376. _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  377. [_searchBtn setImage:ImageByName(@"ym_home_page_xunzhao") forState: UIControlStateNormal];
  378. [_searchBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  379. _searchBtn.titleLabel.font = LCFont(11);
  380. WS(weakSelf)
  381. [[[_searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  382. [weakSelf.viewModel gotoSearchUser];
  383. }];
  384. }
  385. return _searchBtn;
  386. }
  387. - (UIButton *)zhidingBtn{
  388. if (!_zhidingBtn) {
  389. _zhidingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  390. [_zhidingBtn setImage:ImageByName(@"home_msg_zhiding") forState:UIControlStateNormal];
  391. _zhidingBtn.hidden = true;
  392. WS(weakSelf)
  393. [[[_zhidingBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  394. [weakSelf showZhidingBottomSheet];
  395. }];
  396. }
  397. return _zhidingBtn;
  398. }
  399. /**
  400. * 显示置顶功能底部选择弹窗
  401. * 包含自动置顶、群打招呼、取消三个选项
  402. */
  403. - (void)showZhidingBottomSheet {
  404. // 创建底部弹窗视图
  405. YMSheetPopupView *sheetView = [[YMSheetPopupView alloc] init];
  406. // 配置弹窗选项列表
  407. NSArray *optionList = @[
  408. @"自动置顶",
  409. @"群打招呼"
  410. ];
  411. // 配置弹窗数据
  412. [sheetView configutationWithItemList:optionList];
  413. // 设置选择回调
  414. WS(weakSelf)
  415. sheetView.selectIndexBlock = ^(NSInteger index) {
  416. [weakSelf handleZhidingSelection:index];
  417. };
  418. // 设置关闭回调(对应"取消"选项)
  419. sheetView.closeBlock = ^{
  420. // 用户点击取消按钮
  421. NSLog(@"用户取消了置顶操作");
  422. [YMPopupView removeLastPopView];
  423. };
  424. // 创建弹窗管理器并显示
  425. YMPopupView *popupView = [YMPopupView initWithCustomView:sheetView];
  426. popupView.popDuration = 0.3; // 弹出动画时间
  427. popupView.positionStyle = YMPositionStyleBottom; // 底部弹出
  428. popupView.popStyle = YMPopupStyleSmoothFromBottom; // 从底部滑入动画
  429. popupView.dismissStyle = YMDismissStyleSmoothToBottom; // 滑出到底部动画
  430. popupView.isClickBgDismiss = YES; // 点击背景关闭
  431. popupView.bgAlpha = 0.5; // 背景透明度
  432. // 显示弹窗
  433. [popupView pop];
  434. }
  435. /**
  436. * 处理置顶选择结果
  437. * @param index 选择的选项索引(0:自动置顶, 1:群打招呼)
  438. */
  439. - (void)handleZhidingSelection:(NSInteger)index {
  440. switch (index) {
  441. case 0:
  442. // 自动置顶
  443. NSLog(@"选择了:自动置顶");
  444. [self performAutoZhiding];
  445. break;
  446. case 1:
  447. // 群打招呼
  448. NSLog(@"选择了:群打招呼");
  449. [self performGroupGreeting];
  450. break;
  451. default:
  452. break;
  453. }
  454. // 关闭弹窗
  455. [YMPopupView removeLastPopView];
  456. }
  457. /**
  458. * 执行自动置顶功能
  459. */
  460. - (void)performAutoZhiding {
  461. // 调用原有的置顶数据方法
  462. [self.viewModel zhidingData];
  463. // 可以添加额外的自动置顶逻辑
  464. // 例如:显示成功提示、刷新列表等
  465. NSLog(@"自动置顶功能已执行");
  466. }
  467. /**
  468. * 执行群打招呼功能
  469. */
  470. - (void)performGroupGreeting {
  471. // 先请求获取推荐用户列表
  472. [self requestGroupGreetingUserList:YES];
  473. }
  474. /**
  475. * 请求群打招呼用户列表
  476. */
  477. - (void)requestGroupGreetingUserList:(BOOL)isNew {
  478. WS(weakSelf)
  479. [self.groupGreetingViewModel getGroupGreetingDataIsNew:isNew completion:^(BOOL isSuccess) {
  480. if (isSuccess) {
  481. [weakSelf showGroupGreetingPopupView];
  482. }
  483. }];
  484. }
  485. /**
  486. * 显示群打招呼弹窗
  487. */
  488. - (void)showGroupGreetingPopupView {
  489. [_greetingPopupView dismiss];
  490. // 创建群打招呼弹窗
  491. _greetingView = [[YMGroupGreetingPopupView alloc] initWithFrame:UIScreen.mainScreen.bounds];
  492. [_greetingView configureWithUserList:self.groupGreetingViewModel.listDataArray];
  493. WS(weakSelf)
  494. // 设置换一换回调
  495. _greetingView.refreshBlock = ^{
  496. [weakSelf requestGroupGreetingUserList:NO];
  497. };
  498. // 设置发送打招呼回调
  499. _greetingView.sendBlock = ^{
  500. [weakSelf sendGroupGreetingRequest];
  501. };
  502. _greetingView.clickBlankAreaBlock = ^{
  503. [weakSelf.greetingPopupView dismiss];
  504. };
  505. // 使用YMPopupView显示弹窗
  506. _greetingPopupView = [YMPopupView initWithCustomView:_greetingView];
  507. _greetingPopupView.positionStyle = YMPositionStyleCenter;
  508. _greetingPopupView.popDuration = 0.3; // 弹出动画时间
  509. _greetingPopupView.popStyle = YMPopupStyleFade; // 从底部滑入动画
  510. _greetingPopupView.dismissStyle = YMDismissStyleFade; // 滑出到底部动画
  511. _greetingPopupView.isClickBgDismiss = YES; // 点击背景关闭
  512. _greetingPopupView.bgAlpha = 0.5; // 背景透明度
  513. // 设置关闭回调
  514. _greetingView.closeBlock = ^{
  515. [weakSelf.greetingPopupView dismiss];
  516. };
  517. [_greetingPopupView pop];
  518. }
  519. /**
  520. * 发送群打招呼请求
  521. */
  522. - (void)sendGroupGreetingRequest {
  523. // 显示加载提示
  524. [ZCHUDHelper show];
  525. NSArray *arr = self.groupGreetingViewModel.listDataArray;
  526. NSString *str = @"";
  527. for (int i = 0; i < arr.count; i++) {
  528. YMGroupGreetingUserModel *model = arr[i];
  529. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@",@(model.userId)]];
  530. if (i != arr.count - 1) {
  531. str = [str stringByAppendingString:@","];
  532. }
  533. }
  534. str = [NSString stringWithFormat:@"[%@]",str];
  535. // 请求参数
  536. NSDictionary *params = @{
  537. @"user_ids": str
  538. };
  539. [LCHttpHelper requestWithURLString:HomeBeckonSend parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  540. [ZCHUDHelper dismiss];
  541. NSDictionary *dict = (NSDictionary *)responseObject;
  542. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  543. if (code == 0) {
  544. //NSString *message = [dict stringValueForKey:@"message" defaultValue:@"打招呼发送成功"];
  545. [ZCHUDHelper showTitle:@"打招呼成功" showtime:2];
  546. [self.greetingPopupView dismiss];
  547. //[self.greetingView makeToast:@"打招呼成功" duration:2 position:CSToastPositionCenter];
  548. } else {
  549. NSString *message = [dict stringValueForKey:@"message" defaultValue:@"打招呼发送失败"];
  550. //[ZCHUDHelper showTitle:message];
  551. [ZCHUDHelper showTitle:message];
  552. //[self.greetingView makeToast:message duration:2 position:CSToastPositionCenter];
  553. }
  554. } failure:^(NSError *error) {
  555. [ZCHUDHelper dismiss];
  556. [ZCHUDHelper showTitle:@"网络请求失败"];
  557. }];
  558. }
  559. #pragma mark - TYCyclePagerViewDataSource
  560. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  561. return self.youpaipimageURLStringsGroup.count;
  562. }
  563. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  564. YOUPAILZHomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndex:index];
  565. NSString *url;
  566. // absoluteString
  567. if (self.youpaipimageURLStringsGroup) {
  568. url = [self.youpaipimageURLStringsGroup[index] absoluteString];
  569. [cell.youpaipbgImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"banner_default"]];
  570. }
  571. cell.layer.cornerRadius = ScaleSize(10);
  572. cell.layer.masksToBounds = YES;
  573. cell.backgroundColor = [UIColor clearColor];
  574. // cell.backgroundColor = _datas[index];
  575. // cell.label.text = [NSString stringWithFormat:@"index->%ld",index];
  576. return cell;
  577. }
  578. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  579. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  580. layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
  581. layout.itemSpacing = 20;
  582. // ScaleSize(10.0f)
  583. layout.layoutType = TYCyclePagerTransformLayoutNormal;
  584. //layout.minimumAlpha = 0.3;
  585. return layout;
  586. }
  587. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
  588. YOUPAILCBannerModel* model = self.youpaipbannerArray[index];
  589. if (model.youpaiplink_type==1) {
  590. ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
  591. baseWeb.title = @"详情页";
  592. baseWeb.contentUrl = model.youpaiplink_url;
  593. [self.navigationController pushViewController:baseWeb animated:YES];
  594. }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){
  595. [self youpaifpageToStr:model.youpaiplink_url];
  596. }
  597. }
  598. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  599. self.youpaippageControl.currentPage = toIndex;
  600. }
  601. /// 获取banner数据
  602. - (void)youpaifrequestBannerData{
  603. @weakify(self);
  604. [LCHttpHelper requestWithURLString:HomeBanner parameters:@{@"cate_id":@"5"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  605. @strongify(self);
  606. NSDictionary* dict = (NSDictionary*)responseObject;
  607. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  608. if (code==0) {//成功
  609. self.youpaipbannerArray = [YOUPAILCBannerModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"banner"]];
  610. [self youpaifreloadBannerData];
  611. }
  612. } failure:^(NSError *error) {
  613. }];
  614. }
  615. -(void)youpaifreloadBannerData{
  616. NSMutableArray *imgUrlArray = [NSMutableArray array];
  617. for (YOUPAILCBannerModel* model in self.youpaipbannerArray) {
  618. [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]];
  619. }
  620. self.youpaippageControl.numberOfPages = imgUrlArray.count;
  621. self.youpaipimageURLStringsGroup = imgUrlArray;
  622. [self.youpaipbannerView reloadData];
  623. }
  624. #pragma mark - 获取首冲弹框数据
  625. //获取首冲弹框数据
  626. - (void)youpaifloadAdvert1 {
  627. @weakify(self);
  628. [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"6"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  629. @strongify(self);
  630. NSDictionary* dict = (NSDictionary*)responseObject;
  631. //NSLog(@"输出🍀\n%@",dict);
  632. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  633. // 请求成功才会继续后面的逻辑
  634. if (code != 0) { return; }
  635. NSDictionary *dataDict = [dict objectForKey:@"data"];
  636. NSInteger is_open = [[dataDict objectForKey:@"is_open"] integerValue];
  637. NSArray *listArr = [dataDict objectForKey:@"list"];
  638. // 弹窗打开,才会进行数据解析
  639. if (is_open != 1) {
  640. return;
  641. }
  642. for (NSDictionary *advDict in listArr) {
  643. YMAdvertModel *model = [YMAdvertModel yy_modelWithDictionary:advDict];
  644. NSArray *advModelTags = YMGlobalUtils.shared.advModelTags;
  645. if (![advModelTags containsObject:model.tag]) {
  646. [YMGlobalUtils.shared.advModels addObject:model];
  647. }
  648. }
  649. for (YMAdvertModel *model in YMGlobalUtils.shared.advModels) {
  650. if (model.window_type != 1 && model.showedTag != 0) {
  651. continue;
  652. }
  653. model.showedTag = 1;
  654. CGFloat delay = model.delayed_time;
  655. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  656. YOUPAIZYFirstRechargeWindow *VC = [[YOUPAIZYFirstRechargeWindow alloc]init];
  657. //VC.youpaipdelegate = self;
  658. VC.vWidth = KScreenWidth - adapt(80);
  659. VC.vHeight = KScreenHeight * 0.6;
  660. VC.youpaipimageurl = model.image;
  661. VC.youpaiplink_type = model.link_type;
  662. VC.youpaiplink_url = model.link_url;
  663. VC.isTouchDismiss = YES;
  664. VC.youpaipimgV.contentMode = UIViewContentModeScaleAspectFill;
  665. [[LCTools getCurrentVC] TFPresentVC:VC completion:^{}];
  666. UIView *containerView = VC.baseView;
  667. UILabel *titleLabel = [[UILabel alloc] init];
  668. titleLabel.font = [UIFont systemFontOfSize:24 weight:(UIFontWeightBold)];
  669. titleLabel.textColor = UIColor.blackColor;
  670. titleLabel.textAlignment = NSTextAlignmentCenter;
  671. titleLabel.text = model.title;
  672. [containerView addSubview:titleLabel];
  673. UITextView *textView = [[UITextView alloc] init];
  674. textView.text = model.content;
  675. textView.font = [UIFont systemFontOfSize:15 weight:(UIFontWeightRegular)];
  676. textView.textColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
  677. textView.backgroundColor = UIColor.clearColor;
  678. textView.editable = NO;
  679. [containerView addSubview:textView];
  680. [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  681. make.top.equalTo(containerView).offset(adapt(20));
  682. make.left.right.equalTo(containerView);
  683. make.height.mas_equalTo(adapt(40));
  684. }];
  685. [textView mas_remakeConstraints:^(MASConstraintMaker *make) {
  686. make.top.equalTo(titleLabel.mas_bottom).offset(adapt(20));
  687. make.left.equalTo(containerView).offset(adapt(20));
  688. make.right.equalTo(containerView).offset(adapt(-20));
  689. make.bottom.equalTo(containerView).offset(adapt(-20));
  690. }];
  691. });
  692. }
  693. } failure:^(NSError *error) {}];
  694. }
  695. //获取首冲弹框数据
  696. - (void)getAdvertCompletion: (void(^)(void))completion {
  697. @weakify(self);
  698. [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"6"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  699. @strongify(self);
  700. NSDictionary* dict = (NSDictionary*)responseObject;
  701. //NSLog(@"输出🍀\n%@",dict);
  702. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  703. // 请求成功才会继续后面的逻辑
  704. if (code != 0) { return; }
  705. NSDictionary *dataDict = [dict objectForKey:@"data"];
  706. NSInteger is_open = [[dataDict objectForKey:@"is_open"] integerValue];
  707. NSArray *listArr = [dataDict objectForKey:@"list"];
  708. // 弹窗打开,才会进行数据解析
  709. if (is_open != 1) {
  710. return;
  711. }
  712. for (NSDictionary *advDict in listArr) {
  713. YMAdvertModel *model = [YMAdvertModel yy_modelWithDictionary:advDict];
  714. NSArray *advModelTags = YMGlobalUtils.shared.advModelTags;
  715. if (![advModelTags containsObject:model.tag]) {
  716. [YMGlobalUtils.shared.advModels addObject:model];
  717. }
  718. }
  719. completion();
  720. } failure:^(NSError *error) {}];
  721. }
  722. - (void)showAdvert {
  723. for (YMAdvertModel *model in YMGlobalUtils.shared.advModels) {
  724. if (model.window_type != 1 && model.showedTag != 0) {
  725. continue;
  726. }
  727. model.showedTag = 1;
  728. CGFloat delay = model.delayed_time;
  729. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  730. YOUPAIZYFirstRechargeWindow *VC = [[YOUPAIZYFirstRechargeWindow alloc]init];
  731. //VC.youpaipdelegate = self;
  732. VC.vWidth = KScreenWidth - adapt(80);
  733. VC.vHeight = KScreenHeight * 0.6;
  734. VC.youpaipimageurl = model.image;
  735. VC.youpaiplink_type = model.link_type;
  736. VC.youpaiplink_url = model.link_url;
  737. VC.isTouchDismiss = YES;
  738. VC.youpaipimgV.contentMode = UIViewContentModeScaleAspectFill;
  739. [[LCTools getCurrentVC] TFPresentVC:VC completion:^{}];
  740. UIView *containerView = VC.baseView;
  741. UILabel *titleLabel = [[UILabel alloc] init];
  742. titleLabel.font = [UIFont systemFontOfSize:24 weight:(UIFontWeightBold)];
  743. titleLabel.textColor = UIColor.blackColor;
  744. titleLabel.textAlignment = NSTextAlignmentCenter;
  745. titleLabel.text = model.title;
  746. [containerView addSubview:titleLabel];
  747. UITextView *textView = [[UITextView alloc] init];
  748. textView.text = model.content;
  749. textView.font = [UIFont systemFontOfSize:15 weight:(UIFontWeightRegular)];
  750. textView.textColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
  751. textView.backgroundColor = UIColor.clearColor;
  752. textView.editable = NO;
  753. [containerView addSubview:textView];
  754. [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  755. make.top.equalTo(containerView).offset(adapt(20));
  756. make.left.right.equalTo(containerView);
  757. make.height.mas_equalTo(adapt(40));
  758. }];
  759. [textView mas_remakeConstraints:^(MASConstraintMaker *make) {
  760. make.top.equalTo(titleLabel.mas_bottom).offset(adapt(20));
  761. make.left.equalTo(containerView).offset(adapt(20));
  762. make.right.equalTo(containerView).offset(adapt(-20));
  763. make.bottom.equalTo(containerView).offset(adapt(-20));
  764. }];
  765. });
  766. }
  767. }
  768. @end