猎豆优选

LDGoodCollectionCell.m 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. //
  2. // LDGoodCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDGoodCollectionCell.h"
  9. #import "LDGoodTagsView.h"
  10. @interface LDGoodCollectionCell ()
  11. @property (nonatomic, strong) UIImageView *imgView; //大图
  12. @property (nonatomic, strong) YYLabel *titleLabel; //标题
  13. @property (nonatomic, strong) YYLabel *priceLabel; //原价
  14. @property (nonatomic, strong) UILabel *saleCount; // 月销量
  15. @property (nonatomic, strong) YYLabel *disPriceL; // 优惠后价格
  16. @property (nonatomic, strong) UIImageView *ticketNumber; //
  17. @property (nonatomic, strong) UILabel *totalCount; // 总件数
  18. @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券
  19. @property (nonatomic, strong) UILabel *ticketType;
  20. @property (nonatomic, strong) UILabel *volum;
  21. @property (nonatomic, strong) LDGoodTagsView *tagsView;
  22. @property (nonatomic, strong) YYLabel *shopInfo;
  23. @property (nonatomic, strong) UIView *commissionBg;
  24. @property (nonatomic, strong) UILabel *commissionLabel;
  25. @property (nonatomic, strong) UILabel *redpriceLabel;//红包
  26. @property (nonatomic, strong) UIImageView *redImgV;
  27. @end
  28. @implementation LDGoodCollectionCell
  29. - (instancetype)initWithFrame:(CGRect)frame {
  30. self = [super initWithFrame:frame];
  31. if (self) {
  32. self.layer.cornerRadius = 6;
  33. self.layer.masksToBounds = YES;
  34. self.contentView.backgroundColor = [UIColor whiteColor];
  35. [self initSubViews];
  36. }
  37. return self;
  38. }
  39. - (void)initSubViews {
  40. [self.contentView addSubview:self.imgView];
  41. [self.contentView addSubview:self.titleLabel];
  42. [self.contentView addSubview:self.disPriceL];
  43. [self.contentView addSubview:self.ticketNumber];
  44. [self.ticketNumber addSubview:self.ticketType];
  45. [self.ticketNumber addSubview:self.zheKou];
  46. [self.contentView addSubview:self.saleCount];
  47. [self.contentView addSubview:self.shopInfo];
  48. [self.commissionBg addSubview:self.commissionLabel];
  49. [self.contentView addSubview:self.commissionBg];
  50. [self.contentView addSubview:self.volum];
  51. [self.contentView addSubview:self.redpriceLabel];
  52. [self.contentView addSubview:self.redImgV];
  53. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.right.top.mas_equalTo(0);
  55. make.height.mas_equalTo((SCREEN_WIDTH-5)/2.f);
  56. }];
  57. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(10);
  59. make.right.mas_equalTo(-10);
  60. make.top.mas_equalTo(self.imgView.mas_bottom).mas_offset(4);
  61. }];
  62. [self.shopInfo mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.mas_equalTo(self.titleLabel.mas_left);
  64. make.right.mas_equalTo(-10);
  65. make.top.mas_equalTo(self.imgView.mas_bottom).mas_offset(45);
  66. }];
  67. [self.disPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(self.titleLabel.mas_left).mas_offset(-2);
  69. make.top.mas_equalTo(self.shopInfo.mas_bottom).mas_offset(5);
  70. }];
  71. [self.volum mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(10);
  73. make.centerY.mas_equalTo(self.disPriceL.mas_centerY);
  74. }];
  75. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.mas_equalTo(self.titleLabel.mas_left);
  77. make.width.mas_equalTo(78);
  78. make.height.mas_equalTo(15);
  79. make.bottom.mas_equalTo(-7);
  80. }];
  81. [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.top.bottom.mas_equalTo(0);
  83. make.width.mas_equalTo(20);
  84. }];
  85. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.mas_equalTo(self.ticketType.mas_right);
  87. make.top.mas_equalTo(0);
  88. make.height.mas_equalTo(14);
  89. make.width.mas_equalTo(44);
  90. }];
  91. [self.redImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(5);
  93. make.left.mas_equalTo(self.titleLabel.mas_left);
  94. make.width.mas_equalTo(13);
  95. make.height.mas_equalTo(15);
  96. }];
  97. [self.redpriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.top.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(5);
  99. make.left.mas_equalTo(self.redImgV.mas_right);
  100. make.height.mas_equalTo(15);
  101. make.width.mas_equalTo(65);
  102. }];
  103. [self.commissionBg mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.mas_equalTo(self.redpriceLabel.mas_right).offset(30);
  105. make.width.mas_equalTo(65);
  106. make.height.mas_equalTo(15);
  107. make.top.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(5);
  108. }];
  109. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
  111. }];
  112. }
  113. - (void)setModel:(LDChildGoodModel *)model {
  114. _model = model;
  115. //标题
  116. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
  117. attri.yy_font = [UIFont boldSystemFontOfSize:14];
  118. attri.yy_color = [UIColor blackColor];
  119. attri.yy_lineSpacing = 6;
  120. self.titleLabel.attributedText = attri;
  121. [self.imgView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  122. NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  123. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price];
  124. attrStr.yy_font = [UIFont systemFontOfSize:11];
  125. attrStr.yy_color = [UIColor YHColorWithHex:0x999999];
  126. YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]];
  127. [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)];
  128. self.priceLabel.attributedText = attrStr;
  129. self.volum.text = [NSString stringWithFormat:@"月销 %@",model.volume];\
  130. self.redImgV.hidden=NO;
  131. self.redpriceLabel.hidden=NO;
  132. self.commissionBg.hidden=NO;
  133. if ([model.is_coupon boolValue]) {
  134. self.ticketNumber.hidden=NO;
  135. }else{
  136. self.ticketNumber.hidden=YES;
  137. }
  138. if (model.red_active_status.integerValue == 1) {//有红包的时候
  139. self.redpriceLabel.text=[NSString stringWithFormat:@" %@元红包 ",model.red_active_money];
  140. if (model.commission_price.length>0 ) {//有返佣金
  141. [self.commissionBg mas_updateConstraints:^(MASConstraintMaker *make) {
  142. make.left.mas_equalTo(self.redpriceLabel.mas_right).offset(30);
  143. }];
  144. }else{
  145. self.commissionBg.hidden=YES;
  146. }
  147. }else{//没有红包的时候
  148. self.redImgV.hidden=YES;
  149. self.redpriceLabel.hidden=YES;
  150. if (model.commission_price.length>0 ) {//有返佣金
  151. [self.commissionBg mas_updateConstraints:^(MASConstraintMaker *make) {
  152. make.left.mas_equalTo(self.titleLabel.mas_left);
  153. }];
  154. }else{
  155. self.commissionBg.hidden=YES;
  156. }
  157. }
  158. //店铺信息
  159. if (model.shop_title.length > 0) {
  160. UIImage *img;
  161. if ([model.shop_type isEqualToString:@"1"]) {
  162. img= [UIImage imageNamed:@"tm_shop"];
  163. }else {
  164. img= [UIImage imageNamed:@"taobao_shop"];
  165. }
  166. YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
  167. imgeView.frame = CGRectMake(0, 0, 15, 15);
  168. NSMutableAttributedString *shopAtti = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.shop_title]];
  169. NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
  170. [shopAtti insertAttributedString:mua atIndex:0];
  171. shopAtti.yy_font = [UIFont systemFontOfSize:12];
  172. shopAtti.yy_color = [UIColor YHColorWithHex:0x9B9B9B];
  173. self.shopInfo.attributedText = shopAtti;
  174. self.shopInfo.hidden = NO;
  175. }else {
  176. self.shopInfo.hidden = YES;
  177. }
  178. //折后价
  179. NSString *disStr;
  180. if ([model.is_coupon boolValue]) {
  181. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  182. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  183. self.ticketType.text = @"券";
  184. }else {
  185. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  186. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  187. self.ticketType.text = @"折";
  188. }
  189. CGFloat width = [model.is_coupon boolValue] ? 64 : 0;
  190. // [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  191. // make.width.mas_equalTo(width);
  192. // }];
  193. //券后价格
  194. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  195. [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(0, disStr.length)];
  196. disAttr.yy_color = [UIColor homeRedColor];
  197. self.disPriceL.attributedText = disAttr;
  198. self.commissionLabel.text = [NSString stringWithFormat:@"返¥%.2f",[model.commission_price floatValue]];
  199. // 预估佣金视图
  200. //券的位置
  201. [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  202. make.width.mas_equalTo(width);
  203. }];
  204. // // 预估佣金视图
  205. // if (model.commission_price.floatValue>0) {//判断是否有预估佣金,
  206. //
  207. // [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  208. //
  209. // if (model.red_active_status.integerValue == 1) {
  210. // make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(85);
  211. // }else{
  212. // make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(75);
  213. // }
  214. // }];
  215. // [self.commissionBg mas_updateConstraints:^(MASConstraintMaker *make) {
  216. // if (model.red_active_status.integerValue == 1) {
  217. // make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(10);
  218. // }else{
  219. // make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(0);
  220. // }
  221. //
  222. // }];
  223. // }else {
  224. // [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  225. // make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(5);
  226. // }];
  227. // }
  228. //
  229. // self.commissionBg.hidden = !(model.commission_price.length>0);
  230. //
  231. // self.ticketNumber.hidden = ![model.is_coupon boolValue];
  232. }
  233. - (UIImageView *)imgView {
  234. if (!_imgView) {
  235. _imgView = [[UIImageView alloc] init];
  236. _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0];
  237. }
  238. return _imgView;
  239. }
  240. - (YYLabel *)titleLabel {
  241. if (!_titleLabel) {
  242. _titleLabel = [[YYLabel alloc] init];
  243. _titleLabel.displaysAsynchronously = YES;
  244. _titleLabel.font = [UIFont boldSystemFontOfSize:14];
  245. _titleLabel.textColor = [UIColor blackColor];
  246. _titleLabel.numberOfLines = 2;
  247. _titleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH/2-Fitsize(20);
  248. }
  249. return _titleLabel;
  250. }
  251. - (YYLabel *)priceLabel {
  252. if (!_priceLabel) {
  253. _priceLabel = [[YYLabel alloc] init];
  254. _priceLabel.displaysAsynchronously = YES;
  255. _priceLabel.font = [UIFont systemFontOfSize:11];
  256. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  257. }
  258. return _priceLabel;
  259. }
  260. - (UILabel *)saleCount {
  261. if (!_saleCount) {
  262. _saleCount = [[UILabel alloc] init];
  263. _saleCount.font = [UIFont systemFontOfSize:10];
  264. _saleCount.textColor = [UIColor YHColorWithHex:0x999999];
  265. _saleCount.textAlignment = NSTextAlignmentRight;
  266. _saleCount.hidden = YES;
  267. }
  268. return _saleCount;
  269. }
  270. - (YYLabel *)disPriceL {
  271. if (!_disPriceL) {
  272. _disPriceL = [[YYLabel alloc] init];
  273. _disPriceL.displaysAsynchronously = YES;
  274. _disPriceL.font = [UIFont systemFontOfSize:16];
  275. _disPriceL.textColor = [UIColor homeRedColor];
  276. }
  277. return _disPriceL;
  278. }
  279. - (UIImageView *)ticketNumber {
  280. if (!_ticketNumber) {
  281. _ticketNumber = [[UIImageView alloc] init];
  282. _ticketNumber.image = [UIImage imageNamed:@"quan_bg"];
  283. }
  284. return _ticketNumber;
  285. }
  286. - (UILabel *)totalCount {
  287. if (!_totalCount) {
  288. _totalCount = [[UILabel alloc] init];
  289. _totalCount.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  290. _totalCount.layer.cornerRadius = 3;
  291. _totalCount.font = [UIFont systemFontOfSize:10];
  292. _totalCount.textAlignment = NSTextAlignmentCenter;
  293. _totalCount.textColor = [UIColor YHColorWithHex:0xffffff];
  294. }
  295. return _totalCount;
  296. }
  297. - (UILabel *)zheKou {
  298. if (!_zheKou) {
  299. _zheKou = [[UILabel alloc] init];
  300. _zheKou.textColor = [UIColor homeRedColor];
  301. _zheKou.textAlignment = NSTextAlignmentCenter;
  302. _zheKou.font = [UIFont systemFontOfSize:10];
  303. }
  304. return _zheKou;
  305. }
  306. - (UILabel *)ticketType {
  307. if (!_ticketType) {
  308. _ticketType = [[UILabel alloc] init];
  309. _ticketType.font = [UIFont systemFontOfSize:10];
  310. _ticketType.textAlignment = NSTextAlignmentCenter;
  311. _ticketType.textColor = [UIColor homeRedColor];
  312. }
  313. return _ticketType;
  314. }
  315. - (YYLabel *)shopInfo {
  316. if (!_shopInfo) {
  317. _shopInfo = [[YYLabel alloc] init];
  318. _shopInfo.displaysAsynchronously = YES;
  319. _shopInfo.font = [UIFont systemFontOfSize:12];
  320. _shopInfo.textColor = [UIColor YHColorWithHex:0x9B9B9B];
  321. }
  322. return _shopInfo;
  323. }
  324. - (UIView *)commissionBg {
  325. if (!_commissionBg) {
  326. _commissionBg = [[UIView alloc] init];
  327. _commissionBg.backgroundColor = [UIColor YHColorWithHex:0xFFF4DF];
  328. }
  329. return _commissionBg;
  330. }
  331. - (UILabel *)commissionLabel {
  332. if (!_commissionLabel) {
  333. _commissionLabel = [[UILabel alloc] init];
  334. _commissionLabel.textColor = [UIColor YHColorWithHex:0x99520F];
  335. _commissionLabel.font = [UIFont systemFontOfSize:10];
  336. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  337. }
  338. return _commissionLabel;
  339. }
  340. - (UILabel *)volum {
  341. if (!_volum) {
  342. _volum = [[UILabel alloc] init];
  343. _volum.textColor = [UIColor YHColorWithHex:0xBBB9BB];
  344. _volum.font = [UIFont systemFontOfSize:10];
  345. }
  346. return _volum;
  347. }
  348. //- (LDGoodTagsView *)tagsView {
  349. // if (!_tagsView) {
  350. // _tagsView = [[LDGoodTagsView alloc] init];
  351. // }
  352. // return _tagsView;
  353. //}
  354. -(UIImageView *)redImgV
  355. {
  356. if (!_redImgV) {
  357. _redImgV = [[UIImageView alloc] init];
  358. // _redImgV.backgroundColor=[UIColor redColor];
  359. _redImgV.image = [UIImage imageNamed:@"red_detail"];
  360. }
  361. return _redImgV;
  362. }
  363. -(UILabel *)redpriceLabel
  364. {
  365. if (!_redpriceLabel) {
  366. _redpriceLabel = [[UILabel alloc] init];
  367. _redpriceLabel.textColor = [UIColor YHColorWithHex:0x99520F];
  368. _redpriceLabel.backgroundColor=[UIColor YHColorWithHex:0xFFF4DF];
  369. _redpriceLabel.font = [UIFont systemFontOfSize:10];
  370. _redpriceLabel.textAlignment = NSTextAlignmentCenter;
  371. }
  372. return _redpriceLabel;
  373. }
  374. @end