KSChatUserDetailViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // KSChatUserDetailViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/10/18.
  6. //
  7. #import "KSChatUserDetailViewController.h"
  8. #import "UserDetailNavView.h"
  9. #import "ChatUserInfo.h"
  10. #import "UserDetailBodyView.h"
  11. #import "UserDetailBottomView.h"
  12. #import "RecentPracticeModel.h"
  13. #import "KSBaseWKWebViewController.h"
  14. @interface KSChatUserDetailViewController ()<UIScrollViewDelegate>
  15. @property (nonatomic, strong) UserDetailNavView *navView;
  16. @property (nonatomic, strong) ChatUserInfo *userInfo;
  17. @property (nonatomic, strong) UserDetailBodyView *bodyView;
  18. @property (nonatomic, strong) UserDetailBottomView *bottomView;
  19. @end
  20. @implementation KSChatUserDetailViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. self.ks_prefersNavigationBarHidden = YES;
  25. [self configUI];
  26. }
  27. - (void)configUI {
  28. UIImage *bgImage = [UIImage imageNamed:@"user_detailBg"];
  29. CGFloat height = bgImage.size.height / bgImage.size.width * kScreenWidth;
  30. UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
  31. imageView.frame = CGRectMake(0, 0, kScreenWidth, height);
  32. [self.view addSubview:imageView];
  33. [self.view addSubview:self.navView];
  34. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.right.top.mas_equalTo(self.view);
  36. make.height.mas_equalTo(kNaviBarHeight);
  37. }];
  38. self.scrollView.backgroundColor = [UIColor clearColor];
  39. self.scrollView.delegate = self;
  40. [self.view bringSubviewToFront:self.scrollView];
  41. [self.view bringSubviewToFront:self.navView];
  42. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  43. make.top.mas_equalTo(self.view.mas_top);
  44. make.left.right.mas_equalTo(self.view);
  45. make.bottom.mas_equalTo(self.view.mas_bottom);
  46. }];
  47. UIView *headView = [[UIView alloc] init];
  48. headView.backgroundColor = [UIColor clearColor];
  49. [self.scrollView addSubview:headView];
  50. [headView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.mas_equalTo(self.scrollView.mas_top);
  52. make.left.right.mas_equalTo(self.view);
  53. make.height.mas_equalTo(kNaviBarHeight);
  54. }];
  55. [self.view addSubview:self.bodyView];
  56. CGFloat bodyViewHeight = [UserDetailBodyView getViewHeight];
  57. if (bodyViewHeight < KPortraitHeight - kNaviBarHeight - 70) {
  58. bodyViewHeight = KPortraitHeight - kNaviBarHeight - 70;
  59. }
  60. [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.top.mas_equalTo(headView.mas_bottom);
  62. make.left.right.mas_equalTo(self.view);
  63. make.height.mas_equalTo(bodyViewHeight);
  64. }];
  65. [self.view addSubview:self.bottomView];
  66. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.right.mas_equalTo(self.view);
  68. make.top.mas_equalTo(self.bodyView.mas_bottom);
  69. make.bottom.mas_equalTo(self.scrollView.mas_bottom);
  70. make.height.mas_equalTo(70);
  71. }];
  72. }
  73. - (void)viewWillAppear:(BOOL)animated {
  74. [super viewWillAppear:animated];
  75. [self requestUserMessage];
  76. }
  77. - (void)requestUserMessage {
  78. [self showhud];
  79. [KSNetworkingManager queryUserById:KS_GET rongCloudUserId:self.rongCloudId success:^(NSDictionary * _Nonnull dic) {
  80. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  81. self.userInfo = [[ChatUserInfo alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  82. [self requestRecentPractice];
  83. }
  84. else {
  85. }
  86. } faliure:^(NSError * _Nonnull error) {
  87. [self removehub];
  88. }];
  89. }
  90. - (void)requestRecentPractice {
  91. [KSNetworkingManager queryUserRecentRequest:KS_GET userId:[NSString stringWithFormat:@"%.0f",self.userInfo.userId] success:^(NSDictionary * _Nonnull dic) {
  92. [self removehub];
  93. NSLog(@"%@", [dic mj_JSONString]);
  94. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  95. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  96. [self evaluateSource:sourceArray];
  97. }
  98. else {
  99. }
  100. } faliure:^(NSError * _Nonnull error) {
  101. [self removehub];
  102. }];
  103. }
  104. - (void)evaluateSource:(NSArray *)musicArray {
  105. NSMutableArray *source = [NSMutableArray array];
  106. for (NSDictionary *dic in musicArray) {
  107. RecentPracticeModel *model = [[RecentPracticeModel alloc] initWithDictionary:dic];
  108. [source addObject:model];
  109. }
  110. MJWeakSelf;
  111. [self.bodyView configUserMessage:self.userInfo musicArray:source callback:^(NSString *songId) {
  112. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  113. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
  114. [weakSelf.navigationController pushViewController:ctrl animated:YES];
  115. }];
  116. }
  117. #pragma mark ----- lazying
  118. - (UserDetailNavView *)navView {
  119. if (!_navView) {
  120. _navView = [UserDetailNavView shareInstance];
  121. MJWeakSelf;
  122. [_navView navAction:^{
  123. [weakSelf backAction];
  124. }];
  125. }
  126. return _navView;
  127. }
  128. - (UserDetailBodyView *)bodyView {
  129. if (!_bodyView) {
  130. _bodyView = [UserDetailBodyView shareInstance];
  131. }
  132. return _bodyView;
  133. }
  134. - (UserDetailBottomView *)bottomView {
  135. if (!_bottomView) {
  136. _bottomView = [UserDetailBottomView shareInstance];
  137. }
  138. return _bottomView;
  139. }
  140. /*
  141. #pragma mark - Navigation
  142. // In a storyboard-based application, you will often want to do a little preparation before navigation
  143. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  144. // Get the new view controller using [segue destinationViewController].
  145. // Pass the selected object to the new view controller.
  146. }
  147. */
  148. @end