猎豆优选

LDGoodHorzitolCollectionCell.m 12KB

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