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.
 
 
 

267 lines
9.3 KiB

//
// FunctionView.m
// LekangGuard
//
// Created by ecell on 2022/11/17.
//
#import "FunctionView.h"
#import "MenuCollectionViewCell.h"
#import "ContactsViewController.h"
#import "ClockAndOtherViewController.h"
#import "FamilyNumberViewController.h"
#import "SOSViewController.h"
#import "EditDeviceViewController.h"
#import "StepViewController.h"
#import "TimingViewController.h"
#import "VideoChatViewController.h"
#import "MemberManagementViewController.h"
#import "ChatViewController.h"
@interface FunctionView ()<WSLWaterFlowLayoutDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, assign) WSLWaterFlowLayoutStyle flowLayoutStyle;
@property (nonatomic ,strong) UICollectionView *menuCollectionView;
@end
@implementation FunctionView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = KKClearColor;
[self subHeaderView];
}
return self;
}
- (void)setImgArr:(NSArray *)imgArr
{
_imgArr = imgArr;
}
- (void)setTitleArr:(NSArray *)titleArr
{
_titleArr = titleArr;
// [self.menuCollectionView reloadData];
}
- (void)setChatCoutn:(NSInteger)chatCoutn
{
_chatCoutn = chatCoutn;
[self.menuCollectionView reloadData];
}
- (void)setMunberCoutn:(NSInteger)munberCoutn
{
_munberCoutn = munberCoutn;
[self.menuCollectionView reloadData];
}
- (void)subHeaderView
{
WSLWaterFlowLayout *FlowLayout = [[WSLWaterFlowLayout alloc] init];
FlowLayout.delegate = self;
FlowLayout.flowLayoutStyle = self.flowLayoutStyle;
_menuCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, SCREEN_HEIGHT) collectionViewLayout:FlowLayout];
_menuCollectionView.backgroundColor = KKWhiteColorColor;
_menuCollectionView.dataSource = self;
_menuCollectionView.delegate = self;
_menuCollectionView.showsVerticalScrollIndicator = NO;
_menuCollectionView.alwaysBounceVertical = NO;
_menuCollectionView.scrollEnabled = NO;
_menuCollectionView.layer.cornerRadius = 8;
_menuCollectionView.layer.masksToBounds = YES;
if (@available(iOS 11.0, *))
_menuCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[_menuCollectionView registerClass:MenuCollectionViewCell.class forCellWithReuseIdentifier:NSStringFromClass(MenuCollectionViewCell.class)];
[self addSubview:_menuCollectionView];
[_menuCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self).inset(10);
make.top.equalTo(self).offset(0);
make.bottom.equalTo(self.mas_bottom).inset(0);
}];
}
#pragma mark - WSLWaterFlowLayoutDelegate
//返回每个item大小
- (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake((SCREEN_WIDTH-20)/4, (SCREEN_WIDTH-20)/4.5);
}
/** 头视图Size */
-(CGSize )waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForHeaderViewInSection:(NSInteger)section
{
return CGSizeMake(SCREEN_WIDTH, 0);
}
/** 列数*/
-(CGFloat)columnCountInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
{
return 4;
}
/** 列间距*/
-(CGFloat)columnMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
{
return 0;
}
/** 行间距*/
-(CGFloat)rowMarginInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
{
return 0;
}
/** 边缘之间的间距*/
-(UIEdgeInsets)edgeInsetInWaterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout
{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
#pragma mark - UICollectionView数据源
//组个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
//组内成员个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.titleArr.count;
}
//设置元素内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MenuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(MenuCollectionViewCell.class) forIndexPath:indexPath];
//if (self.titleArr.count > 1)
{
cell.imgStr = self.imgArr[indexPath.row];
cell.titleStr = self.titleArr[indexPath.row];
cell.chatCoutn = self.chatCoutn;
cell.munberCoutn = self.munberCoutn;
}
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *title = self.titleArr[indexPath.row];
if ([title isEqualToString:GJText(@"打电话")])
{
if(APIManager.sharedManager.deviceModel.phone.length == 0)
{
}
else
{
NSString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",APIManager.sharedManager.deviceModel.phone];
if(APIManager.sharedManager.deviceModel.phone.length == 11)
string = [NSString stringWithFormat:@"tel:+86-%@", APIManager.sharedManager.deviceModel.phone];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string] options:@{} completionHandler:nil];
}
}
if ([title isEqualToString:@"成员管理"])
{
MemberManagementViewController *vc = [[MemberManagementViewController alloc] init];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"电话本")] || [title isEqualToString:GJText(@"管理员")])
{
ContactsViewController *vc = [ContactsViewController new];
vc.viewType = [title isEqualToString:GJText(@"电话本")] ? 1 : 2;
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"设备闹钟")] || [title isEqualToString:GJText(@"上课禁用")])
{
ClockAndOtherViewController *vc = [ClockAndOtherViewController new];
vc.viewType = [title isEqualToString:GJText(@"设备闹钟")] ? 1 : 2;
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:@"微聊"])
{
ChatViewController *vc = [[ChatViewController alloc] init];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"查找设备")])
{
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"查找设备") subtitle:GJText(@"\n点击查找设备,设备接收到指令,会响铃60秒,按任意键可以取消。若设备处于关机或未联网状态,则无法向设备端发送相关指令") 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 QueryDevice];
}];
}];
[alertV showAlertView];
}
if ([title isEqualToString:GJText(@"亲情号")])
{
FamilyNumberViewController *vc = [FamilyNumberViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"SOS号码")])
{
SOSViewController *vc = [SOSViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"设备资料")])
{
EditDeviceViewController *vc = [EditDeviceViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"计步")])
{
StepViewController *vc = [StepViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"定时开关机")])
{
TimingViewController *vc = [TimingViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
if ([title isEqualToString:GJText(@"设备WIFI")])
{
}
if ([title isEqualToString:GJText(@"视频通话")])
{
VideoChatViewController *vc = [VideoChatViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
}
#pragma 查找设备
- (void)QueryDevice
{
[UICommon MessageUpload:@"加载中"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
[[[APIManager sharedManager] APGET:QueryDevice_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) {
[UICommon HidenLoading];
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end