猎豆优选

LDRankGoodCollectionCell.m 11KB

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