YXFamilyInfoViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // YXFamilyInfoViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/2/16.
  6. //
  7. #import "YXFamilyInfoViewController.h"
  8. #import "ScrollMenuView.h"
  9. #import "YXFamilyViewController.h"
  10. #import "YXAddFamilyViewController.h"
  11. @interface YXFamilyInfoViewController ()<ScrollMenuViewDelegate>
  12. @property(nonatomic,assign) NSInteger selectIndex;
  13. @property(nonatomic,strong) ScrollMenuView *menuView;
  14. @property(nonatomic,strong) NSMutableArray *titleArray;
  15. @end
  16. @implementation YXFamilyInfoViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.navigationItem.title = @"我的家庭";
  20. self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  21. [self addRightItem];
  22. self.titleArray = [[NSMutableArray alloc]initWithCapacity:5];
  23. [self createMenuView];
  24. }
  25. -(void)viewWillAppear:(BOOL)animated
  26. {
  27. [super viewWillAppear:animated];
  28. [self p_getHomeList];
  29. }
  30. - (void)p_getHomeList
  31. {
  32. RDS_WEAKSELF(weakSelf)
  33. [RDSHudShower showWithStatus:@"正在获取" autoDismiss:NO];
  34. [RDSHomeModel rds_getHomeListIsAdmin:YES finished:^(NSError * _Nullable error) {
  35. [RDSHudShower dismissHUD];
  36. [weakSelf.titleArray removeAllObjects];
  37. for (int i = 0; i < TheDataManager.homes.count; i++) {
  38. RDSHomeModel *model = TheDataManager.homes[i];
  39. [weakSelf.titleArray addObject:model.name];
  40. if ([model.record_id isEqualToString:TheDataManager.current_home_id]) {
  41. weakSelf.selectIndex = i;
  42. }
  43. }
  44. [weakSelf setSubViews];
  45. [weakSelf.menuView changeViewWithAnimate:self.selectIndex];
  46. }];
  47. }
  48. -(void)addRightItem
  49. {
  50. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  51. [rightBtn setImage:[UIImage imageNamed:@"my_family_add"] forState:UIControlStateNormal];
  52. [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  53. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
  54. self.navigationItem.rightBarButtonItem = rightItem;
  55. }
  56. -(void)rightBtnAction:(UIButton *)btn
  57. {
  58. YXAddFamilyViewController *addVc = [[YXAddFamilyViewController alloc]init];
  59. [self.navigationController pushViewController:addVc animated:YES];
  60. }
  61. -(void)createMenuView
  62. {
  63. ScrollMenuView *menuView = [[ScrollMenuView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kNavHeight - kSafeBottomHeight)];
  64. menuView.delegate = self;
  65. menuView.backgroundColor = [UIColor whiteColor];
  66. menuView.backColor = [UIColor whiteColor];
  67. menuView.normalColor = [UIColor colorWithHexString:@"#999999"];
  68. menuView.selectColor = [UIColor colorWithHexString:@"#333333"];
  69. [self.view addSubview:menuView];
  70. self.menuView = menuView;
  71. }
  72. -(void)setSubViews
  73. {
  74. self.menuView.titleArray = self.titleArray;
  75. NSMutableArray *viewsArray = [[NSMutableArray alloc]init];
  76. for (int i = 0; i < TheDataManager.homes.count; i++) {
  77. YXFamilyViewController *fVc = [[YXFamilyViewController alloc]init];
  78. fVc.model = TheDataManager.homes[i];
  79. [self addChildViewController:fVc];
  80. fVc.updateFamilyInfo = ^{
  81. [self p_getHomeList];
  82. };
  83. UIView *view = fVc.view;
  84. view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  85. [viewsArray addObject:view];
  86. }
  87. self.menuView.subArray = viewsArray;
  88. [self.menuView setScrollMenuView];
  89. }
  90. -(void)scrollMenuViewAtIndexPath:(NSInteger)index
  91. {
  92. self.selectIndex = index;
  93. }
  94. /*
  95. #pragma mark - Navigation
  96. // In a storyboard-based application, you will often want to do a little preparation before navigation
  97. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  98. // Get the new view controller using [segue destinationViewController].
  99. // Pass the selected object to the new view controller.
  100. }
  101. */
  102. @end