Files
xj-ios/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomePageV2HeardView.m
T
2026-03-04 18:07:02 +08:00

495 lines
17 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// XJHomePageV2HeardView.m
// XinjiangProject
//
// Created by Apple on 2026/2/9.
//
#import "XJHomePageV2HeardView.h"
#import "SDCycleScrollView.h"
#import "HealthyToolsView.h"
#import "MyMessageModel.h"
#import "HomeBannerModel.h"
#import "XJHomeWatchDataView.h"
@interface XJHomePageV2HeardView ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) UIView *messageview;
@property (nonatomic, strong) SDCycleScrollView *adTitleView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) XJHomeWatchDataView *watchDataView;
@end
@implementation XJHomePageV2HeardView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = CViewBgColor;
[self createUI];
}
return self;
}
- (void)createUI {
UIImageView * backImage = [[UIImageView alloc] init];
backImage.userInteractionEnabled = true;
backImage.image = [UIImage imageNamed:@"homePageHeardTop"];
[self addSubview:backImage];
[backImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_offset(0);
make.height.mas_offset(kRealValue(405));
make.top.mas_offset(0);
}];
UIView * messageView = [[UIView alloc] init];
messageView.layer.cornerRadius = 8;
messageView.layer.masksToBounds = true;
messageView.userInteractionEnabled = true;
self.messageview = messageView;
[backImage addSubview:messageView];
[messageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(12);
make.right.mas_offset(-12);
make.height.mas_offset(40);
make.top.mas_offset(kRealValue(145));
}];
UIImageView * messageImg = [[UIImageView alloc] init];
messageImg.image = [UIImage imageNamed:@"messageBackImg"];
messageImg.userInteractionEnabled = true;
[messageView addSubview:messageImg];
[messageImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.offset(0);
}];
UIImageView * labaImg = [[UIImageView alloc] init];
labaImg.image = [UIImage imageNamed:@"homeLaba"];
[messageView addSubview:labaImg];
[labaImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(10);
make.width.height.mas_offset(17);
make.centerY.mas_equalTo(messageView);
}];
self.adTitleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
self.adTitleView.titleLabelTextColor = UIColorHex(#77849E);
self.adTitleView.titleLabelBackgroundColor = KClearColor;
self.adTitleView.scrollDirection = UICollectionViewScrollDirectionVertical;
self.adTitleView.onlyDisplayText = YES;
NSArray *titles = @[];
self.adTitleView.titlesGroup = [titles copy];
[self.adTitleView disableScrollGesture];
[messageView addSubview:self.adTitleView];
[self.adTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(labaImg.mas_right).offset(9);
make.right.equalTo(messageView).offset(-12);
make.top.bottom.equalTo(messageView);
}];
DLog(@"%@", self.adTitleView);
if ([HQCommonUtils isLogin]) {
messageView.hidden = false;
}else
{
messageView.hidden = true;
}
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.textColor = KWhiteColor;
self.nameLabel.font = BOLDSYSTEMFONT(12);
self.nameLabel.text = @"Hi~";
self.nameLabel.textAlignment = NSTextAlignmentLeft;
[backImage addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(24);
make.right.mas_offset(-12);
if (messageView.hidden == false) {
make.top.mas_equalTo(messageView.mas_bottom).offset(10);
}else
{
make.top.mas_offset(kRealValue(145));
}
}];
//姓名
if ([HQCommonUtils isLogin]) {
HQUserInfo * user = [HQCommonUtils keyedUnarchiverWithKey:LoginUserInfo];
self.nameLabel.text = [NSString stringWithFormat:@"Hi~%@",user.realname];
}
//
UIView * toolsView = [[UIView alloc] init];
toolsView.layer.cornerRadius = 12;
toolsView.layer.masksToBounds = true;
toolsView.alpha = 0.5;
toolsView.backgroundColor = UIColorHex(#EBFFFD);
[backImage addSubview:toolsView];
[toolsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(6);
make.right.mas_offset(-6);
make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(8);
make.height.mas_offset(126);
}];
UILabel * toolTitleLab = [[UILabel alloc] init];
toolTitleLab.text = @"今日健康积分 0 | 累计积分 0";
toolTitleLab.textColor = UIColorHex(#116F6B);
toolTitleLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
[toolsView addSubview:toolTitleLab];
[toolTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(18);
make.top.mas_offset(8);
make.right.mas_offset(0);
}];
NSArray * toolsArray = @[@[@"健康档案",@"homeTools_1"],@[@"健康体检",@"homeTools_2"],@[@"应急就医",@"homeTools_3"],@[@"健康银行",@"homeTools_4"]];
UIView * customView = [[UIView alloc] init];
customView.layer.cornerRadius = 6;
customView.layer.masksToBounds = true;
customView.backgroundColor = KWhiteColor;
[backImage addSubview:customView];
[customView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(12);
make.right.mas_offset(-12);
make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(35);
make.height.mas_offset(93);
}];
NSInteger count = toolsArray.count;
NSMutableArray *itemViews = [NSMutableArray array];
for (int i = 0; i < count; i++) {
NSArray *item = toolsArray[i];
UIView *itemView = [[UIView alloc] init];
itemView.tag = i;
itemView.userInteractionEnabled = YES;
[customView addSubview:itemView];
[itemViews addObject:itemView];
/// 点击手势
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(cenetrFunctionItemTap:)];
[itemView addGestureRecognizer:tap];
/// 上图
UIImageView *icon = [[UIImageView alloc] init];
icon.image = [UIImage imageNamed:item[1]];
icon.contentMode = UIViewContentModeScaleAspectFit;
[itemView addSubview:icon];
/// 下文
UILabel *title = [[UILabel alloc] init];
title.text = item[0];
title.font = MEDIUMFONT(14);
title.textColor = [UIColor blackColor];
title.textAlignment = NSTextAlignmentCenter;
[itemView addSubview:title];
/// icon 布局
[icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(10);
make.centerX.equalTo(itemView);
make.width.height.mas_equalTo(40);
}];
/// label 布局
[title mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(icon.mas_bottom).offset(6);
make.left.right.equalTo(itemView);
}];
}
[itemViews mas_distributeViewsAlongAxis:MASAxisTypeHorizontal
withFixedSpacing:0
leadSpacing:0
tailSpacing:0];
[itemViews mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(customView);
}];
// 先用图片实现
NSArray *imageConfigs = @[
@{@"img": @"heardTopImg_1", @"height": @65},
@{@"img": @"heardTopImg_2", @"height": @60},
];
SDCycleScrollView *lastImageView = nil;
for (int i = 0; i < imageConfigs.count; i++) {
NSDictionary *config = imageConfigs[i];
SDCycleScrollView * SDCycles = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage: [UIImage imageNamed:@"placeholder"]];
SDCycles.layer.cornerRadius = 12;
SDCycles.layer.masksToBounds = true;
SDCycles.backgroundColor = KClearColor;
// UIViewContentModeScaleToFill,
// UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
// UIViewContentModeScaleAspectFill,
SDCycles.bannerImageViewContentMode = UIViewContentModeScaleToFill;
SDCycles.currentPageDotImage = [UIImage imageNamed:@"pageControlDot"];
SDCycles.pageDotImage = [UIImage imageNamed:@"pageControlNomalDot"]; SDCycles.pageDotColor = KWhiteColor;
SDCycles.tag = 50 + i; //
SDCycles.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
SDCycles.pageControlDotSize = CGSizeMake(6, 4);
[self addSubview:SDCycles];
// UIImageView *imageView = [[UIImageView alloc] init];
// imageView.image = [UIImage imageNamed:config[@"img"]];
// imageView.userInteractionEnabled = YES;
// imageView.tag = 50 + i; // 用于区分点击的是哪一个
// imageView.contentMode = UIViewContentModeScaleAspectFill;
// imageView.layer.cornerRadius = 8;
// imageView.layer.masksToBounds = true;
// imageView.clipsToBounds = YES;
//
// [self addSubview:imageView];
/// 点击手势
// UITapGestureRecognizer *tap =
// [[UITapGestureRecognizer alloc] initWithTarget:self
// action:@selector(topImageTap:)];
//
// [SDCycles addGestureRecognizer:tap];
/// 布局
[SDCycles mas_makeConstraints:^(MASConstraintMaker *make) {
if (lastImageView) {
make.top.equalTo(lastImageView.mas_bottom).offset(12);
} else {
make.top.equalTo(toolsView.mas_bottom).offset(12);
}
make.left.mas_equalTo(12);
make.right.mas_equalTo(-12);
make.height.mas_equalTo([config[@"height"] floatValue]);
}];
lastImageView = SDCycles;
}
[self layoutIfNeeded];
// @{@"img": @"heardTopImg_3", @"height": @120}
//手表数据
self.watchDataView = [[XJHomeWatchDataView alloc] initWithFrame:CGRectZero];
self.watchDataView.tabTitles = @[@"心脑血管", @"癌症", @"慢呼", @"糖尿病", @"亚健康"];
self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) {
DLog(@"选中 %ld - %@", index, title);
// 切换 collectionView 到对应 page
};
MJWeakSelf
self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) {
// tab 0 完整高度,其他收缩(header 40 + tab 52 + 内容区 68 = 160
CGFloat height = (index == 0) ? 250 : 160;
[weakSelf.watchDataView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(height);
}];
[UIView animateWithDuration:0.25 animations:^{
[weakSelf layoutIfNeeded];
}];
};
self.watchDataView.watchMoreBlock = ^{
if ([self.homeTopDelegate respondsToSelector:@selector(watchDetailClick)]) {
[self.homeTopDelegate watchDetailClick];
}
};
[self addSubview:self.watchDataView];
[self.watchDataView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(12);
make.right.mas_offset(-12);
make.height.mas_offset(250);
make.top.mas_equalTo(lastImageView.mas_bottom).offset(12);
}];
SDCycleScrollView * questionSDCycles = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
questionSDCycles.backgroundColor = KClearColor;
questionSDCycles.layer.cornerRadius = 12;
questionSDCycles.layer.masksToBounds = true;
questionSDCycles.bannerImageViewContentMode = UIViewContentModeScaleToFill;
questionSDCycles.currentPageDotImage = [UIImage imageNamed:@"pageControlDot"];
questionSDCycles.pageDotImage = [UIImage imageNamed:@"pageControlNomalDot"]; questionSDCycles.pageDotColor = KWhiteColor;
questionSDCycles.tag = 52; //
questionSDCycles.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
questionSDCycles.pageControlDotSize = CGSizeMake(6, 4);
[self addSubview:questionSDCycles];
/// 布局
[questionSDCycles mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.watchDataView.mas_bottom).offset(12);
make.left.mas_equalTo(12);
make.right.mas_equalTo(-12);
make.height.mas_equalTo(@120);
make.bottom.mas_offset(-12);
}];
}
- (void)setModel:(XJHomeWatchModel *)model {
_model = model;
self.watchDataView.watchModel = _model;
}
- (void)setWatchArray:(NSArray *)watchArray {
_watchArray = watchArray;
self.watchDataView.dataList = _watchArray;
}
- (void)setDataArray:(NSArray *)dataArray {
_dataArray = dataArray;
NSMutableArray * titlesArray = [[NSMutableArray alloc] init];
for (MyMessageModel * model in _dataArray) {
//直接处理图片吧
[titlesArray addObject:model.title];
}
if(titlesArray.count == 0) {
self.messageview.hidden = true;
[self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(24);
make.right.mas_offset(-12);
make.top.mas_offset(kRealValue(145));
}];
[self layoutIfNeeded];
}else
{
self.messageview.hidden = false;
[self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(24);
make.right.mas_offset(-12);
make.top.mas_equalTo(self.messageview.mas_bottom).offset(10);
}];
[self layoutIfNeeded];
}
self.adTitleView.titlesGroup = titlesArray;
}
- (void)setBannerArray:(NSArray *)bannerArray {
// 1 首页体检模块。2 首页心理模块 3 健康咨询模块。4 ai随访
//处理数据
_bannerArray = bannerArray;
SDCycleScrollView * oneSDView = [self viewWithTag:50]; //体检
SDCycleScrollView * twoSDView = [self viewWithTag:51]; //EAP
SDCycleScrollView * threeSDView = [self viewWithTag:52]; //健康咨询
NSMutableArray * tijianArray = [[NSMutableArray alloc] init];
NSMutableArray * eapArray = [[NSMutableArray alloc] init];
NSMutableArray * questionArray = [[NSMutableArray alloc] init];
for (HomeBannerModel * model in _bannerArray) {
//直接处理图片吧
NSString * photo = [NSString stringWithFormat:@"%@%@",ResourceAddress,model.photoUrl];
NSString * str1 = @"\\";
photo = [ photo stringByReplacingOccurrencesOfString:str1 withString:@"/"];
NSString *encodedString3 = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef) photo, (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", NULL, kCFStringEncodingUTF8));
if ([model.showLocation intValue] == 1) {
[tijianArray addObject:encodedString3];
}
if ([model.showLocation intValue] == 2) {
[eapArray addObject:encodedString3];
}
if ([model.showLocation intValue] == 3) {
[questionArray addObject:encodedString3];
}
}
oneSDView.imageURLStringsGroup = tijianArray;
twoSDView.imageURLStringsGroup = eapArray;
threeSDView.imageURLStringsGroup = questionArray;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
DLog(@"++%ld",index);
if (cycleScrollView == self.adTitleView) {
if ([self.homeTopDelegate respondsToSelector:@selector(SDTitleItemClick)]) {
[self.homeTopDelegate SDTitleItemClick];
}
}else
{
CGFloat currentBanner = cycleScrollView.tag;
if([self.homeTopDelegate respondsToSelector:@selector(heardImageClick:)]) {
[self.homeTopDelegate heardImageClick:currentBanner];
}
}
}
- (void)cenetrFunctionItemTap:(UITapGestureRecognizer *)tap {
UIView *view = tap.view;
NSInteger index = view.tag;
if([self.homeTopDelegate respondsToSelector:@selector(heardTopToolsClick:)]) {
[self.homeTopDelegate heardTopToolsClick:index];
}
}
@end