123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //
- // FKBasketBottomView.m
- // FirstLink
- //
- // Created by jack on 16/2/19.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBasketBottomView.h"
- @interface FKBasketBottomView ()
- @property (nonatomic, strong) UILabel *allCountLabel;
- @property (nonatomic, strong) UILabel *postageLabel;
- @property (nonatomic, strong) MASConstraint *postageWidthConst;
- @property (nonatomic, strong) MASConstraint *totalFeeWidthConst;
- @end
- @implementation FKBasketBottomView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addAllSubviews];
- self.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)addAllSubviews{
-
- UIView *topLine = ({
- UIView *view = [[UIView alloc]init];
- view.backgroundColor = UIColorFromRGB(0xe5e5e5);
- view;
- });
-
- UILabel *allSelectLabel = ({
- UILabel *label = [[UILabel alloc]init];
- label.text = @"全选";
- label.font = [UIFont systemFontOfSize:15];
- label.textColor = UIColorFromRGB(0x333333);
- label;
- });
-
- [self addSubview:self.selectBtn];
- [self addSubview:self.totalFeeLabel];
- [self addSubview:self.commitBtn];
-
- [self addSubview:topLine];
- [self addSubview:self.allCountLabel];
- [self addSubview:self.postageLabel];
- [self addSubview:allSelectLabel];
-
- [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.equalTo(self);
- make.height.mas_equalTo(0.5);
- }];
-
- [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self);
- make.centerY.equalTo(self);
- make.size.mas_equalTo(CGSizeMake(48, 45));
- }];
-
- [allSelectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.selectBtn.mas_right).offset(- 5);
- make.centerY.equalTo(self);
- }];
-
- [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.right.bottom.equalTo(self);
- make.width.mas_equalTo(100);
- }];
-
- [self.totalFeeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.postageLabel).offset(- 2);
- make.bottom.equalTo(self.mas_centerY);
- self.totalFeeWidthConst = make.width.mas_equalTo(80);
- }];
-
- [self.postageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.commitBtn.mas_left);
- make.top.equalTo(self.mas_centerY).offset(2);
- self.postageWidthConst = make.width.mas_equalTo(80);
- }];
-
- [self.allCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.totalFeeLabel.mas_left).offset(- 5);
- make.centerY.equalTo(self);
- }];
-
-
- }
- - (void)refreshWithEdit:(BOOL)edit
- quality:(NSUInteger)quality
- totalFee:(CGFloat)totalFee
- postageFee:(CGFloat)postageFee
- select:(BOOL)select{
-
- self.selectBtn.selected = select;
-
- if (edit) {
- self.allCountLabel.hidden = YES;
- self.totalFeeLabel.hidden = YES;
- self.postageLabel.hidden = YES;
- }else{
- self.allCountLabel.hidden = NO;
- self.totalFeeLabel.hidden = NO;
- self.postageLabel.hidden = NO;
- }
- [self refreshTotalFee:totalFee postage:postageFee];
-
- UIColor *bgColor = UIColorFromRGB(0xff6362);
- NSString *commitTitle = @"结算";
- BOOL commitValid = YES;
-
- if (edit) {
- commitTitle = @"删除";
- }
-
- if (quality == 0){
- bgColor = UIColorFromRGB(0xcccccc);
- commitValid = NO;
- }else if (quality > 0){
- commitTitle = [commitTitle stringByAppendingString:[NSString stringWithFormat:@"(%lu)", (unsigned long)quality]];
- }
-
- [self.commitBtn setTitle:commitTitle forState:UIControlStateNormal];
- [self.commitBtn setBackgroundColor:bgColor];
- self.commitBtn.userInteractionEnabled = commitValid;
- }
- - (void)refreshTotalFee:(CGFloat)totalFee postage:(CGFloat)postage{
-
- self.totalFeeLabel.text = [NSString stringWithFormat:@"¥%.2f", totalFee];
- self.postageLabel.text = [NSString stringWithFormat:@"(含运费¥%.2f)", postage];
-
- CGFloat totalFeeW = [FLStringHelper rectOfString:self.totalFeeLabel.text
- font:self.totalFeeLabel.font
- width:NSIntegerMax].size.width;
-
- CGFloat postageFeeW = [FLStringHelper rectOfString:self.postageLabel.text
- font:self.postageLabel.font
- width:NSIntegerMax].size.width;
-
- CGFloat maxW = totalFeeW;
- if (postageFeeW > totalFeeW) maxW = postageFeeW;
- self.postageWidthConst.mas_equalTo(maxW + 15);
- self.totalFeeWidthConst.mas_equalTo(maxW + 15);
-
- [self setNeedsLayout];
- [self layoutIfNeeded];
- }
- #pragma mark - property
- - (UIButton *)selectBtn{
- if (_selectBtn == nil) {
- _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_selectBtn setImage:[UIImage imageNamed:@"basket_unSelect"] forState:UIControlStateNormal];
- [_selectBtn setImage:[UIImage imageNamed:@"basket_selected"] forState:UIControlStateSelected];
- }
- return _selectBtn;
- }
- - (UILabel *)totalFeeLabel{
- if (_totalFeeLabel == nil) {
- _totalFeeLabel = [[UILabel alloc]init];
- _totalFeeLabel.textColor = UIColorFromRGB(0xf85a5a);
- _totalFeeLabel.font = [UIFont boldSystemFontOfSize:14];
- _totalFeeLabel.text = @"¥0.00";
- [_totalFeeLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
- }
- return _totalFeeLabel;
- }
- - (UILabel *)allCountLabel{
- if (_allCountLabel == nil) {
- _allCountLabel = [[UILabel alloc]init];
- _allCountLabel.text = @"合计:";
- _allCountLabel.font = [UIFont systemFontOfSize:14];
- _allCountLabel.textColor = UIColorFromRGB(0x333333);
- }
- return _allCountLabel;
- }
- - (UILabel *)postageLabel{
- if (_postageLabel == nil) {
- _postageLabel = [[UILabel alloc]init];
- _postageLabel.font = [UIFont systemFontOfSize:11];
- _postageLabel.textColor = UIColorFromRGB(0x999999);
- }
- return _postageLabel;
- }
- - (UIButton *)commitBtn{
- if (_commitBtn == nil) {
- _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_commitBtn setTitle:@"结 算" forState:UIControlStateNormal];
- [_commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _commitBtn.backgroundColor = UIColorFromRGB(0xcccccc);
- _commitBtn.userInteractionEnabled = NO;
- }
- return _commitBtn;
- }
- @end
|