CommentCell.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //
  2. // CommentCell.m
  3. // test12
  4. //
  5. // Created by apple on 15/11/22.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "CommentCell.h"
  9. #import "UIImageView+WebCache.h"
  10. CommentCellStyle cellStyle;
  11. @implementation CommentCell
  12. - (void)awakeFromNib
  13. {
  14. [super awakeFromNib];
  15. }
  16. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  17. {
  18. [super setSelected:NO animated:animated];
  19. }
  20. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  21. {
  22. if ([reuseIdentifier isEqualToString:@"school"])
  23. {
  24. cellStyle = CommentCellStyleSchool;
  25. }
  26. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  27. if (self) {
  28. self.imageView.layer.masksToBounds = YES;
  29. self.backgroundColor = backGroundColor;
  30. UIButton* btn = [[UIButton alloc] init];
  31. [btn setImage:[UIImage imageNamed:@"question_approve_checked_icon.png"] forState:UIControlStateSelected];
  32. [btn setImage:[UIImage imageNamed:@"question_approve_icon.png"] forState:UIControlStateNormal];
  33. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  34. [self.contentView addSubview:btn];
  35. [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  36. _upBtn = btn;
  37. [btn.imageView setContentMode:UIViewContentModeScaleAspectFit];
  38. UIImageView* iv = [[UIImageView alloc] init];
  39. [iv setContentMode:UIViewContentModeScaleAspectFit];
  40. [self.contentView addSubview:iv];
  41. honorIv = iv;
  42. UILabel* lb = [[UILabel alloc] init];
  43. [self.contentView addSubview:lb];
  44. [lb setTextColor:contentTextColor];
  45. celDateLbl = lb;
  46. [celDateLbl setFont:[UIFont scaleSize:12]];
  47. [self.textLabel setTextColor:kTitleColor];
  48. [self.detailTextLabel setTextColor:subTitleColor];
  49. }
  50. [self setSelectionStyle:UITableViewCellSelectionStyleNone];
  51. return self;
  52. }
  53. +(CommentCell*)cellForTableView:(UITableView*)tableView Style:(CommentCellStyle )style
  54. {
  55. cellStyle = style;
  56. NSString* cellid;
  57. /**如果2个风格的cell,需要区分,可以在这设置
  58. */
  59. if (CommentCellStyleQuestion == style) {
  60. cellid= @"CommentCellIdentifier";
  61. }else{
  62. cellid= @"CommentCellIdentifier";
  63. }
  64. CommentCell* cell = [tableView dequeueReusableCellWithIdentifier:cellid];
  65. if (!cell) {
  66. cell = [[CommentCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
  67. [cell setBackgroundColor:backGroundColor];
  68. }
  69. return cell;
  70. }
  71. -(void)setCommentDic:(NSDictionary *)commentDic
  72. {
  73. _commentDic = commentDic;
  74. [self.imageView sd_setImageWithURL:[NSURL URLWithString:commentDic[@"PHOTO"]] placeholderImage:randomPortrait()];
  75. [self.textLabel setText:commentDic[@"QC_NAME"]];
  76. [self.detailTextLabel setText:commentDic[@"QC_DESC"]];
  77. [_upBtn setTitle:commentDic[@"QC_UP_NUM"] forState:UIControlStateNormal];
  78. [_upBtn setSelected:NO];
  79. NSString* str = commentDic[@"QC_CRDATE"];
  80. if (str && str.length >16) {
  81. [celDateLbl setText:[str substringToIndex:16]];
  82. }else{
  83. [celDateLbl setText:str];
  84. }
  85. }
  86. -(void)setDict:(NSDictionary *)dict
  87. {
  88. _dict = dict;
  89. [_upBtn setTitle:dict[@"POINTNUM"] forState:UIControlStateNormal];
  90. [_upBtn setSelected:NO];
  91. self.imageView.contentMode = UIViewContentModeScaleAspectFit;
  92. self.imageView.clipsToBounds = YES;
  93. if (![dict[@"NAME"] isEqualToString:@""] && ![dict[@"NAME"] isEqualToString:@"暂无相关点评~"])
  94. {
  95. _upBtn.hidden = NO;
  96. NSString *path = [Tools imageStringWithPhotoString:dict[@"PHOTO"] HeadImgString:dict[@"HEADIMG"] Type:2];
  97. if (path.length < 1) {
  98. path = nil;
  99. }
  100. [self.imageView sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"portrait%d.png",arc4random()%10 + 1]]];
  101. }else{
  102. _upBtn.hidden = YES;
  103. }
  104. [self.textLabel setText:dict[@"NAME"]];
  105. [self.detailTextLabel setText:[dict[@"PJCONTENT"] isEqualToString:@""]? @"点评内容为空" : dict[@"PJCONTENT"] ];
  106. NSString* str = dict[@"PJSJ"];
  107. if (str && str.length >11) {
  108. [celDateLbl setText:[str substringToIndex:11]];
  109. }else{
  110. [celDateLbl setText:str];
  111. }
  112. }
  113. /**每次cell重用时,这里都会调用一次。
  114. 切记不要再这里创建视图。
  115. */
  116. -(void)layoutSubviews
  117. {
  118. [super layoutSubviews];
  119. CGFloat font = 15;
  120. [self.detailTextLabel setNumberOfLines:0];
  121. [self.detailTextLabel setFont:[UIFont scaleSize:font]];
  122. CGFloat aWid = self.width;
  123. CGFloat x,w,h,y,bd;
  124. x = 5;
  125. w = h = 55;
  126. y = bd = 10;
  127. [self.imageView setFrame:CGRectMake(x, y, w, h)];
  128. self.imageView.layer.cornerRadius = h/2.0;
  129. if (cellStyle == CommentCellStyleQuestion)
  130. {
  131. y += bd;
  132. x = x + w + bd;
  133. h = 25;
  134. [self.textLabel setFrame:CGRectMake(x, y, 260, h)];
  135. y = y + h + bd;
  136. w = aWid - x - bd;
  137. h = [self.detailTextLabel.text heightForWid:w Font:font];
  138. //现在主要是根据desc的内容动态设置宽高了
  139. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  140. y = y+h+bd;
  141. h = 30;
  142. [celDateLbl setFrame:CGRectMake(x, y, 260, h)];
  143. [_upBtn setFrame:CGRectMake(aWid - 100, y, 100, h)];
  144. [honorIv setFrame:CGRectMake(aWid - 55, 5, 55, 55)];
  145. }else{
  146. y += bd;
  147. x = x + w + bd;
  148. h = 25;
  149. [self.textLabel setFrame:CGRectMake(x, y, 180, h)];
  150. y = y + h + bd;
  151. w = aWid - x - bd;
  152. h = [self.detailTextLabel.text heightForWid:w Font:font];
  153. if (h < 40)
  154. {
  155. h = 40;
  156. }
  157. //现在主要是根据desc的内容动态设置宽高了
  158. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  159. y = y+h+bd;
  160. h = 30;
  161. [celDateLbl setFrame:CGRectMake(x, y, 260, h)];
  162. [_upBtn setFrame:CGRectMake(aWid - 100, y, 100, h)];
  163. [honorIv setFrame:CGRectMake(aWid - 55, 5, 55, 55)];
  164. }
  165. }
  166. -(void)btnClick:(UIButton*)sender
  167. {
  168. if ([_VCName isEqualToString:@"SearchComment"]) {
  169. //代表是驾校的页面
  170. return;
  171. }
  172. [self UpLoadApproveComId];
  173. }
  174. - (void)UpLoadApproveComId
  175. {
  176. if (![Util connectedToNetWork]) {
  177. showMsgUnconnect();
  178. return;
  179. }
  180. NSMutableArray *arr=[NSMutableArray array];
  181. NSString *comId = _commentDic ? _commentDic[@"QC_ID"] : _dict[@"ID"];
  182. [arr property:comId forKey:@"cid"];
  183. [arr property:@"1" forKey:@"type"];
  184. if (myDelegate.isLogin) {
  185. [arr property:RQ_USER_MANAGER.currentUser._id forKey:@"userId"];
  186. }else{
  187. [arr property:@"匿名用户" forKey:@"userId"];
  188. }
  189. NSString* method = @"updateQuestionUpOrDown";
  190. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  191. RemoveHUD();
  192. if (!dict) {
  193. ShowMsg(@"操作失败");
  194. return;
  195. }
  196. if ( [dict[@"code"] isEqualToString:@"1"]) {
  197. ShowMsg(dict[@"body"]);
  198. [_upBtn setSelected:YES];
  199. return;
  200. }
  201. if ( [dict[@"code"] isEqualToString:@"0"]) {
  202. [LoadingView showMsg:@"点赞成功" Style:1];
  203. }
  204. NSString *comUpNum = _commentDic ? _commentDic[@"QC_UP_NUM"] : _dict[@"POINTNUM"];
  205. comUpNum = [NSString stringWithFormat:@"%d",comUpNum.intValue+1];
  206. [_upBtn setTitle:comUpNum forState:UIControlStateNormal];
  207. [_upBtn setSelected:YES];
  208. }];
  209. }
  210. @end