123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- //
- // FKBasketSiteHeaderView.m
- // FirstLink
- //
- // Created by jack on 16/2/19.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBasketSiteHeaderView.h"
- #import "FKBasketPriceView.h"
- #import "FKBasketViewModel.h"
- @interface FKBasketSiteHeaderView ()
- @property (nonatomic, strong) UIView *containerView;
- @property (nonatomic, strong) UIView *bottomLine;
- @property (nonatomic, strong) UIButton *moreActionBtn;
- @property (nonatomic, strong) UIImageView *flagImgView;
- @property (nonatomic, strong) UILabel *siteNameLabel;
- @property (nonatomic, strong) UILabel *advLabel;
- @property (nonatomic, strong) UILabel *authenLabel; // 认证采购
- @property (nonatomic, strong) UILabel *postageDescLabel;
- @property (nonatomic, strong) FKBasketPriceView *priceView;
- @property (nonatomic, strong) FKBasketUnitItem *unitItem;
- @end
- @implementation FKBasketSiteHeaderView
- - (instancetype)init {
- if (self = [super init]) {
- self.backgroundColor = [UIColor whiteColor];
- [self addAllSubviews];
- }
- return self;
- }
- - (void)addAllSubviews {
- UIButton *seeMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [seeMoreBtn addTarget:self action:@selector(clickMoreAction:) forControlEvents:UIControlEventTouchUpInside];
-
- [self addSubview:self.containerView];
- [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
-
- [self.containerView addSubview:self.selectBtn];
- [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.containerView);
- make.centerY.equalTo(self.containerView);
- make.width.mas_equalTo(48);
- make.height.mas_equalTo(45);
- }];
-
- [self.containerView addSubview:self.flagImgView];
- [self.flagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.selectBtn.mas_right);
- make.top.equalTo(self.containerView).offset(15);
- make.size.mas_equalTo(CGSizeMake(20, 13));
- }];
-
- [self.containerView addSubview:self.siteNameLabel];
- [self.siteNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.flagImgView.mas_right).offset(10);
- make.centerY.equalTo(self.flagImgView);
- }];
-
- [self.containerView addSubview:self.authenLabel];
- [self.authenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.siteNameLabel.mas_right).offset(10);
- make.centerY.equalTo(self.siteNameLabel);
- make.size.mas_equalTo(CGSizeMake(40, 13));
- }];
-
-
- [self.containerView addSubview:self.moreActionBtn];
- [self.moreActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.containerView);
- make.centerX.equalTo(self.containerView.mas_right).offset(- 20);
- make.size.mas_equalTo(CGSizeMake(60, 40));
- }];
-
- [self.containerView addSubview:self.advLabel];
- [self.advLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.flagImgView).offset(- 7);
- make.top.equalTo(self.flagImgView.mas_bottom).offset(5);
- make.width.mas_equalTo(UISCREENWIDTH - 15 - 48);
- }];
-
- CGFloat descWidth = UISCREENWIDTH - 100;
- [self.containerView addSubview:self.postageDescLabel];
- [self.postageDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.flagImgView);
- make.top.equalTo(self.advLabel.mas_bottom).offset(5);
- make.width.mas_equalTo(descWidth);
- }];
-
- [self.containerView addSubview:seeMoreBtn];
- [seeMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.bottom.equalTo(self.containerView);
- make.width.mas_equalTo(UISCREENWIDTH / 2.0f);
- }];
-
- [self addSubview:self.bottomLine];
- [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self);
- make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
- }];
-
- self.priceView.hidden = YES;
- [self addSubview:self.priceView];
- }
- - (void)configWithUnitItem:(FKBasketUnitItem *)unitItem viewModel:(FKBasketViewModel *)viewModel {
- if ([unitItem isKindOfClass:[FKBasketUnitItem class]]){
-
- self.selectBtn.hidden = ([unitItem hasCanBeBuyProduct] ? NO : YES);
- if (unitItem.beingEdit) self.selectBtn.hidden = NO;
- self.selectBtn.selected = unitItem.allSelected;
-
- self.flagImgView.image = nil;
- [self.flagImgView setImageWithURL:unitItem.countryInfo.countryPicUrl placeholderImage:nil width:20 height:13];
-
- self.siteNameLabel.text = unitItem.supplyInfo.supplyName;
-
- NSString *shipTypeText = @" ";
- if ([unitItem.supplyInfo shipTypeText]) shipTypeText = [unitItem.supplyInfo shipTypeText];
- if ([unitItem.supplyInfo.postageRule isKindOfClass:[NSString class]]){
- shipTypeText = [shipTypeText stringByAppendingString:unitItem.supplyInfo.postageRule];
- }
- self.advLabel.text = shipTypeText;
-
- BOOL postageDescHidden = YES;
- if ([unitItem getPostageFreeAdv]) {
- postageDescHidden = NO;
- self.postageDescLabel.text = [unitItem getPostageFreeAdv];
- }
-
- self.postageDescLabel.hidden = postageDescHidden;
- self.authenLabel.hidden = ([unitItem.supplyInfo isAuthenedProduct] ? NO : YES);
-
- if ([unitItem getSelectedWeight]) {
- self.priceView.hidden = NO;
- [self.priceView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self);
- make.height.mas_equalTo([FKBasketSiteHeaderView priceViewHeight]);
- }];
-
- [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.equalTo(self);
- make.bottom.equalTo(self.priceView.mas_top);
- }];
-
- [self bringSubviewToFront:self.bottomLine];
- [self.bottomLine mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self);
- make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
- }];
-
- self.priceView.weightLabel.text = [NSString stringWithFormat:@"重量:%ldg", (unsigned long)[unitItem getSelectedWeight]];
- self.priceView.postageLabel.text = [NSString stringWithFormat:@"运费:¥%.2f", [unitItem getMinPostageForUserLevel:viewModel.userLevel]];
- } else {
- self.priceView.hidden = YES;
- [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
-
- [self bringSubviewToFront:self.bottomLine];
- [self.bottomLine mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self);
- make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
- }];
- }
- }
- }
- + (CGFloat)priceViewHeight {
- return 25;
- }
- #pragma mark - action
- - (void)clickMoreAction:(UIButton *)sender{
- if (self.didSeeMore){
- self.didSeeMore(self);
- }
- }
- #pragma mark - property
- - (UIView *)containerView {
- if (!_containerView) {
- _containerView = [UIView new];
- }
- return _containerView;
- }
- - (UIView *)bottomLine {
- if (!_bottomLine) {
- _bottomLine = [UIView new];
- _bottomLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
- }
- return _bottomLine;
- }
- - (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;
- }
- - (UIButton *)moreActionBtn{
- if (_moreActionBtn == nil) {
- _moreActionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_moreActionBtn setImage:[UIImage imageNamed:@"basket_more_action"] forState:UIControlStateNormal];
- _moreActionBtn.userInteractionEnabled = NO;
- // [_moreActionBtn addTarget:self action:@selector(clickMoreAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _moreActionBtn;
- }
- - (UIImageView *)flagImgView{
- if (_flagImgView == nil) {
- _flagImgView = [[UIImageView alloc]init];
- [_flagImgView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
- }
- return _flagImgView;
- }
- - (UILabel *)siteNameLabel{
- if (_siteNameLabel == nil) {
- _siteNameLabel = [[UILabel alloc]init];
- _siteNameLabel.font = [UIFont systemFontOfSize:13];
- _siteNameLabel.textColor = UIColorFromRGB(0x333333);
- [_siteNameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
- }
- return _siteNameLabel;
- }
- - (UILabel *)advLabel{
- if (_advLabel == nil) {
- _advLabel = [[UILabel alloc]init];
- _advLabel.font = [UIFont systemFontOfSize:12];
- _advLabel.textColor = UIColorFromRGB(0x999999);
- }
- return _advLabel;
- }
- - (UILabel *)authenLabel{
- if (_authenLabel == nil) {
- _authenLabel = [[UILabel alloc]init];
- _authenLabel.font = [UIFont systemFontOfSize:9];
- _authenLabel.textColor = UIColorFromRGB(0xF7AC22);
- _authenLabel.text = @"认证采购";
- _authenLabel.textAlignment = NSTextAlignmentCenter;
- _authenLabel.layer.cornerRadius = 3.0;
- _authenLabel.layer.borderWidth = 0.5;
- _authenLabel.layer.borderColor = UIColorFromRGB(0xF7AC22).CGColor;
- }
- return _authenLabel;
- }
- - (UILabel *)postageDescLabel{
- if (_postageDescLabel == nil) {
- _postageDescLabel = [[UILabel alloc]init];
- _postageDescLabel.textColor = UIColorFromRGB(0xff624a);
- _postageDescLabel.font = [UIFont systemFontOfSize:12];
- if (UISCREENWIDTH <= 320) _postageDescLabel.font = [UIFont systemFontOfSize:11];
- _postageDescLabel.lineBreakMode = NSLineBreakByTruncatingTail;
-
- }
- return _postageDescLabel;
- }
- - (FKBasketPriceView *)priceView {
- if (!_priceView) {
- _priceView = [FKBasketPriceView new];
- }
- return _priceView;
- }
- @end
|