GoodsSizeCountCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // GoodsSizeCountCell.m
  3. // westkissMob
  4. //
  5. // Created by 王猛 on 2022/9/23.
  6. //
  7. #import "GoodsSizeCountCell.h"
  8. @implementation GoodsSizeCountCellData
  9. @end
  10. @interface GoodsSizeCountCell ()
  11. @property(nonatomic, strong) UILabel *quantityLab;
  12. @property(nonatomic, strong) UIButton *cutBtn;
  13. @property(nonatomic, strong) UILabel *numLab;
  14. @property(nonatomic, strong) UIButton *addBtn;
  15. @end
  16. @implementation GoodsSizeCountCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  22. [super setSelected:selected animated:animated];
  23. }
  24. - (void)configData:(id)Data{
  25. GoodsSizeCountCellData *model =(GoodsSizeCountCellData *)Data;
  26. self.model = model;
  27. self.numLab.text = [NSString stringWithFormat:@"%ld",(long)self.model.quantityNum];
  28. }
  29. - (void)setupSubviewS{
  30. [self.contentView addSubview:self.quantityLab];
  31. [self.contentView addSubview:self.numLab];
  32. [self.contentView addSubview:self.cutBtn];
  33. [self.contentView addSubview:self.addBtn];
  34. [self.quantityLab mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.top.mas_equalTo(20);
  36. make.right.mas_equalTo(-20);
  37. make.height.mas_equalTo(18);
  38. }];
  39. [self.cutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(self.quantityLab.mas_bottom).offset(20);
  41. make.left.mas_equalTo(20);
  42. make.height.mas_equalTo(32);
  43. make.width.mas_equalTo(32);
  44. }];
  45. [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.top.equalTo(self.quantityLab.mas_bottom).offset(20);
  47. make.height.mas_equalTo(32);
  48. make.width.mas_equalTo(46);
  49. make.left.equalTo(self.cutBtn.mas_right);
  50. }];
  51. [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.top.equalTo(self.quantityLab.mas_bottom).offset(20);
  53. make.left.equalTo(self.numLab.mas_right);
  54. make.height.mas_equalTo(32);
  55. make.width.mas_equalTo(32);
  56. make.bottom.mas_equalTo(-10);
  57. }];
  58. }
  59. #pragma mark - *************** handle ****************
  60. -(void)handle_addNumEvent:(UIButton *)btn{
  61. self.model.quantityNum ++;
  62. [self tool_btnChangeNum:self.model.quantityNum];
  63. self.numLab.text = [NSString stringWithFormat:@"%ld",self.model.quantityNum];
  64. if(self.currencyparameterClose){
  65. self.currencyparameterClose(1, self.model);
  66. }
  67. }
  68. -(void)handle_cutNumEvent:(UIButton *)btn{
  69. self.model.quantityNum--;
  70. [self tool_btnChangeNum:self.model.quantityNum];
  71. self.numLab.text = [NSString stringWithFormat:@"%ld", self.model.quantityNum];
  72. if(self.currencyparameterClose){
  73. self.currencyparameterClose(0, self.model);
  74. }
  75. }
  76. -(void)tool_btnChangeNum:(NSInteger )num{
  77. if(num >= self.model.maxNum){
  78. [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  79. self.addBtn.userInteractionEnabled = NO;
  80. }else{
  81. [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
  82. self.addBtn.userInteractionEnabled = YES;
  83. }
  84. if(num >= 2){
  85. [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
  86. self.cutBtn.userInteractionEnabled = YES;
  87. }else{
  88. [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  89. self.cutBtn.userInteractionEnabled = NO;
  90. }
  91. }
  92. -(UILabel *)quantityLab{
  93. if(!_quantityLab){
  94. _quantityLab = [UILabel new];
  95. _quantityLab.font = [UIFont fontWithName:Rob_Bold size:14];
  96. _quantityLab.textAlignment = NSTextAlignmentLeft;
  97. _quantityLab.text = @"Quantity";
  98. }
  99. return _quantityLab;
  100. }
  101. -(UIButton *)cutBtn{
  102. if(!_cutBtn){
  103. _cutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. [_cutBtn setTitle:@"-" forState:UIControlStateNormal];
  105. [_cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  106. _cutBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18];
  107. _cutBtn.layer.borderWidth = 0.5;
  108. [_cutBtn addTarget:self action:@selector(handle_cutNumEvent:) forControlEvents:UIControlEventTouchUpInside];
  109. _cutBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
  110. _cutBtn.userInteractionEnabled = NO;
  111. }
  112. return _cutBtn;
  113. }
  114. -(UILabel *)numLab{
  115. if(!_numLab){
  116. _numLab = [[UILabel alloc]init];
  117. _numLab.text = @"1";
  118. _numLab.font = [UIFont fontWithName:Rob_Bold size:12];
  119. _numLab.textAlignment = NSTextAlignmentCenter;
  120. _numLab.layer.borderWidth = 0.5;
  121. _numLab.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
  122. }
  123. return _numLab;
  124. }
  125. -(UIButton *)addBtn{
  126. if(!_addBtn){
  127. _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  128. [_addBtn setTitle:@"+" forState:UIControlStateNormal];
  129. [_addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
  130. _addBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18];
  131. _addBtn.layer.borderWidth = 0.5;
  132. _addBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
  133. [_addBtn addTarget:self action:@selector(handle_addNumEvent:) forControlEvents:UIControlEventTouchUpInside];
  134. }
  135. return _addBtn;
  136. }
  137. @end