猎豆优选

KBNativeShopCarCollectionCell.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. //
  2. // KBNativeShopCarCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/6.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBNativeShopCarCollectionCell.h"
  9. @interface KBNativeShopCarCollectionCell ()
  10. @property (nonatomic, strong) UIImageView *icon;
  11. @property (nonatomic, strong) UILabel *title;
  12. @property (nonatomic, strong) YYLabel *couple_price;
  13. @property (nonatomic, strong) YYLabel *price;
  14. @property (nonatomic, strong) YYLabel *endTime;
  15. @property (nonatomic, strong) UILabel *couple_label;
  16. @property (nonatomic, strong) UILabel *commissionLabel;
  17. @property (nonatomic, strong) UILabel *fanLabel;
  18. @property (nonatomic, strong) UIImageView *discountImgV;
  19. @property (nonatomic, strong) UILabel *numlabel;
  20. @property (nonatomic, strong) UILabel *redpriceLabel;//红包
  21. @property (nonatomic, strong) UIImageView *redImgV;
  22. @end
  23. @implementation KBNativeShopCarCollectionCell
  24. - (instancetype)initWithFrame:(CGRect)frame
  25. {
  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.icon];
  35. [self.contentView addSubview:self.title];
  36. [self.contentView addSubview:self.couple_price];
  37. [self.contentView addSubview:self.price];
  38. [self.contentView addSubview:self.endTime];
  39. [self.contentView addSubview:self.couple_label];
  40. [self.icon addSubview:self.commissionLabel];
  41. [self.contentView addSubview:self.discountImgV];
  42. [self.discountImgV addSubview:self.numlabel];
  43. [self.contentView addSubview:self.fanLabel];
  44. [self.contentView addSubview:self.redImgV];
  45. [self.contentView addSubview:self.redpriceLabel];
  46. [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.mas_equalTo(10);
  48. make.top.mas_equalTo(0);
  49. make.width.height.mas_equalTo(100);
  50. }];
  51. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.mas_equalTo(self.icon.mas_right).mas_offset(5);
  53. make.top.mas_equalTo(self.icon.mas_top);
  54. make.height.mas_equalTo(40);
  55. make.right.mas_equalTo(-10);
  56. }];
  57. [self.endTime mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(self.title.mas_left);
  59. make.bottom.mas_equalTo(self.icon.mas_bottom);
  60. }];
  61. [self.couple_price mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.mas_equalTo(self.title.mas_left);
  63. make.top.mas_equalTo(self.title.mas_bottom).mas_offset(10);
  64. }];
  65. [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.mas_equalTo(self.couple_price.mas_right).mas_offset(20);
  67. make.bottom.mas_equalTo(self.couple_price.mas_bottom);
  68. }];
  69. [self.couple_label mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.bottom.mas_equalTo(self.endTime.mas_bottom);
  71. make.right.mas_equalTo(-10);
  72. make.height.mas_equalTo(23);
  73. }];
  74. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.right.bottom.mas_equalTo(0);
  76. make.height.mas_equalTo(12);
  77. }];
  78. [self.redImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.mas_equalTo(self.icon.mas_right).mas_offset(5);
  80. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  81. make.width.mas_equalTo(13);
  82. make.height.mas_equalTo(FITSIZE(15));
  83. }];
  84. [self.redpriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.mas_equalTo(self.redImgV.mas_right);
  86. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  87. make.width.mas_equalTo(65);
  88. make.height.mas_equalTo(FITSIZE(15));
  89. }];
  90. [self.fanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(10);
  92. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  93. make.width.mas_equalTo(FITSIZE(50));
  94. make.height.mas_equalTo(FITSIZE(15));
  95. }];
  96. [self.discountImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.mas_equalTo(self.fanLabel.mas_right).mas_offset(10);
  98. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  99. make.width.mas_equalTo(FITSIZE(60));
  100. make.height.mas_equalTo(FITSIZE(15));
  101. }];
  102. [self.numlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.left.mas_equalTo(20);
  104. make.top.mas_equalTo(0);
  105. make.width.mas_equalTo(FITSIZE(40));
  106. make.height.mas_equalTo(FITSIZE(15));
  107. }];
  108. }
  109. - (void)setModel:(LDChildGoodModel *)model {
  110. _model = model;
  111. [self.icon sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  112. self.title.text = model.title;
  113. self.couple_price.text = [NSString stringWithFormat:@"¥%@",model.discount_price];
  114. self.couple_price.font = [UIFont systemFontOfSize:16];
  115. self.couple_label.hidden=YES;
  116. self.endTime.hidden =YES;
  117. self.price.hidden = ![model.is_coupon boolValue];
  118. self.commissionLabel.hidden = YES;
  119. self.discountImgV.hidden=YES;
  120. self.fanLabel.hidden=YES;
  121. self.redpriceLabel.text=[NSString stringWithFormat:@" %@元红包 ",model.red_active_money];
  122. self.numlabel.text = [NSString stringWithFormat:@"¥%@",model.coupon_price];
  123. self.fanLabel.text = [NSString stringWithFormat:@"返¥%@ ",model.commission_price];
  124. if ([model.red_active_status boolValue]) {//有红包
  125. self.redpriceLabel.hidden=NO;
  126. self.redImgV.hidden=NO;
  127. [self.redImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  128. make.width.mas_equalTo(13);
  129. }];
  130. [self.redpriceLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  131. make.width.mas_equalTo(65);
  132. }];
  133. if (model.is_coupon.integerValue == 1 && model.commission_price.length>0) {//佣金和优惠券都存在的时候
  134. self.discountImgV.hidden=NO;
  135. self.fanLabel.hidden=NO;
  136. [self.fanLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  137. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(10);
  138. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  139. }];
  140. [self.discountImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  141. make.left.mas_equalTo(self.fanLabel.mas_right).mas_offset(10);
  142. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  143. }];
  144. }else if (model.is_coupon.integerValue ==1)//优惠券
  145. {
  146. self.fanLabel.hidden=YES;
  147. self.discountImgV.hidden=NO;
  148. [self.discountImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  149. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(10);
  150. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  151. }];
  152. }else if(model.commission_price.length>0){
  153. self.discountImgV.hidden=YES;
  154. self.fanLabel.hidden=NO;
  155. [self.discountImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  156. make.left.mas_equalTo(self.fanLabel.mas_right).mas_offset(10);
  157. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  158. }];
  159. }else{
  160. self.discountImgV.hidden=YES;
  161. self.fanLabel.hidden=YES;
  162. }
  163. }else{//没有红包的时候
  164. [self.redImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  165. make.width.mas_equalTo(0);
  166. }];
  167. [self.redpriceLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  168. make.width.mas_equalTo(0);
  169. }];
  170. self.redpriceLabel.hidden=YES;
  171. self.redImgV.hidden=YES;
  172. if (model.is_coupon.integerValue == 1 && model.commission_price.length>0) {//佣金和优惠券都存在的时候
  173. self.discountImgV.hidden=NO;
  174. self.fanLabel.hidden=NO;
  175. [self.fanLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  176. make.left.mas_equalTo(self.icon.mas_right).mas_offset(5);
  177. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  178. }];
  179. [self.discountImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  180. make.left.mas_equalTo(self.fanLabel.mas_right).mas_offset(10);
  181. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  182. }];
  183. }else if (model.is_coupon.integerValue ==1)//优惠券
  184. {
  185. self.fanLabel.hidden=YES;
  186. self.discountImgV.hidden=NO;
  187. [self.discountImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  188. make.left.mas_equalTo(self.redpriceLabel.mas_right);
  189. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  190. }];
  191. }else if(model.commission_price.length>0){//返佣金
  192. self.discountImgV.hidden=YES;
  193. self.fanLabel.hidden=NO;
  194. [self.fanLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  195. make.left.mas_equalTo(self.redpriceLabel.mas_right);
  196. make.top.mas_equalTo(self.couple_price.mas_bottom).mas_offset(10);
  197. }];
  198. }else{
  199. self.discountImgV.hidden=YES;
  200. self.fanLabel.hidden=YES;
  201. }
  202. }
  203. }
  204. #pragma mark -----
  205. - (UIImageView *)icon {
  206. if (!_icon) {
  207. _icon = [[UIImageView alloc] init];
  208. _icon.layer.cornerRadius = 6;
  209. _icon.layer.masksToBounds=YES;
  210. _icon.backgroundColor = [UIColor yhGrayColor];
  211. }
  212. return _icon;
  213. }
  214. - (UILabel *)title {
  215. if (!_title) {
  216. _title = [[UILabel alloc] init];
  217. _title.numberOfLines = 2;
  218. _title.font = [UIFont systemFontOfSize:14];
  219. }
  220. return _title;
  221. }
  222. - (YYLabel *)couple_price {
  223. if (!_couple_price) {
  224. _couple_price = [[YYLabel alloc] init];
  225. _couple_price.textColor = [UIColor YHColorWithHex:0xEE000E];
  226. _couple_price.font = [UIFont systemFontOfSize:18];
  227. _couple_price.displaysAsynchronously = YES;
  228. }
  229. return _couple_price;
  230. }
  231. - (YYLabel *)price {
  232. if (!_price) {
  233. _price = [[YYLabel alloc] init];
  234. _price.textColor = [UIColor YHColorWithHex:0xA2A0A0];
  235. _price.font = [UIFont systemFontOfSize:12];
  236. _price.displaysAsynchronously = YES;
  237. }
  238. return _price;
  239. }
  240. - (YYLabel *)endTime {
  241. if (!_endTime) {
  242. _endTime = [[YYLabel alloc] init];
  243. _endTime.font = [UIFont systemFontOfSize:11];
  244. _endTime.textColor = [UIColor YHColorWithHex:0xA2A0A0];
  245. _endTime.displaysAsynchronously = YES;
  246. }
  247. return _endTime;
  248. }
  249. - (UILabel *)couple_label {
  250. if (!_couple_label) {
  251. _couple_label = [[UILabel alloc] init];
  252. _couple_label.textColor = [UIColor whiteColor];
  253. _couple_label.font = [UIFont systemFontOfSize:13];
  254. _couple_label.textAlignment = NSTextAlignmentCenter;
  255. _couple_label.backgroundColor = [UIColor homeRedColor];
  256. }
  257. return _couple_label;
  258. }
  259. - (UILabel *)commissionLabel {
  260. if (!_commissionLabel) {
  261. _commissionLabel = [[UILabel alloc] init];
  262. _commissionLabel.font = [UIFont systemFontOfSize:11];
  263. _commissionLabel.textColor = [UIColor whiteColor];
  264. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  265. _commissionLabel.backgroundColor = [UIColor homeRedColor];
  266. _commissionLabel.adjustsFontSizeToFitWidth = YES;
  267. }
  268. return _commissionLabel;
  269. }
  270. -(UILabel *)fanLabel
  271. {
  272. if (!_fanLabel) {
  273. _fanLabel =[[UILabel alloc]init];
  274. _fanLabel.backgroundColor=[UIColor YHColorWithHex:0xFFF4DF];
  275. _fanLabel.textColor=[UIColor YHColorWithHex:0x99520F];
  276. _fanLabel.font=[UIFont systemFontOfSize:FITSIZE(10)];
  277. _fanLabel.textAlignment=NSTextAlignmentCenter;
  278. }
  279. return _fanLabel;
  280. }
  281. -(UILabel *)numlabel
  282. {
  283. if (!_numlabel) {
  284. _numlabel =[[UILabel alloc]init];
  285. _numlabel.textColor=[UIColor YHColorWithHex:0xFA2D36];
  286. _numlabel.font=[UIFont systemFontOfSize:FITSIZE(10)];
  287. _numlabel.textAlignment=NSTextAlignmentCenter;
  288. }
  289. return _numlabel;
  290. }
  291. -(UIImageView *)discountImgV
  292. {
  293. if (!_discountImgV) {
  294. _discountImgV =[[UIImageView alloc]init];
  295. _discountImgV.image=[UIImage imageNamed:@"quan_bg"];
  296. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, FITSIZE(15))];
  297. label.textColor=[UIColor YHColorWithHex:0xFA2D36];
  298. label.font=[UIFont systemFontOfSize:FITSIZE(10)];
  299. label.textAlignment=NSTextAlignmentCenter;
  300. label.text=@"券";
  301. [_discountImgV addSubview:label];
  302. }
  303. return _discountImgV;
  304. }
  305. -(UIImageView *)redImgV
  306. {
  307. if (!_redImgV) {
  308. _redImgV = [[UIImageView alloc] init];
  309. // _redImgV.backgroundColor=[UIColor redColor];
  310. _redImgV.image = [UIImage imageNamed:@"red_detail"];
  311. }
  312. return _redImgV;
  313. }
  314. -(UILabel *)redpriceLabel
  315. {
  316. if (!_redpriceLabel) {
  317. _redpriceLabel = [[UILabel alloc] init];
  318. _redpriceLabel.textColor = [UIColor YHColorWithHex:0x99520F];
  319. _redpriceLabel.backgroundColor=[UIColor YHColorWithHex:0xFFF4DF];
  320. _redpriceLabel.font = [UIFont systemFontOfSize:10];
  321. _redpriceLabel.textAlignment = NSTextAlignmentCenter;
  322. }
  323. return _redpriceLabel;
  324. }
  325. @end