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.

283 lines
10 KiB

2 years ago
//
// MoreServiceViewController.m
// LekangGuard
//
// Created by ecell on 2022/10/19.
//
#import "MoreServiceViewController.h"
#import "MoreMenuTitleView.h"
#import "FunctionView.h"
#import "DeviceSetView.h"
@interface MoreServiceViewController ()
@property (nonatomic ,strong) UIScrollView *menuScroll;
@property (nonatomic ,strong) NSMutableArray *menuArr;
@property (nonatomic ,strong) NSMutableArray *menuImgArr;
@property (nonatomic ,assign) DeviceSetView *setView;
@end
@implementation MoreServiceViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = KKBackgroundGrey;
self.zx_navTitle = GJText(@"更多服务");
[self setMenu];
[self.view addSubview:self.menuScroll];
[self.menuScroll mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.bottom.equalTo(self.view.mas_bottom);
}];
[self SubOneView];
}
- (void)SubOneView
{
MoreMenuTitleView *titleView = [[MoreMenuTitleView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 30)];
titleView.titleStr = GJText(@"常用功能");
[self.menuScroll addSubview:titleView];
CGFloat sizes = (SCREEN_WIDTH-65)/4;
CGFloat hh = 0;
if (self.menuImgArr.count > 0 && self.menuImgArr.count < 5) hh = sizes;
else if (self.menuImgArr.count > 4 && self.menuImgArr.count < 9) hh = sizes*2+20;
else if (self.menuImgArr.count > 8 && self.menuImgArr.count < 13) hh = sizes*3+20;
else if (self.menuImgArr.count > 12 && self.menuImgArr.count < 17) hh = sizes*4+35;
else if (self.menuImgArr.count > 16 && self.menuImgArr.count < 21) hh = sizes*5+50;
else if (self.menuImgArr.count > 20 && self.menuImgArr.count < 25) hh = sizes*6+65;
FunctionView *funView = [[FunctionView alloc] initWithFrame:CGRectMake(0, titleView.bottom+5, SCREEN_WIDTH, hh)];
funView.imgArr = self.menuImgArr;
funView.titleArr = self.menuArr;
[self.menuScroll addSubview:funView];
[self subTwoView:funView];
}
- (void)subTwoView:(UIView *)views
{
MoreMenuTitleView *titleView = [[MoreMenuTitleView alloc] initWithFrame:CGRectMake(0, views.bottom+10, SCREEN_WIDTH, 30)];
titleView.titleStr = GJText(@"设备设置");
[self.menuScroll addSubview:titleView];
DeviceSetView *setView = [[DeviceSetView alloc] initWithFrame:CGRectMake(0, titleView.bottom+5, SCREEN_WIDTH, [APIManager sharedManager].deviceModel.dial ? Adapted(165) : Adapted(110))];
self.setView = setView;
[self.menuScroll addSubview:setView];
setView.isOpenState = ^{
[super updataNotificat];
};
[setView DevicePosition];
/// 远程关机
UIButton *shutdownBtn = [UICommon ui_buttonSimple:CGRectMake(10, setView.bottom+Adapted(60), SCREEN_WIDTH-20, Adapted(44)) font:FontADA_(15) normalColor:KKWhiteColorColor normalText:GJText(@"远程关机") click:^(id x) {
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"远程关机") subtitle:GJText(@"\n设备将会远程关机,”是否“确认") AlertViewType:AlertViewTypeSystemAlert config:nil];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil];
}];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
[self DeviceShutDown];
}];
}];
[alertV showAlertView];
}];
shutdownBtn.backgroundColor = KKMainColor;
shutdownBtn.layer.cornerRadius = 5;
shutdownBtn.layer.masksToBounds = YES;
[self.menuScroll addSubview:shutdownBtn];
NSString *msg = GJText(@"\n解除绑定后,将无法对设备进行监护,设备将重启,其他绑定该设备的用户,将自动解绑");
if(APIManager.sharedManager.deviceModel.identity == 2)
msg = GJText(@"\n您是设备的管理员,如果您进行解绑,其他绑定该设备的用户,将自动解绑,确认解除绑定吗?");
/// 解除与设备的绑定
UIButton *unbundleBtn = [UICommon ui_buttonSimple:CGRectMake(10, shutdownBtn.bottom+Adapted(15), SCREEN_WIDTH-20, Adapted(44)) font:FontADA_(15) normalColor:KKMainColor normalText:GJText(@"解除与设备的绑定") click:^(id x) {
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"设备解绑") subtitle:GJText(msg) AlertViewType:AlertViewTypeSystemAlert config:nil];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil];
}];
[alertV addAlertItem:^EasyAlertItem *{
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) {
[self DeviceUnbind];
}];
}];
[alertV showAlertView];
}];
unbundleBtn.backgroundColor = KKWhiteColorColor;
unbundleBtn.layer.cornerRadius = 5;
unbundleBtn.layer.masksToBounds = YES;
[self.menuScroll addSubview:unbundleBtn];
[self.menuScroll setContentSize:CGSizeMake(SCREEN_WIDTH, unbundleBtn.bottom+iPhoneX_TabbarSafeBottomMargin)];
}
- (UIScrollView *)menuScroll
{
if (!_menuScroll)
{
_menuScroll = [UIScrollView new];
_menuScroll.backgroundColor = KKClearColor;
}
return _menuScroll;
}
/// 菜单设置
- (void)setMenu
{
self.menuArr = [NSMutableArray new];
self.menuImgArr = [NSMutableArray new];
// if ([APIManager sharedManager].deviceModel.identity == 2)
// [self.menuArr addObject:GJText(@"管理员")];
// else
[self.menuArr addObject:GJText(@"电话本")];
[self.menuImgArr addObject:@"icon_home_phone_book"];
if([APIManager sharedManager].deviceModel.videoModelName != 0)
{
[self.menuArr addObject:GJText(@"视频通话")];
[self.menuImgArr addObject:@"icon_more_video_call"];
}
if ([APIManager sharedManager].deviceModel.watchAlarmClock )
{
[self.menuArr addObject:GJText(@"设备闹钟")];
[self.menuImgArr addObject:@"icon_more_watch_the_clock"];
}
if ([APIManager sharedManager].deviceModel.classDisable )
{
[self.menuArr addObject:GJText(@"上课禁用")];
[self.menuImgArr addObject:@"icon_more_class_disable"];
}
if ([APIManager sharedManager].deviceModel.sosPhone)
{
[self.menuArr addObject:GJText(@"SOS号码")];
[self.menuImgArr addObject:@"icon_more_sos"];
}
// if([APIManager sharedManager].deviceModel.watchWiff)
// {
// [self.menuArr addObject:GJText(@"设备WIFI")];
// [self.menuImgArr addObject:@"icon_more_watch_wifi"];
// }
if([APIManager sharedManager].deviceModel.timingSwitch)
{
[self.menuArr addObject:GJText(@"定时开关机")];
[self.menuImgArr addObject:@"icon_more_timing_switch"];
}
if([APIManager sharedManager].deviceModel.lookupFun)
{
[self.menuArr addObject:GJText(@"查找设备")];
[self.menuImgArr addObject:@"icon_more_looking_watch"];
}
if([APIManager sharedManager].deviceModel.stepRecorder)
{
[self.menuArr addObject:GJText(@"计步")];
[self.menuImgArr addObject:@"icon_more_step_gauge"];
}
// 学生卡
//if([APIManager sharedManager].deviceModel.familyPhone)
{
[self.menuArr addObject:GJText(@"亲情号")];
[self.menuImgArr addObject:@"icon_home_phone_book"];
}
// // 学生资料
// if([APIManager sharedManager].deviceModel.deviceType == 2)
// {
// [self.menuArr addObject:GJText(@"学生资料")];
// [self.menuImgArr addObject:@"icon_more_watch_data"];
// }
// if ([APIManager sharedManager].deviceModel.whiteList)
// {
// [self.menuArr addObject:GJText(@"通讯录")];
// [self.menuImgArr addObject:@"icon_home_phone_book"];
// }
[self.menuArr addObject:GJText(@"设备资料")];
[self.menuImgArr addObject:@"icon_more_watch_data"];
}
#pragma mark 设备远程关机
/// 设备远程关机
- (void)DeviceShutDown
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APGET:DeviceShutDown_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
[super updataNotificat];
[UICommon MessageSuccessText:@"远程关机成功"];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
#pragma mark 解除与设备绑定
/// 解除与设备绑定
- (void)DeviceUnbind
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[parameters setValue:APIManager.sharedManager.loginModel.openid forKey:@"userId"];
[[[APIManager sharedManager] APPOST:DeviceUnbind_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
[APIManager.sharedManager cleardeviceInfo];
[UICommon MessageSuccessText:@"解绑成功"];
[[NSNotificationCenter defaultCenter] postNotificationName:UPDATA_DeviceList object:nil];
AfterDispatch(0.5, ^{
[self.navigationController popViewControllerAnimated:YES];
});
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
- (void)updateAllMessage
{
AfterDispatch(1, ^{
[self.setView DevicePosition];
});
}
/*
#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