No Description

FKBasketBottomView.m 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // FKBasketBottomView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/2/19.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBasketBottomView.h"
  9. @interface FKBasketBottomView ()
  10. @property (nonatomic, strong) UILabel *allCountLabel;
  11. @property (nonatomic, strong) UILabel *postageLabel;
  12. @property (nonatomic, strong) MASConstraint *postageWidthConst;
  13. @property (nonatomic, strong) MASConstraint *totalFeeWidthConst;
  14. @end
  15. @implementation FKBasketBottomView
  16. - (instancetype)initWithFrame:(CGRect)frame{
  17. if (self = [super initWithFrame:frame]) {
  18. [self addAllSubviews];
  19. self.backgroundColor = [UIColor whiteColor];
  20. }
  21. return self;
  22. }
  23. - (void)addAllSubviews{
  24. UIView *topLine = ({
  25. UIView *view = [[UIView alloc]init];
  26. view.backgroundColor = UIColorFromRGB(0xe5e5e5);
  27. view;
  28. });
  29. UILabel *allSelectLabel = ({
  30. UILabel *label = [[UILabel alloc]init];
  31. label.text = @"全选";
  32. label.font = [UIFont systemFontOfSize:15];
  33. label.textColor = UIColorFromRGB(0x333333);
  34. label;
  35. });
  36. [self addSubview:self.selectBtn];
  37. [self addSubview:self.totalFeeLabel];
  38. [self addSubview:self.commitBtn];
  39. [self addSubview:topLine];
  40. [self addSubview:self.allCountLabel];
  41. [self addSubview:self.postageLabel];
  42. [self addSubview:allSelectLabel];
  43. [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.top.right.equalTo(self);
  45. make.height.mas_equalTo(0.5);
  46. }];
  47. [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.equalTo(self);
  49. make.centerY.equalTo(self);
  50. make.size.mas_equalTo(CGSizeMake(48, 45));
  51. }];
  52. [allSelectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(self.selectBtn.mas_right).offset(- 5);
  54. make.centerY.equalTo(self);
  55. }];
  56. [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.right.bottom.equalTo(self);
  58. make.width.mas_equalTo(100);
  59. }];
  60. [self.totalFeeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.equalTo(self.postageLabel).offset(- 2);
  62. make.bottom.equalTo(self.mas_centerY);
  63. self.totalFeeWidthConst = make.width.mas_equalTo(80);
  64. }];
  65. [self.postageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.right.equalTo(self.commitBtn.mas_left);
  67. make.top.equalTo(self.mas_centerY).offset(2);
  68. self.postageWidthConst = make.width.mas_equalTo(80);
  69. }];
  70. [self.allCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.right.equalTo(self.totalFeeLabel.mas_left).offset(- 5);
  72. make.centerY.equalTo(self);
  73. }];
  74. }
  75. - (void)refreshWithEdit:(BOOL)edit
  76. quality:(NSUInteger)quality
  77. totalFee:(CGFloat)totalFee
  78. postageFee:(CGFloat)postageFee
  79. select:(BOOL)select{
  80. self.selectBtn.selected = select;
  81. if (edit) {
  82. self.allCountLabel.hidden = YES;
  83. self.totalFeeLabel.hidden = YES;
  84. self.postageLabel.hidden = YES;
  85. }else{
  86. self.allCountLabel.hidden = NO;
  87. self.totalFeeLabel.hidden = NO;
  88. self.postageLabel.hidden = NO;
  89. }
  90. [self refreshTotalFee:totalFee postage:postageFee];
  91. UIColor *bgColor = UIColorFromRGB(0xff6362);
  92. NSString *commitTitle = @"结算";
  93. BOOL commitValid = YES;
  94. if (edit) {
  95. commitTitle = @"删除";
  96. }
  97. if (quality == 0){
  98. bgColor = UIColorFromRGB(0xcccccc);
  99. commitValid = NO;
  100. }else if (quality > 0){
  101. commitTitle = [commitTitle stringByAppendingString:[NSString stringWithFormat:@"(%lu)", (unsigned long)quality]];
  102. }
  103. [self.commitBtn setTitle:commitTitle forState:UIControlStateNormal];
  104. [self.commitBtn setBackgroundColor:bgColor];
  105. self.commitBtn.userInteractionEnabled = commitValid;
  106. }
  107. - (void)refreshTotalFee:(CGFloat)totalFee postage:(CGFloat)postage{
  108. self.totalFeeLabel.text = [NSString stringWithFormat:@"¥%.2f", totalFee];
  109. self.postageLabel.text = [NSString stringWithFormat:@"(含运费¥%.2f)", postage];
  110. CGFloat totalFeeW = [FLStringHelper rectOfString:self.totalFeeLabel.text
  111. font:self.totalFeeLabel.font
  112. width:NSIntegerMax].size.width;
  113. CGFloat postageFeeW = [FLStringHelper rectOfString:self.postageLabel.text
  114. font:self.postageLabel.font
  115. width:NSIntegerMax].size.width;
  116. CGFloat maxW = totalFeeW;
  117. if (postageFeeW > totalFeeW) maxW = postageFeeW;
  118. self.postageWidthConst.mas_equalTo(maxW + 15);
  119. self.totalFeeWidthConst.mas_equalTo(maxW + 15);
  120. [self setNeedsLayout];
  121. [self layoutIfNeeded];
  122. }
  123. #pragma mark - property
  124. - (UIButton *)selectBtn{
  125. if (_selectBtn == nil) {
  126. _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  127. [_selectBtn setImage:[UIImage imageNamed:@"basket_unSelect"] forState:UIControlStateNormal];
  128. [_selectBtn setImage:[UIImage imageNamed:@"basket_selected"] forState:UIControlStateSelected];
  129. }
  130. return _selectBtn;
  131. }
  132. - (UILabel *)totalFeeLabel{
  133. if (_totalFeeLabel == nil) {
  134. _totalFeeLabel = [[UILabel alloc]init];
  135. _totalFeeLabel.textColor = UIColorFromRGB(0xf85a5a);
  136. _totalFeeLabel.font = [UIFont boldSystemFontOfSize:14];
  137. _totalFeeLabel.text = @"¥0.00";
  138. [_totalFeeLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  139. }
  140. return _totalFeeLabel;
  141. }
  142. - (UILabel *)allCountLabel{
  143. if (_allCountLabel == nil) {
  144. _allCountLabel = [[UILabel alloc]init];
  145. _allCountLabel.text = @"合计:";
  146. _allCountLabel.font = [UIFont systemFontOfSize:14];
  147. _allCountLabel.textColor = UIColorFromRGB(0x333333);
  148. }
  149. return _allCountLabel;
  150. }
  151. - (UILabel *)postageLabel{
  152. if (_postageLabel == nil) {
  153. _postageLabel = [[UILabel alloc]init];
  154. _postageLabel.font = [UIFont systemFontOfSize:11];
  155. _postageLabel.textColor = UIColorFromRGB(0x999999);
  156. }
  157. return _postageLabel;
  158. }
  159. - (UIButton *)commitBtn{
  160. if (_commitBtn == nil) {
  161. _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  162. [_commitBtn setTitle:@"结 算" forState:UIControlStateNormal];
  163. [_commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  164. _commitBtn.backgroundColor = UIColorFromRGB(0xcccccc);
  165. _commitBtn.userInteractionEnabled = NO;
  166. }
  167. return _commitBtn;
  168. }
  169. @end