Files
xj-ios/XinjiangProject/XinjiangProject/Project/HomeV2/XJHomePageV2ViewController.m
T
2026-03-05 18:07:03 +08:00

1204 lines
39 KiB
Objective-C

//
// XJHomePageV2ViewController.m
// XinjiangProject
//
// Created by Apple on 2026/2/9.
//
#import "XJHomePageV2ViewController.h"
#import "QuestionViewController.h"
#import "HealthyQuestionTable.h"
#import "HealthyQuestionHeardView.h"
#import "XJDoctorMainViewController.h"
#import "XJExpertMainViewController.h"
#import "XJQustionRecordViewController.h"
#import "ChatViewController.h"
#import "SmallHelpIMDataModel.h"
#import <AMapLocationKit/AMapLocationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
#import <CoreLocation/CoreLocation.h>
#import "PSAppInfo.h"
#import "PSCheckVersionView.h"
#import "RoomDoctorRecordsVC.h"
#import "HomeQusetionRecordsModel.h"
#import "XJDoctorMainViewController.h"
#import "UPAppVesionModel.h"
#import "BannarDetailViewController.h"
#import "HomeBannerModel.h"
//新版首页
#import "XJHomePageV2HeardView.h"
#import "MyMessageModel.h"
#import "XJHomePageV2BottomTools.h"
#import "XJHomePageV2QuestionTableView.h"
#import "MyMessageListViewController.h"
#import "EmptyFunctionDevelopmentVC.h"
#import "XJSOSLookDoctoreViewController.h"
#import "HomeBannerModel.h"
#import "SDCycleScrollView.h"
#import "BRPickerView.h"
static CGFloat const kEmptyTableMinHeight = 250; // 或屏幕高度的一半
@interface XJHomePageV2ViewController ()<questionToolsProtocl,V2TIMSDKListener,V2TIMConversationListener, TUILoginListener,V2TIMAPNSListener, TUICallObserver,V2TIMSimpleMsgListener,AMapLocationManagerDelegate,homePageHeardDelegate,SDCycleScrollViewDelegate>
@property (nonatomic, strong) XJHomePageV2QuestionTableView * homeTable;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, strong) PSCheckVersionView * checkVersionView;
@property (nonatomic, strong) UIView * coverView;
//定位相关
@property (nonatomic, strong) AMapSearchAPI *search;
@property (nonatomic, strong) AMapLocationManager *locationManager;
@property (nonatomic, copy) AMapLocatingCompletionBlock completionBlock;
//定位相关
@property (nonatomic, strong) CLLocationManager * userlocationManager;
@property (nonatomic, strong) NSMutableArray * dataArray;
@property (nonatomic, strong) HomeQusetionRecordsModel * recomendModel;
//更新一版用scrollview处理
@property (nonatomic, strong) UIScrollView * mainScrollView;
@property (nonatomic, strong) UIView * contentView;
@property (nonatomic, strong) MASConstraint *tableHeightConstraint;
@property (nonatomic, strong) XJHomePageV2HeardView * topView;
//用gcd做轮询
//@property (nonatomic, strong) dispatch_source_t timer;
@property (nonatomic, assign) BOOL polling; //失败了也轮询?先不管 有需要回调处理去
@property (nonatomic, strong) SDCycleScrollView * AIBannerImage;
@end
@implementation XJHomePageV2ViewController
- (NSMutableArray *)dataArray {
if(!_dataArray) {
_dataArray = [[NSMutableArray alloc] init];
}
return _dataArray;
}
- (UIView *)coverView {
if (!_coverView) {
_coverView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5f];
}
return _coverView;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = CViewBgColor;
self.userlocationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// Request the desired authorization
[self.userlocationManager requestWhenInUseAuthorization];
self.isHidenNaviBar = true;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateHomeDate)
name:KNotificAgreeProtoocl
object:nil];
// [self createUI];
[self updateV2UI];
[self getUpDateinfo];
//请求banner图
[self getBannerListData];
self.page = 1;
[self verifyTokenData];
[self initCompleteBlock];
[self configLocationManager];
[self reGeocodeAction];
//请求手表数据
// 4. 添加 V2TIMSDKListener 的事件监听器,self 是 id<V2TIMSDKListener> 的实现类,如果您不需要监听 IM SDK 的事件,这个步骤可以忽略。
[[V2TIMManager sharedInstance] addIMSDKListener:self];
// 5. 初始化 IM SDK,调用这个接口后,可以立即调用登录接口。
[[V2TIMManager sharedInstance] addSimpleMsgListener:self];
[[TUICallEngine createInstance] addObserver:self];
}
#pragma mark:校验token
- (void)verifyTokenData {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
// 获取应用的版本号
HQUserInfo * user = [HQCommonUtils keyedUnarchiverWithKey:LoginUserInfo];
if (ValidStr(user.token)) {
[parmDic setObject:@"" forKey:@"token"];
}
else
{
[parmDic setObject:user.token forKey:@"token"];
}
XJPNetAPI * homeRemakerApi = [[XJPNetAPI alloc] init:self tag:@"verifyToken" NeedToken:@""];
[homeRemakerApi GetverifyToken:parmDic];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.polling = YES; //轮询开始
//请求token获取数据
[self verifyTokenData];
//登录了那就走轮询
if ([HQCommonUtils isLogin]) {
//请求消息列表
[self getMessageListData];
[self getUserWatchData];
}
}
- (void)reGeocodeAction
{
//进行单次带逆地理定位请求
[self.locationManager requestLocationWithReGeocode:YES completionBlock:self.completionBlock];
}
- (void)configLocationManager
{
self.locationManager = [[AMapLocationManager alloc] init];
[self.locationManager setDelegate:self];
//设置期望定位精度
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
//设置不允许系统暂停定位
[self.locationManager setPausesLocationUpdatesAutomatically:NO];
//设置允许在后台定位
[self.locationManager setAllowsBackgroundLocationUpdates:NO];
//设置定位超时时间
[self.locationManager setLocationTimeout:10];
//设置逆地理超时时间
[self.locationManager setReGeocodeTimeout:3];
//设置开启虚拟定位风险监测,可以根据需要开启
[self.locationManager setDetectRiskOfFakeLocation:NO];
}
- (void)cleanUpAction
{
//停止定位
[self.locationManager stopUpdatingLocation];
[self.locationManager setDelegate:nil];
}
#pragma mark:更新
- (void)getUpDateinfo {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
// 获取应用的版本号
[parmDic setObject:@"com.questionTools.XinjiangProject" forKey:@"packageName"];
[parmDic setObject:@"2" forKey:@"androidOrIos"];
XJPNetAPI * homeRemakerApi = [[XJPNetAPI alloc] init:self tag:@"UPVERSION" NeedToken:@""];
[homeRemakerApi GetAppVesionUpdata:parmDic];
}
- (void)initCompleteBlock
{
self.completionBlock = ^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error)
{
if (error != nil && error.code == AMapLocationErrorLocateFailed)
{
//定位错误
// var mCurrentLat = 34.327271
// var mCheckToken = false
// var mCurrentLon = 108.949845
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
[user setObject:@(87.627704) forKey:USERDEFAULLONG];
[user setObject:@(43.793026) forKey:USERDEFAULLATITUDE];
[user synchronize];
return;
}
else if (error != nil
&& (error.code == AMapLocationErrorReGeocodeFailed
|| error.code == AMapLocationErrorTimeOut
|| error.code == AMapLocationErrorCannotFindHost
|| error.code == AMapLocationErrorBadURL
|| error.code == AMapLocationErrorNotConnectedToInternet
|| error.code == AMapLocationErrorCannotConnectToHost))
{
//逆地理错误:在带逆地理的单次定位中,逆地理过程可能发生错误,此时location有返回值,regeocode无返回值,进行annotation的添加
}
else if (error != nil && error.code == AMapLocationErrorRiskOfFakeLocation)
{
//存在虚拟定位的风险:此时location和regeocode没有返回值,不进行annotation的添加
//存在虚拟定位的风险的定位结果
__unused CLLocation *riskyLocateResult = [error.userInfo objectForKey:@"AMapLocationRiskyLocateResult"];
//存在外接的辅助定位设备
__unused NSDictionary *externalAccressory = [error.userInfo objectForKey:@"AMapLocationAccessoryInfo"];
return;
}
else
{
//没有错误:location有返回值,regeocode是否有返回值取决于是否进行逆地理操作,进行annotation的添加
}
//有无逆地理信息,annotationView的标题显示的字段不一样
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
[user setObject:@(location.coordinate.longitude) forKey:USERDEFAULLONG];
[user setObject:@(location.coordinate.latitude) forKey:USERDEFAULLATITUDE];
[user synchronize];
};
}
- (void)backUp {
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)updateHomeDate {
if (self.homeTable) {
[self verifyTokenData]; //token
[self getBannerListData]; //banner
}else
{
}
}
- (void)getData {
[self showMBProgressHUDWithString:@"数据加载中,请稍候..." autoHidden:false];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(1) forKey:@"pageNo"];
[parmDic setObject:@(3) forKey:@"pageSize"];
XJPNetAPI * searchApi = [[XJPNetAPI alloc] init:self tag:@"RECOMMEND" NeedToken:@""];
[searchApi GetQuetsionRecordsList:parmDic];
}
#pragma mark:手表
- (void)getUserWatchData {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:User_ID forKey:@"userId"];
XJPNetAPI * searchApi = [[XJPNetAPI alloc] init:self tag:@"WEARWATCH" NeedToken:@""];
[searchApi getHomeWatchWearBool:parmDic];
}
#pragma mark:请求手表详情
- (void)getWatchDetailData {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
NSDate * localDate = [NSDate date];
NSString * str = [NSDate br_stringFromDate:localDate dateFormat:@"yyyy-MM-dd"];
[parmDic setObject:str forKey:@"date"];
XJPNetAPI * searchApi = [[XJPNetAPI alloc] init:self tag:@"WATCHDETAIL" NeedToken:@""];
[searchApi getHomeWatchData:parmDic];
}
- (void)Failed:(NSString*)message tag:(NSString*)tag
{
[self.mainScrollView.mj_footer endRefreshing];
[self.mainScrollView.mj_header endRefreshing];
MJWeakSelf
if ([tag isEqualToString:@"LIST"]) {
//请求失败 轮询? 看需求
// self.polling = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(120 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
if ([HQCommonUtils isLogin]) {
//请求消息列表
[weakSelf getMessageListData];
}
});
}
if ([tag isEqualToString:@"WEARWATCH"]) {
self.topView.watchArray = @[];
}
if ([tag isEqualToString:@"WEARWATCH"]) {
self.topView.watchArray = @[];
}
[self showMBProgressHUDOnlyWithString:message];
[self hiddenAllMBProgressHUD];
}
#pragma mark:请求结果
- (void)Sucess:(id)response tag:(NSString*)tag
{
[self.mainScrollView.mj_footer endRefreshing];
[self.mainScrollView.mj_header endRefreshing];
if ([tag isEqualToString:@"RECOMMEND"]) {
NSArray * array = response ;
if (self.page == 1) {
[self.dataArray removeAllObjects];
}
for (NSDictionary * dic in array) {
HomeQusetionRecordsModel * model = [HomeQusetionRecordsModel modelWithDictionary:dic];
[self.dataArray addObject:model];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.view.window) return;
self.homeTable.dataArray = self.dataArray;
});
[self hiddenAllMBProgressHUD];
}
if ([tag isEqualToString:@"verifyToken"]) {
BOOL isLogin = [response boolValue];
if (isLogin == true) {
[self getData];
}
}
if ([tag isEqualToString:@"IMAPI"]) {
[self hiddenAllMBProgressHUD];
NSDictionary * pamrDic = response;
IMUserInfoModel * model = [IMUserInfoModel modelWithDictionary:pamrDic];
IMUserInfoModel * iminfoModel = [[IMUserInfoModel alloc] init];
iminfoModel.IMInfo = pamrDic;
[HQCommonUtils keyedArchiverWithData:iminfoModel key:IMLoginUserInfo];
// 1. 从即时通信 IM 控制台获取应用 SDKAppID。
// 2. 初始化 config 对象
V2TIMSDKConfig *config = [[V2TIMSDKConfig alloc] init];
// 3. 指定 log 输出级别。
config.logLevel = V2TIM_LOG_INFO;
// 4. 添加 V2TIMSDKListener 的事件监听器,self 是 id<V2TIMSDKListener> 的实现类,如果您不需要监听 IM SDK 的事件,这个步骤可以忽略。
[[V2TIMManager sharedInstance] addIMSDKListener:self];
// 5. 初始化 IM SDK,调用这个接口后,可以立即调用登录接口。
[[V2TIMManager sharedInstance] initSDK:[model.sdkAppId intValue] config:config];
config.logLevel = V2TIM_LOG_INFO;
[TUILogin login:[model.sdkAppId intValue] userID:model.userId userSig:model.userSig succ:^{
} fail:^(int code, NSString *msg) {
[EasyTextView showErrorText:msg];
}];
}
if ([tag isEqualToString:@"SMALLHELP"]) {
[self hiddenAllMBProgressHUD];
SmallHelpIMDataModel * model = [SmallHelpIMDataModel modelWithDictionary:response];
ChatViewController * chatVC = [[ChatViewController alloc] init];
chatVC.isGroupID = YES;
chatVC.chatID = model.groupId;
chatVC.smallHelp_id = model.small_id;
chatVC.isVideo = false;
chatVC.eableSendReport = YES;
chatVC.eableMapTools = false;
chatVC.navTitle = @"全科医生";
chatVC.eablehaveHelathData = YES;
chatVC.tfNew = model.tfNew;
[self.navigationController pushViewController:chatVC animated:YES];
}
if ([tag isEqualToString:@"loginIMAPI"]) {
[self hiddenAllMBProgressHUD];
NSDictionary * pamrDic = response;
IMUserInfoModel * model = [IMUserInfoModel modelWithDictionary:pamrDic];
IMUserInfoModel * iminfoModel = [[IMUserInfoModel alloc] init];
iminfoModel.IMInfo = pamrDic;
[HQCommonUtils keyedArchiverWithData:iminfoModel key:IMLoginUserInfo];
[ESCTUIManager loginInitTUISDKAppidWith:[model.sdkAppId intValue] UserID:model.userId userSig:model.userSig];
[self smallQuestionAction];
}
if ([tag isEqualToString:@"loginIMList"]) {
[self hiddenAllMBProgressHUD];
NSDictionary * pamrDic = response;
IMUserInfoModel * model = [IMUserInfoModel modelWithDictionary:pamrDic];
IMUserInfoModel * iminfoModel = [[IMUserInfoModel alloc] init];
iminfoModel.IMInfo = pamrDic;
[HQCommonUtils keyedArchiverWithData:iminfoModel key:IMLoginUserInfo];
[ESCTUIManager loginInitTUISDKAppidWith:[model.sdkAppId intValue] UserID:model.userId userSig:model.userSig];
ChatViewController * chatVC = [[ChatViewController alloc] init];
chatVC.isGroupID = YES;
chatVC.chatID = self.recomendModel.imId ;
chatVC.eableSendReport = true;
chatVC.eablehaveHelathData = false;
chatVC.navTitle = @"图文咨询";
chatVC.isVideo = NO;
chatVC.pictureEnd_id = self.recomendModel.records_id;
chatVC.questionType = 2;
chatVC.medicalRecordsId = self.recomendModel.memberId;
if ([self.recomendModel.contentStatus intValue] == 5) {
chatVC.isEveal = true;
}else
{
chatVC.isEveal = false;
}
if ([self.recomendModel.contentStatus intValue] >=4 ) {
chatVC.endRecordType = 100;
}
[self.navigationController pushViewController:chatVC animated:YES];
}
if ([tag isEqualToString:@"UPVERSION"]) {
NSDictionary * dic = response;
UPAppVesionModel * model = [UPAppVesionModel modelWithDictionary:dic];
// 避免1.0.10 跟 1.0.1 出错
NSString *version =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *versionCode =
[version stringByReplacingOccurrencesOfString:@"." withString:@""];
NSInteger loctaionVesion = [versionCode integerValue];
NSDictionary * infoDic = @{
@"version":[NSString stringWithFormat:@"%@",model.versionName] ,
@"releaseNotes":model.updateContent,
@"currentVersionReleaseDate":model.updateTime};
PSAppInfo * info = [[PSAppInfo alloc] initWithDict:infoDic];
//是否需要强制更新
BOOL isNeed = [model.forced integerValue] == 1 ? YES : NO;
if ( model.versionNo > loctaionVesion) {
[self show:info isNeedUpdate:isNeed];
}else
{
DLog(@"不需要更新");
}
}
if ([tag isEqualToString:@"BANNER"]) {
NSArray * array = response;
//自己处理数据
[self customBannerData:array];
}
if ([tag isEqualToString:@"LIST"]) {
//请求成功 yes 继续轮询
DLog(@"轮询111---%@",response);
[self hiddenAllMBProgressHUD];
NSArray * array = response;
NSMutableArray * dataArray = [[NSMutableArray alloc] init];
for (NSDictionary * dic in array) {
MyMessageModel * model = [MyMessageModel modelWithDictionary:dic];
[dataArray addObject:model];
}
MJWeakSelf
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.view.window) return;
self.topView.dataArray = dataArray;
});
// ⭐️ 成功后 2 分钟再轮询
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(120 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
if ([HQCommonUtils isLogin]) {
//请求消息列表
[weakSelf getMessageListData];
}
});
}
if ([tag isEqualToString:@"WEARWATCH"]) {
NSDictionary * responseDic = response;
XJHomeWatchModel * model = [XJHomeWatchModel modelWithDictionary:responseDic];
//有手表再去调数据
if (model.hasWatch == true) {
self.topView.model = model;
//请求手表数据
[self getWatchDetailData];
}else
{
self.topView.watchArray = @[];
//没手表直接显示没佩戴
}
}
if ([tag isEqualToString:@"WATCHDETAIL"]) {
// 数据类型:0=心率 1=血氧 2=压力 3=体温 4=睡眠
NSArray *array = response;
// 容错:接口返回非数组时不处理
if (!ValidArray(array)) {
self.topView.watchArray = @[];
return;
}
NSMutableArray *dataArray = [[NSMutableArray alloc] init];
for (NSDictionary *dic in array) {
// 容错:过滤非字典数据
if (!ValidDict(dic)) continue;
XJHomeWatchModel *model = [XJHomeWatchModel modelWithDictionary:dic];
// 容错:type 不在有效范围 0-4 内的数据丢弃
NSInteger type = [model.type intValue];
if (type < 0 || type > 4) continue;
[dataArray addObject:model];
}
// 按 type 升序排列,保证 collectionView 顺序固定为 0→1→2→3→4
NSArray *sortedArray = [dataArray sortedArrayUsingComparator:^NSComparisonResult(XJHomeWatchModel *a, XJHomeWatchModel *b) {
return [@([a.type intValue]) compare:@([b.type intValue])];
}];
self.topView.watchArray = sortedArray;
}
}
//是否需要更新
- (void)show:(PSAppInfo *)info isNeedUpdate:(BOOL)isNeed {
__weak typeof(self)weakSelf = self;
if(isNeed == true) { //强制更新
self.checkVersionView = [[PSCheckVersionView alloc]
initWithAppInfo:info
confirm:^{
[weakSelf jumpAppStoreUpdate];
}];
}else {
self.checkVersionView = [[PSCheckVersionView alloc] initWithAppInfo:info confirm:^{
[weakSelf jumpAppStoreUpdate];
} cancel:^{
[self.coverView removeFromSuperview];
}];
}
[self.coverView addSubview:self.checkVersionView];
[self.checkVersionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(self.coverView).multipliedBy(0.75);
make.height.equalTo(self.coverView).multipliedBy(0.33);
make.center.equalTo(self.coverView);
}];
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:self.coverView];
}
#pragma mark: 强制退出
- (void)jumpAppStoreUpdate {
//强制退出
exit(0);
}
#pragma mark:小助手的回调
- (void)loginImAccount {
XJPNetAPI * proctocolApi = [[XJPNetAPI alloc] init:self tag:@"loginIMAPI" NeedToken:nil];
[proctocolApi GetIMLoginAccount:nil];
}
#pragma mark:列表点击回调
- (void)loginImAccountList {
XJPNetAPI * proctocolApi = [[XJPNetAPI alloc] init:self tag:@"loginIMList" NeedToken:nil];
[proctocolApi GetIMLoginAccount:nil];
}
#pragma mark:医生列表点击事件
- (void)doctorListClick:(NSString *)doctorID {
XJExpertMainViewController * mainVC = [[XJExpertMainViewController alloc] init];
mainVC.doctorId = doctorID;
[self.navigationController pushViewController:mainVC animated:YES];
}
#pragma mark:找专家 小助手 我的咨询
- (void)foundQuestionAction {
RoomDoctorRecordsVC * foundVC = [[RoomDoctorRecordsVC alloc] init];
[self.navigationController pushViewController:foundVC animated:true];
}
- (void)smallQuestionAction {
if ([ESCTUIManager TUIUserStatus] == false) {
[self loginImAccount];
return;
}
NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
[self showMBProgressHUDWithString:@"咨询中,请稍候..." autoHidden:NO];
XJPNetAPI * searchApi = [[XJPNetAPI alloc] init:self tag:@"SMALLHELP" NeedToken:@""];
[searchApi postSmallHelpGroup:dic];
}
- (void)myQuestionAction {
XJQustionRecordViewController * myVC = [[XJQustionRecordViewController alloc] init];
[self.navigationController pushViewController:myVC animated:true];
}
//在线时票据过期:此时您需要生成新的 userSig,并再次重新调用初始化。
- (void)onKickedOffline {
[HQCommonUtils keyedArchiverWithData:nil key:LoginUserInfo];
[ESCTUIManager outLoginTUISDK];
KPostNotification(KNotificationLoginStateChange, @NO);
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusNotDetermined:
// 用户还未决定是否授权
break;
case kCLAuthorizationStatusRestricted:
// 位置服务被限制(例如家长控制)
[self handleLocationServicesRestricted];
break;
case kCLAuthorizationStatusDenied:
// 用户拒绝了位置权限
[self showAlertToOpenSettings];
break;
case kCLAuthorizationStatusAuthorizedAlways:
case kCLAuthorizationStatusAuthorizedWhenInUse:
// 用户授权了位置权限
// [self startLocationUpdates];
break;
default:
break;
}
}
- (void)handleLocationServicesRestricted {
// 处理位置服务受限的情况
DLog(@"位置服务被限制");
[self showAlertToOpenSettings];
}
- (void)handleLocationServicesDenied {
// 处理位置服务被拒绝的情况
DLog(@"位置服务被拒绝");
[self showAlertToOpenSettings];
}
- (void)handleLocationServicesDisabled {
// 处理设备的定位服务被禁用的情况
DLog(@"设备的定位服务被禁用");
[self showAlertToOpenSettings];
}
- (void)showAlertToOpenSettings {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"定位服务已关闭"
message:@"请在设置中启用定位服务"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settingsURL]) {
[[UIApplication sharedApplication] openURL:settingsURL options:@{} completionHandler:nil];
}
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:settingsAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
//更新一版scrollview
- (void)updateV2UI {
self.mainScrollView = [[UIScrollView alloc] init];
self.mainScrollView.backgroundColor = CViewBgColor;
self.mainScrollView.showsVerticalScrollIndicator = false;
self.mainScrollView.showsHorizontalScrollIndicator = false;
self.mainScrollView.contentInset = UIEdgeInsetsZero; // 让 scrollView 从顶部开始
self.mainScrollView.scrollIndicatorInsets = UIEdgeInsetsZero; // 滚动指示器也不受影响
self.mainScrollView.contentSize = CGSizeMake(kScreenWidth, kScreenHeight - kTabBarHeight);
// 如果使用自动调整
if (@available(iOS 11.0, *)) {
self.mainScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[self.view addSubview:self.mainScrollView];
// 创建一个 contentView(所有内容都加在这个 view 上)
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = CViewBgColor;
self.contentView = contentView;
[self.mainScrollView addSubview:contentView];
// 约束 UIScrollView
[self.mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.mas_offset(0);
}];
// 约束 contentView
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.mainScrollView); // contentView 贴合 UIScrollView 的四边
make.width.equalTo(self.mainScrollView); // **宽度等于 UIScrollView**,防止横向滚动
}];
MJWeakSelf
self.mainScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
self.page = 1;
[self getBannerListData];
if ([HQCommonUtils isLogin]) {
//请求消息列表
[self getUserWatchData];
}
[self verifyTokenData];
}];
XJHomePageV2HeardView * topView = [[XJHomePageV2HeardView alloc] initWithFrame:CGRectZero];
self.topView = topView;
topView.homeTopDelegate = self;
[self.contentView addSubview:topView];
//
[topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_offset(0);
}];
self.homeTable = [[XJHomePageV2QuestionTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
if (@available(iOS 15.0, *)) {
self.homeTable.sectionHeaderTopPadding = 0;
}
self.homeTable.backgroundColor = KWhiteColor;
self.homeTable.scrollEnabled = NO;
self.homeTable.sectionFooterHeight = CGFLOAT_MIN;
[self.contentView addSubview:self.homeTable];
MASConstraint *tableHeightConstraint;
[self.homeTable mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(topView.mas_bottom);
make.left.mas_offset(12);
make.right.mas_offset(-12);
self.tableHeightConstraint = make.height.mas_equalTo(kEmptyTableMinHeight);
}];
//代理
self.homeTable.headDelegate = self;
//监听
[self.homeTable addObserver:self
forKeyPath:@"contentSize"
options:NSKeyValueObservingOptionNew
context:nil];
kWeakSelf(self);
self.homeTable.lookMoreBlock = ^{
if(![HQCommonUtils isLogin]) {
KPostNotification(KNotificationLoginStateChange, @NO);
return;
}
[weakself myQuestionAction];
};
//初始化一个emptyView
LYEmptyView *emptyView = [LYEmptyView emptyViewWithImage:[UIImage imageNamed:@"noQuetionList"]
titleStr:@"暂无咨询记录" detailStr:@""];
//元素竖直方向的间距
emptyView.titleLabMargin = kRealValue(5);
emptyView.contentViewY = kRealValue(80);
emptyView.backgroundColor = KWhiteColor;
emptyView.imageSize = CGSizeMake(kRealValue(101), kRealValue(60));
//标题颜色
emptyView.titleLabTextColor =UIColorHex(#14BEBE);
//描述字体
emptyView.titleLabFont = [UIFont systemFontOfSize:15];
//按钮背景色
//设置空内容占位图
self.homeTable.ly_emptyView = emptyView;
XJHomePageV2BottomTools * bottomTools = [[XJHomePageV2BottomTools alloc] init];
bottomTools.backgroundColor = CViewBgColor;
[self.contentView addSubview:bottomTools];
[bottomTools mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.homeTable.mas_bottom).offset(-1);
make.left.right.mas_offset(0);
make.height.mas_offset(124);
}];
bottomTools.imgeBlock = ^(NSInteger imgIndex) {
EmptyFunctionDevelopmentVC * vc = [[EmptyFunctionDevelopmentVC alloc] init];
if (imgIndex == 1) {
vc.navigationItem.title = @"智慧体重";
}
if (imgIndex == 2) {
vc.navigationItem.title = @"一人一案";
}
[self.navigationController pushViewController:vc animated:YES];
};
//最下面的一张图
// self.aiImage = [[UIImageView alloc] init];
//// self.aiImage.image = [UIImage imageNamed:@"bottomAIImg"];
// self.aiImage.userInteractionEnabled = true;
// [self.contentView addSubview:self.aiImage];
self.AIBannerImage = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
self.AIBannerImage.backgroundColor = KClearColor;
self.AIBannerImage.placeholderImage = nil;
self.AIBannerImage.delegate = self;
self.AIBannerImage.layer.cornerRadius = 12;
self.AIBannerImage.layer.masksToBounds = true;
self.AIBannerImage.currentPageDotImage = [UIImage imageNamed:@"pageControlDot"];
self.AIBannerImage.pageDotImage = [UIImage imageNamed:@"pageControlNomalDot"];
self.AIBannerImage.pageDotColor = KWhiteColor;
self.AIBannerImage.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
self.AIBannerImage.pageControlDotSize = CGSizeMake(6, 4);
[self.contentView addSubview:self.AIBannerImage];
[self.AIBannerImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(12);
make.right.mas_offset(-12);
make.top.mas_equalTo(bottomTools.mas_bottom).offset(2);
make.height.mas_offset(120);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-18);
}];
}
// 计算table的高度
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (object == self.homeTable &&
[keyPath isEqualToString:@"contentSize"]) {
CGFloat height = self.homeTable.contentSize.height;
// 空数据
if (self.dataArray.count <= 0) {
height = kEmptyTableMinHeight;
}
[self.tableHeightConstraint uninstall];
[self.homeTable mas_makeConstraints:^(MASConstraintMaker *make) {
self.tableHeightConstraint = make.height.mas_equalTo(height);
}];
}
}
-(void)SDCycleScrollViewItemClick {
BannarDetailViewController * detailVC = [[BannarDetailViewController alloc] init];
[self.navigationController pushViewController:detailVC animated:YES];
}
#pragma mark: 请求banner图
- (void)getBannerListData {
NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
//2 首页Banner
XJPNetAPI * searchApi = [[XJPNetAPI alloc] init:self tag:@"BANNER" NeedToken:@""];
[searchApi getHomeBannerAllData:dic];
}
#pragma mark: 请求消息列表
- (void)getMessageListData {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(1) forKey:@"pageNo"];
[parmDic setObject:@"10" forKey:@"pageSize"];
XJPNetAPI * listApi = [[XJPNetAPI alloc] init:self tag:@"LIST" NeedToken:@""];
[listApi getUserMessageList:parmDic];
}
#pragma mark:消息轮播点击
- (void)SDTitleItemClick {
MyMessageListViewController * messageVC = [[MyMessageListViewController alloc] init];
[self.navigationController pushViewController:messageVC animated:YES];
}
#pragma mark:工具类
-(void)heardTopToolsClick:(NSInteger)type {
if (type == 0) {
EmptyFunctionDevelopmentVC * vc = [[EmptyFunctionDevelopmentVC alloc] init];
vc.navigationItem.title = @"健康档案";
[self.navigationController pushViewController:vc animated:YES];
}
if (type == 1) {
EmptyFunctionDevelopmentVC * vc = [[EmptyFunctionDevelopmentVC alloc] init];
vc.navigationItem.title = @"健康体检";
[self.navigationController pushViewController:vc animated:YES];
}
if (type == 2) {
if(![HQCommonUtils isLogin]) {
KPostNotification(KNotificationLoginStateChange, @NO);
return;
}
KPostNotification(KNotificSelectSOSCenterTabbar,nil);
// XJSOSLookDoctoreViewController * vc = [[XJSOSLookDoctoreViewController alloc] init];
// [self.navigationController pushViewController:vc animated:YES];
}
if (type == 3) {
EmptyFunctionDevelopmentVC * vc = [[EmptyFunctionDevelopmentVC alloc] init];
vc.navigationItem.title = @"健康银行";
[self.navigationController pushViewController:vc animated:YES];
}
}
#pragma mark:图片点击
- (void)heardImageClick:(NSInteger)imageIndex {
if (imageIndex == 50) {
EmptyFunctionDevelopmentVC * vc = [[EmptyFunctionDevelopmentVC alloc] init];
vc.navigationItem.title = @"体检套餐";
[self.navigationController pushViewController:vc animated:YES];
}
if (imageIndex == 51) {
BannarDetailViewController * detailVC = [[BannarDetailViewController alloc] init];
[self.navigationController pushViewController:detailVC animated:YES];
}
if (imageIndex == 52) {
KPostNotification(KNotificSelectQuestionTabbar,nil);
}
}
#pragma mark:点击
- (void)aiImageTap {
EmptyFunctionDevelopmentVC * vc = [[EmptyFunctionDevelopmentVC alloc] init];
vc.navigationItem.title = @"AI随访";
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark:处理数据
- (void)customBannerData:(NSArray *)dataArray {
NSMutableArray * bannerArray = [[NSMutableArray alloc] init];
NSMutableArray * AIArray = [[NSMutableArray alloc] init];
for (NSDictionary * dic in dataArray) {
HomeBannerModel * model = [HomeBannerModel modelWithDictionary:dic];
//直接处理图片吧
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] == 4) {
[AIArray addObject:encodedString3];
}
[bannerArray addObject:model];
}
self.topView.bannerArray = bannerArray;
self.AIBannerImage.imageURLStringsGroup = AIArray;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
[self aiImageTap];
}
- (void)watchDetailClick {
if([HQCommonUtils isLogin]) {
KPostNotification(KNotificSelectWatchTabbar,nil);
}else
{
KPostNotification(KNotificationLoginStateChange, @NO);
}
}
#pragma mark:退出页面停止轮询
//- (void)viewWillDisappear:(BOOL)animated {
// [super viewWillDisappear:animated];
// [self stopPolling];
//}
//
//- (void)stopPolling {
// if (self.timer) {
// dispatch_source_cancel(self.timer);
// self.timer = nil;
// }
//}
//
//- (void)startPolling {
// if (self.timer) return; // 防止重复创建
//
// 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_time(DISPATCH_TIME_NOW, 0),
// 120 * NSEC_PER_SEC,
// 1 * NSEC_PER_SEC);
//
// __weak typeof(self) weakSelf = self;
// dispatch_source_set_event_handler(self.timer, ^{
// [weakSelf getMessageListData];
// });
//
// dispatch_resume(self.timer);
//}
@end