// // DRGoodDetailBottomView.m // YouHuiProject // // Created by xiaoxi on 2018/1/25. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRGoodDetailBottomView.h" #import "DRGoodDetailModel.h" @interface DRGoodDetailBottomView () @end @implementation DRGoodDetailBottomView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } - (void)initSubviews { [self addSubview:self.collectButton]; [self addSubview:self.buyButton]; [self addSubview:self.commissionButton]; [self.collectButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(0); make.width.mas_equalTo(Fitsize(96)); make.bottom.mas_equalTo(0); }]; [self.commissionButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.collectButton.mas_right); make.top.bottom.mas_equalTo(0); make.width.mas_equalTo((SCREEN_WIDTH-Fitsize(96))/2); }]; [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.commissionButton.mas_right); make.top.bottom.mas_equalTo(0); make.right.mas_equalTo(0); }]; } - (void)setGoodModel:(DRGoodDetailModel *)goodModel { _goodModel = goodModel; if ([goodModel.is_favorites isEqual:@1]) { self.collectButton.selected = YES; } else { self.collectButton.selected = NO; } // NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@", goodModel.discount_price] attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:FITSIZE(20)],NSForegroundColorAttributeName:[UIColor whiteColor]}]; // NSAttributedString *att1 = [[NSAttributedString alloc] initWithString:@"去领券¥\n" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:FITSIZE(11)],NSForegroundColorAttributeName:[UIColor whiteColor]}]; // [att appendAttributedString:att1]; // [_buyButton setAttributedTitle:att forState:UIControlStateNormal]; // NSString *isCoup =@""; // // if ([self.goodModel.is_coupon integerValue]==1) { // isCoup=@"领券购"; // }else{ // isCoup=@"优惠购"; // } // NSString *price=[NSString stringWithFormat:@"%@¥%.2f",isCoup,[goodModel.discount_price floatValue]]; // [_buyButton setTitle:price forState:UIControlStateNormal]; // if ([AccountTool isLogin]&&![@"" isEqualToString:self.goodModel.commission_price]) { // NSString *price2 = [NSString stringWithFormat:@"立即购买"]; // [_commissionButton setTitle:price2 forState:UIControlStateNormal]; // }else{ // NSString *price2 = [NSString stringWithFormat:@"马上分享"]; // [_commissionButton setTitle:price2 forState:UIControlStateNormal]; // } [_commissionButton setTitle:@"马上分享" forState:UIControlStateNormal]; [_buyButton setTitle:@"立即购买" forState:UIControlStateNormal]; } - (void)buttonAction:(UIButton *)sender { // switch (sender.tag) { case 1: { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailBottomViewClickCollectButton)]) { [self.delegate yh_GoodDetailBottomViewClickCollectButton]; } } break; case 2: { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailBottomViewClickCommissionButton)]) { [self.delegate yh_GoodDetailBottomViewClickCommissionButton]; } } break; case 3: { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailBottomViewClickBuyButton)]) { [self.delegate yh_GoodDetailBottomViewClickBuyButton]; } } break; default: break; } } #pragma mark - lazy - (UIButton *)shopButton { if (!_shopButton) { _shopButton = [UIButton buttonWithType:UIButtonTypeCustom]; _shopButton.backgroundColor = [UIColor clearColor]; [_shopButton setTitleColor:[UIColor YHColorWithHex:0x444444] forState:UIControlStateNormal]; _shopButton.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(10)]; [_shopButton setTitle:@"店铺" forState:UIControlStateNormal]; [_shopButton setImage:[UIImage imageNamed:@"detail_shop"] forState:UIControlStateNormal]; [_shopButton setButtonStyle:WSLButtonStyleImageTop spacing:5]; _shopButton.tag = 1; [_shopButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _shopButton; } - (UIButton *)collectButton { if (!_collectButton) { _collectButton = [UIButton buttonWithType:UIButtonTypeCustom]; _collectButton.backgroundColor = [UIColor clearColor]; [_collectButton setTitleColor:[UIColor YHColorWithHex:0x444444] forState:UIControlStateNormal]; _collectButton.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(10)]; [_collectButton setTitle:@"收藏" forState:UIControlStateNormal]; [_collectButton setImage:[UIImage imageNamed:@"detail_collect"] forState:UIControlStateNormal]; [_collectButton setImage:[UIImage imageNamed:@"detail_collect_selected"] forState:UIControlStateSelected]; [_collectButton setButtonStyle:WSLButtonStyleImageTop spacing:5]; _collectButton.tag = 1; [_collectButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _collectButton; } - (UIButton *)buyButton { if (!_buyButton) { _buyButton = [UIButton buttonWithType:UIButtonTypeCustom]; _buyButton.backgroundColor = [UIColor homeRedColor]; _buyButton.titleLabel.numberOfLines = 1; _buyButton.titleLabel.textAlignment = NSTextAlignmentCenter; _buyButton.tag = 3; [_buyButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; _buyButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [_buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } return _buyButton; } - (UIButton *)commissionButton { if (!_commissionButton) { _commissionButton = [UIButton buttonWithType:UIButtonTypeCustom]; _commissionButton.backgroundColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFEC800] toColor:[UIColor YHColorWithHex:0xFD9D03] withWidth:(SCREEN_WIDTH-Fitsize(90))/2]; _commissionButton.titleLabel.textAlignment = NSTextAlignmentCenter; _commissionButton.tag = 2; [_commissionButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; _commissionButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [_commissionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } return _commissionButton; } @end