省钱达人

DRGoodCollectionCell.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. //
  2. // DRGoodCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRGoodCollectionCell.h"
  9. #import "DRGoodTagsView.h"
  10. @interface DRGoodCollectionCell ()
  11. @property (nonatomic, strong) UIImageView *imgView; //大图
  12. @property (nonatomic, strong) UILabel *titleLabel; //标题
  13. @property (nonatomic, strong) UILabel *priceLabel; //原价
  14. @property (nonatomic, strong) UILabel *saleCount; // 月销量
  15. @property (nonatomic, strong) UILabel *disPriceL; // 优惠后价格
  16. @property (nonatomic, strong) UIImageView *ticketNumber; //
  17. @property (nonatomic, strong) UILabel *totalCount; // 总件数
  18. @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券
  19. @property (nonatomic, strong) UILabel *ticketType;
  20. @property (nonatomic, strong) UILabel *commissionLabel; //预估佣金
  21. @property (nonatomic, strong) DRGoodTagsView *tagsView;
  22. @end
  23. @implementation DRGoodCollectionCell
  24. - (instancetype)initWithFrame:(CGRect)frame {
  25. self = [super initWithFrame:frame];
  26. if (self) {
  27. self.layer.borderWidth = 1;
  28. self.layer.borderColor = [UIColor YHColorWithHex:0xE7E7E7].CGColor;
  29. self.layer.cornerRadius = 6;
  30. self.layer.masksToBounds = YES;
  31. self.contentView.backgroundColor = [UIColor whiteColor];
  32. [self initSubViews];
  33. }
  34. return self;
  35. }
  36. - (void)initSubViews {
  37. [self.contentView addSubview:self.imgView];
  38. [self.contentView addSubview:self.titleLabel];
  39. [self.contentView addSubview:self.disPriceL];
  40. [self.contentView addSubview:self.priceLabel];
  41. [self.contentView addSubview:self.ticketNumber];
  42. [self.contentView addSubview:self.commissionLabel];
  43. [self.ticketNumber addSubview:self.ticketType];
  44. [self.ticketNumber addSubview:self.zheKou];
  45. [self.contentView addSubview:self.saleCount];
  46. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.right.top.mas_equalTo(0);
  48. make.height.mas_equalTo((SCREEN_WIDTH-5)/2.f);
  49. }];
  50. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.right.mas_equalTo(0);
  52. make.top.mas_equalTo(self.imgView.mas_bottom).mas_offset(3);
  53. make.height.mas_equalTo(0).priorityLow();
  54. }];
  55. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(10);
  57. make.right.mas_equalTo(-10);
  58. make.top.mas_equalTo(self.commissionLabel.mas_bottom).mas_offset(4);
  59. }];
  60. [self.disPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.mas_equalTo(self.titleLabel.mas_left);
  62. make.bottom.mas_equalTo(-10);
  63. }];
  64. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(self.titleLabel.mas_left);
  66. make.width.mas_equalTo(64);
  67. make.height.mas_equalTo(14);
  68. make.bottom.mas_equalTo(self.disPriceL.mas_top).mas_offset(-10);
  69. }];
  70. [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.top.bottom.mas_equalTo(0);
  72. make.width.mas_equalTo(20);
  73. }];
  74. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.mas_equalTo(self.ticketType.mas_right);
  76. make.top.mas_equalTo(0);
  77. make.height.mas_equalTo(14);
  78. make.width.mas_equalTo(44);
  79. }];
  80. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(5);
  82. make.bottom.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(-2);
  83. }];
  84. // [self.tagsView mas_makeConstraints:^(MASConstraintMaker *make) {
  85. // make.left.mas_equalTo(self.ticketNumber.mas_right).mas_offset(5);
  86. // make.centerY.mas_equalTo(self.ticketNumber.mas_centerY);
  87. // make.width.mas_equalTo(80);
  88. // make.height.mas_equalTo(12);
  89. // }];
  90. //
  91. [self.saleCount mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.right.mas_equalTo(-10);
  93. make.centerY.mas_equalTo(self.disPriceL.mas_centerY);
  94. }];
  95. }
  96. - (void)setModel:(DRChildGoodModel *)model {
  97. _model = model;
  98. //标题
  99. NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  100. UIImage *img;
  101. if ([model.shop_type isEqualToString:@"1"]) {
  102. img= [UIImage imageNamed:@"tm_shop"];
  103. }else if([model.shop_type isEqualToString:@"0"]){
  104. }
  105. if (img) {
  106. textAttach.image = img;
  107. textAttach.bounds = CGRectMake(0, -2, 15, 15);
  108. }
  109. NSMutableAttributedString *attri;
  110. if ([model.shop_type isEqualToString:@"1"]) {
  111. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.title]];
  112. }else {
  113. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
  114. }
  115. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  116. [attri insertAttributedString:string atIndex:0];
  117. self.titleLabel.attributedText = attri;
  118. //大图
  119. // [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
  120. // [self.imgView yy_setImageWithURL:[NSURL URLWithString:model.img] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
  121. // [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  122. // if (image) {
  123. // if (cacheType != SDImageCacheTypeMemory) { // 防止上划,出现图片交替现象
  124. // self.imgView.alpha = 0.3;
  125. // [UIView transitionWithView:self.imgView duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
  126. // [self.imgView setImage:image];
  127. // self.imgView.alpha = 1.0;
  128. // } completion:nil];
  129. // } else{
  130. // self.imgView.alpha = 1.0;
  131. // [self.imgView setImage:image];
  132. // }
  133. // }
  134. // }];
  135. [self.imgView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  136. NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  137. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price
  138. attributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleNone)}];
  139. [attrStr setAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),
  140. NSBaselineOffsetAttributeName:@0}
  141. range:NSMakeRange(0, price.length)];
  142. self.priceLabel.attributedText = attrStr;
  143. self.saleCount.text = [NSString stringWithFormat:@"月销:%@",model.volume];
  144. //折后价
  145. NSString *disStr;
  146. if ([model.is_coupon boolValue]) {
  147. disStr = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]];
  148. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  149. self.ticketType.text = @"券";
  150. }else {
  151. disStr = [NSString stringWithFormat:@"折后¥%.2f",[model.discount_price floatValue]];
  152. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  153. self.ticketType.text = @"折";
  154. }
  155. //券相关
  156. self.ticketNumber.hidden = ![model.is_coupon boolValue];
  157. CGFloat margin = [model.is_coupon boolValue] ? 5 : 0;
  158. CGFloat width = [model.is_coupon boolValue] ? 64 : 0;
  159. [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  160. make.width.mas_equalTo(width);
  161. }];
  162. // [self.tagsView mas_updateConstraints:^(MASConstraintMaker *make) {
  163. // make.left.mas_equalTo(self.ticketNumber.mas_right).mas_offset(margin);
  164. // }];
  165. //券后价格
  166. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  167. [disAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor homeRedColor]} range:NSMakeRange(0, disAttr.length)];
  168. [disAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]} range:NSMakeRange(0, 3)];
  169. self.disPriceL.attributedText = disAttr;
  170. }
  171. - (UIImageView *)imgView {
  172. if (!_imgView) {
  173. _imgView = [[UIImageView alloc] init];
  174. _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0];
  175. }
  176. return _imgView;
  177. }
  178. - (UILabel *)titleLabel {
  179. if (!_titleLabel) {
  180. _titleLabel = [[UILabel alloc] init];
  181. _titleLabel.font = [UIFont systemFontOfSize:14];
  182. _titleLabel.textColor = [UIColor YHColorWithHex:0x444444];
  183. _titleLabel.numberOfLines = 2;
  184. }
  185. return _titleLabel;
  186. }
  187. - (UILabel *)priceLabel {
  188. if (!_priceLabel) {
  189. _priceLabel = [[UILabel alloc] init];
  190. _priceLabel.font = [UIFont systemFontOfSize:11];
  191. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  192. }
  193. return _priceLabel;
  194. }
  195. - (UILabel *)saleCount {
  196. if (!_saleCount) {
  197. _saleCount = [[UILabel alloc] init];
  198. _saleCount.font = [UIFont systemFontOfSize:10];
  199. _saleCount.textColor = [UIColor YHColorWithHex:0x999999];
  200. _saleCount.textAlignment = NSTextAlignmentRight;
  201. _saleCount.hidden = YES;
  202. }
  203. return _saleCount;
  204. }
  205. - (UILabel *)disPriceL {
  206. if (!_disPriceL) {
  207. _disPriceL = [[UILabel alloc] init];
  208. _disPriceL.font = [UIFont systemFontOfSize:16];
  209. _disPriceL.textColor = [UIColor homeRedColor];
  210. }
  211. return _disPriceL;
  212. }
  213. - (UIImageView *)ticketNumber {
  214. if (!_ticketNumber) {
  215. _ticketNumber = [[UIImageView alloc] init];
  216. _ticketNumber.image = [UIImage imageNamed:@"quan_bg"];
  217. }
  218. return _ticketNumber;
  219. }
  220. - (UILabel *)totalCount {
  221. if (!_totalCount) {
  222. _totalCount = [[UILabel alloc] init];
  223. _totalCount.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  224. _totalCount.layer.cornerRadius = 3;
  225. _totalCount.font = [UIFont systemFontOfSize:10];
  226. _totalCount.textAlignment = NSTextAlignmentCenter;
  227. _totalCount.textColor = [UIColor YHColorWithHex:0xffffff];
  228. }
  229. return _totalCount;
  230. }
  231. - (UILabel *)zheKou {
  232. if (!_zheKou) {
  233. _zheKou = [[UILabel alloc] init];
  234. _zheKou.textColor = [UIColor whiteColor];
  235. _zheKou.textAlignment = NSTextAlignmentCenter;
  236. _zheKou.font = [UIFont systemFontOfSize:10];
  237. }
  238. return _zheKou;
  239. }
  240. - (UILabel *)ticketType {
  241. if (!_ticketType) {
  242. _ticketType = [[UILabel alloc] init];
  243. _ticketType.font = [UIFont systemFontOfSize:10];
  244. _ticketType.textAlignment = NSTextAlignmentCenter;
  245. _ticketType.textColor = [UIColor whiteColor];
  246. }
  247. return _ticketType;
  248. }
  249. - (UILabel *)commissionLabel {
  250. if (!_commissionLabel) {
  251. _commissionLabel = [[UILabel alloc] init];
  252. _commissionLabel.font = [UIFont systemFontOfSize:11];
  253. _commissionLabel.textColor = [UIColor whiteColor];
  254. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  255. _commissionLabel.backgroundColor = [UIColor changeColor];
  256. }
  257. return _commissionLabel;
  258. }
  259. //- (DRGoodTagsView *)tagsView {
  260. // if (!_tagsView) {
  261. // _tagsView = [[DRGoodTagsView alloc] init];
  262. // }
  263. // return _tagsView;
  264. //}
  265. @end