口袋优选

KBGoodCollectionCell.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. //
  2. // KBGoodCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBGoodCollectionCell.h"
  9. #import "KBGoodTagsView.h"
  10. @interface KBGoodCollectionCell ()
  11. @property (nonatomic, strong) UIImageView *imgView; //大图
  12. @property (nonatomic, strong) YYLabel *titleLabel; //标题
  13. @property (nonatomic, strong) YYLabel *priceLabel; //原价
  14. @property (nonatomic, strong) UILabel *saleCount; // 月销量
  15. @property (nonatomic, strong) YYLabel *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) KBGoodTagsView *tagsView;
  22. @end
  23. @implementation KBGoodCollectionCell
  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:(KBChildGoodModel *)model {
  97. _model = model;
  98. //标题
  99. UIImage *img;
  100. if ([model.shop_type isEqualToString:@"1"]) {
  101. img= [UIImage imageNamed:@"tm_shop"];
  102. }
  103. YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
  104. if ([model.shop_type isEqualToString:@"1"]) {
  105. imgeView.frame = CGRectMake(0, 0, 15, 15);
  106. }else {
  107. imgeView.frame = CGRectMake(0, 0, 0, 0);
  108. }
  109. NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
  110. NSMutableAttributedString *attri;
  111. if ([model.shop_type isEqualToString:@"1"]) {
  112. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.title]];
  113. }else {
  114. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
  115. }
  116. [attri insertAttributedString:mua atIndex:0];
  117. attri.yy_font = [UIFont systemFontOfSize:14];
  118. attri.yy_color = [UIColor YHColorWithHex:0x444444];
  119. attri.yy_lineSpacing = 4;
  120. self.titleLabel.attributedText = attri;
  121. [self.imgView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  122. NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  123. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price];
  124. attrStr.yy_font = [UIFont systemFontOfSize:11];
  125. attrStr.yy_color = [UIColor YHColorWithHex:0x999999];
  126. YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]];
  127. [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)];
  128. self.priceLabel.attributedText = attrStr;
  129. self.saleCount.text = [NSString stringWithFormat:@"月销:%@",model.volume];
  130. //折后价
  131. NSString *disStr;
  132. if ([model.is_coupon boolValue]) {
  133. disStr = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]];
  134. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  135. self.ticketType.text = @"券";
  136. }else {
  137. disStr = [NSString stringWithFormat:@"折后¥%.2f",[model.discount_price floatValue]];
  138. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  139. self.ticketType.text = @"折";
  140. }
  141. //券相关
  142. self.ticketNumber.hidden = ![model.is_coupon boolValue];
  143. CGFloat width = [model.is_coupon boolValue] ? 64 : 0;
  144. // [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  145. // make.width.mas_equalTo(width);
  146. // }];
  147. //券后价格
  148. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  149. [disAttr yy_setFont:[UIFont systemFontOfSize:10] range:NSMakeRange(0, 3)];
  150. [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, disStr.length-3)];
  151. disAttr.yy_color = [UIColor homeRedColor];
  152. self.disPriceL.attributedText = disAttr;
  153. }
  154. - (UIImageView *)imgView {
  155. if (!_imgView) {
  156. _imgView = [[UIImageView alloc] init];
  157. _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0];
  158. }
  159. return _imgView;
  160. }
  161. - (YYLabel *)titleLabel {
  162. if (!_titleLabel) {
  163. _titleLabel = [[YYLabel alloc] init];
  164. _titleLabel.displaysAsynchronously = YES;
  165. _titleLabel.font = [UIFont systemFontOfSize:14];
  166. _titleLabel.textColor = [UIColor YHColorWithHex:0x444444];
  167. _titleLabel.numberOfLines = 2;
  168. _titleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH/2-Fitsize(20);
  169. }
  170. return _titleLabel;
  171. }
  172. - (YYLabel *)priceLabel {
  173. if (!_priceLabel) {
  174. _priceLabel = [[YYLabel alloc] init];
  175. _priceLabel.displaysAsynchronously = YES;
  176. _priceLabel.font = [UIFont systemFontOfSize:11];
  177. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  178. }
  179. return _priceLabel;
  180. }
  181. - (UILabel *)saleCount {
  182. if (!_saleCount) {
  183. _saleCount = [[UILabel alloc] init];
  184. _saleCount.font = [UIFont systemFontOfSize:10];
  185. _saleCount.textColor = [UIColor YHColorWithHex:0x999999];
  186. _saleCount.textAlignment = NSTextAlignmentRight;
  187. _saleCount.hidden = YES;
  188. }
  189. return _saleCount;
  190. }
  191. - (YYLabel *)disPriceL {
  192. if (!_disPriceL) {
  193. _disPriceL = [[YYLabel alloc] init];
  194. _disPriceL.displaysAsynchronously = YES;
  195. _disPriceL.font = [UIFont systemFontOfSize:16];
  196. _disPriceL.textColor = [UIColor homeRedColor];
  197. }
  198. return _disPriceL;
  199. }
  200. - (UIImageView *)ticketNumber {
  201. if (!_ticketNumber) {
  202. _ticketNumber = [[UIImageView alloc] init];
  203. _ticketNumber.image = [UIImage imageNamed:@"quan_bg"];
  204. }
  205. return _ticketNumber;
  206. }
  207. - (UILabel *)totalCount {
  208. if (!_totalCount) {
  209. _totalCount = [[UILabel alloc] init];
  210. _totalCount.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  211. _totalCount.layer.cornerRadius = 3;
  212. _totalCount.font = [UIFont systemFontOfSize:10];
  213. _totalCount.textAlignment = NSTextAlignmentCenter;
  214. _totalCount.textColor = [UIColor YHColorWithHex:0xffffff];
  215. }
  216. return _totalCount;
  217. }
  218. - (UILabel *)zheKou {
  219. if (!_zheKou) {
  220. _zheKou = [[UILabel alloc] init];
  221. _zheKou.textColor = [UIColor whiteColor];
  222. _zheKou.textAlignment = NSTextAlignmentCenter;
  223. _zheKou.font = [UIFont systemFontOfSize:10];
  224. }
  225. return _zheKou;
  226. }
  227. - (UILabel *)ticketType {
  228. if (!_ticketType) {
  229. _ticketType = [[UILabel alloc] init];
  230. _ticketType.font = [UIFont systemFontOfSize:10];
  231. _ticketType.textAlignment = NSTextAlignmentCenter;
  232. _ticketType.textColor = [UIColor whiteColor];
  233. }
  234. return _ticketType;
  235. }
  236. - (UILabel *)commissionLabel {
  237. if (!_commissionLabel) {
  238. _commissionLabel = [[UILabel alloc] init];
  239. _commissionLabel.font = [UIFont systemFontOfSize:11];
  240. _commissionLabel.textColor = [UIColor whiteColor];
  241. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  242. _commissionLabel.backgroundColor = [UIColor changeColor];
  243. }
  244. return _commissionLabel;
  245. }
  246. //- (KDGoodTagsView *)tagsView {
  247. // if (!_tagsView) {
  248. // _tagsView = [[KDGoodTagsView alloc] init];
  249. // }
  250. // return _tagsView;
  251. //}
  252. @end