123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- //
- // YXMyDeviceViewController.m
- // Temperature
- //
- // Created by TC on 2025/2/22.
- //
- #import "YXMyDeviceViewController.h"
- #import "YXMyDeviceTableViewCell.h"
- #import "YXMyDeviceModel.h"
- #import "YXDeviceInfoViewController.h"
- #import <YBPopupMenu/YBPopupMenu.h>
- #import "YXMyDeviceModel.h"
- #import "RDSRootControl.h"
- @interface YXMyDeviceViewController ()<UITableViewDataSource,UITableViewDelegate,YBPopupMenuDelegate>
- @property (weak, nonatomic) UITableView *tableView;
- @property (copy, nonatomic) NSArray *devicesArray;
- @property (weak, nonatomic) UIButton *menuBtn;
- @property (weak, nonatomic) UILabel *numLabel;
- @property (copy, nonatomic) NSString *homeID;
- @property (strong, nonatomic) UILabel *emptyLabel;
- @end
- @implementation YXMyDeviceViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // 隐藏导航栏
- self.fd_prefersNavigationBarHidden = YES;
-
- self.navigationItem.title = @"设备耗材";
- self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
-
- [self createTableView];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self p_getHomeList];
- }
- - (void)p_getHomeList
- {
- [RDSHomeModel rds_getHomeListIsAdmin:YES finished:^(NSError * _Nullable error) {
- [self getDeviceConsumables:TheDataManager.current_home_id];
- self.homeID = TheDataManager.current_home_id;
- }];
- }
- -(void)getDeviceConsumables:(NSString *)homeId
- {
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_getDeviceConsumablesWithHomeId:homeId Success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
- NSDictionary *dataDic = responseObject[@"data"];
- NSDictionary *devices = dataDic[@"devices"];
-
- NSMutableArray *tempArray = [YXMyDeviceModel mj_objectArrayWithKeyValuesArray:devices];
- for (YXMyDeviceModel *model in tempArray) {
- model.consumables = [YXConsumablesModel mj_objectArrayWithKeyValuesArray:model.consumables];
- }
-
- weakSelf.devicesArray = tempArray;
- if (weakSelf.devicesArray.count == 0) {
- weakSelf.emptyLabel.hidden = NO;
- }else{
- weakSelf.emptyLabel.hidden = YES;
- }
-
- NSNumber *enough = dataDic[@"enough"];
- NSString *desc = dataDic[@"desc"];
- if ([enough integerValue] == 1) {
- self.numLabel.textColor = [UIColor colorWithHexString:@"111111"];
- }else{
- self.numLabel.textColor = [UIColor redColor];
- }
- self.numLabel.text = desc;
-
- [weakSelf.tableView reloadData];
- } else{
- [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)resetDeviceConsumablesWithId:(NSString *)deviceId
- {
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_resetDeviceConsumablesWithId:deviceId success:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 9999) {
- [RDSRootControl shareControl].isLoginSuccess = NO;
- TheDataManager.token = @"";
- }
-
- if ([responseObject[@"code"] intValue] == 0) {
- [RDSHudShower showSuccessWithStatus:@"重置成功"];
- [weakSelf getDeviceConsumables:weakSelf.homeID];
- } else{
- [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- -(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(@0);
- }];
- }
- 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:@"YXMyDeviceTableViewCell" bundle:nil] forCellReuseIdentifier:@"myDeviceCellID"];
- tableView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- tableView.insetsContentViewsToSafeArea = false;
- [self.view addSubview:tableView];
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@0);
- make.right.equalTo(@0);
- make.left.equalTo(@0);
- make.bottom.equalTo(@0);
- }];
- self.tableView = tableView;
-
- [self createTableHeaderView];
- }
- -(void)createTableHeaderView
- {
- UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 190)];
- 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);
- }];
-
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"home_left_arrow"] forState:UIControlStateNormal];
- [backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- [headerView addSubview:backBtn];
- [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@60);
- make.left.equalTo(@15);
- make.width.equalTo(@20);
- make.height.equalTo(@20);
- }];
-
- UILabel *titleLabel = [[UILabel alloc]init];
- titleLabel.textColor = [UIColor colorWithHexString:@"#1E1E1E"];
- titleLabel.font = [UIFont boldSystemFontOfSize:18];
- titleLabel.textAlignment = NSTextAlignmentCenter;
- titleLabel.text = @"设备耗材";
- [headerView addSubview:titleLabel];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(backBtn.mas_centerY);
- make.centerX.equalTo(@0);
- make.width.equalTo(@150);
- make.height.equalTo(@30);
- }];
-
- UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [menuBtn setTitle:TheDataManager.current_home_name forState:UIControlStateNormal];
- menuBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
- [menuBtn setTitleColor:[UIColor colorWithHexString:@"#1E1E1E"] forState:UIControlStateNormal];
- [menuBtn addTarget:self action:@selector(menuBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- [headerView addSubview:menuBtn];
- [menuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(@15);
- make.top.equalTo(backBtn.mas_bottom).offset(30);
- // make.width.equalTo(@150);
- make.height.equalTo(@30);
- }];
- self.menuBtn = menuBtn;
-
- UIImageView *imgView = [[UIImageView alloc]init];
- imgView.image = [UIImage imageNamed:@"home_top_arrow"];
- [headerView addSubview:imgView];
- [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(menuBtn.mas_centerY);
- make.left.equalTo(menuBtn.mas_right).offset(2);
- make.width.equalTo(@25);
- make.height.equalTo(@18);
- }];
-
- UILabel *numLabel = [[UILabel alloc]init];
- numLabel.textColor = [UIColor colorWithHexString:@"#999999"];
- numLabel.font = [UIFont systemFontOfSize:14];
- [headerView addSubview:numLabel];
- [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(menuBtn.mas_bottom).offset(10);
- make.left.equalTo(@15);
- make.right.equalTo(@-15);
- make.height.equalTo(@30);
- }];
- self.numLabel = numLabel;
- }
- #pragma mark - 右上角按钮
- -(void)backBtnAction:(UIButton *)button {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)menuBtnAction:(UIButton *)button {
- NSMutableArray *titleArray = [[NSMutableArray alloc]initWithCapacity:5];
- for (int i = 0; i < TheDataManager.homes.count; i++) {
- RDSHomeModel *model = TheDataManager.homes[i];
- [titleArray addObject:model.name];
- }
-
- [YBPopupMenu showRelyOnView:button titles:titleArray icons:nil menuWidth:130 otherSettings:^(YBPopupMenu *popupMenu) {
- popupMenu.delegate = self;
- popupMenu.animationManager.duration = 0.25;
- popupMenu.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
- }];
- }
- #pragma mark - YPPopupMenuDelegate
- - (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index
- {
- RDSHomeModel *model = TheDataManager.homes[index];
- [self getDeviceConsumables:model.record_id];
- self.homeID = model.record_id;
- [self.menuBtn setTitle:model.name forState:UIControlStateNormal];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.devicesArray.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- YXMyDeviceModel *deviceModel = self.devicesArray[section];
- return deviceModel.consumables.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- YXMyDeviceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myDeviceCellID" forIndexPath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
-
- YXMyDeviceModel *deviceModel = self.devicesArray[indexPath.section];
- YXConsumablesModel *model = deviceModel.consumables[indexPath.row];
-
- if (indexPath.row == deviceModel.consumables.count - 1) {
- cell.lineView.hidden = YES;
- }else{
- cell.lineView.hidden = NO;
- }
-
- if ([model.user_rate floatValue] >= 0) {
- [cell.circleBar setProgress:[model.user_rate floatValue] animated:YES];
- }
-
- cell.titleLabel.text = model.consumable_name;
- cell.detailLabel.text = [NSString stringWithFormat:@"已使用%@天",model.used_time];
-
- RDS_WEAKSELF(weakSelf)
- cell.resetClick = ^(UITableViewCell * cell) {
- [weakSelf resetDeviceConsumablesWithId:model.record_id];
- };
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView *headerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)];
- headerBgView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
-
- UIView *headerView = [[UIView alloc]init];
- headerView.backgroundColor = [UIColor whiteColor];
- [headerBgView addSubview:headerView];
- [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@0);
- make.left.equalTo(@15);
- make.right.equalTo(@-15);
- make.bottom.equalTo(@0);
- }];
-
- UIImageView *imgView = [[UIImageView alloc]init];
- imgView.image = [UIImage imageNamed:@"home_device_1"];
- [headerView addSubview:imgView];
- [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(@0);
- make.left.equalTo(@15);
- make.width.equalTo(@40);
- make.height.equalTo(@40);
- }];
-
- UILabel *titleLabel = [[UILabel alloc]init];
- titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
- titleLabel.font = [UIFont boldSystemFontOfSize:16];
- [headerView addSubview:titleLabel];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(imgView.mas_top);
- make.left.equalTo(imgView.mas_right).offset(15);
- make.right.equalTo(@-15);
- make.height.equalTo(@20);
- }];
- UILabel *textLabel = [[UILabel alloc]init];
- textLabel.textColor = [UIColor colorWithHexString:@"#999999"];
- textLabel.font = [UIFont systemFontOfSize:13];
- [headerView addSubview:textLabel];
- [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(titleLabel.mas_bottom);
- make.left.equalTo(imgView.mas_right).offset(15);
- make.right.equalTo(@-15);
- make.height.equalTo(@20);
- }];
-
- UIView *lineView = [[UIView alloc]init];
- lineView.backgroundColor = [UIColor colorWithHexString:@"#E6E6E6"];
- [headerBgView addSubview:lineView];
- [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(@30);
- make.right.equalTo(@-30);
- make.height.equalTo(@1);
- make.bottom.equalTo(@-1);
- }];
-
- YXMyDeviceModel *deviceModel = self.devicesArray[section];
- if (deviceModel.consumables.count == 0) {
- lineView.hidden = YES;
- }else{
- lineView.hidden = NO;
- }
-
- titleLabel.text = deviceModel.device_name;
- textLabel.text = deviceModel.device_type_name;
-
- return headerBgView;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 10)];
- footerView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
- return footerView;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 80;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 10;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 85;
- }
- /*
- #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
|