YMFriendsListCellViewModel.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // YMFriendsListCellViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/1.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMFriendsListCellViewModel.h"
  9. #import "YMRelationModel.h"
  10. @interface YMFriendsListCellViewModel ()
  11. /// 是否隐藏提醒
  12. @property (nonatomic, assign, readwrite) BOOL isHideReminder;
  13. /// 用户Id
  14. @property (nonatomic, assign, readwrite) NSInteger userId;
  15. /// 用户头像
  16. @property (nonatomic, copy, readwrite) NSString *userAvatar;
  17. /// 用户名称
  18. @property (nonatomic, copy, readwrite) NSString *userNickname;
  19. /// 用户描述
  20. @property (nonatomic, copy, readwrite) NSString *userDesc;
  21. /// 是否关注
  22. @property (nonatomic, assign, readwrite) BOOL isFollow;
  23. /// 是否互相关注
  24. @property (nonatomic, assign, readwrite) BOOL isMutualConcerns;
  25. @end
  26. @implementation YMFriendsListCellViewModel
  27. - (void)ym_initialize{
  28. [super ym_initialize];
  29. if ([self.params[ParamsModel] isKindOfClass:[YMRelationModel class]]) {
  30. YMRelationModel *model = self.params[ParamsModel];
  31. self.isHideReminder = model.is_watch > 0 ? YES : NO;
  32. self.userId = model.userid;
  33. self.userAvatar = model.avatar;
  34. self.userNickname = model.nickname;
  35. NSMutableString *desc = [NSMutableString string];
  36. if (model.gender == 1) {
  37. [desc appendFormat:@"女 | "];
  38. }else{
  39. [desc appendFormat:@"男 | "];
  40. }
  41. if (model.age != 0) {
  42. [desc appendFormat:@"%ld岁 | ",model.age];
  43. }
  44. self.userDesc = [desc substringToIndex:desc.length - 2];
  45. self.isFollow = model.is_follow;
  46. self.isMutualConcerns = model.is_fans;
  47. }
  48. }
  49. - (void)followUser{
  50. [LCHttpHelper requestWithURLString:UserFollow parameters:@{
  51. @"follow_uid":@(self.userId),
  52. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  53. NSDictionary* dict = (NSDictionary*)responseObject;
  54. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  55. if (code == 0) {
  56. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  57. NSString *action = [data stringValueForKey:@"action" defaultValue:@""];
  58. if ([action isEqualToString:@"add"]) {
  59. [ZCHUDHelper showTitle:@"已关注"];
  60. self.isFollow = YES;
  61. }else if ([action isEqualToString:@"delete"]){
  62. [ZCHUDHelper showTitle:@"已取消关注"];
  63. self.isFollow = NO;
  64. }
  65. if (self.changeFollowStatusBlock) {
  66. self.changeFollowStatusBlock();
  67. }
  68. }else{
  69. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  70. }
  71. } failure:^(NSError *error) {
  72. [ZCHUDHelper showTitle:error.localizedDescription];
  73. }];
  74. }
  75. @end