Keine Beschreibung

DetailPriceExplainCell.m 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. //
  2. // DetailPriceExplainCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/7/20.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "DetailPriceExplainCell.h"
  9. @interface DetailPriceExplainCell ()
  10. @property (nonatomic, strong) UIView *cutLine;
  11. @property (nonatomic, strong) UIImageView *priceExplainView;
  12. @property (nonatomic, strong) NSLayoutConstraint *cutLineWidthConst;
  13. @property (nonatomic, strong) UILabel *vipPriceLabel;
  14. @property (nonatomic, strong) UILabel *referPriceTipLabel;
  15. @property (nonatomic, strong) UILabel *referPriceLabel;
  16. @property (nonatomic, strong) UILabel *collectLabel;
  17. @end
  18. @implementation DetailPriceExplainCell
  19. @synthesize priceLabel = _priceLabel;
  20. @synthesize helpBtn = _helpBtn;
  21. @synthesize referPriceLabel = _referPriceLabel;
  22. @synthesize countTimeLabel = _countTimeLabel;
  23. @synthesize collectBtn = _collectBtn;
  24. @synthesize cutLineWidthConst = _cutLineWidthConst;
  25. @synthesize cutLine = _cutLine;
  26. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  27. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  28. if (self) {
  29. [self initialize];
  30. self.selectionStyle = UITableViewCellSelectionStyleNone;
  31. }
  32. return self;
  33. }
  34. #pragma mark -
  35. - (void)setVipPrice:(NSString *)vipPrice {
  36. if (vipPrice.length > 0) {
  37. self.vipPriceLabel.hidden = NO;
  38. self.vipPriceLabel.text = [NSString stringWithFormat:@"VIP价格:%@", vipPrice];
  39. } else {
  40. self.vipPriceLabel.hidden = YES;
  41. [self.referPriceTipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  42. make.left.equalTo(self.contentView).offset(15);
  43. make.centerY.equalTo(self.vipPriceLabel);
  44. }];
  45. }
  46. }
  47. #pragma method
  48. - (void)initialize{
  49. [self.contentView addSubview:self.priceLabel];
  50. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.equalTo(self.contentView).offset(12);
  52. make.top.equalTo(self.contentView).offset(14);
  53. make.width.greaterThanOrEqualTo(@20);
  54. }];
  55. [self.contentView addSubview:self.helpBtn];
  56. [self.helpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.left.equalTo(self.priceLabel.mas_right).offset(7);
  58. make.centerY.equalTo(self.priceLabel);
  59. }];
  60. [self.contentView addSubview:self.countTimeLabel];
  61. [self.countTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.equalTo(self.helpBtn.mas_right).offset(7);
  63. make.centerY.equalTo(self.helpBtn);
  64. make.height.mas_equalTo(16);
  65. }];
  66. [self.contentView addSubview:self.priceExplainView];
  67. [self.priceExplainView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.centerX.equalTo(self.helpBtn).offset(10);
  69. make.top.equalTo(self.priceLabel.mas_bottom);
  70. make.height.equalTo(@0);
  71. }];
  72. [self.contentView addSubview:self.vipPriceLabel];
  73. [self.vipPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.equalTo(self.contentView).offset(15);
  75. make.top.equalTo(self.priceExplainView.mas_bottom).offset(-12);
  76. make.bottom.equalTo(self.contentView);
  77. }];
  78. [self.contentView addSubview:self.referPriceTipLabel];
  79. [self.referPriceTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.equalTo(self.vipPriceLabel.mas_right).offset(15);
  81. make.centerY.equalTo(self.vipPriceLabel);
  82. }];
  83. [self.contentView addSubview:self.referPriceLabel];
  84. [self.referPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(self.referPriceTipLabel.mas_right).offset(2);
  86. make.centerY.equalTo(self.referPriceTipLabel);
  87. }];
  88. [self.contentView addSubview:self.collectBtn];
  89. [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.equalTo(self.contentView).offset(10);
  91. make.right.equalTo(self.contentView).offset(- 20);
  92. make.size.mas_equalTo(CGSizeMake(40, 40));
  93. }];
  94. [self.contentView addSubview:self.collectLabel];
  95. [self.collectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.top.equalTo(self.collectBtn.mas_bottom).offset(- 3);
  97. make.centerX.equalTo(self.collectBtn);
  98. }];
  99. [self.contentView addSubview:self.cutLine];
  100. [self.cutLine mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.center.equalTo(self.referPriceLabel);
  102. make.height.equalTo(@0.5);
  103. make.width.equalTo(@0);
  104. }];
  105. }
  106. #pragma mark - DetailCellProtocol
  107. - (void)configWithDetailViewModel:(PindanDetailViewModel *)viewModel indexPath:(NSIndexPath *)indexPath{
  108. if (![viewModel isKindOfClass:[PindanDetailViewModel class]]) return;
  109. self.priceLabel.attributedText = [viewModel totalPriceAttributedString];
  110. self.referPrice = [FLStringHelper convertFenStringToYuanValue:[viewModel referPrice]];
  111. self.collectBtn.selected = [viewModel isFavorite];
  112. [self setVipPrice:[viewModel vipPrice]];
  113. if (viewModel.pindanState == kPindanStateWaitBegin) {
  114. [self resetTimeStrWithInterval:[viewModel timeInterval] isBegin:NO];
  115. }else if ([viewModel isProductStateSaleDone]) {
  116. self.priceLabel.textColor = UIColorFromRGB(0xcccccc);
  117. self.countTimeLabel.text = @"拼单已抢光";
  118. } else if ([viewModel isProductStateEnd]){
  119. self.priceLabel.textColor = UIColorFromRGB(0xcccccc);
  120. self.countTimeLabel.text = @"拼单已结束";
  121. } else{
  122. [self resetTimeStrWithInterval:[viewModel timeInterval] isBegin:YES];
  123. }
  124. }
  125. - (void)resetTimeStrWithInterval:(NSTimeInterval)timeCount isBegin:(BOOL)isBegin{
  126. if (isBegin) {
  127. self.countTimeLabel.text = [NSString stringWithFormat:@"剩余%@", [FLStringHelper convertTimeIntervalToCountString:timeCount]];
  128. }else{
  129. NSString *timeStr = [FLStringHelper convertTimeIntervalToCountString:timeCount];
  130. NSString *lastStr = @" 后开启";
  131. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@", timeStr, lastStr]];
  132. [attr addAttribute:NSForegroundColorAttributeName value:APP_BUTTON_COLOR range:NSMakeRange(timeStr.length, lastStr.length)];
  133. self.countTimeLabel.attributedText = attr;
  134. }
  135. }
  136. #pragma mark - event response
  137. - (void)helpBtnClick:(UIButton *)sender {
  138. _showHelpeView = !_showHelpeView;
  139. [self changePriceExplainViewLayout];
  140. if ([self.delegate respondsToSelector:@selector(priceDetailCell:showPriceExplain:)]) {
  141. [self.delegate priceDetailCell:self showPriceExplain:_showHelpeView];
  142. }
  143. }
  144. - (void)changePriceExplainViewLayout {
  145. __block typeof(_showHelpeView) block_showHelper = _showHelpeView;
  146. [self.priceExplainView mas_remakeConstraints:^(MASConstraintMaker *make) {
  147. make.centerX.equalTo(self.helpBtn).offset(45);
  148. make.top.equalTo(self.priceLabel.mas_bottom).offset(2);
  149. if (!block_showHelper) {
  150. make.height.equalTo(@0);
  151. }
  152. }];
  153. }
  154. #pragma mark - getter && setter
  155. - (UILabel *)priceLabel {
  156. if (_priceLabel == nil) {
  157. _priceLabel = [[UILabel alloc]init];
  158. _priceLabel.backgroundColor = [UIColor clearColor];
  159. _priceLabel.textColor = UIColorFromRGB(0x333333);
  160. _priceLabel.font = [UIFont boldSystemFontOfSize:18];
  161. _priceLabel.textAlignment = NSTextAlignmentCenter;
  162. [_priceLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
  163. }
  164. return _priceLabel;
  165. }
  166. - (UIButton *)helpBtn {
  167. if (_helpBtn == nil) {
  168. _helpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  169. [_helpBtn setImage:[UIImage imageNamed:@"detail_info"] forState:UIControlStateNormal];
  170. [_helpBtn addTarget:self action:@selector(helpBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  171. }
  172. return _helpBtn;
  173. }
  174. - (UILabel *)countTimeLabel {
  175. if (_countTimeLabel == nil) {
  176. _countTimeLabel = [[UILabel alloc]init];
  177. _countTimeLabel.backgroundColor = [UIColor clearColor];
  178. _countTimeLabel.textColor = UIColorFromRGB(0x666666);
  179. _countTimeLabel.font = [UIFont systemFontOfSize:13];
  180. _countTimeLabel.textAlignment = NSTextAlignmentCenter;
  181. }
  182. return _countTimeLabel;
  183. }
  184. - (UIImageView *)priceExplainView {
  185. if (_priceExplainView == nil) {
  186. _priceExplainView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"details_body_explanation1_n"]];
  187. [_priceExplainView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
  188. }
  189. return _priceExplainView;
  190. }
  191. - (UILabel *)vipPriceLabel {
  192. if (_vipPriceLabel == nil) {
  193. _vipPriceLabel = [[UILabel alloc]init];
  194. _vipPriceLabel.backgroundColor = [UIColor clearColor];
  195. _vipPriceLabel.textColor = UIColorFromRGB(0x999999);
  196. _vipPriceLabel.font = [UIFont systemFontOfSize:11];
  197. _vipPriceLabel.textAlignment = NSTextAlignmentCenter;
  198. _vipPriceLabel.text = @"¥-.--";
  199. }
  200. return _vipPriceLabel;
  201. }
  202. - (UILabel *)referPriceLabel {
  203. if (_referPriceLabel == nil) {
  204. _referPriceLabel = [[UILabel alloc]init];
  205. _referPriceLabel.backgroundColor = [UIColor clearColor];
  206. _referPriceLabel.textColor = UIColorFromRGB(0x999999);
  207. _referPriceLabel.font = [UIFont systemFontOfSize:11];
  208. _referPriceLabel.textAlignment = NSTextAlignmentCenter;
  209. }
  210. return _referPriceLabel;
  211. }
  212. - (UIButton *)collectBtn {
  213. if (_collectBtn == nil) {
  214. _collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  215. [_collectBtn setImage:[UIImage imageNamed:@"detail_collect_n"] forState:UIControlStateNormal];
  216. [_collectBtn setImage:[UIImage imageNamed:@"collectHeartSelected"] forState:UIControlStateSelected];
  217. _collectBtn.alpha = 0.8;
  218. }
  219. return _collectBtn;
  220. }
  221. - (UIView *)cutLine {
  222. if (_cutLine == nil) {
  223. _cutLine = [[UIView alloc]init];
  224. _cutLine.backgroundColor = UIColorFromRGB(0x999999);
  225. }
  226. return _cutLine;
  227. }
  228. - (NSLayoutConstraint *)cutLineWidthConst {
  229. if (_cutLineWidthConst == nil) {
  230. for (NSLayoutConstraint *constraint in self.cutLine.constraints) {
  231. if (constraint.firstItem == self.cutLine && constraint.firstAttribute == NSLayoutAttributeWidth) {
  232. _cutLineWidthConst = constraint;
  233. break;
  234. }
  235. }
  236. }
  237. return _cutLineWidthConst;
  238. }
  239. - (void)setShowHelpeView:(BOOL)showHelpeView {
  240. _showHelpeView = showHelpeView;
  241. [self changePriceExplainViewLayout];
  242. }
  243. - (UILabel *)referPriceTipLabel {
  244. if (_referPriceTipLabel == nil) {
  245. _referPriceTipLabel = [[UILabel alloc]init];
  246. _referPriceTipLabel.text = @"国内价:";
  247. _referPriceTipLabel.textColor = UIColorFromRGB(0x999999);
  248. _referPriceTipLabel.font = [UIFont systemFontOfSize:11];
  249. }
  250. return _referPriceTipLabel;
  251. }
  252. - (UILabel *)collectLabel {
  253. if (_collectLabel == nil) {
  254. _collectLabel = [[UILabel alloc]init];
  255. _collectLabel.text = @"收藏";
  256. _collectLabel.font = [UIFont systemFontOfSize:12];
  257. _collectLabel.textColor = UIColorFromRGB(0x999999);
  258. }
  259. return _collectLabel;
  260. }
  261. - (void)setReferPrice:(CGFloat)referPrice {
  262. self.cutLine.hidden = YES;
  263. if (referPrice <= 0) {
  264. self.referPriceTipLabel.text = @"";
  265. self.referPriceLabel.text = @"国内无售";
  266. } else {
  267. self.cutLine.hidden = NO;
  268. self.referPriceLabel.text = [NSString stringWithFormat:@"¥%.2f",referPrice];
  269. CGRect stringRect = [FLStringHelper rectOfString:self.referPriceLabel.text font:self.referPriceLabel.font height:CGFLOAT_MAX];
  270. self.cutLineWidthConst.constant = CGRectGetWidth(stringRect);
  271. }
  272. }
  273. @end