Nessuna descrizione

FKProSourceCell.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // FKProSourceCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/15.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProSourceCell.h"
  9. #import "FKProDetailViewModel.h"
  10. @interface FKProSourceCell ()
  11. @property (nonatomic, strong) UIImageView *flagImgView;
  12. @property (nonatomic, strong) UILabel *sourceLabel;
  13. @property (nonatomic, strong) UILabel *advLabel;
  14. @property (nonatomic, strong) UILabel *authenLabel; // 第三方认证
  15. @property (nonatomic, strong) UILabel *countLabel;
  16. @property (nonatomic, strong) UIImageView *rightArrow;
  17. @end
  18. @implementation FKProSourceCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  20. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  21. [self addAllSubviews];
  22. self.selectionStyle = UITableViewCellSelectionStyleNone;
  23. self.contentView.backgroundColor = [UIColor whiteColor];
  24. }
  25. return self;
  26. }
  27. - (void)addAllSubviews{
  28. [self.contentView addSubview:self.flagImgView];
  29. [self.contentView addSubview:self.sourceLabel];
  30. [self.contentView addSubview:self.authenLabel];
  31. [self.contentView addSubview:self.countLabel];
  32. [self.contentView addSubview:self.rightArrow];
  33. [self.contentView addSubview:self.advLabel];
  34. [self.flagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.equalTo(self.contentView).offset(15);
  36. make.top.equalTo(self.contentView).offset(14);
  37. make.size.mas_equalTo(CGSizeMake(20, 13));
  38. }];
  39. [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.equalTo(self.flagImgView.mas_right).offset(5);
  41. make.centerY.equalTo(self.flagImgView);
  42. }];
  43. [self.authenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.equalTo(self.sourceLabel.mas_right).offset(5);
  45. make.centerY.equalTo(self.sourceLabel);
  46. make.size.mas_equalTo(CGSizeMake(40, 13));
  47. }];
  48. [self.advLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.equalTo(self.sourceLabel);
  50. make.top.equalTo(self.sourceLabel.mas_bottom).offset(6);
  51. }];
  52. [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.right.equalTo(self.contentView).offset(-15);
  54. make.centerY.equalTo(self.contentView);
  55. }];
  56. [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.right.equalTo(self.rightArrow.mas_left).offset(-4);
  58. make.centerY.equalTo(self.rightArrow);
  59. }];
  60. }
  61. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  62. if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
  63. FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
  64. [self.flagImgView setImageWithURL:detailModel.dataItem.countryInfoItem.countryPicUrl cdnWidth:20];
  65. self.sourceLabel.text = detailModel.dataItem.supplier.name;
  66. NSString *postageRule = detailModel.dataItem.supplier.postageRule;
  67. if ([FLStringHelper isValidString:postageRule]) {
  68. self.advLabel.hidden = NO;
  69. self.advLabel.text = [NSString stringWithFormat:@"(%@)", postageRule];
  70. } else {
  71. self.advLabel.hidden = YES;
  72. }
  73. self.authenLabel.hidden = [detailModel.dataItem.supplier isAuthenedProduct] ? NO : YES;
  74. NSString *validCount = detailModel.dataItem.supplier.validProdCount;
  75. if (validCount.integerValue >= 10) {
  76. self.countLabel.hidden = NO;
  77. NSString *text = @"";
  78. if (validCount.integerValue < 10000) {
  79. text = validCount;
  80. } else {
  81. text = [NSString stringWithFormat:@"%ldw+", validCount.integerValue/10000];
  82. }
  83. self.countLabel.text = [NSString stringWithFormat:@"%@件", text];
  84. } else {
  85. self.countLabel.hidden = YES;
  86. }
  87. }
  88. }
  89. #pragma mark - property
  90. - (UIImageView *)flagImgView{
  91. if (_flagImgView == nil) {
  92. _flagImgView = [[UIImageView alloc]init];
  93. _flagImgView.contentMode = UIViewContentModeScaleAspectFit;
  94. }
  95. return _flagImgView;
  96. }
  97. - (UILabel *)sourceLabel{
  98. if (_sourceLabel == nil) {
  99. _sourceLabel = [[UILabel alloc]init];
  100. _sourceLabel.textColor = UIColorFromRGB(0x333333);
  101. _sourceLabel.font = [UIFont systemFontOfSize:14];
  102. }
  103. return _sourceLabel;
  104. }
  105. - (UIImageView *)rightArrow{
  106. if (_rightArrow == nil) {
  107. _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more_right_arrow"]];
  108. }
  109. return _rightArrow;
  110. }
  111. - (UILabel *)advLabel{
  112. if (_advLabel == nil) {
  113. _advLabel = [[UILabel alloc]init];
  114. _advLabel.textColor = UIColorFromRGB(0x999999);
  115. _advLabel.font = [UIFont systemFontOfSize:12];
  116. _advLabel.numberOfLines = 1;
  117. _advLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  118. }
  119. return _advLabel;
  120. }
  121. - (UILabel *)authenLabel{
  122. if (_authenLabel == nil) {
  123. _authenLabel = [[UILabel alloc]init];
  124. _authenLabel.font = [UIFont systemFontOfSize:9];
  125. _authenLabel.textColor = UIColorFromRGB(0xF7AC22);
  126. _authenLabel.text = @"认证采购";
  127. _authenLabel.textAlignment = NSTextAlignmentCenter;
  128. _authenLabel.layer.cornerRadius = 3.0;
  129. _authenLabel.layer.borderWidth = 0.5;
  130. _authenLabel.layer.borderColor = UIColorFromRGB(0xF7AC22).CGColor;
  131. }
  132. return _authenLabel;
  133. }
  134. - (UILabel *)countLabel {
  135. if (_countLabel == nil) {
  136. _countLabel = [[UILabel alloc]init];
  137. _countLabel.textAlignment = NSTextAlignmentRight;
  138. _countLabel.textColor = UIColorFromRGB(0x999999);
  139. _countLabel.font = [UIFont systemFontOfSize:13];
  140. }
  141. return _countLabel;
  142. }
  143. @end