SKMineViewController+baby.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // SKMineViewController+baby.m
  3. // Overseas Watch
  4. //
  5. // Created by 刘振兴 on 2024/1/19.
  6. // Copyright © 2024 BaH Cy. All rights reserved.
  7. //
  8. #import "SKMineViewController+baby.h"
  9. #import "SKBabyListCellViewCell.h"
  10. #import "SKBabyDetailInfoViewController.h"
  11. #import "SKBabyQRCodeViewController.h"
  12. @implementation SKMineViewController (baby)
  13. - (UITableViewCell *)babyTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  14. static NSString *cellID = @"BabyListCellID";
  15. SKBabyListCellViewCell *cell = (SKBabyListCellViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
  16. if(cell == nil) {
  17. cell = [[SKBabyListCellViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
  18. }
  19. [cell setData:indexPath.row];
  20. cell.mCellCallback = ^(NSInteger rowIndex, NSInteger btnIndex) {
  21. self.seletedBabyIdx = rowIndex;
  22. if (btnIndex == 1) {
  23. [self showAlert:1];
  24. } else if (btnIndex == 2) {
  25. [self showAlert:2];
  26. } else if (btnIndex == 3) {
  27. [self showBind:rowIndex];
  28. } else if (btnIndex == 11) {
  29. [self showBabyDetail:rowIndex];
  30. } else if (btnIndex == 12) {
  31. [self showBabyQRCode:rowIndex];
  32. }
  33. };
  34. return cell;
  35. }
  36. - (void)babyTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  37. }
  38. - (void)deleteWatch:(NSInteger)index {
  39. ChildModel *child = [[DataManager shared] getIndexChild:index];
  40. NSDictionary *param = @{
  41. @"cid":child.cid,
  42. @"deviceId":@(child.device.did),
  43. @"ticket":child.device.ticket,
  44. };
  45. //@"解绑中..."
  46. [self ShowHUBWithText:NSLocalizedString(@"DB.Remove.Bind.Ing", nil)];
  47. [ERequest httpRequest:param httpURL:URL_DEVICE_DELETE httpMethod:@"POST" onSuccess:^(NSDictionary *result) {
  48. [self HiddenHUB];
  49. if ([ERequest isSuccessWithResult:result]) {
  50. //@"解绑成功"
  51. [EasyTextView showSuccessText:NSLocalizedString(@"DB.Remove.Bind.Success", nil)];
  52. [[DataManager shared] removeDevice:index];
  53. [self.mTableView reloadData];
  54. } else {
  55. [EasyTextView showErrorText:result[@"message"]];
  56. }
  57. } onFailure:^(NSError *error) {
  58. [self HiddenHUB];
  59. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
  60. }];
  61. }
  62. - (void)deleteChild:(NSInteger)index {
  63. ChildModel *child = [[DataManager shared] getIndexChild:index];
  64. NSString* cid = child.cid;
  65. [self ShowHUBWithText:NSLocalizedString(@"Cancel.Following...", nil)];//@"取消关注中..."];
  66. [ERequest httpRequest:@{} path:cid httpURL:URL_CHILD_DELETE httpMethod:@"GET" onSuccess:^(NSDictionary *result) {
  67. [self HiddenHUB];
  68. if ([ERequest isSuccessWithResult:result]) {
  69. if([[DataManager shared] getChildCount] - 1 > 0) {
  70. if (index >= 0) {
  71. [[DataManager shared] removeData:index];
  72. }
  73. [self.mTableView reloadData];
  74. [EUtil postInformation:@"RELOAD_CHILDS_DEVICES"];
  75. } else {
  76. [[DataManager shared] logout];
  77. }
  78. } else {
  79. [EasyTextView showErrorText:result[@"message"]];
  80. }
  81. } onFailure:^(NSError *error) {
  82. [self HiddenHUB];
  83. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];//@"网络错误"];
  84. }];
  85. }
  86. - (void)showBind:(NSInteger)index {
  87. [MobClick event:@"ClickAddBindAgain"];
  88. ChildModel *child = [[DataManager shared] getIndexChild:index];
  89. [DataManager shared].bindOptions = BO_REBIND;
  90. SKBabyDetailInfoViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"BabyDetailInfo"];
  91. controller.opType = 3;
  92. controller.childModel = child;
  93. [self pushViewController:controller animated:YES];
  94. }
  95. - (void)showBabyDetail:(NSInteger)index {
  96. ChildModel* model = [[DataManager shared] getIndexChild:index];
  97. if (model.role > ROLE_ADMIN)
  98. return;
  99. ChildModel *child = [[DataManager shared] getIndexChild:index];
  100. SKBabyDetailInfoViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"BabyDetailInfo"];
  101. controller.opType = 1;
  102. controller.childModel = [child mutableCopy];
  103. [self pushViewController:controller animated:YES];
  104. }
  105. - (void)showBabyQRCode:(NSInteger)index {
  106. [MobClick event:@"ClickBabyQRCode"];
  107. ChildModel *child = [[DataManager shared] getIndexChild:index];
  108. SKBabyQRCodeViewController *controller = [[self storyboard] instantiateViewControllerWithIdentifier:@"BabyQRCodeVC"];
  109. controller.cid = child.cid;
  110. [self pushViewController:controller animated:YES];
  111. }
  112. #pragma mark - popup
  113. - (void)showAlert:(NSInteger)type {
  114. NSString* title;
  115. NSString* content;
  116. if (type == 1) {
  117. title = NSLocalizedString(@"Baby.List.Alert.1", nil);
  118. content = NSLocalizedString(@"Baby.List.Alert.Content.1", nil);
  119. } else {
  120. title = NSLocalizedString(@"Baby.List.Alert.2", nil);
  121. content = NSLocalizedString(@"Baby.List.Alert.Content.2", nil);
  122. }
  123. UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
  124. [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SK.Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  125. }]];
  126. [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SK.Confirm", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  127. if (type == 1) {
  128. [self deleteWatch:self.seletedBabyIdx];
  129. } else if (type == 2) {
  130. [self deleteChild:self.seletedBabyIdx];
  131. }
  132. }]];
  133. [self presentViewController:alert animated:YES completion:nil];
  134. }
  135. @end