YMHomePageViewController.m 33 KB

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