酷店

KDPRecommendGoodCell.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //
  2. // KDPRecommendGoodCell.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPRecommendGoodCell.h"
  9. @implementation KDPRecommendGoodCell
  10. -(instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self=[super initWithFrame:frame];
  13. if (self) {
  14. UIView *backV =[[UIView alloc]init];
  15. backV.backgroundColor=[UIColor whiteColor];
  16. [self addSubview:backV];
  17. [backV mas_makeConstraints:^(MASConstraintMaker *make) {
  18. make.left.mas_equalTo (10);
  19. make.right.mas_equalTo(-10);
  20. make.top.mas_equalTo(0);
  21. make.bottom.mas_equalTo(-1);
  22. }];
  23. [backV addSubview:self.couponImgV];
  24. [self.couponImgV addSubview:self.couponPriceL];
  25. [backV addSubview:self.recomImgV];
  26. [backV addSubview:self.recomTitleL];
  27. [backV addSubview:self.recomShopL];
  28. [backV addSubview:self.recomShopiconImg];
  29. [backV addSubview:self.recomVolumeL];
  30. [backV addSubview:self.recomPriceL];
  31. // [backV addSubview:self.recomOriginL];
  32. [backV addSubview:self.recomprofitL];
  33. [self.recomImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.top.mas_equalTo(10);
  35. make.bottom.mas_equalTo(-11);
  36. make.width.height.mas_equalTo(100);
  37. }];
  38. [self.recomTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.mas_equalTo(self.recomImgV.mas_right).offset(10);
  40. make.top.mas_equalTo(self.recomImgV.mas_top);
  41. make.height.mas_equalTo(21);
  42. make.right.mas_equalTo(-10);
  43. }];
  44. [self.recomShopiconImg mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.mas_equalTo(self.recomTitleL.mas_left);
  46. make.top.mas_equalTo(self.recomTitleL.mas_bottom).offset(9);
  47. make.width.height.mas_equalTo(13);
  48. }];
  49. [self.recomShopL mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.mas_equalTo(self.recomShopiconImg.mas_right).offset(6);
  51. make.top.mas_equalTo(self.recomTitleL.mas_bottom).offset(7);
  52. make.right.mas_equalTo(self.recomVolumeL.mas_left);
  53. make.height.mas_equalTo(17);
  54. }];
  55. [self.recomVolumeL mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.right.mas_equalTo(-10);
  57. make.top.mas_equalTo(self.recomTitleL.mas_bottom).offset(7);
  58. make.height.mas_equalTo(17);
  59. }];
  60. [self.recomPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.mas_equalTo(self.recomTitleL.mas_left);
  62. make.top.mas_equalTo(self.recomShopiconImg.mas_bottom).offset(11);
  63. make.height.mas_equalTo(25);
  64. }];
  65. // [self.recomOriginL mas_makeConstraints:^(MASConstraintMaker *make) {
  66. // make.left.mas_equalTo(self.recomPriceL.mas_right).offset(8);
  67. // make.height.mas_equalTo(25);
  68. // make.top.mas_equalTo(self.recomPriceL.mas_top);
  69. //
  70. // }];
  71. [self.recomprofitL mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.right.mas_equalTo(-10);
  73. make.height.mas_equalTo(26);
  74. make.top.mas_equalTo(self.recomVolumeL.mas_bottom).offset(21);
  75. }];
  76. [self.couponImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.mas_equalTo(self.recomShopiconImg.mas_bottom).offset(42);
  78. make.height.mas_equalTo(16);
  79. make.width.mas_equalTo(60);
  80. make.left.mas_equalTo(self.recomPriceL.mas_left);
  81. }];
  82. [self.couponPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.mas_equalTo(20);
  84. make.top.right.bottom.mas_equalTo(0);
  85. }];
  86. UIView *lineV=[[UIView alloc]init];
  87. lineV.backgroundColor=[UIColor colorWithHexString:LineColor];
  88. [self addSubview:lineV];
  89. [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.mas_equalTo(10);
  91. make.right.mas_equalTo(-10);
  92. make.top.mas_equalTo(self.mas_bottom).offset(-1);
  93. make.height.mas_equalTo(1);
  94. }];
  95. }
  96. return self;
  97. }
  98. -(UIImageView *)recomImgV
  99. {
  100. if (!_recomImgV) {
  101. _recomImgV=[[UIImageView alloc]init];
  102. _recomImgV.backgroundColor=[UIColor colorWithHexString:@"D8D8D8"];
  103. _recomImgV.layer.cornerRadius=8;
  104. _recomImgV.layer.masksToBounds=YES;
  105. }
  106. return _recomImgV;
  107. }
  108. -(UILabel *)recomTitleL
  109. {
  110. if (!_recomTitleL) {
  111. _recomTitleL=[[UILabel alloc]init];
  112. _recomTitleL.attributedText=[KDPublicMethod sethanggaoWithStr:@"这是一个商品名这是一个商品名商品名这是一个商品名这是一个商品名商品名" linSpacing:5];
  113. _recomTitleL.numberOfLines=0;
  114. _recomTitleL.font=[UIFont systemFontOfSize:15];
  115. _recomTitleL.textColor=[UIColor colorWithHexString:fontColor];
  116. }
  117. return _recomTitleL;
  118. }
  119. -(UIImageView *)recomShopiconImg
  120. {
  121. if (!_recomShopiconImg) {
  122. _recomShopiconImg=[[UIImageView alloc]init];
  123. _recomShopiconImg.image=[UIImage imageNamed:@"taobao_icon"];
  124. }
  125. return _recomShopiconImg;
  126. }
  127. -(UILabel *)recomShopL
  128. {
  129. if (!_recomShopL) {
  130. _recomShopL=[[UILabel alloc]init];
  131. _recomShopL.text=@"-------";
  132. _recomShopL.textColor=[UIColor colorWithHexString:@"#666666"];
  133. _recomShopL.font=[UIFont systemFontOfSize:12];
  134. }
  135. return _recomShopL;
  136. }
  137. -(UILabel *)recomPriceL
  138. {
  139. if (!_recomPriceL) {
  140. _recomPriceL=[[UILabel alloc]init];
  141. _recomPriceL.textColor=[UIColor colorWithHexString:fontColor];
  142. _recomPriceL.font=[UIFont boldSystemFontOfSize:18];
  143. _recomPriceL.text=@"¥--";
  144. }
  145. return _recomPriceL;
  146. }
  147. -(UILabel *)recomOriginL
  148. {
  149. if (!_recomOriginL) {
  150. _recomOriginL =[[UILabel alloc]init];
  151. _recomOriginL.textColor=[UIColor colorWithHexString:@"#999999"];
  152. _recomOriginL.font=[UIFont systemFontOfSize:13];
  153. //中划线
  154. NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
  155. NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:@"¥---" attributes:attribtDic];
  156. // 赋值
  157. _recomOriginL.attributedText = attribtStr;
  158. }
  159. return _recomOriginL;
  160. }
  161. -(UILabel *)recomVolumeL
  162. {
  163. if (!_recomVolumeL) {
  164. _recomVolumeL =[[UILabel alloc]init];
  165. _recomVolumeL.text=@"月销:--";
  166. _recomVolumeL.textAlignment=NSTextAlignmentRight;
  167. _recomVolumeL.textColor=[UIColor colorWithHexString:@"#999999"];
  168. _recomVolumeL.font=[UIFont systemFontOfSize:12];
  169. }
  170. return _recomVolumeL;
  171. }
  172. -(UILabel *)recomprofitL
  173. {
  174. if (!_recomprofitL) {
  175. _recomprofitL =[[UILabel alloc]init];
  176. _recomprofitL.text=@"利润 --%";
  177. _recomprofitL.textColor=[UIColor whiteColor];
  178. _recomprofitL.backgroundColor=[UIColor gradientOneColor:[UIColor colorWithHexString:@"#FF235F"] toColor:[UIColor colorWithHexString:@"#FF7676"] Width:78];
  179. _recomprofitL.layer.cornerRadius=6;
  180. _recomprofitL.layer.masksToBounds=YES;
  181. _recomprofitL.textAlignment=NSTextAlignmentCenter;
  182. }
  183. return _recomprofitL;
  184. }
  185. -(UIImageView *)couponImgV
  186. {
  187. if (!_couponImgV) {
  188. _couponImgV=[[UIImageView alloc]init];
  189. _couponImgV.image=[UIImage imageNamed:@"coupon_icon"];
  190. UILabel *quanL=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, 16)];
  191. quanL.text=@"券";
  192. quanL.font=[UIFont systemFontOfSize:12];
  193. quanL.textColor=[UIColor whiteColor];
  194. quanL.textAlignment=NSTextAlignmentCenter;
  195. [_couponImgV addSubview:quanL];
  196. }
  197. return _couponImgV;
  198. }
  199. -(UILabel *)couponPriceL
  200. {
  201. if (!_couponPriceL) {
  202. _couponPriceL=[[UILabel alloc]init];
  203. _couponPriceL.text=@"---";
  204. _couponPriceL.textColor=[UIColor colorWithHexString:ThemeColor];
  205. _couponPriceL.font=[UIFont systemFontOfSize:12];
  206. _couponPriceL.textAlignment=NSTextAlignmentCenter;
  207. }
  208. return _couponPriceL;
  209. }
  210. -(void)setModel:(KDPGoodsModel *)model
  211. {
  212. _model = model;
  213. //设置字体字号和字体类别
  214. NSString *timetitle= [NSString stringWithFormat:@" 利润 %@ ",model.commission_rate];
  215. NSMutableAttributedString *timestr = [[NSMutableAttributedString alloc] initWithString:timetitle];
  216. [timestr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,3)]; //设置字体
  217. self.recomprofitL.attributedText=timestr;
  218. [self.recomImgV sd_setImageWithURL:[NSURL URLWithString:model.img]placeholderImage:[UIImage imageNamed:placholderImg]];
  219. self.recomShopL.text=model.shop_title;
  220. self.recomTitleL.attributedText=[KDPublicMethod sethanggaoWithStr:model.title linSpacing:5];
  221. if (model.shop_type.integerValue == 1) {
  222. self.recomShopiconImg.image =[UIImage imageNamed:@"tm_icon"];
  223. }else{
  224. self.recomShopiconImg.image =[UIImage imageNamed:@"taobao_icon"];
  225. }
  226. //原件
  227. NSString *textStr =[NSString stringWithFormat:@"¥%@",model.price];
  228. //中划线
  229. NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
  230. NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
  231. // 赋值
  232. self.recomOriginL.attributedText = attribtStr;
  233. NSString *pricetitle= [NSString stringWithFormat:@"¥%@",model.discount_price];
  234. NSMutableAttributedString *prictS = [[NSMutableAttributedString alloc] initWithString:pricetitle];
  235. [prictS addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,1)]; //设置字体
  236. self.recomPriceL.attributedText=prictS;
  237. self.recomVolumeL.text=[NSString stringWithFormat:@"月销%@",model.volume];
  238. if (model.coupon_price.floatValue>0) {
  239. self.couponImgV.hidden=NO;
  240. self.couponPriceL.text=model.coupon_price;
  241. [self.recomPriceL mas_updateConstraints:^(MASConstraintMaker *make) {
  242. make.top.mas_equalTo(self.recomShopiconImg.mas_bottom).offset(11);
  243. }];
  244. }else{
  245. self.couponImgV.hidden=YES;
  246. [self.recomPriceL mas_updateConstraints:^(MASConstraintMaker *make) {
  247. make.top.mas_equalTo(self.recomShopiconImg.mas_bottom).offset(25);
  248. }];
  249. }
  250. }
  251. @end