// // HomeHeaderTableView.m // tongxin // // Created by ecell on 2023/6/20. // Copyright © 2023 xTT. All rights reserved. // #import "HomeHeaderTableView.h" #import "WebViewController.h" #import "ZZBadgeButton.h" #import "User.h" #import "ContactsViewController.h" #import #import #import #import #import "AppDelegate.h" #import "SLMarqueeControl.h" //默认的定位位置 北京 #define DefineLocate CLLocationCoordinate2DMake(39.9086828351,116.3980865479) @interface HomeHeaderTableView () @property (nonatomic ,strong) NSMutableArray *btnArr; @property (nonatomic ,weak) UILabel *titleLabel; @property (strong, nonatomic) Locate *curLocate;// 设备当前的 位置 //逆地理编码 @property (nonatomic, strong) AMapReGeocodeSearchRequest *regeo; //逆地理编码使用的 @property (nonatomic, strong) AMapSearchAPI *search; /// 设备信息View @property (nonatomic ,strong) UIView *msgView; /// 设备头像 @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; @end @implementation HomeHeaderTableView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = KKClearColor; [self subHeaderView]; } return self; } - (void)subHeaderView { _tempCarouselView = [[XRCarouselView alloc] initWithFrame:CGRectMake(20, 10, ScreenWidth-40, ScreenWidth*0.45)]; _tempCarouselView.changeMode = ChangeModeFade; _tempCarouselView.time = 5.0f; _tempCarouselView.layer.cornerRadius = 10; _tempCarouselView.layer.masksToBounds = YES; _tempCarouselView.imageArray = @[[UIImage imageNamed:@"img_banner"]]; _tempCarouselView.placeholderImage = [UIImage imageNamed:@"img_banner"]; [self addSubview:_tempCarouselView]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(14) textColor:KKTextColor text:@"设备信息" Radius:0]; [self addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(20); make.top.equalTo(_tempCarouselView.mas_bottom).offset(10); }]; [self addSubview:self.msgView]; [self.msgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self).inset(20); 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:KKTextColor text:@"常用功能" Radius:0]; [self addSubview:titleLabel1]; [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(titleLabel); make.top.equalTo(self.msgView.mas_bottom).offset(10); }]; /// 按钮背景View UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor]; self.bgView = bgView; [self addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self).inset(20); make.top.equalTo(titleLabel1.mas_bottom).offset(10); make.height.mas_equalTo(85); }]; [self subBtnView]; } - (void)subBtnView { [self updateMessage]; for (UIButton *views in self.bgView.subviews) { [views removeFromSuperview]; } self.btnArr = [NSMutableArray new]; NSMutableArray *titleArray = [NSMutableArray new]; NSMutableArray *imageArray = [NSMutableArray new]; [titleArray addObject:@"电话"]; [imageArray addObject:@"icon_answer"]; if (cUser.cDevice.support_alarm && cUser.cDevice.support_alarm.intValue == 1) { [titleArray addObject:@"设备闹钟"]; [imageArray addObject:@"icon_alarm"]; } if (cUser.cDevice.support_disturb && cUser.cDevice.support_disturb.intValue == 1) { [titleArray addObject:@"上课禁用"]; [imageArray addObject:@"icon_disabled"]; } if(cUser.cDevice.support_video) { [titleArray addObject:@"视频通话"]; [imageArray addObject:@"icon_home_video_call"]; } else //if (cUser.cDevice.support_whiteList && cUser.cDevice.support_whiteList.intValue ==0) { [titleArray addObject:cUser.cDevice.support_whiteList.intValue ==0 ? @"电话本" : @"管理员"]; [imageArray addObject:@"icon_phonebook"]; } // [titleArray addObject:@"更多"]; // [imageArray addObject:@"icon_more"]; CGFloat masx = (ScreenWidth-40)/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]; button.tag = i; button.frame = CGRectMake(i*masx, 15, masx, 60); [self.bgView addSubview:button]; [self.btnArr addObject:button]; } } - (void)buttonClickAction:(UIButton *)sender { if ([sender.currentTitle isEqualToString:@"电话"]) { [cUser.cDevice makePhoneCallWithViewController:self.getViewController]; } else if ([sender.currentTitle isEqualToString:@"设备闹钟"]) { [UICommon pusXibViewController:@"VoiceAlarmViewController"]; } else if ([sender.currentTitle isEqualToString:@"上课禁用"]) { [UICommon pusXibViewController:@"DisturbBanViewController"]; } else if ([sender.currentTitle isEqualToString:@"电话本"] || [sender.currentTitle isEqualToString:@"管理员"]) { ContactsViewController *vc = (ContactsViewController *)[UICommon pusXibViewController:@"ContactsViewController"]; vc.viewType = [sender.currentTitle isEqualToString:@"电话本"] ? 999 : 888; } else if([sender.currentTitle isEqualToString:@"视频通话"]) { [UICommon pusXibViewController:@"VideoCallViewController"]; } // else if ([sender.currentTitle isEqualToString:@"更多"]) // { // [UICommon pusXibViewController:@"MoreFunctionsViewController"]; // } } - (void)setData:(NSArray*)modelArr WithPlaceholderImage:(NSString *)pImage { _modelArr = modelArr; _tempCarouselView.placeholderImage = [UIImage imageNamed:pImage]; if (modelArr && modelArr.count > 0){ NSMutableArray *tempImageURLArr = [NSMutableArray array]; for (SlideshowModel *model in modelArr) { [tempImageURLArr addObject:model.image]; } _tempCarouselView.imageArray = tempImageURLArr; WEAKSELF _tempCarouselView.imageClickBlock = ^(NSInteger index) { SlideshowModel *model = weakSelf.modelArr[index]; [cUser postSlideshowInfoWithID:model.id Success:^(id responseObject) { xLog(@"点击轮播图 ID:%@ name:%@, url:%@",model.id,model.title,model.url); } failure:^(id faiObject) { xLog(@"点击轮播图上传失败"); }]; if([model.url containsString:@"://"]){ WebViewController *vc = [WebViewController new]; vc.url = model.url; vc.title = model.title; vc.hidesBottomBarWhenPushed = YES; // vc.isHiddenNavigationBar = YES; [weakSelf.getViewController.navigationController pushViewController:vc animated:YES]; } }; } } - (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(42, 42, 42) forState:UIControlStateNormal]; [customButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; return customButton; } - (void)updateMessage { if(cUser.cDevice.lastLocation) { self.curLocate = cUser.cDevice.lastLocation; self.positionImg.image = ImageName_(@"home_icon_gps"); if (self.curLocate.address.length > 0) self.marqueeControl.marqueeLabel.text = self.curLocate.address; self.regeo.location = [AMapGeoPoint locationWithLatitude:[self.curLocate.lat floatValue] longitude:[self.curLocate.lon floatValue]]; [self.search AMapReGoecodeSearch:self.regeo]; } else { self.positionImg.image = ImageName_(@"home_icon_gps_inaccurate"); self.marqueeControl.marqueeLabel.text = @"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位"; } [self.iconImg sd_setImageWithURL:[NSURL URLWithString:cUser.avator] placeholderImage:[myHelper getImageWithName:@"默认用户头像"] options:SDWebImageRetryFailed]; self.nameLabel.text = cUser.cDevice.name; self.idLabel.text = [NSString stringWithFormat:@"账号:%@",cUser.cDevice.imei]; } - (AMapReGeocodeSearchRequest *)regeo { if (!_regeo) { _regeo = [[AMapReGeocodeSearchRequest alloc]init]; _regeo.requireExtension = YES; } return _regeo; } - (AMapSearchAPI *)search { if (!_search) { _search = [[AMapSearchAPI alloc]init]; _search.delegate = self; } return _search; } #pragma mark ====高德地图位置解析回调==== -(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{ if (response.regeocode != nil) { NSString *name = response.regeocode.formattedAddress; self.marqueeControl.marqueeLabel.text = name; self.positionImg.image = ImageName_(@"home_icon_gps"); } } - (UIView *)msgView { if (!_msgView) { _msgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor]; /// 设备头像 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) { UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"EditDeviceViewController"]; [vc setValue:@(NO) forKey:@"isAdd"]; [self.getViewController.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:KKTextColor 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:@"comm_right_icon"]; [_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, ScreenWidth-40-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)); }]; // UITapGestureRecognizer *tapPress = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapViewtapPressed)]; // [_msgView addGestureRecognizer:tapPress]; } return _msgView; } - (void)mapViewtapPressed { [UICommon currentVC].tabBarController.selectedIndex = 2; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end