CommodityEvaluationCell.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // CommodityEvaluationCell.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/27.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "CommodityEvaluationCell.h"
  9. #import "ShowDetailVC.h"
  10. #import "YBImageView.h"
  11. @implementation CommodityEvaluationCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. // Initialization code
  15. }
  16. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  17. [super setSelected:selected animated:animated];
  18. // Configure the view for the selected state
  19. }
  20. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  21. {
  22. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  23. if (self) {
  24. _imgWidth =( _window_width-100-30)/4;
  25. [self creatUI];
  26. }
  27. return self;
  28. }
  29. -(void)creatUI{
  30. _headImg = [[UIImageView alloc]init];
  31. _headImg.frame = CGRectMake(15, 15, 24, 24);
  32. _headImg.layer.cornerRadius = 12;
  33. _headImg.layer.masksToBounds = YES;
  34. [self addSubview:_headImg];
  35. _nameLb = [[UILabel alloc]init];
  36. _nameLb.frame = CGRectMake(_headImg.right+10, 0, _window_width-_headImg.right-10, 20);
  37. _nameLb.centerY = _headImg.centerY;
  38. _nameLb.textColor = [UIColor grayColor];
  39. _nameLb.font = [UIFont systemFontOfSize:14];
  40. [self addSubview:_nameLb];
  41. _starView = [[CWStarRateView alloc]initWithFrame:CGRectMake(_nameLb.left, _headImg.bottom+5, 90, 15) numberOfStars:5 andSelImg:Comm_FOREGROUND_STAR_IMAGE_NAME andNormalImg:Comm_BACKGROUND_STAR_IMAGE_NAME];
  42. _starView.userInteractionEnabled = NO;
  43. _starView.delegate = self;
  44. [self addSubview:_starView];
  45. contentLb = [[UILabel alloc]init];
  46. contentLb.font = [UIFont systemFontOfSize:14];
  47. contentLb.numberOfLines = 0;
  48. contentLb.lineBreakMode = NSLineBreakByWordWrapping;
  49. contentLb.textColor = [UIColor blackColor];
  50. [self addSubview:contentLb];
  51. }
  52. -(void)setCommodityModel:(CommodityDetailModel *)model andListModel:(NSDictionary *)listDic{
  53. _model = model;
  54. NSString *quality_points = minstr([listDic valueForKey:@"quality_points"]);
  55. _starView.scorePercent = [quality_points floatValue]/5;
  56. NSLog(@"ssssss======:%f",_starView.scorePercent);
  57. [_headImg sd_setImageWithURL:[NSURL URLWithString:minstr([listDic valueForKey:@"avatar"])]];
  58. _nameLb.text = minstr([listDic valueForKey:@"user_nickname"]);
  59. NSString *content = minstr([listDic valueForKey:@"content"]);
  60. CGFloat content_height = [PublicObj heightOfString:content andFont:[UIFont systemFontOfSize:14] andWidth:_window_width-50];
  61. contentLb.frame =CGRectMake(_headImg.right+10, _starView.bottom+5, _window_width-_headImg.right-30, content_height+5);
  62. contentLb.text = content;
  63. NSArray *imgeArr =[listDic valueForKey:@"thumb_format"];
  64. NSString *video_thumb =minstr([listDic valueForKey:@"video_thumb"]);
  65. NSString *video_url =minstr([listDic valueForKey:@"video_url"]);
  66. _allArr = [NSMutableArray array];
  67. CGFloat imgY = contentLb.bottom+10;;
  68. if (imgeArr.count > 0 && video_url.length > 0) {
  69. [_allArr addObject:video_thumb];
  70. [_allArr addObjectsFromArray:imgeArr];
  71. for (int i = 0; i < _allArr.count; i ++) {
  72. if (i < 3) {
  73. imgY =contentLb.bottom+10;
  74. }else{
  75. imgY =contentLb.bottom+20+_imgWidth;
  76. }
  77. UIImageView *img = [[UIImageView alloc]init];
  78. img.frame = CGRectMake(50+(i%3)*(_imgWidth + 10), imgY, _imgWidth, _imgWidth);
  79. [img sd_setImageWithURL:[NSURL URLWithString:_allArr[i]]];
  80. img.userInteractionEnabled = YES;
  81. [self addSubview:img];
  82. UIButton *tapBtn = [UIButton buttonWithType:0];
  83. tapBtn.frame = CGRectMake(0, 0, img.width, img.height);
  84. tapBtn.tag =5000+i;
  85. [tapBtn addTarget:self action:@selector(detailBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  86. NSDictionary *dataDic = @{@"video_url":video_url,@"imgeArr":imgeArr};
  87. objc_setAssociatedObject(tapBtn, @"tapBtn", dataDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  88. [img addSubview:tapBtn];
  89. if (i == 0) {
  90. [tapBtn setImage:[UIImage imageNamed:@"commodity_播放"] forState:0];
  91. }
  92. }
  93. }else if (imgeArr.count < 1 && video_url.length > 0){
  94. [_allArr addObject:video_thumb];
  95. imgY =contentLb.bottom+10;
  96. UIImageView *img = [[UIImageView alloc]init];
  97. img.frame = CGRectMake(50, imgY, _imgWidth, _imgWidth);
  98. [img sd_setImageWithURL:[NSURL URLWithString:video_thumb]];
  99. img.userInteractionEnabled = YES;
  100. [self addSubview:img];
  101. UIButton *tapBtn = [UIButton buttonWithType:0];
  102. tapBtn.frame = CGRectMake(0, 0, img.width, img.height);
  103. tapBtn.tag =5000;
  104. [tapBtn addTarget:self action:@selector(detailBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  105. [img addSubview:tapBtn];
  106. [tapBtn setImage:[UIImage imageNamed:@"commodity_播放"] forState:0];
  107. NSDictionary *dataDic = @{@"video_url":video_url,@"imgeArr":@[]};
  108. objc_setAssociatedObject(tapBtn, @"tapBtn", dataDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  109. }else if (imgeArr.count > 0 && video_url.length < 2){
  110. [_allArr addObjectsFromArray:imgeArr];
  111. for (int i = 0; i < _allArr.count; i ++) {
  112. if (i < 3) {
  113. imgY =contentLb.bottom+10;
  114. }else{
  115. imgY =contentLb.bottom+20+_imgWidth;
  116. }
  117. UIImageView *img = [[UIImageView alloc]init];
  118. img.frame = CGRectMake(50+(i%3)*(_imgWidth + 10), imgY, _imgWidth, _imgWidth);
  119. [img sd_setImageWithURL:[NSURL URLWithString:_allArr[i]]];
  120. img.userInteractionEnabled = YES;
  121. [self addSubview:img];
  122. UIButton *tapBtn = [UIButton buttonWithType:0];
  123. tapBtn.frame = CGRectMake(0, 0, img.width, img.height);
  124. tapBtn.tag =5001+i;
  125. [tapBtn addTarget:self action:@selector(detailBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  126. [img addSubview:tapBtn];
  127. NSDictionary *dataDic = @{@"video_url":@"",@"imgeArr":imgeArr};
  128. objc_setAssociatedObject(tapBtn, @"tapBtn", dataDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  129. }
  130. }
  131. if (_allArr.count > 0 && _allArr.count < 4) {
  132. imgY =contentLb.bottom+20+_imgWidth;
  133. }else if (_allArr.count >3)
  134. {
  135. imgY =contentLb.bottom+30+_imgWidth*2;
  136. }else if(_allArr.count == 0){
  137. imgY =contentLb.bottom+10;
  138. }
  139. UILabel *dateLb = [[UILabel alloc]init];
  140. dateLb.frame = CGRectMake(_headImg.right+10, imgY, 100, 20);
  141. dateLb.font = [UIFont systemFontOfSize:13];
  142. dateLb.textColor = [UIColor grayColor];
  143. dateLb.text =minstr([listDic valueForKey:@"time_format"]);
  144. [self addSubview:dateLb];
  145. UILabel *standLb = [[UILabel alloc]init];
  146. standLb.frame = CGRectMake(dateLb.right+10, imgY, 200, 20);
  147. standLb.font = [UIFont systemFontOfSize:13];
  148. standLb.textColor = [UIColor grayColor];
  149. standLb.adjustsFontSizeToFitWidth = YES;
  150. standLb.text =minstr([listDic valueForKey:@"spec_name"]);
  151. [self addSubview:standLb];
  152. UILabel *line = [[UILabel alloc]init];
  153. line.backgroundColor = RGB(240, 240, 240);
  154. [self addSubview:line];
  155. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  156. make.left.equalTo(self).offset(15);
  157. make.right.equalTo(self).offset(-15);
  158. make.bottom.equalTo(self);
  159. make.height.mas_equalTo(1);
  160. }];
  161. }
  162. - (void)starRateView:(CWStarRateView *)starRateView scroePercentDidChange:(CGFloat)newScorePercent{
  163. NSLog(@"%f",newScorePercent);
  164. }
  165. -(void)detailBtnClick:(UIButton *)sender{
  166. NSDictionary *dic = objc_getAssociatedObject(sender, @"tapBtn");
  167. if(sender.tag == 5000){
  168. ShowDetailVC *detail = [[ShowDetailVC alloc]init];
  169. detail.fromStr = @"trendlist";
  170. NSLog(@"=-=-=-=-=-=-=-:%@",minstr([dic valueForKey:@"video_url"]));
  171. detail.videoPath =minstr([dic valueForKey:@"video_url"]);
  172. detail.deleteEvent = ^(NSString *type) {
  173. };
  174. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:detail animated:NO];
  175. }else{
  176. NSArray *imageArr = [dic valueForKey:@"imgeArr"];
  177. NSInteger index = sender.tag - 5001;
  178. YBImageView *imgView = [[YBImageView alloc] initWithImageArray:imageArr andIndex:index andMine:NO isDtCell:NO andBlock:^(NSArray * _Nonnull array) {
  179. }];
  180. [[UIApplication sharedApplication].keyWindow addSubview:imgView];
  181. }
  182. }
  183. @end