YXMyViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. //
  2. // YXMyViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/2/10.
  6. //
  7. #import "YXMyViewController.h"
  8. #import "MyListTableViewCell.h"
  9. #import "YXMyInfoViewController.h"
  10. #import "YXFamilyInfoViewController.h"
  11. #import "YXMyDeviceViewController.h"
  12. #import "YXInviteViewController.h"
  13. #import "RDSSystemSetVC.h"
  14. #import "RDSRootControl.h"
  15. #import <SDWebImage/SDWebImage.h>
  16. #import <MJRefresh/MJRefresh.h>
  17. #import "RDSControlWebVC.h"
  18. @interface YXMyViewController ()<UITableViewDataSource,UITableViewDelegate>
  19. @property (weak, nonatomic) UIView *contentView;
  20. @property (weak, nonatomic) UITableView *tableView;
  21. @property (copy, nonatomic) NSArray *listArray;
  22. @property (copy, nonatomic) NSArray *iconImgArray;
  23. @end
  24. @implementation YXMyViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // 隐藏导航栏
  28. self.fd_prefersNavigationBarHidden = YES;
  29. self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F5FA"];
  30. self.listArray = @[
  31. @"设备耗材",@"系统设置",@"帮助与反馈",
  32. ];
  33. self.iconImgArray = @[
  34. @"my_device",@"my_set",@"my_help",
  35. ];
  36. [self createTableView];
  37. [self refreshUserInfo];
  38. [self p_getCurrentUserInfo];
  39. }
  40. -(void)viewWillAppear:(BOOL)animated
  41. {
  42. [super viewWillAppear:animated];
  43. [self createTableHeaderView];
  44. }
  45. - (void)p_getCurrentUserInfo{
  46. RDS_WEAKSELF(weakSelf)
  47. [RDSUserInfoModel rds_getCurrentUserInfoFinished:^(NSError *error) {
  48. if (!error) {
  49. [weakSelf.tableView reloadData];
  50. [weakSelf.tableView.mj_header endRefreshing];
  51. }
  52. }];
  53. }
  54. -(void)refreshUserInfo
  55. {
  56. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(p_getCurrentUserInfo)];
  57. header.automaticallyChangeAlpha = YES;
  58. header.lastUpdatedTimeLabel.hidden = YES;
  59. self.tableView.mj_header = header;
  60. }
  61. -(void)createTableView
  62. {
  63. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10) style:UITableViewStyleGrouped];
  64. tableView.delegate = self;
  65. tableView.dataSource = self;
  66. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  67. [tableView registerNib:[UINib nibWithNibName:@"MyListTableViewCell" bundle:nil] forCellReuseIdentifier:@"myCellId"];
  68. tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F5FA"];
  69. tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  70. tableView.insetsContentViewsToSafeArea = false;
  71. [self.view addSubview:tableView];
  72. self.tableView = tableView;
  73. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(@0);
  75. make.right.equalTo(@0);
  76. make.left.equalTo(@0);
  77. make.bottom.equalTo(@0);
  78. }];
  79. tableView.layer.cornerRadius = 8;
  80. [self createTableHeaderView];
  81. [self createTableFooterView];
  82. }
  83. -(void)createTableHeaderView
  84. {
  85. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 260)];
  86. headerView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  87. self.tableView.tableHeaderView = headerView;
  88. UIImageView *bgImgView = [[UIImageView alloc]init];
  89. bgImgView.image = [UIImage imageNamed:@"my_top_bg"];
  90. [headerView addSubview:bgImgView];
  91. [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.bottom.left.right.equalTo(@0);
  93. }];
  94. UIView *bgView = [[UIView alloc]init];
  95. bgView.backgroundColor = [UIColor clearColor];
  96. [headerView addSubview:bgView];
  97. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.top.equalTo(@60);
  99. make.right.equalTo(@-15);
  100. make.left.equalTo(@15);
  101. make.height.equalTo(@55);
  102. }];
  103. UIImageView *picView = [[UIImageView alloc]init];
  104. [bgView addSubview:picView];
  105. [picView mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.equalTo(@20);
  107. make.width.equalTo(@55);
  108. make.height.equalTo(@55);
  109. make.centerY.equalTo(@0);
  110. }];
  111. picView.layer.cornerRadius = 27.5;
  112. picView.layer.masksToBounds = YES;
  113. [picView sd_setImageWithURL:[NSURL URLWithString:TheDataManager.currentUser.photo] placeholderImage:[UIImage imageNamed:@"my_pic"]];
  114. UILabel *nameLabel = [[UILabel alloc]init];
  115. nameLabel.textColor = [UIColor colorWithHexString:@"#000000"];
  116. nameLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  117. nameLabel.text = TheDataManager.currentUser.user_name;
  118. [bgView addSubview:nameLabel];
  119. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.top.equalTo(picView.mas_top);
  121. make.left.equalTo(picView.mas_right).offset(15);
  122. make.height.equalTo(@30);
  123. make.width.equalTo(@150);
  124. }];
  125. UILabel *detailLabel = [[UILabel alloc]init];
  126. detailLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  127. detailLabel.font = [UIFont systemFontOfSize:13];
  128. detailLabel.text = [NSString stringWithFormat:@"家庭 %@|智能设备 %@",TheDataManager.currentUser.home_count,TheDataManager.currentUser.all_devices];
  129. [bgView addSubview:detailLabel];
  130. [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.bottom.equalTo(picView.mas_bottom);
  132. make.left.equalTo(picView.mas_right).offset(15);
  133. make.height.equalTo(@30);
  134. make.width.equalTo(@150);
  135. }];
  136. UIImageView *imgView = [[UIImageView alloc]init];
  137. imgView.image = [UIImage imageNamed:@"home_right_arrow"];
  138. [bgView addSubview:imgView];
  139. [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.centerY.equalTo(@0);
  141. make.right.equalTo(@-30);
  142. make.width.equalTo(@9);
  143. make.height.equalTo(@15);
  144. }];
  145. UIView *userBgView = [[UIView alloc]init];
  146. userBgView.backgroundColor = [UIColor whiteColor];
  147. [headerView addSubview:userBgView];
  148. [userBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.top.equalTo(bgView.mas_bottom).offset(30);
  150. make.right.equalTo(@-15);
  151. make.left.equalTo(@15);
  152. make.height.equalTo(@80);
  153. }];
  154. userBgView.layer.cornerRadius = 8;
  155. UILabel *textLabel = [[UILabel alloc]init];
  156. textLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  157. textLabel.font = [UIFont boldSystemFontOfSize:15];
  158. textLabel.text = TheDataManager.current_home_name;
  159. textLabel.textAlignment = NSTextAlignmentLeft;
  160. [userBgView addSubview:textLabel];
  161. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  162. make.top.equalTo(@15);
  163. make.left.equalTo(@15);
  164. make.height.equalTo(@20);
  165. make.width.equalTo(@150);
  166. }];
  167. UIImageView *roomImgView = [[UIImageView alloc]init];
  168. roomImgView.image = [UIImage imageNamed:@"my_icon_room"];
  169. [userBgView addSubview:roomImgView];
  170. [roomImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.top.equalTo(textLabel.mas_bottom).offset(15);
  172. make.left.equalTo(textLabel.mas_left);
  173. make.width.equalTo(@10);
  174. make.height.equalTo(@10);
  175. }];
  176. UILabel *roomLabel = [[UILabel alloc]init];
  177. roomLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  178. roomLabel.font = [UIFont systemFontOfSize:12];
  179. roomLabel.textAlignment = NSTextAlignmentLeft;
  180. [userBgView addSubview:roomLabel];
  181. [roomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.centerY.equalTo(roomImgView.mas_centerY);
  183. make.left.equalTo(roomImgView.mas_right).offset(5);
  184. make.height.equalTo(@20);
  185. make.width.equalTo(@50);
  186. }];
  187. UIImageView *deviceImgView = [[UIImageView alloc]init];
  188. deviceImgView.image = [UIImage imageNamed:@"my_icon_device"];
  189. [userBgView addSubview:deviceImgView];
  190. [deviceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  191. make.centerY.equalTo(roomImgView.mas_centerY);
  192. make.left.equalTo(roomLabel.mas_right).offset(5);
  193. make.width.equalTo(@10);
  194. make.height.equalTo(@10);
  195. }];
  196. UILabel *deviceLabel = [[UILabel alloc]init];
  197. deviceLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  198. deviceLabel.font = [UIFont systemFontOfSize:12];
  199. deviceLabel.textAlignment = NSTextAlignmentLeft;
  200. [userBgView addSubview:deviceLabel];
  201. [deviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  202. make.centerY.equalTo(roomImgView.mas_centerY);
  203. make.left.equalTo(deviceImgView.mas_right).offset(5);
  204. make.height.equalTo(@20);
  205. make.width.equalTo(@50);
  206. }];
  207. UIImageView *mImgView = [[UIImageView alloc]init];
  208. mImgView.image = [UIImage imageNamed:@"my_icon_member"];
  209. [userBgView addSubview:mImgView];
  210. [mImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  211. make.centerY.equalTo(roomImgView.mas_centerY);
  212. make.left.equalTo(deviceLabel.mas_right).offset(5);
  213. make.width.equalTo(@10);
  214. make.height.equalTo(@10);
  215. }];
  216. UILabel *mLabel = [[UILabel alloc]init];
  217. mLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  218. mLabel.font = [UIFont systemFontOfSize:12];
  219. mLabel.textAlignment = NSTextAlignmentLeft;
  220. [userBgView addSubview:mLabel];
  221. [mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  222. make.centerY.equalTo(roomImgView.mas_centerY);
  223. make.left.equalTo(mImgView.mas_right).offset(5);
  224. make.height.equalTo(@20);
  225. make.width.equalTo(@50);
  226. }];
  227. UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  228. [addBtn setTitle:@"邀请" forState:UIControlStateNormal];
  229. [addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  230. [addBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  231. addBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  232. addBtn.backgroundColor = [UIColor colorWithHexString:@"#267AFF"];
  233. [userBgView addSubview:addBtn];
  234. [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  235. make.height.equalTo(@30);
  236. make.width.equalTo(@60);
  237. make.right.equalTo(@-15);
  238. make.centerY.equalTo(@0);
  239. }];
  240. addBtn.layer.cornerRadius = 5;
  241. if (TheDataManager.homes.count > TheDataManager.current_home_index) {
  242. RDSHomeModel *model = TheDataManager.homes[TheDataManager.current_home_index];
  243. roomLabel.text = [NSString stringWithFormat:@"房间 %ld",model.room.count];
  244. deviceLabel.text = [NSString stringWithFormat:@"设备 %ld",model.devices.count];
  245. mLabel.text = [NSString stringWithFormat:@"成员 %ld",model.member.count];
  246. }
  247. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userInfoTapAction)];
  248. [bgView addGestureRecognizer:tap];
  249. UITapGestureRecognizer *roomTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(roomTapAction)];
  250. [userBgView addGestureRecognizer:roomTap];
  251. }
  252. -(void)userInfoTapAction
  253. {
  254. YXMyInfoViewController *infoVc = [[YXMyInfoViewController alloc]init];
  255. infoVc.hidesBottomBarWhenPushed = YES;
  256. [self.navigationController pushViewController:infoVc animated:true];
  257. }
  258. -(void)roomTapAction
  259. {
  260. YXFamilyInfoViewController *roomVc = [[YXFamilyInfoViewController alloc]init];
  261. roomVc.hidesBottomBarWhenPushed = YES;
  262. [self.navigationController pushViewController:roomVc animated:true];
  263. }
  264. -(void)addBtnAction:(UIButton *)btn
  265. {
  266. YXInviteViewController *inviteVc = [[YXInviteViewController alloc]init];
  267. inviteVc.homeName = TheDataManager.current_home_name;
  268. inviteVc.homeId = TheDataManager.current_home_id;
  269. inviteVc.hidesBottomBarWhenPushed = YES;
  270. [self.navigationController pushViewController:inviteVc animated:YES];
  271. }
  272. -(void)createTableFooterView
  273. {
  274. UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)];
  275. footerView.backgroundColor = [UIColor clearColor];
  276. self.tableView.tableFooterView = footerView;
  277. UIButton *logoutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  278. [logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
  279. [logoutBtn addTarget:self action:@selector(logoutBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  280. [logoutBtn setTitleColor:[UIColor colorWithHexString:@"#267AFF"] forState:UIControlStateNormal];
  281. logoutBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
  282. logoutBtn.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  283. [footerView addSubview:logoutBtn];
  284. [logoutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  285. make.height.equalTo(@55);
  286. make.left.equalTo(@15);
  287. make.right.equalTo(@-15);
  288. make.top.equalTo(@15);
  289. }];
  290. logoutBtn.layer.cornerRadius = 8;
  291. }
  292. -(void)logoutBtnAction:(UIButton *)btn
  293. {
  294. RDS_WEAKSELF(weakSelf)
  295. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确定退出登录?" preferredStyle:UIAlertControllerStyleAlert];
  296. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  297. [self logoutAlert];
  298. }];
  299. [alertController addAction:sureAction];
  300. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  301. }];
  302. [alertController addAction:cancelAction];
  303. [self presentViewController:alertController animated:YES completion:nil];
  304. }
  305. -(void)logoutAlert
  306. {
  307. [RDSHudShower showWithStatus:@"加载中..." autoDismiss:NO];
  308. [RDSDemoApiHelper rds_logoutSuccess:^(id responseObject) {
  309. if ([responseObject[@"code"] intValue] == 0) {
  310. [RDSHudShower dismissHUD];
  311. [RDSRootControl shareControl].isLoginSuccess = NO;
  312. } else{
  313. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  314. }
  315. } failure:^(NSError *error) {
  316. [RDSHudShower showBottomToast:@"连接服务器失败"];
  317. [RDSRootControl shareControl].isLoginSuccess = NO;
  318. }];
  319. TheDataManager.token = @"";
  320. }
  321. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  322. {
  323. return 1;
  324. }
  325. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  326. {
  327. return self.listArray.count;
  328. }
  329. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  330. {
  331. MyListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCellId" forIndexPath:indexPath];
  332. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  333. NSString *name = self.listArray[indexPath.row];
  334. cell.titleLabel.text = name;
  335. NSString *img = self.iconImgArray[indexPath.row];
  336. cell.iconImgView.image = [UIImage imageNamed:img];
  337. return cell;
  338. }
  339. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  340. {
  341. if (indexPath.row == 0) {
  342. YXMyDeviceViewController *myDeviceVc = [[YXMyDeviceViewController alloc]init];
  343. myDeviceVc.hidesBottomBarWhenPushed = YES;
  344. [self.navigationController pushViewController:myDeviceVc animated:YES];
  345. } else if (indexPath.row == 1){
  346. RDSSystemSetVC *setVc = [[RDSSystemSetVC alloc]init];
  347. setVc.hidesBottomBarWhenPushed = YES;
  348. [self.navigationController pushViewController:setVc animated:YES];
  349. } else if (indexPath.row == 2){
  350. RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
  351. webVc.requestURL = [NSString stringWithFormat:@"%@helpList",kBaseUrlH5];
  352. webVc.hidesBottomBarWhenPushed = YES;
  353. [self.navigationController pushViewController:webVc animated:YES];
  354. }
  355. }
  356. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  357. {
  358. UIView *headerView = [[UIView alloc]init];
  359. return headerView;
  360. }
  361. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  362. {
  363. UIView *footerView = [[UIView alloc]init];
  364. return footerView;
  365. }
  366. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  367. {
  368. return 0.01;
  369. }
  370. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  371. {
  372. return 0.01;
  373. }
  374. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  375. {
  376. return 65;
  377. }
  378. /*
  379. #pragma mark - Navigation
  380. // In a storyboard-based application, you will often want to do a little preparation before navigation
  381. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  382. // Get the new view controller using [segue destinationViewController].
  383. // Pass the selected object to the new view controller.
  384. }
  385. */
  386. @end