TopicComCell.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // TopicComCell.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/12/7.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "TopicComCell.h"
  9. @interface TopicComCell ()
  10. /**显示-》回复XXX:*****
  11. */
  12. @property(nonatomic,strong) UILabel *lblContent;
  13. /**回复按钮.为了设置frame。才保留的引用。
  14. */
  15. @property(nonatomic,strong) UIButton *btnCom;
  16. /**采纳按钮.为了设置frame。才保留的引用。
  17. */
  18. @property(nonatomic,strong) UIButton *btnAdopt;
  19. @end
  20. @implementation TopicComCell
  21. - (void)awakeFromNib {
  22. // Initialization code
  23. [super awakeFromNib];
  24. }
  25. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  26. [super setSelected:selected animated:animated];
  27. }
  28. +(TopicComCell*)cellForTableView:(UITableView*)tableView
  29. {
  30. NSString* cellid;
  31. cellid= @"TopicComCellIdentifier";
  32. TopicComCell* cell = [tableView dequeueReusableCellWithIdentifier:cellid];
  33. if (!cell) {
  34. cell = (TopicComCell*)[[TopicComCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
  35. [cell.textLabel setTextColor:kTitleColor];
  36. [cell.detailTextLabel setTextColor:contentTextColor];
  37. UILabel* lbl = [[UILabel alloc] init];
  38. [lbl setFont:[UIFont scaleSize:17]];
  39. [cell addSubview:lbl];
  40. cell .lblContent = lbl;
  41. lbl.numberOfLines = 0;
  42. [cell.lblContent setTextColor:subTitleColor];
  43. UIButton* btn = [[UIButton alloc] init];
  44. [cell addSubview:btn];
  45. cell.btnCom = btn;
  46. [btn setImage:[UIImage imageNamed:@"community2.png"] forState:UIControlStateNormal];
  47. [btn addTarget:cell action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  48. cell.btnAdopt = [[UIButton alloc] init];
  49. [cell addSubview:cell.btnAdopt];
  50. cell.btnAdopt.layer.masksToBounds = YES;
  51. cell.btnAdopt.layer.cornerRadius = 15;
  52. UIColor *myColor = [UIColor colorWithRed:207/255.0 green:207/255.0 blue:207/255.0 alpha:1];
  53. cell.btnAdopt.layer.borderColor = myColor.CGColor;
  54. cell.btnAdopt.layer.borderWidth = 1;
  55. [cell.btnAdopt setTitle:@"采纳" textColor:myColor font:12 fotState:UIControlStateNormal];
  56. [cell.btnAdopt addTarget:cell action:@selector(btnClickToAdopt:) forControlEvents:UIControlEventTouchUpInside];
  57. }
  58. return cell;
  59. }
  60. -(void)setModel:(NSDictionary *)model
  61. {
  62. _model = model;
  63. //评论的头像地址
  64. NSString *headImg = model[@"HEADIMG"];
  65. if (headImg && ![headImg hasPrefix:@"http"]){
  66. headImg = [imgPreFix stringByAppendingString:headImg];
  67. }
  68. //dansonimg
  69. [self.imageView sd_setImageWithURL:[NSURL URLWithString:headImg] placeholderImage:randomPortrait()];
  70. if (_isAdopt) {
  71. [self.btnAdopt setHidden:NO];
  72. if ([model[@"ACCEPT"] integerValue] > 0) {
  73. [self.btnAdopt.layer setBorderColor:defGreen.CGColor];
  74. [self.btnAdopt setTitleColor:defGreen forState:UIControlStateNormal];
  75. self.btnAdopt.tag = 7;
  76. }else{
  77. UIColor *myColor = [UIColor colorWithRed:207/255.0 green:207/255.0 blue:207/255.0 alpha:1];
  78. [self.btnAdopt.layer setBorderColor:myColor.CGColor];
  79. [self.btnAdopt setTitleColor:myColor forState:UIControlStateNormal];
  80. self.btnAdopt.tag = 0;
  81. }
  82. }else{
  83. [self.btnAdopt setHidden:YES];
  84. }
  85. [self.textLabel setText:model[@"STUNAME"]];
  86. [self.detailTextLabel setText:model[@"ADDTIME"]];
  87. NSString * str = model[@"REPLYUSERNAME"];
  88. if (!str || [str isEqualToString:@""]) {
  89. [self.lblContent setText:model[@"CONTENT"]];
  90. }else{
  91. [self.lblContent setText:[NSString stringWithFormat:@"回复%@:%@",str,model[@"CONTENT"]]];
  92. }
  93. }
  94. -(void)layoutSubviews
  95. {
  96. [super layoutSubviews];
  97. CGFloat wid = self.frame.size.width;
  98. CGFloat x,y,w,h,bd;
  99. bd = 10;
  100. w = h = 50;
  101. x = y = bd;
  102. self.imageView.frame = CGRectMake(x, y, w, h);
  103. self.imageView.layer.cornerRadius = w/2.0;
  104. self.imageView.layer.masksToBounds = YES;
  105. x += bd+w;
  106. w = wid - x - bd - 30;
  107. h /= 2.0;
  108. self.textLabel.frame =CGRectMake(x, y, w, h);
  109. y+= h;
  110. self.detailTextLabel.frame =CGRectMake(x, y, w, h);
  111. w = wid - x - bd;
  112. y += bd + h;
  113. h = [_lblContent.text heightForWid:w Font:17]+bd;
  114. _lblContent.frame =CGRectMake(x, y, w, h);
  115. y = bd + 10;
  116. w = h = 30;
  117. x = kSize.width - bd - w;
  118. self.btnCom.frame = CGRectMake(x, y, w, h);
  119. x = kSize.width - 2*bd - 2*w;
  120. self.btnAdopt.frame = CGRectMake(x, y, w, h);
  121. }
  122. -(void)btnClick:(UIButton*)sender
  123. {
  124. if ([_delegate respondsToSelector:@selector(gotoCommentsByName:)]) {
  125. // NSLog(@"对评论的回复-----><>%@",_model);
  126. [_delegate gotoCommentsByName:_model[@"CRUSER"]];
  127. }
  128. }
  129. -(void)btnClickToAdopt:(UIButton*)sender
  130. {
  131. if (sender.tag == 7) {
  132. ShowMsg(@"请勿重复采纳");
  133. return;
  134. }
  135. [self uploadTopicAdopt];
  136. }
  137. -(void)uploadTopicAdopt
  138. {
  139. if (![Util connectedToNetWork]) {
  140. showMsgUnconnect();
  141. return;
  142. }
  143. NSMutableArray* arr = [NSMutableArray array];
  144. [arr addPro:@"user" Value:defUser.sfzmhm];
  145. [arr addPro:@"commentId" Value:_model[@"ID"]];
  146. NSString* method = @"uploadTopicCommentReply";
  147. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  148. if (!root) {
  149. ShowMsgFailed();
  150. }
  151. if ([root[@"code"] isEqualToString:@"1"]) {
  152. ShowMsg([NSString stringWithFormat:@"%@",root[@"body"]]);
  153. }
  154. [self.btnAdopt.layer setBorderColor:defGreen.CGColor];
  155. [self.btnAdopt setTitleColor:defGreen forState:UIControlStateNormal];
  156. }];
  157. }
  158. @end
  159. CGFloat TopicComCellHeight(NSDictionary* dict )
  160. {
  161. CGFloat h = [dict[@"CONTENT"] heightForWid:(kSize.width - 80) Font:17]+10;
  162. return 80 + h;
  163. }