SLUserCenterViewController.m 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // SLUserCenterViewController.m
  3. // SLAiELTS
  4. //
  5. // Created by Gusont on 2023/3/9.
  6. //
  7. #import "SLUserCenterViewController.h"
  8. #import "SLBaseTableViewCell.h"
  9. #import "SLModifyNicknameVc.h"
  10. #import "SLChangeMobileVc.h"
  11. #import "SLImagePickerAndUpload.h"
  12. #import "SLCitySetVc.h"
  13. #import "SLMsgBgSetVc.h"
  14. @interface SLUserCenterViewController ()<UITableViewDelegate, UITableViewDataSource>
  15. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  16. @property (nonatomic, strong) NSMutableArray<NSArray<SLPageModelDetail *> *> *dataModels;
  17. @property (nonatomic, strong) SLImagePickerAndUpload *imageUpload;
  18. @end
  19. @implementation SLUserCenterViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view from its nib.
  23. self.title = self.isSetting ? NSLocalizedString(@"通用设置", nil) : NSLocalizedString(@"个人中心", nil);
  24. if (@available(iOS 11.0, *)) {
  25. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  26. } else {
  27. self.automaticallyAdjustsScrollViewInsets = NO;
  28. }
  29. self.tableView.estimatedRowHeight = 100;
  30. [self.tableView registerNibCellWithReuseIdentifierClass:SLBaseTableViewCell.class];
  31. self.tableView.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated {
  34. [super viewWillAppear: animated];
  35. _dataModels = nil;
  36. [self.tableView reloadData];
  37. }
  38. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  39. SLBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SLBaseTableViewCell"];
  40. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  41. [cell confignCell:detail];
  42. return cell;
  43. }
  44. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  45. return [self.dataModels objectAtIndex:section].count;
  46. }
  47. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  48. return self.dataModels.count;
  49. }
  50. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  51. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  52. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  53. if ([detail.title isEqualToString:NSLocalizedString(@"头像", nil)]) {
  54. [self.imageUpload willShowActionSheet];
  55. }
  56. if ([detail.title isEqualToString:NSLocalizedString(@"昵称", nil)]) {
  57. SLModifyNicknameVc *vc = [SLModifyNicknameVc loadViewControllewWithNib];
  58. [self navPushViewController:vc animated:YES];
  59. }
  60. if ([detail.title isEqualToString:NSLocalizedString(@"手机号", nil)]) {
  61. SLChangeMobileVc *vc = [SLChangeMobileVc loadViewControllewWithNib];
  62. [self navPushViewController:vc animated:YES];
  63. }
  64. if ([detail.title isEqualToString:NSLocalizedString(@"地区", nil)]) {
  65. SLCitySetVc *vc = [SLCitySetVc loadViewControllewWithNib];
  66. [self navPushViewController:vc animated:YES];
  67. }
  68. if ([detail.title isEqualToString:NSLocalizedString(@"退出登录", nil)]) {
  69. [SLCustomizeAlert showAletrWithTitle:NSLocalizedString(@"退出确认", nil) message:NSLocalizedString(@"是否确认退出登录?", nil) sureBtnTitle:NSLocalizedString(@"确定", nil) cancelBtnTitle:NSLocalizedString(@"取消", nil) sureBtnAction:^{
  70. [[SLGlobalInfo SharedInstance] userLogout];
  71. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  72. [appDelegate setLoginVcWithRootWindow];
  73. } cancelBtnAction:^{
  74. }];
  75. }
  76. if ([detail.title isEqualToString:NSLocalizedString(@"用户服务协议", nil)]) {
  77. NSString *urlStr = @"http://115.238.47.234:8446/index.html";
  78. SLWebViewController *vc = [SLWebViewController loadViewControllewWithNib];
  79. vc.webUrlStr = urlStr;
  80. vc.title = detail.title;
  81. [self navPushViewController:vc animated:YES];
  82. }
  83. if ([detail.title isEqualToString:NSLocalizedString(@"免责声明", nil)]) {
  84. NSString *urlStr = @"http://115.238.47.234:8446/mzsm.html";
  85. SLWebViewController *vc = [SLWebViewController loadViewControllewWithNib];
  86. vc.webUrlStr = urlStr;
  87. vc.title = detail.title;
  88. [self navPushViewController:vc animated:YES];
  89. }
  90. if ([detail.title isEqualToString:NSLocalizedString(@"清空聊天记录", nil)]) {
  91. [SLCustomizeAlert showAletrWithTitle:NSLocalizedString(@"温馨提示", nil) message:NSLocalizedString(@"是否清空聊天记录?", nil) sureBtnTitle:NSLocalizedString(@"确定", nil) cancelBtnTitle:NSLocalizedString(@"取消", nil) sureBtnAction:^{
  92. [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Chat/ResetChatRecord" parameter:@{} success:^(id responseObject) {
  93. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  94. NSDictionary *dic = [userDefaults dictionaryRepresentation];
  95. for (id key in dic) {
  96. if ([key isKindOfClass:NSString.class] && [key containsString:[NSString stringWithFormat:@"%@--to--",[SLGlobalInfo SharedInstance].loginInfo.user.userId]]) {
  97. [userDefaults removeObjectForKey:key];
  98. }
  99. }
  100. [userDefaults synchronize];
  101. //语音文件
  102. NSString *voicePath = [YMPath_DOCUMENT stringByAppendingFormat:@"/%@", @"voices"];
  103. [[NSFileManager defaultManager] removeItemAtPath:voicePath error:nil];
  104. [ZFToast ShowWithMessage:@"清空成功"];
  105. } failure:^(SPRequestError *error) {
  106. }];
  107. } cancelBtnAction:^{
  108. }];
  109. }
  110. if ([detail.title isEqualToString:NSLocalizedString(@"聊天背景", nil)]) {
  111. SLMsgBgSetVc *vc = [SLMsgBgSetVc loadViewControllewWithNib];
  112. [self navPushViewController:vc animated:YES];
  113. }
  114. if ([detail.title isEqualToString:NSLocalizedString(@"语言设置", nil)]) {
  115. SLMsgBgSetVc *vc = [SLMsgBgSetVc loadViewControllewWithNib];
  116. [self navPushViewController:vc animated:YES];
  117. NSArray *arr = @[
  118. @[[SLPageModelDetail initWithTitle:@"简体中文" subTitle:@"" bgImage:@""],
  119. [SLPageModelDetail initWithTitle:@"English" subTitle:@"" bgImage:@""]],
  120. ];
  121. vc.dataModels = [NSMutableArray arrayWithArray:arr];
  122. vc.title = NSLocalizedString(@"语言设置", nil);
  123. }
  124. }
  125. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  126. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  127. if ([detail.title isEqualToString:NSLocalizedString(@"头像", nil)]) {
  128. return 68.0f;
  129. }
  130. return 50.0f;
  131. }
  132. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  133. return 20.f;
  134. }
  135. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  136. return 0.001f;
  137. }
  138. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  139. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 20)];
  140. view.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  141. return view;
  142. }
  143. - (NSMutableArray<NSArray<SLPageModelDetail *> *> *)dataModels {
  144. if (!_dataModels) {
  145. SLUserModel *user = [SLGlobalInfo SharedInstance].loginInfo.user;
  146. NSArray *arr = @[
  147. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"头像", nil) subTitle:@""],
  148. [SLPageModelDetail initWithTitle:NSLocalizedString(@"昵称", nil) subTitle:user.userName],
  149. [SLPageModelDetail initWithTitle:NSLocalizedString(@"手机号", nil) subTitle:user.phone],
  150. [SLPageModelDetail initWithTitle:@"DLid" subTitle:user.dlId canEdit:YES],
  151. [SLPageModelDetail initWithTitle:NSLocalizedString(@"性别", nil) subTitle:NSLocalizedString(user.sex, nil) canEdit:YES],
  152. [SLPageModelDetail initWithTitle:NSLocalizedString(@"地区", nil) subTitle:[NSString stringWithFormat:@"%@%@",user.province,user.city]],
  153. [SLPageModelDetail initWithTitle:NSLocalizedString(@"星座", nil) subTitle:user.starSign canEdit:YES],],
  154. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"用户服务协议", nil) subTitle:@"" bgImage:@""],
  155. [SLPageModelDetail initWithTitle:NSLocalizedString(@"免责声明", nil) subTitle:@"" bgImage:@""]],
  156. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"退出登录", nil) subTitle:@"" bgImage:@""],]];
  157. if (self.isSetting) {
  158. arr = @[
  159. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"语言设置", nil) subTitle:@"" bgImage:@""],
  160. [SLPageModelDetail initWithTitle:NSLocalizedString(@"聊天背景", nil) subTitle:@"" bgImage:@""]],
  161. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"清空聊天记录", nil) subTitle:@"" bgImage:@""],]];
  162. }
  163. _dataModels = [NSMutableArray arrayWithArray:arr];
  164. }
  165. return _dataModels;
  166. }
  167. - (SLImagePickerAndUpload *)imageUpload {
  168. if (!_imageUpload) {
  169. _imageUpload = [[SLImagePickerAndUpload alloc] init];
  170. _imageUpload.isUploadHeadImage = YES;
  171. WS(weakSelf);
  172. _imageUpload.uploadBlock = ^(NSString *imageUrl) {
  173. weakSelf.dataModels = nil;
  174. [weakSelf.tableView reloadData];
  175. };
  176. }
  177. return _imageUpload;
  178. }
  179. @end