// // KWMineHomeOrderSubView.m // westkissMob // // Created by iOS on 2022/10/12. // #import "KWMineHomeOrderSubView.h" @interface KWMineHomeOrderSubView () @property (nonatomic, strong) UILabel *titleLB; @property (nonatomic, strong) UILabel *priceLb; @property (nonatomic, strong) UILabel *xLB; @property (nonatomic, strong) UILabel *numLB; @property (nonatomic, strong) UIImageView *imgV; @property (nonatomic, strong) UILabel *giftTipV; @property (nonatomic, strong) UIButton *editBt; @property (nonatomic, strong) KWMineOrderProInfoModel *m; @end @implementation KWMineHomeOrderSubView - (void)setData:(KWMineOrderProInfoModel *)model canEdit:(BOOL)canEdit { self.m = model; self.titleLB.text = model.name; self.priceLb.text = [NSString stringWithFormat:@"%@%@", model.currency_symbol, model.price]; self.numLB.text = model.qty_ordered; NSString *imageStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,model.image]; [self.imgV sd_setImageWithURL:[NSURL URLWithString:imageStr.urlEncode] placeholderImage:[UIImage imageNamed:@"product_defualtImg"]]; self.editBt.hidden = !canEdit; [self showGift:model.is_gift.intValue == 1]; } - (void)showGift:(BOOL)isGift { self.giftTipV.hidden = !isGift; self.numLB.hidden = isGift; self.xLB.hidden = isGift; self.priceLb.hidden = isGift; if (isGift) { self.editBt.hidden = true; } } - (void)btAction:(UIButton *)bt { if (self.m && self.toAddCommentBlock) { self.toAddCommentBlock(self.m); } UIViewController *vc = [CTMediator.sharedInstance Goods_WriteReview:@{@"entity_id":self.m.product_id}]; [Current_normalTool.currentNav pushViewController:vc animated:true]; } -(instancetype)init { self = [super init]; if (self) { [self loadSubV]; } return self; } - (void)loadSubV { self.backgroundColor = UIColor.clearColor; [self addSubview:self.imgV]; [self addSubview:self.titleLB]; [self addSubview:self.priceLb]; [self addSubview:self.xLB]; [self addSubview:self.numLB]; [self addSubview:self.editBt]; [self addSubview:self.giftTipV]; [_imgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(0); make.left.equalTo(self).offset(0); make.bottom.equalTo(self).offset(0); make.width.height.equalTo(@86); }]; [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imgV); make.left.equalTo(self.imgV.mas_right).offset(10); make.right.equalTo(self).offset(0); make.height.equalTo(@35); }]; [self.priceLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.imgV); make.left.equalTo(self.titleLB); make.height.equalTo(@17); }]; [self.xLB mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@17); make.height.equalTo(@17); make.left.equalTo(self.priceLb.mas_right); make.centerY.equalTo(self.priceLb); }]; [self.numLB mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@25); make.height.equalTo(@17); make.left.equalTo(self.xLB.mas_right); make.centerY.equalTo(self.priceLb); }]; [self.editBt mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.centerY.equalTo(self.priceLb); make.width.height.equalTo(@24); make.right.equalTo(self); }]; [self.giftTipV mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.titleLB); make.bottom.equalTo(self.imgV); make.width.equalTo(@86); make.height.equalTo(@23); }]; } - (UIImageView *)imgV { if (!_imgV) { UIImageView *imgV = [[UIImageView alloc] init]; _imgV = imgV; } return _imgV; } - (UILabel *)titleLB { if (!_titleLB) { UILabel *lb = [[UILabel alloc] init]; lb.font = [UIFont fontWithName:Rob_Regular size:12]; lb.textColor = [UIColor blackColor]; lb.backgroundColor = [UIColor clearColor]; lb.numberOfLines = 2; _titleLB = lb; } return _titleLB; } - (UILabel *)priceLb { if (!_priceLb) { UILabel *lb = [[UILabel alloc] init]; lb.font = [UIFont fontWithName:Rob_Bold size:14]; lb.textColor = _0B0B0B; lb.backgroundColor = [UIColor clearColor]; _priceLb = lb; } return _priceLb; } - (UILabel *)xLB { if (!_xLB) { UILabel *lb = [[UILabel alloc] init]; lb.font = [UIFont fontWithName:Rob_Regular size:14]; lb.textColor = _0B0B0B; lb.backgroundColor = [UIColor clearColor]; lb.textAlignment = NSTextAlignmentCenter; lb.text = @"x"; _xLB = lb; } return _xLB; } - (UILabel *)numLB { if (!_numLB) { UILabel *lb = [[UILabel alloc] init]; lb.font = [UIFont fontWithName:Rob_Regular size:14]; lb.textColor = _0B0B0B; lb.backgroundColor = [UIColor clearColor]; _numLB = lb; } return _numLB; } - (UIButton *)editBt { if (!_editBt) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt setImage:[UIImage imageNamed:@"mine_add_comment"] forState:UIControlStateNormal]; [bt addTarget:self action:@selector(btAction:) forControlEvents:UIControlEventTouchUpInside]; _editBt = bt; } return _editBt; } - (UILabel *)giftTipV { if (!_giftTipV) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Regular size:12]; lb.textAlignment = NSTextAlignmentCenter; lb.textColor = Col_000; lb.text = @"Gift"; lb.backgroundColor = _F0FFF9; lb.layer.cornerRadius = 3; lb.layer.masksToBounds = true; lb.hidden = true; _giftTipV = lb; } return _giftTipV; } @end