123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- //
- // ASCheckoutGoodsItemCell.m
- // Asteria
- //
- // Created by xingyu on 2024/5/10.
- //
- #import "ASCheckoutGoodsItemCell.h"
- #import "QtyCountV.h"
- #import "AlertMyCartDeleteV.h"
- @interface ASCheckoutGoodsItemCell ()
- @property (nonatomic, strong) CartTotalsItemsM *itemM;
- @property (nonatomic, strong) UIView *bgV;
- @property (nonatomic, strong) UIStackView *stackV;
- @property (nonatomic, strong) UIView *topV;
- @property (nonatomic, strong) UIImageView *leftImg;
- @property (nonatomic, strong) UILabel *nameLab;
- @property (nonatomic, strong) UIButton *closeBtn;
- @property (nonatomic, strong) QMUILabel *optionsLab;
- @property (nonatomic, strong) QMUILabel *gitfLab;
- @property (nonatomic, strong) UIStackView *rowStackV;
- @property (nonatomic, strong) QMUILabel *priceLab;
- @property (nonatomic, strong) QtyCountV *countV;
- @property (nonatomic, strong) QMUILabel *bgDesLab;
- @end
- @implementation ASCheckoutGoodsItemCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- }
- - (void)setupSubviewS{
- // self.contentView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
-
- self.contentView.backgroundColor = ThemeLightColor;
-
- [self.contentView addSubview:self.bgV];
- [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 10, 10, 10));
- }];
-
- [self.bgV addSubview:self.stackV];
- [self.stackV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.bgV).insets(UIEdgeInsetsMake(20, 10, 15, 10));
- }];
-
- [self.stackV addArrangedSubview:self.topV];
- [self.stackV addArrangedSubview:self.rowStackV];
- [self.stackV addArrangedSubview:self.bgDesLab];
- [self.topV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(KScreenWidth-40);
- make.height.mas_equalTo(86+10);
- }];
- [self.rowStackV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.stackV);
- make.height.mas_equalTo(32);
- }];
- [self.bgDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(23);
- make.width.mas_greaterThanOrEqualTo(86);
- }];
-
- [self.topV addSubview:self.leftImg];
- [self.topV addSubview:self.nameLab];
- [self.topV addSubview:self.closeBtn];
- [self.topV addSubview:self.optionsLab];
- [self.topV addSubview:self.gitfLab];
- [self.leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(0);
- make.width.height.mas_equalTo(86);
- }];
- [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.right.mas_equalTo(-5);
- make.width.height.mas_offset(22);
- }];
- [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(4);
- make.left.equalTo(self.leftImg.mas_right).offset(10);
- make.right.equalTo(self.closeBtn.mas_left).offset(-10);
- make.height.mas_lessThanOrEqualTo(40);
- }];
- [self.optionsLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.nameLab.mas_bottom).offset(10);;
- make.left.equalTo(self.leftImg.mas_right).offset(10);
- make.right.equalTo(self.closeBtn.mas_left).offset(-10);
- }];
- [self.gitfLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.leftImg.mas_right).offset(10);
- make.bottom.equalTo(self.leftImg);
- make.width.mas_equalTo(86);
- make.height.mas_equalTo(23);
- }];
-
- [self.rowStackV addArrangedSubview:self.priceLab];
- [self.rowStackV addArrangedSubview:self.countV];
- [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(20);
- }];
- [self.countV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(self.countV.mj_w);
- make.height.mas_equalTo(self.countV.mj_h);
- }];
- [self subViewsTapBlock];
- }
- - (void)subViewsTapBlock{
- @weakify(self)
- self.countV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {//0 - ; 1+
- @strongify(self)
- NSString *qtyStr = (NSString *)data;
- CartTotalsItemsM *itemM =[[CartTotalsItemsM alloc]init];
- itemM = self.itemM;
- itemM.qty = qtyStr;
- if(self.currencyparameterClose){
- self.currencyparameterClose(1,itemM);
- }
- };
- }
- - (void)configData:(id)Data{
- CartTotalsItemsM *itemM = (CartTotalsItemsM *)Data;
- self.itemM = itemM;
- NSString *imgStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,itemM.image];
- [self.leftImg sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:UIImageDefaultImg_SD];
- self.nameLab.text = itemM.name;
-
-
- NSArray *array = [Current_normalTool arrFromjsonStr:itemM.options];
-
- NSString *optionStr = @"";
- for (int i = 0; i < array.count; i++) {
- NSDictionary *dic = [array objectAtIndex:i];
- optionStr = [NSString stringWithFormat:@"%@%@:%@", optionStr, dic[@"label"], dic[@"value"]];
-
- if (i < array.count - 1) {
- optionStr = [NSString stringWithFormat:@"%@\n", optionStr];
- }
- }
- self.optionsLab.text = optionStr;
-
-
- self.priceLab.attributedText = [ASCheckoutGoodsItemCell tool_changePriceAtr:itemM];
-
- self.closeBtn.hidden = itemM.isGift;
- self.optionsLab.hidden = itemM.isGift;
- self.gitfLab.hidden = !itemM.isGift;
- self.rowStackV.hidden = itemM.isGift;
- if(itemM.isGift){
- self.bgDesLab.hidden = YES;
- }else{
- self.bgDesLab.hidden = YES;
- // self.bgDesLab.text = [NSString stringWithFormat:@"SAVE %@%.2f",itemM.currency_symbol,[itemM.initial_price floatValue]-[itemM.price floatValue]];
- self.countV.numLab.text = MM_str(itemM.qty);
- [self.countV xxx_changeBtnIsEnable:YES num:[self.countV.numLab.text integerValue]];
- }
- }
- #pragma mark - **************** handle ****************
- -(void)handle_CloseEvent:(UIButton *)btn{ //进入删除弹窗
- AlertMyCartDeleteV *alertV = [[AlertMyCartDeleteV alloc]initWithAlertVtitle:[[NSMutableAttributedString alloc] initWithString:@"Do You Want To Remove It?"]];
- alertV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
- if(num ==1){
- if(self.currencyparameterClose){
- self.currencyparameterClose(0,self.itemM);
- }
- }
- };
- }
- #pragma mark - **************** tool ****************
- +(NSMutableAttributedString *)tool_changePriceAtr:(CartTotalsItemsM *)model{
- NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%.2f",model.currency_symbol, [model.price_incl_tax floatValue]]];
- [priceAtr addAttribute: NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#0B0B0B"] range:NSMakeRange(0, priceAtr.length)];
- [priceAtr addAttribute:NSFontAttributeName value:[UIFont fontWithName:Rob_Bold size:20] range:NSMakeRange(0, priceAtr.length)];
- [priceAtr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
- NSMutableAttributedString *priceAtrSub1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%.2f",model.currency_symbol, [model.initial_price floatValue]]];
- [priceAtrSub1 addAttribute:NSForegroundColorAttributeName
- value:[UIColor colorWithHexString:@"#8c8c8c"]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtrSub1 addAttribute:NSFontAttributeName
- value:[UIFont fontWithName:Rob_Regular size:14]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtrSub1 addAttribute:NSStrikethroughStyleAttributeName
- value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtr appendAttributedString:priceAtrSub1];
- return priceAtr;
- }
- #pragma mark - **************** lazy ****************
- - (UIView *)bgV {
- if (!_bgV) {
- _bgV = [[UIView alloc] init];
- _bgV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
- _bgV.layer.cornerRadius = 4;
- _bgV.clipsToBounds = YES;
- }
- return _bgV;
- }
- - (UIStackView *)stackV { ///根据高度进行变化
- if (!_stackV) {
- UIStackView *stv = [[UIStackView alloc] init];
- stv.axis = UILayoutConstraintAxisVertical;
- stv.distribution = UIStackViewDistributionFill;
- stv.alignment = UIStackViewAlignmentLeading;
- stv.spacing = 5;
- _stackV = stv;
- }
- return _stackV;
- }
- -(UIImageView *)leftImg{
- if(!_leftImg){
- _leftImg = [[UIImageView alloc]init];
- }
- return _leftImg;
- }
- -(UILabel *)nameLab{
- if(!_nameLab){
- _nameLab = [[UILabel alloc]init];
- _nameLab.font = [UIFont fontWithName:Rob_Regular size:12];
- _nameLab.textColor = [UIColor colorWithHexString:@"#000000"];
- _nameLab.numberOfLines =2;
- }
- return _nameLab;
- }
- -(UIButton *)closeBtn{
- if(!_closeBtn){
- _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeBtn setBackgroundImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal];
- [_closeBtn addTarget:self action:@selector(handle_CloseEvent:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeBtn;
- }
- -(QtyCountV *)countV{
- if(!_countV){
- _countV = [[QtyCountV alloc]initWithFrame:CGRectMake(0, 0, 32*2+46, 32)];
- _countV.goodsmaxNum = 10;
- }
- return _countV;
- }
- - (QMUILabel *)optionsLab {
- if (!_optionsLab) {
- _optionsLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _optionsLab.textAlignment = NSTextAlignmentLeft;
- _optionsLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
- _optionsLab.numberOfLines = 0;
- _optionsLab.font = [UIFont fontWithName:Rob_Regular size:12];
- }
- return _optionsLab;
- }
- - (QMUILabel *)priceLab {
- if (!_priceLab) {
- _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _priceLab.textAlignment = NSTextAlignmentLeft;
- _priceLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
- _priceLab.font = [UIFont fontWithName:Rob_Bold size:14];
- }
- return _priceLab;
- }
- - (QMUILabel *)bgDesLab {
- if (!_bgDesLab) {
- _bgDesLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _bgDesLab.textAlignment = NSTextAlignmentCenter;
- _bgDesLab.backgroundColor = ThemeLightColor;
- _bgDesLab.textColor = [UIColor colorWithHexString:@"#000000"];
- _bgDesLab.font = [UIFont fontWithName:Rob_Regular size:12];
- _bgDesLab.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
- }
- return _bgDesLab;
- }
- - (QMUILabel *)gitfLab {
- if (!_gitfLab) {
- _gitfLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _gitfLab.textAlignment = NSTextAlignmentCenter;
- _gitfLab.textColor = [UIColor colorWithHexString:@"#000000"];
- _gitfLab.font = [UIFont fontWithName:Rob_Regular size:12];
- _gitfLab.text = @"Gift";
- _gitfLab.backgroundColor = ThemeLightColor;
- }
- return _gitfLab;
- }
- - (UIView *)topV {
- if (!_topV) {
- _topV = [[UIView alloc] init];
- }
- return _topV;
- }
- - (UIStackView *)rowStackV {
- if (!_rowStackV) {
- _rowStackV = [[UIStackView alloc] init];
- UIStackView *stv = [[UIStackView alloc] init];
- stv.axis = UILayoutConstraintAxisHorizontal;
- stv.distribution = UIStackViewDistributionFill;
- stv.alignment = UIStackViewAlignmentCenter;
- }
- return _rowStackV;
- }
- @end
|