123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- //
- // RXFamilyViewController.m
- // Temperature
- //
- // Created by TC on 2025/2/16.
- //
- #import "YXFamilyViewController.h"
- #import "YXFamilyTableViewCell.h"
- #import "YXMemberItemView.h"
- #import "YXMemberInfoViewController.h"
- #import "YXRoomManagerViewController.h"
- #import "YXInviteViewController.h"
- #import <SDWebImage/SDWebImage.h>
- #import "YXAddressViewController.h"
- #import "RDSRootControl.h"
- @interface YXFamilyViewController ()<UITableViewDataSource,UITableViewDelegate>
- @property (weak, nonatomic) UITableView *tableView;
- @property (copy, nonatomic) NSArray *listArray;
- @property (copy, nonatomic) NSArray *itemArray;
- @property (weak, nonatomic) UIScrollView *memberScrollView;
- @property (weak, nonatomic) UILabel *roomLabel;
- @property (weak, nonatomic) UILabel *deviceLabel;
- @property (weak, nonatomic) UILabel *mLabel;
- @property (nonatomic,copy) NSString *name;
- @property (nonatomic,copy) NSString *province;
- @property (nonatomic,copy) NSString *city;
- @property (nonatomic,copy) NSString *area;
- @property (nonatomic,copy) NSString *address;
- @end
- @implementation YXFamilyViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
-
- self.listArray = @[
- @"家庭名称",@"家庭位置",@"房间管理",
- ];
-
- [self createTableView];
- [self createFooterView];
-
- }
- -(void)p_updateHomeInfo
- {
- self.name = self.name.length == 0 ? self.model.name : self.name;
- self.province = self.province.length == 0 ? self.model.province : self.province;
- self.city = self.city.length == 0 ? self.model.city : self.city;
- self.area = self.area.length == 0 ? self.model.district : self.area;
- self.address = self.address.length == 0 ? self.model.address : self.address;
-
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_updateHomeInfoWithHomeId:self.model.record_id name:self.name province:self.province city:self.city district:self.area address:self.address rooms:nil success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
- [RDSHudShower showBottomToast:@"家庭信息更新成功"];
- weakSelf.model.name = weakSelf.name;
- weakSelf.model.province = weakSelf.province;
- weakSelf.model.city = weakSelf.city;
- weakSelf.model.district = weakSelf.area;
- weakSelf.model.address = weakSelf.address;
- [weakSelf.tableView reloadData];
-
- if (weakSelf.updateFamilyInfo) {
- weakSelf.updateFamilyInfo();
- }
-
- } else{
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)createFooterView
- {
- UIView *footerView = [[UIView alloc]init];
- footerView.backgroundColor = [UIColor clearColor];
- [self.view addSubview:footerView];
- [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@100);
- make.right.equalTo(@0);
- make.left.equalTo(@0);
- make.bottom.equalTo(@0);
- }];
-
- UIButton *deletBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [deletBtn setTitle:@"删除家庭" forState:UIControlStateNormal];
- [deletBtn addTarget:self action:@selector(deleteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- [deletBtn setTitleColor:[UIColor colorWithHexString:@"#E50023"] forState:UIControlStateNormal];
- deletBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
- deletBtn.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
- [footerView addSubview:deletBtn];
- [deletBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@45);
- make.left.equalTo(@15);
- make.right.equalTo(@-15);
- make.top.equalTo(@20);
- }];
- deletBtn.layer.cornerRadius = 22.5;
-
- }
- -(void)deleteBtnAction:(UIButton *)btn
- {
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_delHomeWithHomeId:self.model.record_id success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
- [RDSHudShower showBottomToast:@"删除成功"];
- [weakSelf popViewControllerAnimated:YES];
- } else{
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
- [RDSHudShower showBottomToast:@"连接服务器失败"];
- }];
- }
- -(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:@"YXFamilyTableViewCell" bundle:nil] forCellReuseIdentifier:@"fCellId"];
- tableView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- [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];
- }
- -(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;
-
- UIView *userBgView = [[UIView alloc]init];
- userBgView.backgroundColor = [UIColor clearColor];
- [headerView addSubview:userBgView];
- [userBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@0);
- make.right.equalTo(@0);
- make.left.equalTo(@0);
- make.height.equalTo(@90);
- }];
-
- [userBgView setNeedsLayout];
- [userBgView layoutIfNeeded];
- CAGradientLayer *gl = [CAGradientLayer layer];
- gl.frame = userBgView.bounds;
- gl.startPoint = CGPointMake(0.5, 0);
- gl.endPoint = CGPointMake(0.5, 1);
- gl.colors = @[(__bridge id)[UIColor colorWithRed:229/255.0 green:238/255.0 blue:254/255.0 alpha:1].CGColor, (__bridge id)[UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1].CGColor];
- [userBgView.layer addSublayer:gl];
-
- UILabel *textLabel = [[UILabel alloc]init];
- textLabel.textColor = [UIColor colorWithHexString:@"#333333"];
- textLabel.font = [UIFont boldSystemFontOfSize:16];
- textLabel.text = @"家庭信息";
- textLabel.textAlignment = NSTextAlignmentLeft;
- [userBgView addSubview:textLabel];
- [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@25);
- make.left.equalTo(@20);
- 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);
- }];
- self.roomLabel = roomLabel;
-
- 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);
- }];
- self.deviceLabel = deviceLabel;
-
- 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);
- }];
- self.mLabel = mLabel;
-
- UIView *memberBgView = [[UIView alloc]init];
- memberBgView.backgroundColor = [UIColor whiteColor];
- [headerView addSubview:memberBgView];
- [memberBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(userBgView.mas_bottom).offset(15);
- make.right.equalTo(@-15);
- make.left.equalTo(@15);
- make.height.equalTo(@135);
- }];
-
- UILabel *memberLabel = [[UILabel alloc]init];
- memberLabel.textColor = [UIColor colorWithHexString:@"#333333"];
- memberLabel.font = [UIFont boldSystemFontOfSize:15];
- memberLabel.text = @"家庭成员";
- memberLabel.textAlignment = NSTextAlignmentLeft;
- [memberBgView addSubview:memberLabel];
- [memberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@15);
- make.left.equalTo(@15);
- make.height.equalTo(@20);
- make.width.equalTo(@150);
- }];
-
- UIScrollView *mScrollView = [[UIScrollView alloc]init];
- mScrollView.showsVerticalScrollIndicator = NO;
- mScrollView.showsHorizontalScrollIndicator = NO;
- [memberBgView addSubview:mScrollView];
- [mScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(memberLabel.mas_bottom).offset(15);
- make.left.equalTo(@15);
- make.right.equalTo(@-15);
- make.bottom.equalTo(@15);
- }];
- self.memberScrollView = mScrollView;
-
- NSInteger num = self.model.member.count;
- mScrollView.contentSize = CGSizeMake((num + 1)*(50 + 30), 80);
- for (int i = 0; i <= num; i++) {
-
- YXMemberItemView *itemView = [[YXMemberItemView alloc]initWithFrame:CGRectMake(i*(50 + 30), 0, 50, 80)];
- [self.memberScrollView addSubview:itemView];
-
- if (i == num) {
- itemView.picImgView.image = [UIImage imageNamed:@"my_add"];
- itemView.nameLabel.text = @"邀请家人";
- UITapGestureRecognizer *addTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addTapAction:)];
- [itemView addGestureRecognizer:addTap];
- }else{
- YXMemberModel *memberModel = self.model.member[i];
- itemView.nameLabel.text = memberModel.user_name;
- [itemView.picImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", TheApiHelper.baseUrlHeadImg, memberModel.photo]] placeholderImage:[UIImage imageNamed:@"my_pic"]];
-
- if ([self.model.admin_id isEqualToString:memberModel.user_id]) {
- itemView.markLabel.hidden = NO;
- } else {
- itemView.markLabel.hidden = YES;
- }
- itemView.tag = i;
- UITapGestureRecognizer *infoTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(infoTapAction:)];
- [itemView addGestureRecognizer:infoTap];
- }
- }
-
- [self setHeaderData];
- }
- -(void)setHeaderData
- {
- self.roomLabel.text = [NSString stringWithFormat:@"房间 %ld |",self.model.room.count];
-
- self.deviceLabel.text = [NSString stringWithFormat:@"设备 %ld |",self.model.devices.count];
-
- self.mLabel.text = [NSString stringWithFormat:@"成员 %ld",self.model.member.count];
- }
- -(void)addTapAction:(UITapGestureRecognizer *) tap
- {
- YXInviteViewController *inviteVc = [[YXInviteViewController alloc]init];
- inviteVc.homeName = self.model.name;
- inviteVc.homeId = self.model.record_id;
- [self.navigationController pushViewController:inviteVc animated:YES];
- }
- -(void)infoTapAction:(UITapGestureRecognizer *) tap
- {
- NSInteger tag = tap.view.tag;
- YXMemberModel *model = self.model.member[tag];
- YXMemberInfoViewController *infoVc = [[YXMemberInfoViewController alloc]init];
- infoVc.model = model;
- infoVc.familyName = self.model.name;
-
- if ([self.model.admin_id isEqualToString:model.user_id]) {
- infoVc.isCreator = YES;
- } else {
- infoVc.isCreator = NO;
- }
-
- [self.navigationController pushViewController:infoVc animated:YES];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.listArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- YXFamilyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fCellId" forIndexPath:indexPath];
- cell.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- NSString *name = self.listArray[indexPath.row];
- cell.nameLabel.text = name;
-
- if (indexPath.row == 0) {
- cell.textLabel.text = self.model.name;
- } else if (indexPath.row == 1) {
- cell.textLabel.text = [NSString stringWithFormat:@"%@%@%@%@",self.model.province,self.model.city,self.model.district,self.model.address];
- } else if (indexPath.row == 2) {
- cell.textLabel.text = [NSString stringWithFormat:@" %ld个房间",self.model.room.count];
- }
-
- if (indexPath.row == 2) {
- cell.lineView.hidden = YES;
- }else{
- cell.lineView.hidden = NO;
- }
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.row == 0) {
- [self alertWithText:@"家庭名称"];
- } else if (indexPath.row == 1) {
- RDS_WEAKSELF(weakSelf)
- YXAddressViewController *vc = [[YXAddressViewController alloc]init];
- vc.oldProvince = self.model.province;
- vc.oldCity = self.model.city;
- vc.oldArea = self.model.district;
- vc.oldDetail = self.model.address;
-
- [self.navigationController pushViewController:vc animated:YES];
- vc.sureBtnClick = ^(NSString * _Nonnull province, NSString * _Nonnull city, NSString * _Nonnull area, NSString * _Nonnull address) {
- weakSelf.province = province;
- weakSelf.city = city;
- weakSelf.area = area;
- weakSelf.address = address;
-
- [weakSelf p_updateHomeInfo];
- };
-
- } else if (indexPath.row == 2) {
- YXRoomManagerViewController *roomVc = [[YXRoomManagerViewController alloc] init];
- roomVc.homeID = self.model.record_id;
- [self.navigationController pushViewController:roomVc 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;
- }
- -(void)alertWithText:(NSString *)text
- {
- RDS_WEAKSELF(weakSelf)
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:text message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- UITextField *txt = [alertController.textFields objectAtIndex:0];
- NSLog(@"%@",txt.text);
- weakSelf.name = txt.text;
-
- [weakSelf p_updateHomeInfo];
- }];
- [alertController addAction:sureAction];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertController addAction:cancelAction];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.placeholder = [NSString stringWithFormat:@"请输入%@",text];
- textField.text = self.model.name;
- }];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- /*
- #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
|