123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900 |
- //
- // YMHomePageViewController.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/4.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMHomePageViewController.h"
- #import "YMHomePageViewModel.h"
- #import "YMGroupGreetingPopupView.h"
- #import "JXCategoryView.h"
- #import "JXPagerView.h"
- #import "YMHomePageBannerView.h"
- #import "YMHomePageListViewController.h"
- #import "YMHomePageListViewControllerOnline.h"
- #import "YMSheetPopupView.h" // 添加底部弹窗组件导入
- #import "YMPopupView.h" // 添加弹窗管理器导入
- #import "YMGroupGreetingViewModel.h"
- #import "YOUPAILCBannerModel.h"
- #import "YOUPAILZHomeBannerCell.h"
- #import "LCHttpHelper.h"
- #import "YMAdvertModel.h"
- #import "YOUPAIZYFirstRechargeWindow.h"
- #import "LCTools.h"
- #import "UIViewController+TFPresent.h"
- #define LZCategoryViewHeight 40.0f
- @interface YMHomePageViewController ()<JXCategoryViewDelegate, JXPagerViewDelegate,JXPagerMainTableViewGestureDelegate,TYCyclePagerViewDataSource, TYCyclePagerViewDelegate>
- {
- dispatch_source_t _timer;
- }
- /// 首页VM
- @property (nonatomic, strong) YMHomePageViewModel *viewModel;
- @property (nonatomic, strong) YMGroupGreetingViewModel *groupGreetingViewModel;
- @property (nonatomic, strong) YMGroupGreetingPopupView *greetingView;
- @property (nonatomic, strong) YMPopupView *greetingPopupView;
- /// 首页Banner视图
- @property (nonatomic, strong) YMHomePageBannerView *bannerView;
- @property (nonatomic, weak) TYCyclePagerView *youpaipbannerView;
- @property (strong, nonatomic) TYPageControl *youpaippageControl;
- @property (strong, nonatomic) NSMutableArray *youpaipimageURLStringsGroup;
- @property (nonatomic, strong) NSArray <YOUPAILCBannerModel *> *youpaipbannerArray;
- @property (nonatomic, strong) UIView *headerV;
- /// 分类标题视图
- @property (nonatomic, strong) JXCategoryTitleView *categoryView;
- /// 分类分页视图
- @property (nonatomic, strong) JXPagerView *pagerView;
- /// 搜索按钮
- @property (nonatomic, strong) UILabel *searchLabel;
- /// 搜索按钮
- @property (nonatomic, strong) UIButton *searchBtn;
- @property (nonatomic, strong) UIButton *zhidingBtn;
- /// banner视图高度
- @property (nonatomic, assign) CGFloat bannerViewHeight;
- @property (nonatomic, assign) NSInteger count;
- @end
- @implementation YMHomePageViewController
- @dynamic viewModel;
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavHidden:YES];
- [[YMGlobalUtils shared] getConfig];
- [OCNotificationCenter addObserver:self selector:@selector(updateOnline) name:@"youpaifuserOnlineUpdate" object:nil];
-
- self.groupGreetingViewModel = [[YMGroupGreetingViewModel alloc] initWithParams:@{}];
-
- // 设置背景图
- UIImageView *topBgImgv = [[UIImageView alloc] init];
- topBgImgv.image = ImageByName(@"ym_home_page_top_bg");
- topBgImgv.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
- [self.view insertSubview:topBgImgv atIndex:0];
-
- NSLog(@"输出🍀\nYMHomePageViewController viewDidLoad");
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
-
- NSLog(@"输出🍀\nYMHomePageViewController viewDidAppear");
-
- // [self getAdvertCompletion:^{
- //
- // NSLog(@"输出🍀\n%@",YMGlobalUtils.shared.advModels);
- // [self showAdvert];
- // }];
-
- // [self youpaifloadAdvert1];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.viewModel judgementsIsOpenAdolescentModel];
-
- [self youpaifrequestBannerData];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- - (void)ym_setupViews{
- [self.view addSubview:self.pagerView];
- [self.view setNeedsUpdateConstraints];
- [self.view updateConstraintsIfNeeded];
- }
- - (void)updateViewConstraints{
-
- [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view).offset(0);
- make.left.equalTo(self.view);
- make.right.equalTo(self.view);
- make.bottom.equalTo(self.view);
- }];
-
- [super updateViewConstraints];
- }
- - (void)ym_bindViewModel{
- [self.bannerView ym_bindViewModel:self.viewModel.bannerVM];
-
- [[YMGlobalUtils shared] getConfig];
- if ([self.viewModel isFemaleGender]) {
- self.zhidingBtn.hidden = false;
- } else {
- self.zhidingBtn.hidden = true;
- }
- [self headerRefreshing];
-
- }
- /// 更新在线状态
- - (void)updateOnline{
- NSLog(@"updateOnline 更新在线状态");
-
- if (self->_timer) {
- dispatch_source_cancel(self->_timer);
- }
- if ([LCSaveData getTokenString] == nil) {
- return;
- }
- [LCHttpHelper requestWithURLString:onlineUpdate parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSInteger user_online_open = [[[dict objectForKey:@"data"]objectForKey:@"user_online_open"] integerValue];
- int user_online_time = [[[dict objectForKey:@"data"]objectForKey:@"user_online_time"] intValue];
- if (user_online_open == 1) {
- __block int timeout= user_online_time;
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- self->_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(self->_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(self->_timer, ^{
- if(timeout<=0){
- dispatch_source_cancel(self->_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- [self updateOnline];
- });
- }else{
- // NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout];
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置
- //NSLog(@"strTime strTime %@",strTime);
- //NSLog(@"当前时间挫%lld",[[LCTools getCurrentTimestamp] longLongValue]);
- });
- timeout--;
- }});
- dispatch_resume(self->_timer);
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)headerRefreshing{
- [self.viewModel getAdvertData];
- // [self.viewModel getLevelIconData];
- [self.viewModel getBadgesAndNobilityIconData];
- [self.viewModel.bannerVM getOnTvData];
- [OCNotificationCenter postNotificationName:REFRESH_HOME_NOTIFICATION object:nil userInfo:@{}];
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- //return kYMStatusBarHeight + adapt(70);
- CGFloat bannerViewHeight = kYMStatusBarHeight + 18.0f + ScaleSize(82.0f);
- self.bannerViewHeight = bannerViewHeight;
- return bannerViewHeight;
- //return 0.1;
- //return self.bannerViewHeight;
- }
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return self.headerV;
- //return self.bannerView;
- //return [[UIView alloc] init];
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return 20 + LZCategoryViewHeight;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- UIView *sectionView = [[UIView alloc]init];
- [sectionView addSubview:self.categoryView];
- [sectionView addSubview:self.zhidingBtn];
- [sectionView addSubview:self.searchBtn];
- [sectionView addSubview:self.searchLabel];
-
- [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
- //make.top.equalTo(sectionView).offset(kYMStatusBarHeight);
- make.centerY.equalTo(sectionView);
- make.left.equalTo(sectionView).offset(10);
- //make.bottom.equalTo(sectionView).offset(-10);
- make.height.equalTo(LZCategoryViewHeight);
- }];
-
- [self.zhidingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(sectionView);
- make.left.equalTo(self.categoryView.mas_right).offset(adapt(10));
- make.width.equalTo(44);
- make.height.equalTo(44);
- }];
-
- [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- //make.top.equalTo(sectionView).offset(adapt(10));
- make.left.equalTo(self.zhidingBtn.mas_right).offset(adapt(10));
- make.right.equalTo(sectionView).offset(adapt(-10));
- //make.bottom.equalTo(sectionView).offset(adapt(-10));
- make.centerY.equalTo(sectionView);
- make.width.equalTo(44);
- make.height.equalTo(44);
- }];
- [self.searchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.searchBtn).offset(8);
- make.centerY.equalTo(self.searchBtn).offset(3);
- }];
- return sectionView;
- }
- - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
- return self.categoryView.titles.count;
- }
- - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index{
- // if (index != 0) {
- // YMHomePageListViewControllerOnline *childVC = [[YMHomePageListViewControllerOnline alloc] initWithViewModel:self.viewModel.homePageVMListDataArray[index]];
- // childVC.jxCategoryPageIndex = index;
- // childVC.jxPageTitle = self.categoryView.titles[index];
- // return childVC;
- // }
- YMHomePageListViewController *listVC = [[YMHomePageListViewController alloc] initWithViewModel:self.viewModel.homePageVMListDataArray[index]];
- listVC.pageIndex = index;
- listVC.jxPageTitle = self.categoryView.titles[index];
- @weakify(self)
- listVC.refreshBlock = ^{
- @strongify(self)
- [self.pagerView.mainTableView.mj_header endRefreshing];
- };
- return listVC;
- }
- - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
- //NSLog(@"%f",scrollView.contentOffset.y);
- //NSLog(@"%f",self.bannerViewHeight - kYMStatusBarHeight);
- if ((scrollView.contentOffset.y + 1) >= (self.bannerViewHeight - kYMStatusBarHeight)) {
- //self.bannerView.hidden = true;
- self.headerV.hidden = true;
- } else {
- //self.bannerView.hidden = false;
- self.headerV.hidden = false;
- }
- }
- #pragma mark - JXCategoryViewDelegate
- //滑动table获得的数组
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- }
- #pragma mark - JXPagerMainTableViewGestureDelegate
- - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- //禁止categoryView左右滑动的时候,上下和左右都可以滚动
- if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
- return NO;
- }
- return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
- }
- - (UIView *)headerV{
- if (!_headerV) {
- _headerV = [[UIView alloc]init];
- UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 18.0f + ScaleSize(82.0f))];
- //headerV.frame = CGRectMake(0, 0, kScreenWidth, 0.1);
- headerV.hidden = NO;
- [self.view addSubview:headerV];
- _headerV = headerV;
-
- TYCyclePagerView *bannerView = [[TYCyclePagerView alloc]initWithFrame:CGRectMake(10, kYMStatusBarHeight + 9.0f, KScreenWidth - 20,ScaleSize(82.0f))];
- [headerV addSubview:bannerView];
- bannerView.isInfiniteLoop = YES;
- bannerView.autoScrollInterval = 4.0;
- bannerView.layer.cornerRadius = ScaleSize(10.0f);
- bannerView.clipsToBounds = YES;
- bannerView.dataSource = self;
- bannerView.delegate = self;
- [bannerView registerClass:[YOUPAILZHomeBannerCell class] forCellWithReuseIdentifier:@"cellId"];
- self.youpaipbannerView = bannerView;
- bannerView.backgroundColor = [UIColor clearColor];
- TYPageControl *pageControl = [[TYPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(_youpaipbannerView.frame) - 26, CGRectGetWidth(_youpaipbannerView.frame), 26)];
- //pageControl.numberOfPages = _datas.count;
- pageControl.currentPageIndicatorSize = CGSizeMake(6, 6);
- pageControl.pageIndicatorSize = CGSizeMake(6, 6);
- //pageControl.currentPageIndicatorTintColor = [UIColor redColor];
- //pageControl.pageIndicatorTintColor = [UIColor grayColor];
- pageControl.pageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_n"];
- pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_s"];
- pageControl.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
- pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- pageControl.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- pageControl.pageIndicatorSpaing = 1;
- [bannerView addSubview:pageControl];
- self.youpaippageControl = pageControl;
- }
- return _headerV;
- }
- - (YMHomePageBannerView *)bannerView{
- if (!_bannerView) {
- _bannerView = [[YMHomePageBannerView alloc]init];
- @weakify(self)
- _bannerView.bannerViewHeightBlock = ^(CGFloat bannerViewHeight) {
- @strongify(self)
- self.bannerViewHeight = bannerViewHeight;
- [self.pagerView resizeTableHeaderViewHeightWithAnimatable:NO duration:0 curve:0];
- };
- }
- return _bannerView;
- }
- - (JXCategoryTitleView *)categoryView{
- if (!_categoryView) {
- _categoryView = [[JXCategoryTitleView alloc]initWithFrame:CGRectMake(0, 0,kFrameWidth, adapt(50))];
- _categoryView.delegate = self;
- if (self.viewModel.isFemaleGender) {
- _categoryView.titles = @[@"推荐", @"高颜值女神", @"活跃", @"男神"];
- } else {
- _categoryView.titles = @[@"推荐", @"高颜值女神", @"活跃"];
- }
- _categoryView.titleLabelZoomEnabled = NO;
- _categoryView.titleColorGradientEnabled = YES;
- _categoryView.titleColor = HexColorFromRGB(0xC6C6C6);
- _categoryView.titleSelectedColor = HexColorFromRGB(0x0A0A0A);
- _categoryView.titleFont = LCFont(17);
- _categoryView.titleSelectedFont = LCBoldFont(18);
- _categoryView.averageCellSpacingEnabled = NO;
- _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
- _categoryView.backgroundColor = [UIColor clearColor];
- JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc]init];
- lineView.indicatorColor = UIColor.clearColor;
- lineView.verticalMargin = adapt(8);
- lineView.indicatorWidth = JXCategoryViewAutomaticDimension;
- lineView.indicatorHeight = adapt(5);
- lineView.indicatorCornerRadius = 0;
- _categoryView.indicators = @[lineView];
- _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
-
- JXCategoryIndicatorImageView *indicatorImageView = [[JXCategoryIndicatorImageView alloc] init];
- indicatorImageView.indicatorImageViewSize = CGSizeMake(adapt(68), 44);
- UIImageView *indicatorImgv = [[UIImageView alloc] init];
- indicatorImgv.image = [UIImage imageWithColor:HexColorFromRGB(0xFC8997) size:CGSizeMake(adapt(40), adapt(8))];
- indicatorImgv.layer.cornerRadius = adapt(4);
- indicatorImgv.layer.masksToBounds = YES;
- //indicatorImgv.contentMode = UIViewContentModeScaleAspectFit;
- [indicatorImageView addSubview:indicatorImgv];
- [indicatorImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(indicatorImageView);
- make.bottom.equalTo(indicatorImageView).offset(adapt(0));
- make.width.mas_equalTo(adapt(40));
- make.height.mas_equalTo(adapt(8));
- }];
- _categoryView.indicators = @[indicatorImageView];
- }
- return _categoryView;
- }
- - (JXPagerView*)pagerView{
- if (!_pagerView) {
- //需要下拉刷新则要这个代理给设置出来
- _pagerView = [[JXPagerView alloc] initWithDelegate:self];
- _pagerView.mainTableView.backgroundColor = UIColor.clearColor;
- _pagerView.mainTableView.gestureDelegate = self;
- _pagerView.mainTableView.mj_header = self.refreshHeader;
- _pagerView.mainTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
- //当有头部视图的时候设置固定高度
- // _pagerView.pinSectionHeaderVerticalOffset = 50;
- //关闭弹簧效果
- // _pagerView.mainTableView.bounces = NO;
- }
- return _pagerView;
- }
- - (UILabel *)searchLabel {
- if (!_searchLabel) {
- _searchLabel = [[UILabel alloc] init];
- _searchLabel.hidden = YES;
- _searchLabel.text = @"寻找";
- _searchLabel.textColor = UIColor.whiteColor;
- _searchLabel.font = LCFont(11);
- }
- return _searchLabel;
- }
- - (UIButton *)searchBtn {
- if (!_searchBtn) {
- _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_searchBtn setImage:ImageByName(@"ym_home_page_xunzhao") forState: UIControlStateNormal];
- [_searchBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
- _searchBtn.titleLabel.font = LCFont(11);
- WS(weakSelf)
- [[[_searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- [weakSelf.viewModel gotoSearchUser];
- }];
- }
- return _searchBtn;
- }
- - (UIButton *)zhidingBtn{
- if (!_zhidingBtn) {
- _zhidingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_zhidingBtn setImage:ImageByName(@"home_msg_zhiding") forState:UIControlStateNormal];
- _zhidingBtn.hidden = true;
- WS(weakSelf)
- [[[_zhidingBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- [weakSelf showZhidingBottomSheet];
- }];
- }
- return _zhidingBtn;
- }
- /**
- * 显示置顶功能底部选择弹窗
- * 包含自动置顶、群打招呼、取消三个选项
- */
- - (void)showZhidingBottomSheet {
- // 创建底部弹窗视图
- YMSheetPopupView *sheetView = [[YMSheetPopupView alloc] init];
-
- // 配置弹窗选项列表
- NSArray *optionList = @[
- @"自动置顶",
- @"群打招呼"
- ];
-
- // 配置弹窗数据
- [sheetView configutationWithItemList:optionList];
-
- // 设置选择回调
- WS(weakSelf)
- sheetView.selectIndexBlock = ^(NSInteger index) {
- [weakSelf handleZhidingSelection:index];
- };
-
- // 设置关闭回调(对应"取消"选项)
- sheetView.closeBlock = ^{
- // 用户点击取消按钮
- NSLog(@"用户取消了置顶操作");
- [YMPopupView removeLastPopView];
- };
-
- // 创建弹窗管理器并显示
- YMPopupView *popupView = [YMPopupView initWithCustomView:sheetView];
- popupView.popDuration = 0.3; // 弹出动画时间
- popupView.positionStyle = YMPositionStyleBottom; // 底部弹出
- popupView.popStyle = YMPopupStyleSmoothFromBottom; // 从底部滑入动画
- popupView.dismissStyle = YMDismissStyleSmoothToBottom; // 滑出到底部动画
- popupView.isClickBgDismiss = YES; // 点击背景关闭
- popupView.bgAlpha = 0.5; // 背景透明度
-
- // 显示弹窗
- [popupView pop];
- }
- /**
- * 处理置顶选择结果
- * @param index 选择的选项索引(0:自动置顶, 1:群打招呼)
- */
- - (void)handleZhidingSelection:(NSInteger)index {
- switch (index) {
- case 0:
- // 自动置顶
- NSLog(@"选择了:自动置顶");
- [self performAutoZhiding];
- break;
- case 1:
- // 群打招呼
- NSLog(@"选择了:群打招呼");
- [self performGroupGreeting];
- break;
- default:
- break;
- }
-
- // 关闭弹窗
- [YMPopupView removeLastPopView];
- }
- /**
- * 执行自动置顶功能
- */
- - (void)performAutoZhiding {
- // 调用原有的置顶数据方法
- [self.viewModel zhidingData];
-
- // 可以添加额外的自动置顶逻辑
- // 例如:显示成功提示、刷新列表等
- NSLog(@"自动置顶功能已执行");
- }
- /**
- * 执行群打招呼功能
- */
- - (void)performGroupGreeting {
- // 先请求获取推荐用户列表
- [self requestGroupGreetingUserList:YES];
-
- }
- /**
- * 请求群打招呼用户列表
- */
- - (void)requestGroupGreetingUserList:(BOOL)isNew {
- WS(weakSelf)
- [self.groupGreetingViewModel getGroupGreetingDataIsNew:isNew completion:^(BOOL isSuccess) {
- if (isSuccess) {
- [weakSelf showGroupGreetingPopupView];
- }
- }];
-
- }
- /**
- * 显示群打招呼弹窗
- */
- - (void)showGroupGreetingPopupView {
- [_greetingPopupView dismiss];
-
- // 创建群打招呼弹窗
- _greetingView = [[YMGroupGreetingPopupView alloc] initWithFrame:UIScreen.mainScreen.bounds];
- [_greetingView configureWithUserList:self.groupGreetingViewModel.listDataArray];
-
- WS(weakSelf)
-
- // 设置换一换回调
- _greetingView.refreshBlock = ^{
- [weakSelf requestGroupGreetingUserList:NO];
- };
-
- // 设置发送打招呼回调
- _greetingView.sendBlock = ^{
- [weakSelf sendGroupGreetingRequest];
- };
-
- _greetingView.clickBlankAreaBlock = ^{
- [weakSelf.greetingPopupView dismiss];
- };
-
- // 使用YMPopupView显示弹窗
- _greetingPopupView = [YMPopupView initWithCustomView:_greetingView];
- _greetingPopupView.positionStyle = YMPositionStyleCenter;
- _greetingPopupView.popDuration = 0.3; // 弹出动画时间
- _greetingPopupView.popStyle = YMPopupStyleFade; // 从底部滑入动画
- _greetingPopupView.dismissStyle = YMDismissStyleFade; // 滑出到底部动画
- _greetingPopupView.isClickBgDismiss = YES; // 点击背景关闭
- _greetingPopupView.bgAlpha = 0.5; // 背景透明度
- // 设置关闭回调
- _greetingView.closeBlock = ^{
- [weakSelf.greetingPopupView dismiss];
- };
-
- [_greetingPopupView pop];
- }
- /**
- * 发送群打招呼请求
- */
- - (void)sendGroupGreetingRequest {
- // 显示加载提示
- [ZCHUDHelper show];
-
- NSArray *arr = self.groupGreetingViewModel.listDataArray;
- NSString *str = @"";
- for (int i = 0; i < arr.count; i++) {
- YMGroupGreetingUserModel *model = arr[i];
- str = [str stringByAppendingString:[NSString stringWithFormat:@"%@",@(model.userId)]];
- if (i != arr.count - 1) {
- str = [str stringByAppendingString:@","];
- }
- }
- str = [NSString stringWithFormat:@"[%@]",str];
-
- // 请求参数
- NSDictionary *params = @{
- @"user_ids": str
- };
-
- [LCHttpHelper requestWithURLString:HomeBeckonSend parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- [ZCHUDHelper dismiss];
-
- NSDictionary *dict = (NSDictionary *)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
-
- if (code == 0) {
- //NSString *message = [dict stringValueForKey:@"message" defaultValue:@"打招呼发送成功"];
- [ZCHUDHelper showTitle:@"打招呼成功" showtime:2];
- [self.greetingPopupView dismiss];
- //[self.greetingView makeToast:@"打招呼成功" duration:2 position:CSToastPositionCenter];
- } else {
- NSString *message = [dict stringValueForKey:@"message" defaultValue:@"打招呼发送失败"];
- //[ZCHUDHelper showTitle:message];
- [ZCHUDHelper showTitle:message];
- //[self.greetingView makeToast:message duration:2 position:CSToastPositionCenter];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper dismiss];
- [ZCHUDHelper showTitle:@"网络请求失败"];
- }];
- }
- #pragma mark - TYCyclePagerViewDataSource
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
- return self.youpaipimageURLStringsGroup.count;
- }
- - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
- YOUPAILZHomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndex:index];
- NSString *url;
- // absoluteString
- if (self.youpaipimageURLStringsGroup) {
- url = [self.youpaipimageURLStringsGroup[index] absoluteString];
- [cell.youpaipbgImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"banner_default"]];
- }
- cell.layer.cornerRadius = ScaleSize(10);
- cell.layer.masksToBounds = YES;
- cell.backgroundColor = [UIColor clearColor];
- // cell.backgroundColor = _datas[index];
- // cell.label.text = [NSString stringWithFormat:@"index->%ld",index];
- return cell;
- }
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
- TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
- layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
- layout.itemSpacing = 20;
- // ScaleSize(10.0f)
- layout.layoutType = TYCyclePagerTransformLayoutNormal;
- //layout.minimumAlpha = 0.3;
-
- return layout;
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
- YOUPAILCBannerModel* model = self.youpaipbannerArray[index];
- if (model.youpaiplink_type==1) {
- ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
- baseWeb.title = @"详情页";
- baseWeb.contentUrl = model.youpaiplink_url;
- [self.navigationController pushViewController:baseWeb animated:YES];
- }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){
- [self youpaifpageToStr:model.youpaiplink_url];
- }
-
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
- self.youpaippageControl.currentPage = toIndex;
- }
- /// 获取banner数据
- - (void)youpaifrequestBannerData{
- @weakify(self);
- [LCHttpHelper requestWithURLString:HomeBanner parameters:@{@"cate_id":@"5"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- self.youpaipbannerArray = [YOUPAILCBannerModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"banner"]];
- [self youpaifreloadBannerData];
- }
- } failure:^(NSError *error) {
- }];
- }
- -(void)youpaifreloadBannerData{
- NSMutableArray *imgUrlArray = [NSMutableArray array];
- for (YOUPAILCBannerModel* model in self.youpaipbannerArray) {
- [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]];
- }
- self.youpaippageControl.numberOfPages = imgUrlArray.count;
- self.youpaipimageURLStringsGroup = imgUrlArray;
- [self.youpaipbannerView reloadData];
- }
- #pragma mark - 获取首冲弹框数据
- //获取首冲弹框数据
- - (void)youpaifloadAdvert1 {
- @weakify(self);
- [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"6"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
-
- //NSLog(@"输出🍀\n%@",dict);
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- // 请求成功才会继续后面的逻辑
- if (code != 0) { return; }
-
- NSDictionary *dataDict = [dict objectForKey:@"data"];
- NSInteger is_open = [[dataDict objectForKey:@"is_open"] integerValue];
- NSArray *listArr = [dataDict objectForKey:@"list"];
-
- // 弹窗打开,才会进行数据解析
- if (is_open != 1) {
- return;
- }
-
-
-
- for (NSDictionary *advDict in listArr) {
- YMAdvertModel *model = [YMAdvertModel yy_modelWithDictionary:advDict];
- NSArray *advModelTags = YMGlobalUtils.shared.advModelTags;
- if (![advModelTags containsObject:model.tag]) {
- [YMGlobalUtils.shared.advModels addObject:model];
- }
- }
-
- for (YMAdvertModel *model in YMGlobalUtils.shared.advModels) {
- if (model.window_type != 1 && model.showedTag != 0) {
- continue;
- }
-
- model.showedTag = 1;
-
- CGFloat delay = model.delayed_time;
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- YOUPAIZYFirstRechargeWindow *VC = [[YOUPAIZYFirstRechargeWindow alloc]init];
- //VC.youpaipdelegate = self;
- VC.vWidth = KScreenWidth - adapt(80);
- VC.vHeight = KScreenHeight * 0.6;
- VC.youpaipimageurl = model.image;
- VC.youpaiplink_type = model.link_type;
- VC.youpaiplink_url = model.link_url;
- VC.isTouchDismiss = YES;
- VC.youpaipimgV.contentMode = UIViewContentModeScaleAspectFill;
-
- [[LCTools getCurrentVC] TFPresentVC:VC completion:^{}];
-
- UIView *containerView = VC.baseView;
-
- UILabel *titleLabel = [[UILabel alloc] init];
- titleLabel.font = [UIFont systemFontOfSize:24 weight:(UIFontWeightBold)];
- titleLabel.textColor = UIColor.blackColor;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- titleLabel.text = model.title;
- [containerView addSubview:titleLabel];
-
- UITextView *textView = [[UITextView alloc] init];
- textView.text = model.content;
- textView.font = [UIFont systemFontOfSize:15 weight:(UIFontWeightRegular)];
- textView.textColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
- textView.backgroundColor = UIColor.clearColor;
- textView.editable = NO;
- [containerView addSubview:textView];
-
- [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(containerView).offset(adapt(20));
- make.left.right.equalTo(containerView);
- make.height.mas_equalTo(adapt(40));
- }];
- [textView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(titleLabel.mas_bottom).offset(adapt(20));
- make.left.equalTo(containerView).offset(adapt(20));
- make.right.equalTo(containerView).offset(adapt(-20));
- make.bottom.equalTo(containerView).offset(adapt(-20));
- }];
- });
- }
- } failure:^(NSError *error) {}];
-
- }
- //获取首冲弹框数据
- - (void)getAdvertCompletion: (void(^)(void))completion {
- @weakify(self);
- [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"6"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
-
- //NSLog(@"输出🍀\n%@",dict);
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- // 请求成功才会继续后面的逻辑
- if (code != 0) { return; }
-
- NSDictionary *dataDict = [dict objectForKey:@"data"];
- NSInteger is_open = [[dataDict objectForKey:@"is_open"] integerValue];
- NSArray *listArr = [dataDict objectForKey:@"list"];
-
- // 弹窗打开,才会进行数据解析
- if (is_open != 1) {
- return;
- }
-
-
- for (NSDictionary *advDict in listArr) {
- YMAdvertModel *model = [YMAdvertModel yy_modelWithDictionary:advDict];
- NSArray *advModelTags = YMGlobalUtils.shared.advModelTags;
- if (![advModelTags containsObject:model.tag]) {
- [YMGlobalUtils.shared.advModels addObject:model];
- }
- }
- completion();
- } failure:^(NSError *error) {}];
-
- }
- - (void)showAdvert {
- for (YMAdvertModel *model in YMGlobalUtils.shared.advModels) {
- if (model.window_type != 1 && model.showedTag != 0) {
- continue;
- }
-
- model.showedTag = 1;
-
- CGFloat delay = model.delayed_time;
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- YOUPAIZYFirstRechargeWindow *VC = [[YOUPAIZYFirstRechargeWindow alloc]init];
- //VC.youpaipdelegate = self;
- VC.vWidth = KScreenWidth - adapt(80);
- VC.vHeight = KScreenHeight * 0.6;
- VC.youpaipimageurl = model.image;
- VC.youpaiplink_type = model.link_type;
- VC.youpaiplink_url = model.link_url;
- VC.isTouchDismiss = YES;
- VC.youpaipimgV.contentMode = UIViewContentModeScaleAspectFill;
-
- [[LCTools getCurrentVC] TFPresentVC:VC completion:^{}];
-
- UIView *containerView = VC.baseView;
-
- UILabel *titleLabel = [[UILabel alloc] init];
- titleLabel.font = [UIFont systemFontOfSize:24 weight:(UIFontWeightBold)];
- titleLabel.textColor = UIColor.blackColor;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- titleLabel.text = model.title;
- [containerView addSubview:titleLabel];
-
- UITextView *textView = [[UITextView alloc] init];
- textView.text = model.content;
- textView.font = [UIFont systemFontOfSize:15 weight:(UIFontWeightRegular)];
- textView.textColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
- textView.backgroundColor = UIColor.clearColor;
- textView.editable = NO;
- [containerView addSubview:textView];
-
- [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(containerView).offset(adapt(20));
- make.left.right.equalTo(containerView);
- make.height.mas_equalTo(adapt(40));
- }];
- [textView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(titleLabel.mas_bottom).offset(adapt(20));
- make.left.equalTo(containerView).offset(adapt(20));
- make.right.equalTo(containerView).offset(adapt(-20));
- make.bottom.equalTo(containerView).offset(adapt(-20));
- }];
- });
- }
- }
- @end
|