123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- //
- // YXEditRoomViewController.m
- // Temperature
- //
- // Created by TC on 2025/2/7.
- //
- #import "YXEditRoomViewController.h"
- #import "YXHomeRoomModel.h"
- #import "YXRoomManagerTableViewCell.h"
- #import "RDSRootControl.h"
- @interface YXEditRoomViewController ()<UITableViewDataSource,UITableViewDelegate>
- @property (weak, nonatomic) UIView *contentView;
- @property (weak, nonatomic) UITableView *tableView;
- @property (strong, nonatomic) NSMutableArray *dataArray;
- @property (strong, nonatomic) UILabel *emptyLabel;
- @end
- @implementation YXEditRoomViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- self.navigationItem.title = @"房间管理";
- [self addLeftItem];
- [self addRightItem];
-
- [self createTableView];
- }
- -(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_deleteRoomsWithIndex:(NSInteger)index
- {
- YXHomeRoomModel *model = self.dataArray[index];//
- NSArray *deleteArray = @[model.record_id];
-
- NSString *homeIdStr = self.homeID.length == 0 ? TheDataManager.current_home_id : self.homeID;
-
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_deleteRoomsRecordIds:deleteArray homeId:homeIdStr success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
- [weakSelf.dataArray removeObjectAtIndex:index];
- [weakSelf.tableView reloadData];
- } else{
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)p_updateRoomsSequence
- {
- NSMutableArray *idArray = [[NSMutableArray alloc]initWithCapacity:5];
- for (int i = 0; i < self.dataArray.count; i++) {
- YXHomeRoomModel *model = self.dataArray[i];
- [idArray addObject:model.record_id];
- }
-
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_putRoomsSequence:idArray success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
- [weakSelf.navigationController popViewControllerAnimated:YES];
- } else{
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
-
- }
- -(void)addLeftItem
- {
- UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
- [leftBtn addTarget:self action:@selector(leftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- [leftBtn setTitleColor:[UIColor colorWithHexString:@"#267AFF"] forState:UIControlStateNormal];
- leftBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
- self.navigationItem.leftBarButtonItem = leftItem;
- }
- -(void)leftBtnAction:(UIButton *)btn
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(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
- {
- [self.tableView setEditing:NO animated:YES];
- [self p_updateRoomsSequence];
- }
- -(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)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:@"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(@(-kSafeBottomHeight));
- }];
-
- [self.tableView setEditing:YES animated:YES];
- }
- - (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.hidden = YES;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- }
- -(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 - edit
- -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return YES;
- }
- -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return UITableViewCellEditingStyleDelete;
- }
- -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- [self p_deleteRoomsWithIndex:indexPath.row];
- }
- }
- #pragma mark - move
- -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return YES;
- }
- -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
- {
- [self.dataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
- [tableView exchangeSubviewAtIndex:sourceIndexPath.row withSubviewAtIndex:destinationIndexPath.row];
- }
- /*
- #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
|