// // YXMyViewController.m // Temperature // // Created by TC on 2025/2/10. // #import "YXMyViewController.h" #import "MyListTableViewCell.h" #import "YXMyInfoViewController.h" #import "YXFamilyInfoViewController.h" #import "YXMyDeviceViewController.h" #import "YXInviteViewController.h" #import "RDSSystemSetVC.h" #import "RDSRootControl.h" #import #import #import "RDSControlWebVC.h" @interface YXMyViewController () @property (weak, nonatomic) UIView *contentView; @property (weak, nonatomic) UITableView *tableView; @property (copy, nonatomic) NSArray *listArray; @property (copy, nonatomic) NSArray *iconImgArray; @end @implementation YXMyViewController - (void)viewDidLoad { [super viewDidLoad]; // 隐藏导航栏 self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F5FA"]; self.listArray = @[ @"设备耗材",@"系统设置",@"帮助与反馈", ]; self.iconImgArray = @[ @"my_device",@"my_set",@"my_help", ]; [self createTableView]; [self refreshUserInfo]; [self p_getCurrentUserInfo]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self createTableHeaderView]; } - (void)p_getCurrentUserInfo{ RDS_WEAKSELF(weakSelf) [RDSUserInfoModel rds_getCurrentUserInfoFinished:^(NSError *error) { if (!error) { [weakSelf.tableView reloadData]; [weakSelf.tableView.mj_header endRefreshing]; } }]; } -(void)refreshUserInfo { MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(p_getCurrentUserInfo)]; header.automaticallyChangeAlpha = YES; header.lastUpdatedTimeLabel.hidden = YES; self.tableView.mj_header = header; } -(void)createTableView { UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10) style:UITableViewStyleGrouped]; tableView.delegate = self; tableView.dataSource = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [tableView registerNib:[UINib nibWithNibName:@"MyListTableViewCell" bundle:nil] forCellReuseIdentifier:@"myCellId"]; tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F5FA"]; tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; tableView.insetsContentViewsToSafeArea = false; [self.view addSubview:tableView]; self.tableView = tableView; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@0); make.right.equalTo(@0); make.left.equalTo(@0); make.bottom.equalTo(@0); }]; tableView.layer.cornerRadius = 8; [self createTableHeaderView]; [self createTableFooterView]; } -(void)createTableHeaderView { UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 260)]; headerView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"]; self.tableView.tableHeaderView = headerView; UIImageView *bgImgView = [[UIImageView alloc]init]; bgImgView.image = [UIImage imageNamed:@"my_top_bg"]; [headerView addSubview:bgImgView]; [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.right.equalTo(@0); }]; UIView *bgView = [[UIView alloc]init]; bgView.backgroundColor = [UIColor clearColor]; [headerView addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@60); make.right.equalTo(@-15); make.left.equalTo(@15); make.height.equalTo(@55); }]; UIImageView *picView = [[UIImageView alloc]init]; [bgView addSubview:picView]; [picView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@20); make.width.equalTo(@55); make.height.equalTo(@55); make.centerY.equalTo(@0); }]; picView.layer.cornerRadius = 27.5; picView.layer.masksToBounds = YES; [picView sd_setImageWithURL:[NSURL URLWithString:TheDataManager.currentUser.photo] placeholderImage:[UIImage imageNamed:@"my_pic"]]; UILabel *nameLabel = [[UILabel alloc]init]; nameLabel.textColor = [UIColor colorWithHexString:@"#000000"]; nameLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium]; nameLabel.text = TheDataManager.currentUser.user_name; [bgView addSubview:nameLabel]; [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(picView.mas_top); make.left.equalTo(picView.mas_right).offset(15); make.height.equalTo(@30); make.width.equalTo(@150); }]; UILabel *detailLabel = [[UILabel alloc]init]; detailLabel.textColor = [UIColor colorWithHexString:@"#999999"]; detailLabel.font = [UIFont systemFontOfSize:13]; detailLabel.text = [NSString stringWithFormat:@"家庭 %@|智能设备 %@",TheDataManager.currentUser.home_count,TheDataManager.currentUser.all_devices]; [bgView addSubview:detailLabel]; [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(picView.mas_bottom); make.left.equalTo(picView.mas_right).offset(15); make.height.equalTo(@30); make.width.equalTo(@150); }]; UIImageView *imgView = [[UIImageView alloc]init]; imgView.image = [UIImage imageNamed:@"home_right_arrow"]; [bgView addSubview:imgView]; [imgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(@0); make.right.equalTo(@-30); make.width.equalTo(@9); make.height.equalTo(@15); }]; UIView *userBgView = [[UIView alloc]init]; userBgView.backgroundColor = [UIColor whiteColor]; [headerView addSubview:userBgView]; [userBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(bgView.mas_bottom).offset(30); make.right.equalTo(@-15); make.left.equalTo(@15); make.height.equalTo(@80); }]; userBgView.layer.cornerRadius = 8; UILabel *textLabel = [[UILabel alloc]init]; textLabel.textColor = [UIColor colorWithHexString:@"#333333"]; textLabel.font = [UIFont boldSystemFontOfSize:15]; textLabel.text = TheDataManager.current_home_name; textLabel.textAlignment = NSTextAlignmentLeft; [userBgView addSubview:textLabel]; [textLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@15); make.left.equalTo(@15); make.height.equalTo(@20); make.width.equalTo(@150); }]; UIImageView *roomImgView = [[UIImageView alloc]init]; roomImgView.image = [UIImage imageNamed:@"my_icon_room"]; [userBgView addSubview:roomImgView]; [roomImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(textLabel.mas_bottom).offset(15); make.left.equalTo(textLabel.mas_left); make.width.equalTo(@10); make.height.equalTo(@10); }]; UILabel *roomLabel = [[UILabel alloc]init]; roomLabel.textColor = [UIColor colorWithHexString:@"#999999"]; roomLabel.font = [UIFont systemFontOfSize:12]; roomLabel.textAlignment = NSTextAlignmentLeft; [userBgView addSubview:roomLabel]; [roomLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(roomImgView.mas_centerY); make.left.equalTo(roomImgView.mas_right).offset(5); make.height.equalTo(@20); make.width.equalTo(@50); }]; UIImageView *deviceImgView = [[UIImageView alloc]init]; deviceImgView.image = [UIImage imageNamed:@"my_icon_device"]; [userBgView addSubview:deviceImgView]; [deviceImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(roomImgView.mas_centerY); make.left.equalTo(roomLabel.mas_right).offset(5); make.width.equalTo(@10); make.height.equalTo(@10); }]; UILabel *deviceLabel = [[UILabel alloc]init]; deviceLabel.textColor = [UIColor colorWithHexString:@"#999999"]; deviceLabel.font = [UIFont systemFontOfSize:12]; deviceLabel.textAlignment = NSTextAlignmentLeft; [userBgView addSubview:deviceLabel]; [deviceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(roomImgView.mas_centerY); make.left.equalTo(deviceImgView.mas_right).offset(5); make.height.equalTo(@20); make.width.equalTo(@50); }]; UIImageView *mImgView = [[UIImageView alloc]init]; mImgView.image = [UIImage imageNamed:@"my_icon_member"]; [userBgView addSubview:mImgView]; [mImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(roomImgView.mas_centerY); make.left.equalTo(deviceLabel.mas_right).offset(5); make.width.equalTo(@10); make.height.equalTo(@10); }]; UILabel *mLabel = [[UILabel alloc]init]; mLabel.textColor = [UIColor colorWithHexString:@"#999999"]; mLabel.font = [UIFont systemFontOfSize:12]; mLabel.textAlignment = NSTextAlignmentLeft; [userBgView addSubview:mLabel]; [mLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(roomImgView.mas_centerY); make.left.equalTo(mImgView.mas_right).offset(5); make.height.equalTo(@20); make.width.equalTo(@50); }]; UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [addBtn setTitle:@"邀请" forState:UIControlStateNormal]; [addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [addBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal]; addBtn.titleLabel.font = [UIFont systemFontOfSize:16]; addBtn.backgroundColor = [UIColor colorWithHexString:@"#267AFF"]; [userBgView addSubview:addBtn]; [addBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@30); make.width.equalTo(@60); make.right.equalTo(@-15); make.centerY.equalTo(@0); }]; addBtn.layer.cornerRadius = 5; if (TheDataManager.homes.count > TheDataManager.current_home_index) { RDSHomeModel *model = TheDataManager.homes[TheDataManager.current_home_index]; roomLabel.text = [NSString stringWithFormat:@"房间 %ld",model.room.count]; deviceLabel.text = [NSString stringWithFormat:@"设备 %ld",model.devices.count]; mLabel.text = [NSString stringWithFormat:@"成员 %ld",model.member.count]; } UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userInfoTapAction)]; [bgView addGestureRecognizer:tap]; UITapGestureRecognizer *roomTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(roomTapAction)]; [userBgView addGestureRecognizer:roomTap]; } -(void)userInfoTapAction { YXMyInfoViewController *infoVc = [[YXMyInfoViewController alloc]init]; infoVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:infoVc animated:true]; } -(void)roomTapAction { YXFamilyInfoViewController *roomVc = [[YXFamilyInfoViewController alloc]init]; roomVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:roomVc animated:true]; } -(void)addBtnAction:(UIButton *)btn { YXInviteViewController *inviteVc = [[YXInviteViewController alloc]init]; inviteVc.homeName = TheDataManager.current_home_name; inviteVc.homeId = TheDataManager.current_home_id; inviteVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:inviteVc animated:YES]; } -(void)createTableFooterView { UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)]; footerView.backgroundColor = [UIColor clearColor]; self.tableView.tableFooterView = footerView; UIButton *logoutBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal]; [logoutBtn addTarget:self action:@selector(logoutBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [logoutBtn setTitleColor:[UIColor colorWithHexString:@"#267AFF"] forState:UIControlStateNormal]; logoutBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15]; logoutBtn.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"]; [footerView addSubview:logoutBtn]; [logoutBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@55); make.left.equalTo(@15); make.right.equalTo(@-15); make.top.equalTo(@15); }]; logoutBtn.layer.cornerRadius = 8; } -(void)logoutBtnAction:(UIButton *)btn { RDS_WEAKSELF(weakSelf) UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确定退出登录?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self logoutAlert]; }]; [alertController addAction:sureAction]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)logoutAlert { [RDSHudShower showWithStatus:@"加载中..." autoDismiss:NO]; [RDSDemoApiHelper rds_logoutSuccess:^(id responseObject) { if ([responseObject[@"code"] intValue] == 0) { [RDSHudShower dismissHUD]; [RDSRootControl shareControl].isLoginSuccess = NO; } else{ [RDSHudShower showErrorWithStatus:responseObject[@"message"]]; } } failure:^(NSError *error) { [RDSHudShower showBottomToast:@"连接服务器失败"]; [RDSRootControl shareControl].isLoginSuccess = NO; }]; TheDataManager.token = @""; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.listArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCellId" forIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; NSString *name = self.listArray[indexPath.row]; cell.titleLabel.text = name; NSString *img = self.iconImgArray[indexPath.row]; cell.iconImgView.image = [UIImage imageNamed:img]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { YXMyDeviceViewController *myDeviceVc = [[YXMyDeviceViewController alloc]init]; myDeviceVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:myDeviceVc animated:YES]; } else if (indexPath.row == 1){ RDSSystemSetVC *setVc = [[RDSSystemSetVC alloc]init]; setVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:setVc animated:YES]; } else if (indexPath.row == 2){ RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init]; webVc.requestURL = [NSString stringWithFormat:@"%@helpList",kBaseUrlH5]; webVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:webVc animated:YES]; } } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc]init]; return headerView; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc]init]; return footerView; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.01; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 65; } /* #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