ASCheckoutPointApplyCell.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // ASCheckoutPointApplyCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/8.
  6. //
  7. #import "ASCheckoutPointApplyCell.h"
  8. @implementation ASCheckoutPointData
  9. @end
  10. @interface ASCheckoutPointApplyCell ()
  11. @property (nonatomic, strong) UIView *bgView;
  12. @property (nonatomic, strong) UILabel *titleLab;
  13. @property (nonatomic, strong) UILabel *priceLab;
  14. @property (nonatomic, strong) TT_CustonTF *codeTF;
  15. @property (nonatomic, strong) UIButton *applyBtn;
  16. @property (nonatomic, strong) QMUILabel *pointDesLab;
  17. @end
  18. @implementation ASCheckoutPointApplyCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. }
  23. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  24. [super setSelected:selected animated:animated];
  25. // Configure the view for the selected state
  26. }
  27. - (void)setupSubviewS{ //height 200
  28. self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  29. [self.contentView addSubview:self.bgView];
  30. [self.bgView addSubview:self.titleLab];
  31. UIView *applyTmpV = [[UIView alloc]init];
  32. applyTmpV.layer.borderColor = [UIColor colorWithHexString:@"#0B0B0B"].CGColor;
  33. applyTmpV.layer.cornerRadius = 4;
  34. applyTmpV.layer.borderWidth = 1;
  35. applyTmpV.clipsToBounds = YES;
  36. [self.bgView addSubview:applyTmpV];
  37. [applyTmpV addSubview:self.codeTF];
  38. [applyTmpV addSubview:self.applyBtn];
  39. [self.bgView addSubview:self.pointDesLab];
  40. [self.bgView addSubview:self.priceLab];
  41. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.top.mas_equalTo(10);
  43. make.right.mas_equalTo(-10);
  44. make.bottom.mas_equalTo(0);
  45. }];
  46. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.mas_equalTo(10);
  48. make.top.mas_equalTo(20);
  49. make.height.mas_equalTo(20);
  50. make.right.mas_equalTo(-100);
  51. }];
  52. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.equalTo(self.titleLab.mas_right).offset(20);
  54. make.right.mas_equalTo(-10);
  55. make.centerY.mas_equalTo(self.titleLab);
  56. }];
  57. [applyTmpV mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.top.equalTo(self.titleLab.mas_bottom).offset(20);
  59. make.left.mas_equalTo(10);
  60. make.right.mas_equalTo(-10);
  61. make.height.mas_equalTo(45);
  62. }];
  63. [self.codeTF mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.top.bottom.equalTo(applyTmpV);
  65. make.width.mas_equalTo(KScreenWidth-20-95);
  66. }];
  67. [self.applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.right.top.bottom.equalTo(applyTmpV);
  69. make.width.mas_equalTo(self.applyBtn.mj_w);
  70. }];
  71. [self.pointDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.mas_equalTo(20);
  73. make.width.mas_equalTo(KScreenWidth-60);
  74. make.top.equalTo(applyTmpV.mas_bottom).offset(10);
  75. make.bottom.mas_equalTo(-20);
  76. }];
  77. }
  78. #pragma mark - **************** handle_ApplyEvent ****************
  79. -(void)handle_ApplyEvent:(UIButton *)btn{
  80. if( self.codeTF.text.length == 0){
  81. [[Current_normalTool topViewController].view makeToast:@"Please fill in the points count" duration:2 position:CSToastPositionCenter];
  82. return;
  83. }
  84. if(btn.selected == NO){
  85. self.pointCellData.usePoint = self.codeTF.text;
  86. if(self.currencyparameterClose){
  87. self.currencyparameterClose(0,self.pointCellData);
  88. }
  89. }else{
  90. self.pointCellData.usePoint = @"";
  91. if(self.currencyparameterClose){
  92. self.currencyparameterClose(1, self.pointCellData);
  93. }
  94. }
  95. }
  96. - (void)configData:(id)Data{
  97. ASCheckoutPointData *model = (ASCheckoutPointData *)Data;
  98. self.pointCellData = model;
  99. if([model.usePoint integerValue] > 0){
  100. self.codeTF.text = MM_str(model.usePoint);
  101. self.applyBtn.selected = YES;
  102. }else{
  103. self.codeTF.text = @"";
  104. self.applyBtn.selected = NO;
  105. }
  106. if ([model.usePrice floatValue] > 0.00) {
  107. self.priceLab.text = [NSString stringWithFormat:@"-%@%@", model.priceSymbol, model.usePrice];
  108. } else {
  109. self.priceLab.text = @"";
  110. }
  111. NSString *pointStr = [NSString stringWithFormat:@"You have %@ Reward Points available.", model.pointBalance];
  112. NSString *pointLastStr = [NSString stringWithFormat:@"%@ point = %@%@. Input points value below to redeem.", model.pointScale, model.priceSymbol, model.priceScale];
  113. NSMutableAttributedString *couponStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@", pointStr, pointLastStr]];
  114. // couponStr.color = [UIColor colorWithHexString:@"#B2B2B2"];
  115. // couponStr.font = [UIFont fontWithName:Rob_Regular size:12];
  116. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  117. [paragraphStyle setLineSpacing:8];//设置距离
  118. [couponStr addAttribute:NSParagraphStyleAttributeName
  119. value:paragraphStyle
  120. range:NSMakeRange(0, [pointStr length])];
  121. self.pointDesLab.attributedText = couponStr;
  122. }
  123. #pragma mark - **************** lazy ****************
  124. -(UIView *)bgView{
  125. if(!_bgView){
  126. _bgView = [[UIView alloc]init];
  127. _bgView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  128. _bgView.layer.cornerRadius = 4;
  129. _bgView.clipsToBounds = YES;
  130. }
  131. return _bgView;
  132. }
  133. -(UILabel *)titleLab{
  134. if(!_titleLab){
  135. _titleLab = [[UILabel alloc]init];
  136. _titleLab.text = @"Redeem Your Reward Points";
  137. _titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  138. _titleLab.adjustsFontSizeToFitWidth = YES;
  139. _titleLab.font = [UIFont fontWithName:Rob_Bold size:16];
  140. }
  141. return _titleLab;
  142. }
  143. -(TT_CustonTF *)codeTF{
  144. if(!_codeTF){
  145. _codeTF = [[TT_CustonTF alloc] init];
  146. _codeTF.keyboardType = UIKeyboardTypeNumberPad;
  147. _codeTF.placeholder = @"Enter Your Reward Points";
  148. _codeTF.font = [UIFont fontWithName:Rob_Regular size:14];
  149. }
  150. return _codeTF;
  151. }
  152. -(UIButton *)applyBtn{
  153. if(!_applyBtn){
  154. _applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  155. _applyBtn.frame = CGRectMake(0, 0, 95, 45);
  156. [_applyBtn setTitle:@"APPLY" forState:UIControlStateNormal];
  157. [self.applyBtn setTitle:@"CANCEL" forState:UIControlStateSelected];
  158. _applyBtn.backgroundColor = [UIColor colorWithHexString:@"#0B0B0B"];
  159. [_applyBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  160. [_applyBtn addTarget:self action:@selector(handle_ApplyEvent:) forControlEvents:UIControlEventTouchUpInside];
  161. _applyBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  162. _applyBtn.layer.cornerRadius = 4;
  163. }
  164. return _applyBtn;
  165. }
  166. -(UILabel *)priceLab{
  167. if(!_priceLab){
  168. _priceLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B];
  169. _priceLab.textAlignment = NSTextAlignmentRight;
  170. _priceLab.adjustsFontSizeToFitWidth = YES;
  171. }
  172. return _priceLab;
  173. }
  174. -(QMUILabel *)pointDesLab{
  175. if(!_pointDesLab){
  176. _pointDesLab = [[QMUILabel alloc]init];
  177. _pointDesLab.numberOfLines = 0;
  178. _pointDesLab.font = [UIFont fontWithName:Rob_Regular size:12];
  179. _pointDesLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
  180. _pointDesLab.preferredMaxLayoutWidth =KScreenWidth-40;
  181. }
  182. return _pointDesLab;
  183. }
  184. @end