YXFamilyViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. //
  2. // RXFamilyViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/2/16.
  6. //
  7. #import "YXFamilyViewController.h"
  8. #import "YXFamilyTableViewCell.h"
  9. #import "YXMemberItemView.h"
  10. #import "YXMemberInfoViewController.h"
  11. #import "YXRoomManagerViewController.h"
  12. #import "YXInviteViewController.h"
  13. #import <SDWebImage/SDWebImage.h>
  14. #import "YXAddressViewController.h"
  15. #import "RDSRootControl.h"
  16. @interface YXFamilyViewController ()<UITableViewDataSource,UITableViewDelegate>
  17. @property (weak, nonatomic) UITableView *tableView;
  18. @property (copy, nonatomic) NSArray *listArray;
  19. @property (copy, nonatomic) NSArray *itemArray;
  20. @property (weak, nonatomic) UIScrollView *memberScrollView;
  21. @property (weak, nonatomic) UILabel *roomLabel;
  22. @property (weak, nonatomic) UILabel *deviceLabel;
  23. @property (weak, nonatomic) UILabel *mLabel;
  24. @property (nonatomic,copy) NSString *name;
  25. @property (nonatomic,copy) NSString *province;
  26. @property (nonatomic,copy) NSString *city;
  27. @property (nonatomic,copy) NSString *area;
  28. @property (nonatomic,copy) NSString *address;
  29. @end
  30. @implementation YXFamilyViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  34. self.listArray = @[
  35. @"家庭名称",@"家庭位置",@"房间管理",
  36. ];
  37. [self createTableView];
  38. [self createFooterView];
  39. }
  40. -(void)p_updateHomeInfo
  41. {
  42. self.name = self.name.length == 0 ? self.model.name : self.name;
  43. self.province = self.province.length == 0 ? self.model.province : self.province;
  44. self.city = self.city.length == 0 ? self.model.city : self.city;
  45. self.area = self.area.length == 0 ? self.model.district : self.area;
  46. self.address = self.address.length == 0 ? self.model.address : self.address;
  47. RDS_WEAKSELF(weakSelf)
  48. [RDSDemoApiHelper rds_updateHomeInfoWithHomeId:self.model.record_id name:self.name province:self.province city:self.city district:self.area address:self.address rooms:nil success:^(id responseObject) {
  49. if ([responseObject[@"code"] intValue] == 9999) {
  50. [RDSRootControl shareControl].isLoginSuccess = NO;
  51. TheDataManager.token = @"";
  52. }
  53. if ([responseObject[@"code"] intValue] == 0) {
  54. [RDSHudShower showBottomToast:@"家庭信息更新成功"];
  55. weakSelf.model.name = weakSelf.name;
  56. weakSelf.model.province = weakSelf.province;
  57. weakSelf.model.city = weakSelf.city;
  58. weakSelf.model.district = weakSelf.area;
  59. weakSelf.model.address = weakSelf.address;
  60. [weakSelf.tableView reloadData];
  61. if (weakSelf.updateFamilyInfo) {
  62. weakSelf.updateFamilyInfo();
  63. }
  64. } else{
  65. [RDSHudShower showBottomToast:responseObject[@"message"]];
  66. }
  67. } failure:^(NSError *error) {
  68. }];
  69. }
  70. -(void)createFooterView
  71. {
  72. UIView *footerView = [[UIView alloc]init];
  73. footerView.backgroundColor = [UIColor clearColor];
  74. [self.view addSubview:footerView];
  75. [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.height.equalTo(@100);
  77. make.right.equalTo(@0);
  78. make.left.equalTo(@0);
  79. make.bottom.equalTo(@0);
  80. }];
  81. UIButton *deletBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  82. [deletBtn setTitle:@"删除家庭" forState:UIControlStateNormal];
  83. [deletBtn addTarget:self action:@selector(deleteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  84. [deletBtn setTitleColor:[UIColor colorWithHexString:@"#E50023"] forState:UIControlStateNormal];
  85. deletBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
  86. deletBtn.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  87. [footerView addSubview:deletBtn];
  88. [deletBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.height.equalTo(@45);
  90. make.left.equalTo(@15);
  91. make.right.equalTo(@-15);
  92. make.top.equalTo(@20);
  93. }];
  94. deletBtn.layer.cornerRadius = 22.5;
  95. }
  96. -(void)deleteBtnAction:(UIButton *)btn
  97. {
  98. RDS_WEAKSELF(weakSelf)
  99. [RDSDemoApiHelper rds_delHomeWithHomeId:self.model.record_id success:^(id responseObject) {
  100. if ([responseObject[@"code"] intValue] == 9999) {
  101. [RDSRootControl shareControl].isLoginSuccess = NO;
  102. TheDataManager.token = @"";
  103. }
  104. if ([responseObject[@"code"] intValue] == 0) {
  105. [RDSHudShower showBottomToast:@"删除成功"];
  106. [weakSelf popViewControllerAnimated:YES];
  107. } else{
  108. [RDSHudShower showBottomToast:responseObject[@"message"]];
  109. }
  110. } failure:^(NSError *error) {
  111. [RDSHudShower showBottomToast:@"连接服务器失败"];
  112. }];
  113. }
  114. -(void)createTableView
  115. {
  116. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10) style:UITableViewStyleGrouped];
  117. tableView.delegate = self;
  118. tableView.dataSource = self;
  119. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  120. [tableView registerNib:[UINib nibWithNibName:@"YXFamilyTableViewCell" bundle:nil] forCellReuseIdentifier:@"fCellId"];
  121. tableView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  122. [self.view addSubview:tableView];
  123. self.tableView = tableView;
  124. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.top.equalTo(@0);
  126. make.right.equalTo(@0);
  127. make.left.equalTo(@0);
  128. make.bottom.equalTo(@0);
  129. }];
  130. tableView.layer.cornerRadius = 8;
  131. [self createTableHeaderView];
  132. }
  133. -(void)createTableHeaderView
  134. {
  135. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 260)];
  136. headerView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  137. self.tableView.tableHeaderView = headerView;
  138. UIView *userBgView = [[UIView alloc]init];
  139. userBgView.backgroundColor = [UIColor clearColor];
  140. [headerView addSubview:userBgView];
  141. [userBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.top.equalTo(@0);
  143. make.right.equalTo(@0);
  144. make.left.equalTo(@0);
  145. make.height.equalTo(@90);
  146. }];
  147. [userBgView setNeedsLayout];
  148. [userBgView layoutIfNeeded];
  149. CAGradientLayer *gl = [CAGradientLayer layer];
  150. gl.frame = userBgView.bounds;
  151. gl.startPoint = CGPointMake(0.5, 0);
  152. gl.endPoint = CGPointMake(0.5, 1);
  153. gl.colors = @[(__bridge id)[UIColor colorWithRed:229/255.0 green:238/255.0 blue:254/255.0 alpha:1].CGColor, (__bridge id)[UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1].CGColor];
  154. [userBgView.layer addSublayer:gl];
  155. UILabel *textLabel = [[UILabel alloc]init];
  156. textLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  157. textLabel.font = [UIFont boldSystemFontOfSize:16];
  158. textLabel.text = @"家庭信息";
  159. textLabel.textAlignment = NSTextAlignmentLeft;
  160. [userBgView addSubview:textLabel];
  161. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  162. make.top.equalTo(@25);
  163. make.left.equalTo(@20);
  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. self.roomLabel = roomLabel;
  188. UIImageView *deviceImgView = [[UIImageView alloc]init];
  189. deviceImgView.image = [UIImage imageNamed:@"my_icon_device"];
  190. [userBgView addSubview:deviceImgView];
  191. [deviceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  192. make.centerY.equalTo(roomImgView.mas_centerY);
  193. make.left.equalTo(roomLabel.mas_right).offset(5);
  194. make.width.equalTo(@10);
  195. make.height.equalTo(@10);
  196. }];
  197. UILabel *deviceLabel = [[UILabel alloc]init];
  198. deviceLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  199. deviceLabel.font = [UIFont systemFontOfSize:12];
  200. deviceLabel.textAlignment = NSTextAlignmentLeft;
  201. [userBgView addSubview:deviceLabel];
  202. [deviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  203. make.centerY.equalTo(roomImgView.mas_centerY);
  204. make.left.equalTo(deviceImgView.mas_right).offset(5);
  205. make.height.equalTo(@20);
  206. make.width.equalTo(@50);
  207. }];
  208. self.deviceLabel = deviceLabel;
  209. UIImageView *mImgView = [[UIImageView alloc]init];
  210. mImgView.image = [UIImage imageNamed:@"my_icon_member"];
  211. [userBgView addSubview:mImgView];
  212. [mImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  213. make.centerY.equalTo(roomImgView.mas_centerY);
  214. make.left.equalTo(deviceLabel.mas_right).offset(5);
  215. make.width.equalTo(@10);
  216. make.height.equalTo(@10);
  217. }];
  218. UILabel *mLabel = [[UILabel alloc]init];
  219. mLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  220. mLabel.font = [UIFont systemFontOfSize:12];
  221. mLabel.textAlignment = NSTextAlignmentLeft;
  222. [userBgView addSubview:mLabel];
  223. [mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  224. make.centerY.equalTo(roomImgView.mas_centerY);
  225. make.left.equalTo(mImgView.mas_right).offset(5);
  226. make.height.equalTo(@20);
  227. make.width.equalTo(@50);
  228. }];
  229. self.mLabel = mLabel;
  230. UIView *memberBgView = [[UIView alloc]init];
  231. memberBgView.backgroundColor = [UIColor whiteColor];
  232. [headerView addSubview:memberBgView];
  233. [memberBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  234. make.top.equalTo(userBgView.mas_bottom).offset(15);
  235. make.right.equalTo(@-15);
  236. make.left.equalTo(@15);
  237. make.height.equalTo(@135);
  238. }];
  239. UILabel *memberLabel = [[UILabel alloc]init];
  240. memberLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  241. memberLabel.font = [UIFont boldSystemFontOfSize:15];
  242. memberLabel.text = @"家庭成员";
  243. memberLabel.textAlignment = NSTextAlignmentLeft;
  244. [memberBgView addSubview:memberLabel];
  245. [memberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  246. make.top.equalTo(@15);
  247. make.left.equalTo(@15);
  248. make.height.equalTo(@20);
  249. make.width.equalTo(@150);
  250. }];
  251. UIScrollView *mScrollView = [[UIScrollView alloc]init];
  252. mScrollView.showsVerticalScrollIndicator = NO;
  253. mScrollView.showsHorizontalScrollIndicator = NO;
  254. [memberBgView addSubview:mScrollView];
  255. [mScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  256. make.top.equalTo(memberLabel.mas_bottom).offset(15);
  257. make.left.equalTo(@15);
  258. make.right.equalTo(@-15);
  259. make.bottom.equalTo(@15);
  260. }];
  261. self.memberScrollView = mScrollView;
  262. NSInteger num = self.model.member.count;
  263. mScrollView.contentSize = CGSizeMake((num + 1)*(50 + 30), 80);
  264. for (int i = 0; i <= num; i++) {
  265. YXMemberItemView *itemView = [[YXMemberItemView alloc]initWithFrame:CGRectMake(i*(50 + 30), 0, 50, 80)];
  266. [self.memberScrollView addSubview:itemView];
  267. if (i == num) {
  268. itemView.picImgView.image = [UIImage imageNamed:@"my_add"];
  269. itemView.nameLabel.text = @"邀请家人";
  270. UITapGestureRecognizer *addTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addTapAction:)];
  271. [itemView addGestureRecognizer:addTap];
  272. }else{
  273. YXMemberModel *memberModel = self.model.member[i];
  274. itemView.nameLabel.text = memberModel.user_name;
  275. [itemView.picImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", TheApiHelper.baseUrlHeadImg, memberModel.photo]] placeholderImage:[UIImage imageNamed:@"my_pic"]];
  276. if ([self.model.admin_id isEqualToString:memberModel.user_id]) {
  277. itemView.markLabel.hidden = NO;
  278. } else {
  279. itemView.markLabel.hidden = YES;
  280. }
  281. itemView.tag = i;
  282. UITapGestureRecognizer *infoTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(infoTapAction:)];
  283. [itemView addGestureRecognizer:infoTap];
  284. }
  285. }
  286. [self setHeaderData];
  287. }
  288. -(void)setHeaderData
  289. {
  290. self.roomLabel.text = [NSString stringWithFormat:@"房间 %ld |",self.model.room.count];
  291. self.deviceLabel.text = [NSString stringWithFormat:@"设备 %ld |",self.model.devices.count];
  292. self.mLabel.text = [NSString stringWithFormat:@"成员 %ld",self.model.member.count];
  293. }
  294. -(void)addTapAction:(UITapGestureRecognizer *) tap
  295. {
  296. YXInviteViewController *inviteVc = [[YXInviteViewController alloc]init];
  297. inviteVc.homeName = self.model.name;
  298. inviteVc.homeId = self.model.record_id;
  299. [self.navigationController pushViewController:inviteVc animated:YES];
  300. }
  301. -(void)infoTapAction:(UITapGestureRecognizer *) tap
  302. {
  303. NSInteger tag = tap.view.tag;
  304. YXMemberModel *model = self.model.member[tag];
  305. YXMemberInfoViewController *infoVc = [[YXMemberInfoViewController alloc]init];
  306. infoVc.model = model;
  307. infoVc.familyName = self.model.name;
  308. if ([self.model.admin_id isEqualToString:model.user_id]) {
  309. infoVc.isCreator = YES;
  310. } else {
  311. infoVc.isCreator = NO;
  312. }
  313. [self.navigationController pushViewController:infoVc animated:YES];
  314. }
  315. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  316. {
  317. return 1;
  318. }
  319. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  320. {
  321. return self.listArray.count;
  322. }
  323. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  324. {
  325. YXFamilyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fCellId" forIndexPath:indexPath];
  326. cell.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  327. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  328. NSString *name = self.listArray[indexPath.row];
  329. cell.nameLabel.text = name;
  330. if (indexPath.row == 0) {
  331. cell.textLabel.text = self.model.name;
  332. } else if (indexPath.row == 1) {
  333. cell.textLabel.text = [NSString stringWithFormat:@"%@%@%@%@",self.model.province,self.model.city,self.model.district,self.model.address];
  334. } else if (indexPath.row == 2) {
  335. cell.textLabel.text = [NSString stringWithFormat:@" %ld个房间",self.model.room.count];
  336. }
  337. if (indexPath.row == 2) {
  338. cell.lineView.hidden = YES;
  339. }else{
  340. cell.lineView.hidden = NO;
  341. }
  342. return cell;
  343. }
  344. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  345. {
  346. if (indexPath.row == 0) {
  347. [self alertWithText:@"家庭名称"];
  348. } else if (indexPath.row == 1) {
  349. RDS_WEAKSELF(weakSelf)
  350. YXAddressViewController *vc = [[YXAddressViewController alloc]init];
  351. vc.oldProvince = self.model.province;
  352. vc.oldCity = self.model.city;
  353. vc.oldArea = self.model.district;
  354. vc.oldDetail = self.model.address;
  355. [self.navigationController pushViewController:vc animated:YES];
  356. vc.sureBtnClick = ^(NSString * _Nonnull province, NSString * _Nonnull city, NSString * _Nonnull area, NSString * _Nonnull address) {
  357. weakSelf.province = province;
  358. weakSelf.city = city;
  359. weakSelf.area = area;
  360. weakSelf.address = address;
  361. [weakSelf p_updateHomeInfo];
  362. };
  363. } else if (indexPath.row == 2) {
  364. YXRoomManagerViewController *roomVc = [[YXRoomManagerViewController alloc] init];
  365. roomVc.homeID = self.model.record_id;
  366. [self.navigationController pushViewController:roomVc animated:YES];
  367. }
  368. }
  369. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  370. {
  371. UIView *headerView = [[UIView alloc]init];
  372. return headerView;
  373. }
  374. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  375. {
  376. UIView *footerView = [[UIView alloc]init];
  377. return footerView;
  378. }
  379. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  380. {
  381. return 0.01;
  382. }
  383. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  384. {
  385. return 0.01;
  386. }
  387. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  388. {
  389. return 65;
  390. }
  391. -(void)alertWithText:(NSString *)text
  392. {
  393. RDS_WEAKSELF(weakSelf)
  394. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:text message:nil preferredStyle:UIAlertControllerStyleAlert];
  395. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  396. UITextField *txt = [alertController.textFields objectAtIndex:0];
  397. NSLog(@"%@",txt.text);
  398. weakSelf.name = txt.text;
  399. [weakSelf p_updateHomeInfo];
  400. }];
  401. [alertController addAction:sureAction];
  402. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  403. }];
  404. [alertController addAction:cancelAction];
  405. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  406. textField.placeholder = [NSString stringWithFormat:@"请输入%@",text];
  407. textField.text = self.model.name;
  408. }];
  409. [self presentViewController:alertController animated:YES completion:nil];
  410. }
  411. /*
  412. #pragma mark - Navigation
  413. // In a storyboard-based application, you will often want to do a little preparation before navigation
  414. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  415. // Get the new view controller using [segue destinationViewController].
  416. // Pass the selected object to the new view controller.
  417. }
  418. */
  419. @end