123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- //
- // YXRoomManagerViewController.m
- // Temperature
- //
- // Created by TC on 2025/2/6.
- //
- #import "YXRoomManagerViewController.h"
- #import "YXHomeRoomModel.h"
- #import "YXRoomManagerTableViewCell.h"
- #import "YXEditRoomViewController.h"
- #import "YXSetRoomViewController.h"
- #import "RDSRootControl.h"
- @interface YXRoomManagerViewController ()<UITableViewDataSource,UITableViewDelegate>
- @property (weak, nonatomic) UIView *contentView;
- @property (weak, nonatomic) UITableView *tableView;
- @property (strong, nonatomic) NSMutableArray *dataArray;
- @property (strong, nonatomic) UILabel *emptyLabel;
- @end
- @implementation YXRoomManagerViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- self.navigationItem.title = @"房间管理";
- [self addRightItem];
-
- self.dataArray = [[NSMutableArray alloc]initWithCapacity:5];
-
- [self createSubViews];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self rds_getRoomList];
- }
- - (void)rds_getRoomList
- {
- NSString *homeIdStr = self.homeID.length == 0 ? TheDataManager.current_home_id : self.homeID;
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_getRoomListWithHomeId:homeIdStr success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
-
- NSArray *data = responseObject[@"data"];
- NSMutableArray *rooms = [YXHomeRoomModel mj_objectArrayWithKeyValuesArray:data];
- for (YXHomeRoomModel *model in rooms) {
- model.devices = [YXHomeDeviceModel mj_objectArrayWithKeyValuesArray:model.devices];
- }
-
- weakSelf.dataArray = rooms;
- TheDataManager.rooms = rooms.mutableCopy;
- [weakSelf.tableView reloadData];
-
- if (weakSelf.dataArray.count == 0) {
- weakSelf.emptyLabel.hidden = NO;
- }else{
- weakSelf.emptyLabel.hidden = YES;
- }
-
- } else{
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)p_createRoomWithName:(NSString *)name
- {
- NSString *homeIdStr = self.homeID.length == 0 ? TheDataManager.current_home_id : self.homeID;
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_createRoom:name homeId:homeIdStr success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 0) {
- [RDSHudShower showBottomToast:@"房间添加成功"];
- [weakSelf rds_getRoomList];
- // [weakSelf popViewControllerAnimated:YES];
- } else{
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)addRightItem
- {
- UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [rightBtn setTitle:@"编辑" forState:UIControlStateNormal];
- [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- [rightBtn setTitleColor:[UIColor colorWithHexString:@"#267AFF"] forState:UIControlStateNormal];
- rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
- self.navigationItem.rightBarButtonItem = rightItem;
- }
- -(void)rightBtnAction:(UIButton *)btn
- {
- YXEditRoomViewController *editVc = [[YXEditRoomViewController alloc]init];
- editVc.homeID = self.homeID;
- [self.navigationController pushViewController:editVc animated:YES];
- }
- -(UILabel *)emptyLabel
- {
- if (_emptyLabel == nil) {
- _emptyLabel = [[UILabel alloc]init];
- _emptyLabel.text = @"暂无数据";
- _emptyLabel.font = [UIFont systemFontOfSize:20];
- _emptyLabel.textColor = [UIColor colorWithHexString:@"333333"];
- _emptyLabel.textAlignment = NSTextAlignmentCenter;
- _emptyLabel.hidden = YES;
- [self.view addSubview:_emptyLabel];
- [_emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@200);
- make.centerX.equalTo(@0);
- make.height.equalTo(@50);
- make.centerY.equalTo(@-30);
- }];
- }
- return _emptyLabel;
- }
- -(void)createSubViews
- {
- 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:@"YXRoomManagerTableViewCell" bundle:nil] forCellReuseIdentifier:@"roomManagerCellID"];
- tableView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- [self.view addSubview:tableView];
- self.tableView = tableView;
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@10);
- make.right.equalTo(@0);
- make.left.equalTo(@0);
- make.bottom.equalTo(@(-kTabbarHeight));
- }];
-
- 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"];
- [self.view addSubview:addBtn];
- [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@45);
- make.left.equalTo(@20);
- make.right.equalTo(@-20);
- make.bottom.equalTo(@(-kSafeBottomHeight));
- }];
-
- addBtn.layer.cornerRadius = 22.5;
- }
- -(void)addBtnAction:(UIButton *)btn
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"添加房间" message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- UITextField *txt = [alertController.textFields objectAtIndex:0];
- NSLog(@"%@",txt.text);
- if (txt.text.length > 0) {
- [self p_createRoomWithName:txt.text];
- }
- }];
- [alertController addAction:sureAction];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertController addAction:cancelAction];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.placeholder = @"请输入房间名称";
- }];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- YXRoomManagerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"roomManagerCellID" forIndexPath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- YXHomeRoomModel *model = self.dataArray[indexPath.row];
-
- cell.nameLabel.text = model.name;
- cell.numberLabel.text = [NSString stringWithFormat:@"%ld个设备",model.devices.count];
- cell.picImgView.image = [UIImage imageNamed:@"home_right_arrow"];
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- YXHomeRoomModel *model = self.dataArray[indexPath.row];
-
- YXSetRoomViewController *roomVc = [[YXSetRoomViewController alloc]init];
- roomVc.model = model;
- [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;
- }
- /*
- #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
|