123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // GoodsSizeCountCell.m
- // westkissMob
- //
- // Created by 王猛 on 2022/9/23.
- //
- #import "GoodsSizeCountCell.h"
- @implementation GoodsSizeCountCellData
- @end
- @interface GoodsSizeCountCell ()
- @property(nonatomic, strong) UILabel *quantityLab;
- @property(nonatomic, strong) UIButton *cutBtn;
- @property(nonatomic, strong) UILabel *numLab;
- @property(nonatomic, strong) UIButton *addBtn;
- @end
- @implementation GoodsSizeCountCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- }
- - (void)configData:(id)Data{
- GoodsSizeCountCellData *model =(GoodsSizeCountCellData *)Data;
- self.model = model;
- self.numLab.text = [NSString stringWithFormat:@"%ld",(long)self.model.quantityNum];
- }
- - (void)setupSubviewS{
- [self.contentView addSubview:self.quantityLab];
- [self.contentView addSubview:self.numLab];
- [self.contentView addSubview:self.cutBtn];
- [self.contentView addSubview:self.addBtn];
- [self.quantityLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(20);
- make.right.mas_equalTo(-20);
- make.height.mas_equalTo(18);
- }];
- [self.cutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.quantityLab.mas_bottom).offset(20);
- make.left.mas_equalTo(20);
- make.height.mas_equalTo(32);
- make.width.mas_equalTo(32);
- }];
- [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.quantityLab.mas_bottom).offset(20);
- make.height.mas_equalTo(32);
- make.width.mas_equalTo(46);
- make.left.equalTo(self.cutBtn.mas_right);
- }];
- [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.quantityLab.mas_bottom).offset(20);
- make.left.equalTo(self.numLab.mas_right);
- make.height.mas_equalTo(32);
- make.width.mas_equalTo(32);
- make.bottom.mas_equalTo(-10);
- }];
- }
- #pragma mark - *************** handle ****************
- -(void)handle_addNumEvent:(UIButton *)btn{
- self.model.quantityNum ++;
- [self tool_btnChangeNum:self.model.quantityNum];
- self.numLab.text = [NSString stringWithFormat:@"%ld",self.model.quantityNum];
- if(self.currencyparameterClose){
- self.currencyparameterClose(1, self.model);
- }
- }
- -(void)handle_cutNumEvent:(UIButton *)btn{
- self.model.quantityNum--;
- [self tool_btnChangeNum:self.model.quantityNum];
- self.numLab.text = [NSString stringWithFormat:@"%ld", self.model.quantityNum];
- if(self.currencyparameterClose){
- self.currencyparameterClose(0, self.model);
- }
- }
- -(void)tool_btnChangeNum:(NSInteger )num{
- if(num >= self.model.maxNum){
- [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
- self.addBtn.userInteractionEnabled = NO;
- }else{
- [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
- self.addBtn.userInteractionEnabled = YES;
- }
- if(num >= 2){
- [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
- self.cutBtn.userInteractionEnabled = YES;
- }else{
- [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
- self.cutBtn.userInteractionEnabled = NO;
- }
- }
- -(UILabel *)quantityLab{
- if(!_quantityLab){
- _quantityLab = [UILabel new];
- _quantityLab.font = [UIFont fontWithName:Rob_Bold size:14];
- _quantityLab.textAlignment = NSTextAlignmentLeft;
- _quantityLab.text = @"Quantity";
- }
- return _quantityLab;
- }
- -(UIButton *)cutBtn{
- if(!_cutBtn){
- _cutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_cutBtn setTitle:@"-" forState:UIControlStateNormal];
- [_cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
- _cutBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18];
- _cutBtn.layer.borderWidth = 0.5;
- [_cutBtn addTarget:self action:@selector(handle_cutNumEvent:) forControlEvents:UIControlEventTouchUpInside];
- _cutBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
- _cutBtn.userInteractionEnabled = NO;
- }
- return _cutBtn;
- }
- -(UILabel *)numLab{
- if(!_numLab){
- _numLab = [[UILabel alloc]init];
- _numLab.text = @"1";
- _numLab.font = [UIFont fontWithName:Rob_Bold size:12];
- _numLab.textAlignment = NSTextAlignmentCenter;
- _numLab.layer.borderWidth = 0.5;
- _numLab.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
- }
- return _numLab;
- }
- -(UIButton *)addBtn{
- if(!_addBtn){
- _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_addBtn setTitle:@"+" forState:UIControlStateNormal];
- [_addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
- _addBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18];
- _addBtn.layer.borderWidth = 0.5;
- _addBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
- [_addBtn addTarget:self action:@selector(handle_addNumEvent:) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _addBtn;
- }
- @end
|