You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

460 lines
16 KiB

//
// HomeViewController.m
// LekangGuard
//
// Created by ecell on 2022/9/27.
//
#import "HomeViewController.h"
#import "ScanCodeViewController.h"
#import "HomeTableViewCell.h"
#import "HomeHeaderView.h"
#import "HAndTViewController.h"
#import "JCManager.h"
#import "BRManager.h"
#import "TihuManager.h"
#import <JCSDKOC/JCSDKOC.h>
@interface HomeViewController ()<YBPopupMenuDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic ,strong) CommonTableView *homeTable;
@property (nonatomic ,strong) HomeHeaderView *headerView;
/// 设备列表Arr
@property (nonatomic ,strong) NSMutableArray *deviceListArr;
@property (nonatomic ,strong) NSMutableArray *cellMenuArr;
@property (nonatomic ,strong) LatestLocationModel *laloModel;
@end
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = KKBackgroundGrey;
self.zx_navStatusBarStyle = ZXNavStatusBarStyleDefault;
self.zx_navLeftBtn.titleLabel.font = FontBoldADA_(18);
[self.zx_navLeftBtn setTitleColor:KKWhiteColorColor forState:0];
UIImageView *bgImg = [UICommon ui_imageView:self.view.frame fileName:@"home_bg"];
self.ImgType = HomeNoWhat;
self.emptyTitle = GJText(@"您还没有绑定设备");
self.emptyText = GJText(@"赶快去绑定一个设备体验一下吧!");
self.buttonTitle = GJText(@"添加设备");
self.buttonImg = ImageName_(@"home_addBtn");
// [self.view addSubview:bgImg];
// self.zx_navRightBtn.zx_fixImageSize = ImageName_(@"home_icon_add").size;
// self.zx_navRightBtn.zx_fixWidth = 40;
// self.zx_navRightBtn.zx_fixHeight = 40;
[self zx_setRightBtnWithImg:ImageName_(@"home_icon_add") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
[self isShowMenu];
}];
// [self zx_setSubRightBtnWithImgName:@"home_nav_sign" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
//// SingViewController *vc = [[SingViewController alloc] init];
//// [self.navigationController pushViewController:vc animated:YES];
// }];
[self setTotal];
[self QueryMsg];
[self GetBannerList];
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UPDATA_DeviceList object:nil] subscribeNext:^(NSNotification *x) {
[self GetDeviceList];
}];
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"updateBatteryAndLocation" object:nil] subscribeNext:^(NSNotification *x)
{
[self GetLatest:APIManager.sharedManager.deviceModel.imei];
}];
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"deviceNowLocation" object:nil] subscribeNext:^(NSNotification *x)
{
[self GetLatest:APIManager.sharedManager.deviceModel.imei];
}];
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"XIAOHONGHUA" object:nil] subscribeNext:^(NSNotification *x) {
[self getHomeWorkCount];
[self getReadFlowerCount];
}];
[self.view addSubview:self.homeTable];
[self.homeTable mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view.mas_bottom);
}];
// NSLog(@"%f",iPhoneX_NavHeight);
}
/// 收到推送聊天信息
- (void)pusChatMessage:(NSDictionary *)chatModel
{
[self.headerView GetUnreadTotal];
}
- (CommonTableView *)homeTable
{
if (!_homeTable)
{
kWeakSelf(self)
_homeTable = [[CommonTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain cellHeight:0 cellRow:0 isAdaptive:NO isLine:NO commonCell:HomeTableViewCell.class createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) {
HomeTableViewCell *cell = (HomeTableViewCell *)cells;
if (indexPath.row < weakself.cellMenuArr.count)
{
cell.titleStr = weakself.cellMenuArr[indexPath.row];
cell.laLoModel = self.laloModel;
}
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
NSString *title = self.cellMenuArr[indexPath.row];
HAndTViewController *vc = [HAndTViewController new];
vc.type = [title isEqualToString:GJText(@"心率")] ? 1 : 2;
[self.navigationController pushViewController:vc animated:YES];
} DidscrollView:^(UIScrollView * _Nonnull scrollView) {
}];
_homeTable.tableHeaderView = self.headerView;
_homeTable.tableHeaderView.height = Adapted(170)+230+25+28;
_homeTable.backgroundColor = KKClearColor;
[_homeTable bindHeadRefreshHandler:^{
[self GetDeviceList];
[self GetBannerList];
} themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody];
}
return _homeTable;
}
- (HomeHeaderView *)headerView
{
if (!_headerView)
{
_headerView = [HomeHeaderView new];
_headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Adapted(170)+230+25+28);
}
return _headerView;
}
- (void)isShowMenu
{
kWeakSelf(self)
[DeviceSwitchover.sharedManager showMenuViewWithAdd:YES];
[DeviceSwitchover.sharedManager setSwitchDevice:^(NSInteger index) {
if (index == 0)
{
ScanCodeViewController *vc = [ScanCodeViewController new];
[weakself.navigationController pushViewController:vc animated:YES];
}
else
{
DeviceModel *model = weakself.deviceListArr[index-1];
[weakself GetDeviceMenu:model];
}
}];
}
#pragma mark 获取设备列表
/// 获取设备列表
- (void)GetDeviceList
{
kWeakSelf(self)
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[[[APIManager sharedManager] APGET:BindDevice_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) {
[UICommon HidenLoading];
[self.homeTable.headRefreshControl endRefreshing];
[self.deviceListArr removeAllObjects];
self.deviceListArr = APIManager.sharedManager.deviceList;
if (arr.count > 0)
{
weakself.homeTable.emptyDataSetSource = nil;
weakself.homeTable.emptyDataSetDelegate = nil;
if (STRINGHASVALUE(APIManager.sharedManager.deviceModel.imei))
{
// [self.deviceListArr enumerateObjectsUsingBlock:^(DeviceModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
//
// }];
BOOL isY = NO;
for (DeviceModel *obj in self.deviceListArr)
{
if ([obj.imei isEqualToString:APIManager.sharedManager.deviceModel.imei])
{
isY = YES;
[self GetDeviceMenu:obj];
break;
}
}
if (!isY)
{
DeviceModel *model = [DeviceModel yy_modelWithJSON:arr[0]];
[self GetDeviceMenu:model];
}
}
else
{
DeviceModel *model = [DeviceModel yy_modelWithJSON:arr[0]];
[self GetDeviceMenu:model];
}
}
else
{
[self GetDeviceMenu:[DeviceModel new]];
weakself.homeTable.emptyDataSetSource = self;
weakself.homeTable.emptyDataSetDelegate = self;
}
self.homeTable.tableHeaderView.height = arr.count == 0 ? Adapted(170) : Adapted(170)+230+25+28;
self.headerView.isDev = arr.count == 0 ? YES : NO;
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
[self.homeTable.headRefreshControl endRefreshing];
}];
}
#pragma mark 动态显示设备功能列
/// 动态显示设备功能列
- (void)GetDeviceMenu:(DeviceModel *)model
{
APIManager.sharedManager.deviceModel = model;
[APIManager.sharedManager.cache setObject:model forKey:sDeviceKey];
[self.zx_navLeftBtn setTitle:model.name forState:0];
self.headerView.devicemodel = model;
[self GetLatest:model.imei];
[self GetLatestInstructions:model.imei];
if (!APIManager.sharedManager.deviceModel.virtualFlag)
{
[self getHomeWorkCount];
[self getReadFlowerCount];
}
[self.homeTable reloadData];
/// 视频类型名称(0.不支持,1.菊风,2.声网,3.佰锐,4.鹈鹕)
if (model.videoModelName == 1)
{
// 拥有菊风的设备,需要登录 账号 (调试时期暂时停止)
if(![JCManager shared].client)
{
// if([[JCManager shared] initializeWithAPPKey:model.appKey])
// {
// JCClientLoginParam* loginParam = [[JCClientLoginParam alloc] init];
// //loginParam.directConnectEnable = YES;
// [[JCManager shared].client setServerAddress:@"http:cn.router.justalkcloud.com:8080"];
// [[JCManager shared].client login:APIManager.sharedManager.loginModel.openid password:@"test" loginParam:nil];
// [JCManager shared].gMianVC = self;
// NSLog(@"菊风账号是:%@", APIManager.sharedManager.loginModel.openid);
// }
}
}
else if (model.videoModelName == 3)
{
// 拥有佰锐的设备,需要登录 账号
if (![[BRManager shared] isUserLogin]) {
[[BRManager shared] initialize];
[BRManager shared].gMianVC = self;
[[BRManager shared] login:model.baiRuiId nick:model.name];
} else {
NSLog(@"====================>佰锐视频账号已经登录");
}
}
else if (model.videoModelName == 2)
{
}
else if (model.videoModelName == 4)
{
// 拥有鹈鹕的设备,需要登录账号
if (![[TihuManager shared] isUserLogin]) {
[[TihuManager shared] initialize];
[TihuManager shared].gMianVC = self;
[[TihuManager shared] login:APIManager.sharedManager.loginModel.openid pwd:@"123456"];
NSLog(@"鹈鹕账号是:%@", APIManager.sharedManager.loginModel.openid);
} else {
NSLog(@"====>鹈鹕视频账号已经登录");
}
}
}
#pragma mark 获取banner图
/// 获取banner图
- (void)GetBannerList
{
[UICommon MessageUpload:GJText(@"加载中")];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[[[APIManager sharedManager] APPOST:Home_banner_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(NSArray *x) {
[UICommon HidenLoading];
if (ARRAYHASVALUE(x))
{
NSMutableArray *bannerArr = [NSMutableArray new];
for (NSDictionary *dic in x)
{
BannerModel *model = [BannerModel yy_modelWithJSON:dic];
[bannerArr addObject:model.banner];
}
self.headerView.bannerArr = bannerArr;
}
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 获取设备最新位置信息
/// 获取设备最新位置信息
- (void)GetLatest:(NSString *)imei
{
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[[[APIManager sharedManager] APGET:F(@"%@/%@", Latest_location_app_URL,imei) parameters:parameters resultClass:LatestLocationModel.class] subscribeNext:^(LatestLocationModel *model) {
[UICommon HidenLoading];
self.laloModel = model;
self.headerView.laLoModel = model;
[self.homeTable reloadData];
NSLog(@"-->%@",model);
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 主动请求位置下发
/// 主动请求位置下发
- (void)GetLatestInstructions:(NSString *)imei
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[[[APIManager sharedManager] APGET:F(@"%@/%@", Latest_location_app_instructions_URL,imei) parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
NSLog(@"-->%@",x);
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 查看个人资料
/// 查看个人资料
- (void)QueryMsg
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APGET:QueryMsg_URL parameters:parameters resultClass:MyUserMsgModel.class] subscribeNext:^(MyUserMsgModel *model) {
[UICommon HidenLoading];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 用户活跃度统计上传
/// 用户活跃度统计上传
- (void)setTotal
{
// NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
// NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
// [parameters setValue:@"lekangshouhu" forKey:@"channelName"];
// [parameters setValue:version forKey:@"version"];
// [[[APIManager sharedManager] APGET:Total_URL parameters:parameters resultClass:MyUserMsgModel.class] subscribeNext:^(MyUserMsgModel *model) {
// [UICommon HidenLoading];
//
// } error:^(NSError * _Nullable error) {
// NSDictionary *dic = error.userInfo;
// [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
// }];
}
#pragma mark 查询未读作业总数
/// 查询未读作业总数
- (void)getHomeWorkCount
{
kWeakSelf(self)
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APGET:HomeWorkCount_GET_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
// NSNumber *campusCount = x[@"campusCount"];
self.headerView.homeWokeCount = x[@"homeWokeCount"];
[weakself.homeTable reloadData];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 查询小红花未读总数
/// 查询小红花未读总数
- (void)getReadFlowerCount
{
kWeakSelf(self)
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APGET:ReadFlowerCount_GET_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
weakself.headerView.redTotalCount = x[@"totalCount"];
[weakself.homeTable reloadData];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
- (NSMutableArray *)deviceListArr
{
if (!_deviceListArr) _deviceListArr = [NSMutableArray new];
return _deviceListArr;
}
- (NSMutableArray *)cellMenuArr
{
if (!_cellMenuArr) _cellMenuArr = [NSMutableArray new];
return _cellMenuArr;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self GetDeviceList];
}
- (void)updateAllMessage
{
[self GetDeviceList];
}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button
{
ScanCodeViewController *vc = [ScanCodeViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end