YMSpoorCellViewModel.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // YMSpoorCellViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMSpoorCellViewModel.h"
  9. #import "YMRelationModel.h"
  10. #import "YOUPAILCIMSessionVC.h"
  11. @interface YMSpoorCellViewModel ()
  12. /// 用户Id
  13. @property (nonatomic, assign, readwrite) NSInteger userId;
  14. /// 用户头像
  15. @property (nonatomic, copy, readwrite) NSString *userAvatar;
  16. /// 用户名称
  17. @property (nonatomic, copy, readwrite) NSString *userNickname;
  18. /// 用户描述
  19. @property (nonatomic, copy, readwrite) NSString *userDesc;
  20. /// 是否搭讪
  21. @property (nonatomic, assign, readwrite) BOOL isCanPrivateChat;
  22. /// 心动或搭讪按钮标题 “心动”字样是给女用户的 “搭讪”字样是给男用户
  23. @property (nonatomic, strong, readwrite) NSString *heartbeatOrAccostButtonTitle;
  24. /// 心动或搭讪按钮图片
  25. @property (nonatomic, strong, readwrite) NSString *heartbeatOrAccostButtonImage;
  26. /// 心动或搭讪按钮标题颜色
  27. @property (nonatomic, strong, readwrite) UIColor *heartbeatOrAccostButtonTitleColor;
  28. /// 心动或搭讪按钮背景颜色
  29. @property (nonatomic, strong, readwrite) UIColor *heartbeatOrAccostButtonBackgroundColor;
  30. @end
  31. @implementation YMSpoorCellViewModel
  32. - (void)ym_initialize{
  33. [super ym_initialize];
  34. if ([self.params[ParamsModel] isKindOfClass:[YMRelationModel class]]) {
  35. YMRelationModel *model = self.params[ParamsModel];
  36. self.userId = model.userid;
  37. self.userAvatar = model.avatar;
  38. self.userNickname = model.nickname;
  39. NSMutableString *desc = [NSMutableString string];
  40. if (model.gender == 1) {
  41. [desc appendFormat:@"女 | "];
  42. }else{
  43. [desc appendFormat:@"男 | "];
  44. }
  45. if (model.age != 0) {
  46. [desc appendFormat:@"%ld岁 | ",model.age];
  47. }
  48. self.userDesc = [desc substringToIndex:desc.length - 2];
  49. self.isCanPrivateChat = model.is_beckon;
  50. if (self.isCanPrivateChat) {
  51. self.heartbeatOrAccostButtonTitle = @"私信";
  52. self.heartbeatOrAccostButtonImage = @"ym_common_home_siliao";
  53. self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFF70C5);
  54. self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFFFFFF);
  55. } else {
  56. self.heartbeatOrAccostButtonTitle = [self isFemaleGender] ? @"心动" : @"搭讪";
  57. self.heartbeatOrAccostButtonImage = [self isFemaleGender] ? @"ym_common_home_heart" : @"ym_common_home_dashan";
  58. self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFFFFFF);
  59. self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFF70C5);
  60. }
  61. }
  62. }
  63. - (void)sendAccostRequest{
  64. if ([self isNeedGoddessCertified]) {
  65. return;
  66. }
  67. if(self.isCanPrivateChat){
  68. @weakify(self)
  69. NIMSession *session = [NIMSession session:stringFormat(@"%ld",self.userId) type:NIMSessionTypeP2P];
  70. if (session) {
  71. [ZCHUDHelper show];
  72. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  73. @strongify(self)
  74. [ZCHUDHelper dismiss];
  75. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  76. vc.type = @"1";
  77. [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
  78. }];
  79. }
  80. }else{
  81. @weakify(self)
  82. [LCHttpHelper requestWithURLString:HomeBeckonSend parameters:@{
  83. @"user_ids":stringFormat(@"[%ld]",self.userId)
  84. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  85. @strongify(self)
  86. NSDictionary* dict = (NSDictionary*)responseObject;
  87. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  88. if (code == 0) {
  89. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  90. BOOL boole = [data boolValueForKey:@"boole" defaultValue:NO];
  91. if (boole) {
  92. self.isCanPrivateChat = YES;
  93. self.heartbeatOrAccostButtonTitle = @"私信";
  94. self.heartbeatOrAccostButtonImage = @"ym_common_home_siliao";
  95. self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFF70C5);
  96. self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFFFFFF);
  97. if (self.changeAccostStatusBlock) {
  98. self.changeAccostStatusBlock();
  99. }
  100. }
  101. }else{
  102. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  103. }
  104. } failure:^(NSError *error) {
  105. [ZCHUDHelper showTitle:error.localizedDescription];
  106. }];
  107. }
  108. }
  109. @end