Geen omschrijving

FKWantBuyProductCell.m 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // FKWantBuyProductCell.m
  3. // FirstLink
  4. //
  5. // Created by 施昌鹏 on 16/8/18.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKWantBuyProductCell.h"
  9. #import "FKInvalidView.h"
  10. #import "FKWantBuyProItem.h"
  11. #import "FKWantBuyItem.h"
  12. @interface FKWantBuyProductCell ()
  13. @property (nonatomic, strong) UIView *divideView;
  14. @property (nonatomic, strong) UILabel *showLabel;
  15. @property (nonatomic, strong) UILabel *URLLabel;
  16. @property (nonatomic, strong) UILabel *priceLabel;
  17. @property (nonatomic, strong) UILabel *titleLabel;
  18. @property (nonatomic, strong) UIImageView *brandImageView;
  19. @property (nonatomic, strong) UIImageView *productImageView;
  20. @property (nonatomic, strong) FKInvalidView *invalidView;
  21. @end
  22. @implementation FKWantBuyProductCell
  23. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  24. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  25. if (self) {
  26. [self addAllSubviews];
  27. }
  28. return self;
  29. }
  30. -(void)addAllSubviews {
  31. [self.contentView addSubview:self.showLabel];
  32. [self.contentView addSubview:self.URLLabel];
  33. [self.contentView addSubview:self.divideView];
  34. [self.contentView addSubview: self.productImageView];
  35. [self.contentView addSubview:self.priceLabel];
  36. [self.contentView addSubview:self.brandImageView];
  37. [self.contentView addSubview:self.titleLabel];
  38. [self.productImageView addSubview:self.invalidView];
  39. [self.showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.equalTo(self.contentView).offset(15);
  41. make.right.equalTo(self.contentView).offset(-20);
  42. make.top.equalTo(self.contentView).offset(13);
  43. }];
  44. [self.URLLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.right.equalTo(self.showLabel);
  46. make.top.equalTo(self.showLabel.mas_bottom);
  47. }];
  48. [self.divideView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.right.equalTo(self.contentView);
  50. make.top.equalTo(self.contentView).offset(63);
  51. make.height.mas_equalTo(1);
  52. }];
  53. [self.productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.equalTo(self.contentView).offset(15);
  55. make.top.equalTo(self.divideView.mas_bottom).offset(15);
  56. make.height.width.mas_equalTo(75);
  57. }];
  58. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.top.equalTo(self.divideView.mas_bottom).offset(18);
  60. make.right.equalTo(self.contentView).offset(-10);
  61. }];
  62. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.equalTo(self.productImageView.mas_right).offset(9);
  64. make.right.equalTo(self.priceLabel.mas_left).offset(-20);
  65. make.top.equalTo(self.divideView.mas_bottom).offset(18);
  66. }];
  67. [self.brandImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.equalTo(self.titleLabel);
  69. make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
  70. make.height.mas_equalTo(17);
  71. make.width.mas_equalTo(80);
  72. }];
  73. [self.invalidView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.center.equalTo(self.productImageView);
  75. }];
  76. }
  77. #pragma mark - Action
  78. -(void)configWithViewModel:(FKWantBuyViewModel *)viewModel index:(NSIndexPath *)index{
  79. FKWantBuyItem *item = viewModel.dataArray[index.section];
  80. if (item && item.product) {
  81. self.URLLabel.text = item.proUrl;
  82. [self.productImageView setImageWithURL:item.product.productPic cdnWidth:75];
  83. [self.brandImageView fl_setImageWithURL:[NSURL URLWithString:item.product.brand]];
  84. self.titleLabel.text = item.product.proTitle;
  85. self.priceLabel.text = [FLStringHelper convertFenToRMBmoneyString:item.product.price];
  86. if ([FLStringHelper isValidString:item.storageNum]) {
  87. if ([item.storageNum intValue]) {
  88. if ([item.product.status intValue] == 1) {
  89. self.invalidView.hidden = YES;
  90. }else if ([item.product.status intValue] == 3) {
  91. self.invalidView.titleLabel.text = @"已失效";
  92. }else{
  93. self.invalidView.titleLabel.text = @"已抢光";
  94. }
  95. }else{
  96. self.invalidView.titleLabel.text = @"已抢光";
  97. }
  98. }
  99. }
  100. }
  101. #pragma mark- Property
  102. -(UIView *)divideView {
  103. if (_divideView == nil) {
  104. _divideView = [[UIView alloc] init];
  105. _divideView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  106. }
  107. return _divideView;
  108. }
  109. -(UILabel *)priceLabel {
  110. if (_priceLabel == nil) {
  111. _priceLabel = [[UILabel alloc] init];
  112. _priceLabel.font = [UIFont boldSystemFontOfSize:13];
  113. _priceLabel.textColor = UIColorFromRGB(0x333333);
  114. _priceLabel.numberOfLines = 1;
  115. _priceLabel.textAlignment = NSTextAlignmentRight;
  116. [_priceLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  117. }
  118. return _priceLabel;
  119. }
  120. -(UILabel *)showLabel {
  121. if (_showLabel == nil) {
  122. _showLabel = [[UILabel alloc] init];
  123. _showLabel.textColor = UIColorFromRGB(0x333333);
  124. _showLabel.font = [UIFont systemFontOfSize:14];
  125. _showLabel.text = @"商品抓取成功";
  126. }
  127. return _showLabel;
  128. }
  129. -(UILabel *)URLLabel {
  130. if (_URLLabel == nil) {
  131. _URLLabel = [[UILabel alloc] init];
  132. _URLLabel.font = [UIFont systemFontOfSize:14];
  133. _URLLabel.textColor = UIColorFromRGB(0x999999);
  134. _URLLabel.numberOfLines = 1;
  135. }
  136. return _URLLabel;
  137. }
  138. -(UILabel *)titleLabel {
  139. if (_titleLabel == nil) {
  140. _titleLabel = [[UILabel alloc] init];
  141. _titleLabel.font = [UIFont systemFontOfSize:13];
  142. _titleLabel.textColor = UIColorFromRGB(0x666666);
  143. _titleLabel.numberOfLines = 2;
  144. }
  145. return _titleLabel;
  146. }
  147. -(UIImageView *)productImageView {
  148. if (_productImageView == nil) {
  149. _productImageView = [[UIImageView alloc] init];
  150. _productImageView.contentMode = UIViewContentModeScaleAspectFit;
  151. }
  152. return _productImageView;
  153. }
  154. -(UIImageView *)brandImageView {
  155. if (_brandImageView == nil) {
  156. _brandImageView = [[UIImageView alloc] init];
  157. }
  158. return _brandImageView;
  159. }
  160. -(FKInvalidView *)invalidView {
  161. if (_invalidView == nil) {
  162. _invalidView = [[FKInvalidView alloc] init];
  163. }
  164. return _invalidView;
  165. }
  166. @end