123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- //
- // 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 <SDWebImage/SDWebImage.h>
- #import <MJRefresh/MJRefresh.h>
- #import "RDSControlWebVC.h"
- @interface YXMyViewController ()<UITableViewDataSource,UITableViewDelegate>
- @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
|