酷店

KDPRecommendGoodCell.m 9.6KB

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