口袋优选

KBGoodHorzitolCollectionCell.m 11KB

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