TConversationCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // TConversationCell.m
  3. // UIKit
  4. //
  5. // Created by kennethmiao on 2018/9/14.
  6. // Copyright © 2018年 kennethmiao. All rights reserved.
  7. //
  8. #import "TConversationCell.h"
  9. #import "THeader.h"
  10. #import "YBCenterVC.h"
  11. @implementation TConversationCellData
  12. // 更新信息
  13. -(void)updateUserInfo:(NSDictionary *)userInfo;{
  14. _userName = strFormat([userInfo valueForKey:@"user_nickname"]);
  15. _userHeader = strFormat([userInfo valueForKey:@"avatar"]);
  16. _isAtt = strFormat([userInfo valueForKey:@"isattent"]);
  17. _isVIP = strFormat([[userInfo valueForKey:@"vipinfo"] valueForKey:@"isvip"]);
  18. // admin重置时间和最后一条消息
  19. if ([_convId isEqual:@"dsp_admin_1"] || [_convId isEqual:@"dsp_admin_2"]) {
  20. _time = strFormat([userInfo valueForKey:@"last_time"]);
  21. _subTitle = strFormat([userInfo valueForKey:@"last_msg"]);
  22. }
  23. }
  24. @end
  25. @interface TConversationCell ()
  26. @property (nonatomic, strong) TConversationCellData *data;
  27. @end
  28. @implementation TConversationCell
  29. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  30. {
  31. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  32. self.selectionStyle = UITableViewCellSelectionStyleNone;
  33. if(self){
  34. [self setupViews];
  35. [self defaultLayout];
  36. }
  37. return self;
  38. }
  39. + (CGSize)getSize;
  40. {
  41. return CGSizeMake(Screen_Width, TConversationCell_Height);
  42. }
  43. - (void)setData:(TConversationCellData *)data
  44. {
  45. _data = data;
  46. if (![PublicObj checkNull:_data.userHeader]) {
  47. [_headImageView sd_setImageWithURL:[NSURL URLWithString:_data.userHeader]];
  48. }else{
  49. _headImageView.image = [UIImage imageNamed:_data.head];
  50. }
  51. if ([_data.isVIP isEqual:@"1"]) {
  52. _vipImageView.hidden = NO;
  53. }else{
  54. _vipImageView.hidden = YES;
  55. }
  56. _vipImageView.hidden = YES;
  57. if ([_data.convId containsString:@"dsp_admin_1"] && _isSmall == NO) {
  58. _officeFlagIV.hidden = NO;
  59. // _headImageView.image = [UIImage imageNamed:_data.head];
  60. NSString *savaData = [[NSUserDefaults standardUserDefaults]objectForKey:@"sys_time_1"];
  61. if(savaData){
  62. int isNew = [PublicObj compareDate:savaData withDate:_data.time];
  63. NSLog(@"isnew--------:%d",isNew);
  64. if(isNew == 1){
  65. [_unReadView setNum:9999999];
  66. }else{
  67. [_unReadView setNum:_data.unRead];
  68. }
  69. }else{
  70. [_unReadView setNum:9999999];
  71. }
  72. }else if ([_data.convId containsString:@"dsp_admin_2"] && _isSmall == NO) {
  73. _officeFlagIV.hidden = NO;
  74. NSString *savaData = [[NSUserDefaults standardUserDefaults]objectForKey:@"sys_time_2"];
  75. if(savaData){
  76. int isNew = [PublicObj compareDate:savaData withDate:_data.time];
  77. NSLog(@"isnew--------:%d",isNew);
  78. if(isNew == 1){
  79. [_unReadView setNum:9999999];
  80. }else{
  81. [_unReadView setNum:_data.unRead];
  82. }
  83. }else{
  84. [_unReadView setNum:9999999];
  85. }
  86. }else{
  87. _officeFlagIV.hidden = YES;
  88. [_unReadView setNum:_data.unRead];
  89. }
  90. _timeLabel.text = _data.time;
  91. //_titleLabel.text = _data.title;
  92. _titleLabel.text = _data.userName;
  93. _subTitleLabel.text = _data.subTitle;
  94. [self defaultLayout];
  95. }
  96. - (void)setupViews
  97. {
  98. self.backgroundColor = UIColor.whiteColor;
  99. _headImageView = [[UIImageView alloc] init];
  100. _headImageView.layer.masksToBounds = YES;
  101. _headImageView.layer.cornerRadius = 25;
  102. [self addSubview:_headImageView];
  103. UIButton *shadowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. [shadowBtn addTarget:self action:@selector(clickIconBtn) forControlEvents:UIControlEventTouchUpInside];
  105. [self addSubview:shadowBtn];
  106. [shadowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.width.height.centerX.centerY.equalTo(_headImageView);
  108. }];
  109. _officeFlagIV = [[UIImageView alloc]init];
  110. _officeFlagIV.image = [UIImage imageNamed:getImagename(@"msg_gov")];
  111. [self addSubview:_officeFlagIV];
  112. _officeFlagIV.hidden = YES;
  113. [_officeFlagIV mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.width.mas_equalTo(26);
  115. make.height.mas_equalTo(13);
  116. make.top.equalTo(_headImageView.mas_bottom).offset(-8);
  117. make.right.equalTo(_headImageView);
  118. }];
  119. _chatSmallBtn = [[UILabel alloc]init];
  120. _chatSmallBtn.text =YZMsg(@"私聊");
  121. _chatSmallBtn.font = [UIFont systemFontOfSize:14];
  122. _chatSmallBtn.textColor = UIColor.whiteColor;
  123. _chatSmallBtn.backgroundColor = Pink_Cor;
  124. _chatSmallBtn.layer.cornerRadius = 12;
  125. _chatSmallBtn.layer.masksToBounds = YES;
  126. _chatSmallBtn.textAlignment = NSTextAlignmentCenter;
  127. [self.contentView addSubview:_chatSmallBtn];
  128. _chatSmallBtn.hidden = YES;
  129. [_chatSmallBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.height.mas_equalTo(24);
  131. make.width.mas_equalTo(40);
  132. make.centerY.equalTo(_headImageView);
  133. make.right.equalTo(self.mas_right).offset(-10);
  134. }];
  135. // _chatSmallBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  136. // [_chatSmallBtn setTitle:YZMsg(@"私聊") forState:0];
  137. // _chatSmallBtn.titleLabel.font = SYS_Font(15);
  138. // _chatSmallBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
  139. // [_chatSmallBtn setTitleColor:UIColor.whiteColor forState:0];
  140. // _chatSmallBtn.backgroundColor = Pink_Cor;
  141. // _chatSmallBtn.layer.cornerRadius = 12;
  142. // _chatSmallBtn.layer.masksToBounds = YES;
  143. // [self.contentView addSubview:_chatSmallBtn];
  144. // _chatSmallBtn.hidden = YES;
  145. // [_chatSmallBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  146. // make.height.mas_equalTo(24);
  147. // make.centerY.equalTo(_headImageView);
  148. // make.right.equalTo(self.mas_right).offset(-10);
  149. // }];
  150. _timeLabel = [[UILabel alloc] init];
  151. _timeLabel.font = [UIFont systemFontOfSize:12];
  152. _timeLabel.textColor = RGB_COLOR(@"#969696", 1);
  153. _timeLabel.layer.masksToBounds = YES;
  154. [self addSubview:_timeLabel];
  155. _titleLabel = [[UILabel alloc] init];
  156. _titleLabel.font = [UIFont systemFontOfSize:16];
  157. _titleLabel.textColor = [UIColor blackColor];
  158. _titleLabel.layer.masksToBounds = YES;
  159. [self addSubview:_titleLabel];
  160. _vipImageView = [[UIImageView alloc] init];
  161. _vipImageView.image = [UIImage imageNamed:@"vip"];
  162. [self addSubview:_vipImageView];
  163. _unReadView = [[TUnReadView alloc] init];
  164. [self addSubview:_unReadView];
  165. _subTitleLabel = [[UILabel alloc] init];
  166. _subTitleLabel.layer.masksToBounds = YES;
  167. _subTitleLabel.font = [UIFont systemFontOfSize:14];
  168. _subTitleLabel.textColor = RGB_COLOR(@"#969696", 1);;
  169. [self addSubview:_subTitleLabel];
  170. _rightImageView = [[UIImageView alloc] init];
  171. _rightImageView.image = [UIImage imageNamed:@"right_arrow"];
  172. [self addSubview:_rightImageView];
  173. UIView *lineV = [PublicObj lineViewWithFrame:CGRectMake(0, TConversationCell_Height-1, _window_width, 1) andColor:RGB_COLOR(@"#f5f5f5", 1) andView:self];
  174. lineV.hidden = YES;
  175. [self setSeparatorInset:UIEdgeInsetsMake(0, TConversationCell_Margin, 0, 0)];
  176. }
  177. -(void)clickIconBtn {
  178. if (_isSmall) {
  179. return;
  180. }
  181. if ([_data.convId isEqual:@"dsp_admin_1"]||[_data.convId isEqual:@"dsp_admin_2"]) {
  182. return;
  183. }
  184. YBCenterVC *center = [[YBCenterVC alloc]init];
  185. center.otherUid = _data.convId;
  186. center.isPush = YES;
  187. center.hidesBottomBarWhenPushed = YES;
  188. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:center animated:YES];
  189. }
  190. - (void)defaultLayout
  191. {
  192. CGSize size = [TConversationCell getSize];
  193. _headImageView.frame = CGRectMake(TConversationCell_Margin, TConversationCell_Margin, size.height - TConversationCell_Margin * 2, size.height - TConversationCell_Margin * 2);
  194. if ([_data.title isEqual:YZMsg(@"预约")]) {
  195. _rightImageView.frame = CGRectMake(size.width-25, 25, 20, 20);
  196. }else{
  197. _rightImageView.frame = CGRectZero;
  198. }
  199. [_timeLabel sizeToFit];
  200. _timeLabel.frame = CGRectMake(size.width - TConversationCell_Margin - _timeLabel.frame.size.width, TConversationCell_Margin_Text, _timeLabel.frame.size.width, _timeLabel.frame.size.height);
  201. [_titleLabel sizeToFit];
  202. _titleLabel.frame = CGRectMake(_headImageView.frame.origin.x + _headImageView.frame.size.width + TConversationCell_Margin, TConversationCell_Margin_Text, size.width - _timeLabel.frame.size.width - _headImageView.frame.size.width - 4 * TConversationCell_Margin, _titleLabel.frame.size.height);
  203. if (_data.nameShouldCenter) {
  204. float topsss = size.height - _titleLabel.frame.size.height;
  205. _titleLabel.frame = CGRectMake(_headImageView.frame.origin.x + _headImageView.frame.size.width + TConversationCell_Margin, topsss/2, size.width - _timeLabel.frame.size.width - _headImageView.frame.size.width - 4 * TConversationCell_Margin, _titleLabel.frame.size.height);
  206. }
  207. CGFloat wwwwwww = [PublicObj widthOfString:_data.userName andFont:SYS_Font(16) andHeight:20];
  208. _vipImageView.frame = CGRectMake(_titleLabel.x + wwwwwww + 3, TConversationCell_Margin_Text + 2, 25, 15);
  209. _unReadView.frame = CGRectMake(size.width - TConversationCell_Margin - _unReadView.frame.size.width, size.height - TConversationCell_Margin_Text - _unReadView.frame.size.height, _unReadView.frame.size.width, _unReadView.frame.size.height);
  210. [_subTitleLabel sizeToFit];
  211. _subTitleLabel.frame = CGRectMake(_titleLabel.frame.origin.x, size.height - TConversationCell_Margin_Text - _subTitleLabel.frame.size.height, size.width - _headImageView.frame.size.width - 4 * TConversationCell_Margin - _unReadView.frame.size.width, _subTitleLabel.frame.size.height);
  212. }
  213. #pragma mark -
  214. // 私信小窗改变UI
  215. -(void)imsmallViewResetUI;{
  216. _isSmall = YES;
  217. self.backgroundColor = UIColor.whiteColor;
  218. _titleLabel.textColor = RGB_COLOR(@"#323232", 1);
  219. }
  220. -(void)checkImRecordWithHostid:(NSString *)liveuid;{
  221. if ([PublicObj checkNull:_data.subTitle] && [_data.convId isEqual:liveuid]) {
  222. _subTitleLabel.text = YZMsg(@"Hi~我是主播,快来和我聊天吧。");
  223. [_subTitleLabel sizeToFit];
  224. CGSize size = [TConversationCell getSize];
  225. _subTitleLabel.frame = CGRectMake(_titleLabel.frame.origin.x, size.height - TConversationCell_Margin_Text - _subTitleLabel.frame.size.height, size.width - _headImageView.frame.size.width - 4 * TConversationCell_Margin - 60, _subTitleLabel.frame.size.height);
  226. _chatSmallBtn.hidden = NO;
  227. _timeLabel.hidden = YES;
  228. }else{
  229. _chatSmallBtn.hidden = YES;
  230. _timeLabel.hidden = NO;
  231. }
  232. }
  233. @end