口袋优选

KBRankGoodCollectionCell.m 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // KBRankGoodCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/12.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBRankGoodCollectionCell.h"
  9. #import "KBGoodTagsView.h"
  10. @interface KBRankGoodCollectionCell ()
  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. @end
  22. @implementation KBRankGoodCollectionCell
  23. - (instancetype)initWithFrame:(CGRect)frame {
  24. self = [super initWithFrame:frame];
  25. if (self) {
  26. self.contentView.backgroundColor = [UIColor whiteColor];
  27. [self initSubViews];
  28. }
  29. return self;
  30. }
  31. - (void)initSubViews {
  32. [self.contentView addSubview:self.imgView];
  33. [self.contentView addSubview:self.titleLabel];
  34. [self.contentView addSubview:self.priceLabel];
  35. [self.contentView addSubview:self.disPriceL];
  36. [self.contentView addSubview:self.ticketNumber];
  37. [self.contentView addSubview:self.commissionLabel];
  38. [self.ticketNumber addSubview:self.zheKou];
  39. [self.ticketNumber addSubview:self.ticketType];
  40. [self.contentView addSubview:self.saleCount];
  41. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.right.top.mas_equalTo(0);
  43. make.height.mas_equalTo((SCREEN_WIDTH-5)/2.f);
  44. }];
  45. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.right.mas_equalTo(0);
  47. make.top.mas_equalTo(self.imgView.mas_bottom).mas_offset(3);
  48. make.height.mas_equalTo(0);
  49. }];
  50. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.mas_equalTo(10);
  52. make.right.mas_equalTo(-10);
  53. make.top.mas_equalTo(self.commissionLabel.mas_bottom).mas_offset(4);
  54. }];
  55. [self.disPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(self.titleLabel.mas_left);
  57. make.bottom.mas_equalTo(-10);
  58. }];
  59. [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.top.bottom.mas_equalTo(0);
  61. make.width.mas_equalTo(20);
  62. }];
  63. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(20);
  65. make.top.bottom.right.mas_equalTo(0);
  66. }];
  67. // [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. // make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(5);
  69. // make.bottom.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(-2);
  70. // }];
  71. //
  72. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(self.titleLabel.mas_left);
  74. make.width.mas_equalTo(64);
  75. make.height.mas_equalTo(14);
  76. make.bottom.mas_equalTo(self.disPriceL.mas_top).mas_offset(-10);
  77. }];
  78. [self.saleCount mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.right.mas_equalTo(-10);
  80. make.centerY.mas_equalTo(self.disPriceL.mas_centerY);
  81. }];
  82. }
  83. - (void)setModel:(KBBuyLimitGoodModel *)model {
  84. //标题
  85. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:model.title];
  86. self.titleLabel.attributedText = attStr;
  87. //大图
  88. // [self.imgView yy_setImageWithURL:[NSURL URLWithString:model.img] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
  89. [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
  90. NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  91. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price
  92. attributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleNone)}];
  93. [attrStr setAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),
  94. NSBaselineOffsetAttributeName:@0}
  95. range:NSMakeRange(0, price.length)];
  96. self.priceLabel.attributedText = attrStr;
  97. self.saleCount.text = [NSString stringWithFormat:@"月销:%@",model.sale_num];
  98. //折后价
  99. NSString *disStr;
  100. if ([model.is_coupon boolValue]) {
  101. disStr = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]];
  102. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  103. self.ticketType.text = @"券";
  104. }else {
  105. disStr = [NSString stringWithFormat:@"折后¥%.2f",[model.discount_price floatValue]];
  106. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  107. self.ticketType.text = @"折";
  108. }
  109. //券相关
  110. self.ticketNumber.hidden = ![model.is_coupon boolValue];
  111. CGFloat width = [model.is_coupon boolValue] ? 64 : 0;
  112. [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  113. make.width.mas_equalTo(width);
  114. }];
  115. //券后价格
  116. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  117. [disAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor homeRedColor]} range:NSMakeRange(0, disAttr.length)];
  118. [disAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]} range:NSMakeRange(0, 3)];
  119. self.disPriceL.attributedText = disAttr;
  120. }
  121. - (UIImageView *)imgView {
  122. if (!_imgView) {
  123. _imgView = [[UIImageView alloc] init];
  124. _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0];
  125. }
  126. return _imgView;
  127. }
  128. - (UILabel *)titleLabel {
  129. if (!_titleLabel) {
  130. _titleLabel = [[UILabel alloc] init];
  131. _titleLabel.font = [UIFont systemFontOfSize:14];
  132. _titleLabel.textColor = [UIColor YHColorWithHex:0x444444];
  133. _titleLabel.numberOfLines = 2;
  134. }
  135. return _titleLabel;
  136. }
  137. - (UILabel *)priceLabel {
  138. if (!_priceLabel) {
  139. _priceLabel = [[UILabel alloc] init];
  140. _priceLabel.font = [UIFont systemFontOfSize:11];
  141. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  142. }
  143. return _priceLabel;
  144. }
  145. - (UILabel *)saleCount {
  146. if (!_saleCount) {
  147. _saleCount = [[UILabel alloc] init];
  148. _saleCount.font = [UIFont systemFontOfSize:10];
  149. _saleCount.textColor = [UIColor YHColorWithHex:0x999999];
  150. _saleCount.textAlignment = NSTextAlignmentRight;
  151. }
  152. return _saleCount;
  153. }
  154. - (UILabel *)disPriceL {
  155. if (!_disPriceL) {
  156. _disPriceL = [[UILabel alloc] init];
  157. _disPriceL.font = [UIFont systemFontOfSize:16];
  158. _disPriceL.textColor = [UIColor homeRedColor];
  159. }
  160. return _disPriceL;
  161. }
  162. - (UIImageView *)ticketNumber {
  163. if (!_ticketNumber) {
  164. _ticketNumber = [[UIImageView alloc] init];
  165. _ticketNumber.image = [UIImage imageNamed:@"quan_bg"];
  166. }
  167. return _ticketNumber;
  168. }
  169. - (UILabel *)totalCount {
  170. if (!_totalCount) {
  171. _totalCount = [[UILabel alloc] init];
  172. _totalCount.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  173. _totalCount.layer.cornerRadius = 3;
  174. _totalCount.font = [UIFont systemFontOfSize:10];
  175. _totalCount.textAlignment = NSTextAlignmentCenter;
  176. _totalCount.textColor = [UIColor YHColorWithHex:0xffffff];
  177. }
  178. return _totalCount;
  179. }
  180. - (UILabel *)zheKou {
  181. if (!_zheKou) {
  182. _zheKou = [[UILabel alloc] init];
  183. _zheKou.textColor = [UIColor whiteColor];
  184. _zheKou.textAlignment = NSTextAlignmentCenter;
  185. _zheKou.font = [UIFont systemFontOfSize:10];
  186. }
  187. return _zheKou;
  188. }
  189. - (UILabel *)ticketType {
  190. if (!_ticketType) {
  191. _ticketType = [[UILabel alloc] init];
  192. _ticketType.font = [UIFont systemFontOfSize:10];
  193. _ticketType.textAlignment = NSTextAlignmentCenter;
  194. _ticketType.textColor = [UIColor whiteColor];
  195. }
  196. return _ticketType;
  197. }
  198. - (UILabel *)commissionLabel {
  199. if (!_commissionLabel) {
  200. _commissionLabel = [[UILabel alloc] init];
  201. _commissionLabel.font = [UIFont systemFontOfSize:11];
  202. _commissionLabel.textColor = [UIColor whiteColor];
  203. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  204. _commissionLabel.backgroundColor = [UIColor changeColor];
  205. _commissionLabel.hidden = YES;
  206. }
  207. return _commissionLabel;
  208. }
  209. @end