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.
 
 
 

387 lines
14 KiB

//
// HomeHeaderView.m
// LekangGuard
//
// Created by ecell on 2022/10/14.
//
#import "HomeHeaderView.h"
#import <WebKit/WebKit.h>
#import "SLMarqueeControl.h"
#import "KJBannerView.h"
#import "MoreServiceViewController.h"
#import "ContactsViewController.h"
#import "EditDeviceViewController.h"
#import "ChatViewController.h"
#import "VideoChatViewController.h"
#import "ReadFlowerViewController.h"
#import "SchAndJobMessageViewController.h"
@interface HomeHeaderView ()
@property (nonatomic ,weak) KJBannerView *bannerView;
/// 学生证信息View
@property (nonatomic ,weak) UIView *msgView;
/// 按钮菜单View
@property (nonatomic ,weak) UIView *btnView;
/// 设备头像
@property (nonatomic ,weak) UIImageView *iconImg;
/// 设备名称
@property (nonatomic ,weak) UILabel *nameLabel;
@property (nonatomic ,weak) UILabel *idLabel;
@property (nonatomic, weak) SLMarqueeControl *marqueeControl;
/// 位置图片
@property (nonatomic, weak) UIImageView *positionImg;
@property (nonatomic ,strong) NSMutableArray *btnArr;
@property (nonatomic ,weak) UILabel *titleLabel;
@property (nonatomic ,weak) UILabel *titleLabel1;
@end
@implementation HomeHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = KKClearColor;
[self subHeaderView];
}
return self;
}
- (void)setHomeWokeCount:(NSNumber *)homeWokeCount
{
_homeWokeCount = homeWokeCount;
ZZBadgeButton *button = self.btnArr[0];
button.badge = homeWokeCount.integerValue;
}
- (void)setRedTotalCount:(NSNumber *)redTotalCount
{
_redTotalCount = redTotalCount;
ZZBadgeButton *button = self.btnArr[3];
button.badge = redTotalCount.integerValue;
}
- (void)setDevicemodel:(DeviceModel *)devicemodel
{
NSLog(@"%@--%@",self.redTotalCount,self.homeWokeCount);
_devicemodel = devicemodel;
self.nameLabel.text = devicemodel.name;
if (devicemodel.image.length <= 0)
[self.iconImg setImage:ImageName_(devicemodel.sex == 0 ? @"icon_head_girl" : @"icon_head_boy")];
else
[self.iconImg sd_setImageWithURL:[NSURL URLWithString:devicemodel.image] placeholderImage:ImageName_(@"icon_head_boy")];
self.idLabel.text = [NSString stringWithFormat:@"账号:%@",devicemodel.imei];
[self subBtnView];
}
- (void)setBannerArr:(NSArray *)bannerArr
{
_bannerArr = bannerArr;
self.bannerView.imageDatas = bannerArr;
}
- (void)setLaLoModel:(LatestLocationModel *)laLoModel
{
_laLoModel = laLoModel;
if (STRINGHASVALUE(laLoModel.addr))
{
NSString *imgStr = [laLoModel.locationType isEqualToString:@"WIFI"] ? @"icon_wifi_positioning" : [laLoModel.locationType isEqualToString:@"GPS"] ? @"home_icon_gps" : @"icon_base_station";
self.positionImg.image = ImageName_(imgStr);
self.marqueeControl.marqueeLabel.text = laLoModel.addr;
}
else
{
self.positionImg.image = ImageName_(@"home_icon_gps_inaccurate");
self.marqueeControl.marqueeLabel.text = @"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位";
}
}
- (void)setIsDev:(BOOL)isDev
{
_isDev = isDev;
self.msgView.hidden = isDev;
self.btnView.hidden = isDev;
self.titleLabel.hidden = isDev;
self.titleLabel1.hidden = isDev;
}
- (void)subHeaderView
{
KJBannerView *bannerView = [[KJBannerView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH-20, Adapted(170))];
//bannerView.imgCornerRadius = 5;
bannerView.autoScrollTimeInterval = 8;
//bannerView.isZoom = YES;
//bannerView.itemWidth = SCREEN_WIDTH-50;
bannerView.imageType = KJBannerViewImageTypeNetIamge;
bannerView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
bannerView.pageControl.selectColor = KKMainColor;
// bannerView.imageDatas = @[@"home_banner"];
self.bannerView = bannerView;
[self addSubview:bannerView];
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(14) textColor:KKTextBlackColor text:@"设备信息" Radius:0];
self.titleLabel = titleLabel;
[self addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(10);
make.top.equalTo(bannerView.mas_bottom).offset(20);
}];
[self addSubview:self.msgView];
[self.msgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self).inset(10);
make.top.equalTo(titleLabel.mas_bottom).offset(10);
make.height.mas_equalTo(105);
}];
UILabel *titleLabel1 = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(14) textColor:KKTextBlackColor text:@"常用功能" Radius:0];
self.titleLabel1 = titleLabel1;
[self addSubview:titleLabel1];
[titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(titleLabel);
make.top.equalTo(self.msgView.mas_bottom).offset(10);
}];
/// 按钮背景View
UIView *btnView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor];
btnView.height = YES;
self.btnView = btnView;
[self addSubview:btnView];
[btnView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self).inset(10);
make.top.equalTo(titleLabel1.mas_bottom).offset(10);
make.height.mas_equalTo(85);
}];
// [self subBtnView];
}
- (void)subBtnView
{
for (UIButton *views in self.btnView.subviews)
{
[views removeFromSuperview];
}
self.btnArr = [NSMutableArray new];
NSArray *titleArray = @[@"班级作业",@"电话本",@"打电话",@"小红花"];
NSArray *imageArray = @[@"icon_homework",@"icon_phonebook",@"icon_call_up",@"icon_red_flower"];
if (APIManager.sharedManager.deviceModel.virtualFlag)
{
titleArray = @[@"电话本",@"打电话"];
imageArray = @[@"icon_phonebook",@"icon_call_up"];
}
CGFloat masx = (SCREEN_WIDTH-44)/titleArray.count;
for (int i = 0; i < titleArray.count; i++)
{
NSString *title = [titleArray objectAtIndex:i];
NSString *image = [imageArray objectAtIndex:i];
ZZBadgeButton *button = [self createButtonWithTitle:title image:image];
[button addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside];
if ([title isEqualToString:@"班级作业"])
button.badge = self.homeWokeCount.integerValue;
if ([title isEqualToString:@"小红花"])
button.badge = self.redTotalCount.integerValue;
button.tag = i;
button.frame = CGRectMake(i*masx+12, Adapted(15), masx, masx);
[self.btnView addSubview:button];
[self.btnArr addObject:button];
}
}
- (void)setUnreadTotal:(NSInteger)unreadTotal
{
for (ZZBadgeButton *button in self.btnArr)
{
if([button.currentTitle isEqualToString:GJText(@"微聊")])
{
button.badge = unreadTotal;
return;
}
}
}
- (void)buttonClickAction:(UIButton *)btn
{
if ([btn.currentTitle isEqualToString:GJText(@"电话本")])
{
ContactsViewController *vc = [ContactsViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
else if ([btn.currentTitle isEqualToString:GJText(@"班级作业")])
{
SchAndJobMessageViewController *vc = [[SchAndJobMessageViewController alloc] init];
vc.navTitle = @"班级作业";
vc.viewType = 1;
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
else if ([btn.currentTitle isEqualToString:GJText(@"小红花")])
{
ReadFlowerViewController *vc = [[ReadFlowerViewController alloc] init];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
else if ([btn.currentTitle isEqualToString:GJText(@"打电话")])
{
if(self.devicemodel.phone.length == 0)
{
}
else
{
NSString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.devicemodel.phone];
if(self.devicemodel.phone.length == 11)
string = [NSString stringWithFormat:@"tel:+86-%@", self.devicemodel.phone];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string] options:@{} completionHandler:nil];
}
}
else if ([btn.currentTitle isEqualToString:GJText(@"更多")])
{
MoreServiceViewController *vc = [MoreServiceViewController new];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}
}
- (UIView *)msgView
{
if (!_msgView)
{
_msgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor];
_msgView.hidden = YES;
/// 设备头像
UIImageView *iconImg = [UIImageView new];
iconImg.layer.cornerRadius = 25;
iconImg.layer.masksToBounds = YES;
self.iconImg = iconImg;
[_msgView addSubview:iconImg];
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_msgView.mas_left).offset(18);
make.centerY.equalTo(_msgView);
make.size.mas_equalTo(CGSizeMake(50, 50));
}];
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKClearColor normalText:@"" click:^(id x) {
EditDeviceViewController *vc = [[EditDeviceViewController alloc] init];
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
}];
[_msgView addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(_msgView);
make.top.equalTo(_msgView);
make.bottom.equalTo(iconImg.mas_bottom);
}];
/// 设备名称
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(14) textColor:KKTextBlackColor text:@"" Radius:0];
self.nameLabel = nameLabel;
[_msgView addSubview:nameLabel];
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(iconImg.mas_right).offset(18);
make.top.equalTo(_msgView).offset(19.5);
}];
UILabel *idLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:RGB(133, 133, 133) text:@"" Radius:0];
self.idLabel = idLabel;
[_msgView addSubview:idLabel];
[idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(nameLabel.mas_left);
make.centerY.equalTo(_msgView);
}];
/// 右箭头图片
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_enter_gray"];
[_msgView addSubview:rightImg];
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(_msgView.mas_right).inset(18);
make.top.equalTo(_msgView).offset(30.5);
make.size.mas_equalTo(CGSizeMake(8, 15));
}];
UILabel *ttLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:RGB(133, 133, 133) text:@"编辑资料" Radius:0];
[_msgView addSubview:ttLabel];
[ttLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(rightImg.mas_left).inset(10);
make.centerY.equalTo(rightImg.mas_centerY);
}];
/// 位置跑马灯
SLMarqueeControl *control = [[SLMarqueeControl alloc] initWithFrame:CGRectMake(111, 73.5, SCREEN_WIDTH-20-111-15, 12)];
control.backgroundColor = KKClearColor;
control.marqueeLabel.text = @"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位";
self.marqueeControl = control;
[_msgView addSubview:control];
/// 位置图片
UIImageView *positionImg = [UIImageView new];
self.positionImg = positionImg;
[_msgView addSubview:positionImg];
[positionImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(nameLabel);
make.centerY.equalTo(control);
make.size.mas_equalTo(CGSizeMake(15, 15));
}];
}
return _msgView;
}
- (ZZBadgeButton *)createButtonWithTitle:(NSString *)title image:(NSString *)image
{
ZZBadgeButton *customButton = [[ZZBadgeButton alloc] init];
customButton.titleLabel.font = FontADA_(12);
[customButton setTitle:title forState:UIControlStateNormal];
[customButton setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
[customButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
return customButton;
}
#pragma mark 查询当前设备用户微聊未读消息数
/// 查询当前设备用户微聊未读消息数
- (void)GetUnreadTotal
{
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:APIManager.sharedManager.deviceModel.groupid forKey:@"groupId"];
[[[APIManager sharedManager] APGET:UnreadTotal_URL parameters:parameters resultClass:nil] subscribeNext:^(NSString *x) {
[UICommon HidenLoading];
NSInteger coutn = x.integerValue;
[self setUnreadTotal:coutn];
} 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