MyCartCouponCell.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //
  2. // MyCartCouponCell.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/2/1.
  6. //
  7. #import "MyCartCouponCell.h"
  8. @implementation MyCartCouponCellData
  9. @end
  10. @interface MyCartCouponCell ()
  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 *couponDesLab;
  17. @end
  18. @implementation MyCartCouponCell
  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. [self.bgView addSubview:self.priceLab];
  32. UIView *applyTmpV = [[UIView alloc]init];
  33. applyTmpV.layer.borderColor = [UIColor colorWithHexString:@"#0B0B0B"].CGColor;
  34. applyTmpV.layer.cornerRadius = 4;
  35. applyTmpV.layer.borderWidth = 1;
  36. applyTmpV.clipsToBounds = YES;
  37. [self.bgView addSubview:applyTmpV];
  38. [applyTmpV addSubview:self.codeTF];
  39. [applyTmpV addSubview:self.applyBtn];
  40. [self.bgView addSubview:self.couponDesLab];
  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.width.mas_equalTo(150);
  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.top.mas_equalTo(20);
  56. make.height.mas_equalTo(20);
  57. }];
  58. [applyTmpV mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.top.equalTo(self.titleLab.mas_bottom).offset(20);
  60. make.left.mas_equalTo(10);
  61. make.right.mas_equalTo(-10);
  62. make.height.mas_equalTo(45);
  63. }];
  64. [self.codeTF mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.top.bottom.equalTo(applyTmpV);
  66. make.width.mas_equalTo(self.codeTF.mj_w);
  67. }];
  68. [self.applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.right.top.bottom.equalTo(applyTmpV);
  70. make.width.mas_equalTo(self.applyBtn.mj_w);
  71. }];
  72. [self.couponDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(10);
  74. make.width.mas_equalTo(KScreenWidth-40);
  75. make.top.equalTo(applyTmpV.mas_bottom).offset(10);
  76. make.bottom.mas_equalTo(-20);
  77. }];
  78. }
  79. #pragma mark - **************** handle_ApplyEvent ****************
  80. -(void)handle_ApplyEvent:(UIButton *)btn{
  81. if( self.codeTF.text.length == 0){
  82. [[Current_normalTool topViewController].view makeToast:@"Please fill in the coupon code first" duration:2 position:CSToastPositionCenter];
  83. return;
  84. }
  85. if(btn.selected == NO){
  86. self.cellData.coupon_code = self.codeTF.text;
  87. if(self.currencyparameterClose){
  88. self.currencyparameterClose(0,self.cellData);
  89. }
  90. }else{
  91. self.cellData.coupon_code = @"";
  92. if(self.currencyparameterClose){
  93. self.currencyparameterClose(1, self.cellData);
  94. }
  95. }
  96. }
  97. - (void)configData:(id)Data{
  98. MyCartCouponCellData *model = (MyCartCouponCellData *)Data;
  99. self.cellData = model;
  100. NSString *disountStr = @"";
  101. if([model.discount_amount floatValue] <0.00){
  102. CGFloat temF =fabsf([model.discount_amount floatValue]);
  103. disountStr = [NSString stringWithFormat:@"-%@%.2f",model.currency_symbol,temF];
  104. }
  105. self.priceLab.text = disountStr;
  106. if(![model.coupon_code isEmpty] && model.coupon_code.length>0){
  107. self.codeTF.text = MM_str(model.coupon_code);
  108. self.applyBtn.selected = YES;
  109. }else{
  110. self.codeTF.text = @"";
  111. self.applyBtn.selected = NO;
  112. }
  113. NSMutableAttributedString *couponStr = [[NSMutableAttributedString alloc]init];
  114. for (int i=0; i<model.couponAry.count; i++) {
  115. NSDictionary *dic = model.couponAry[i];
  116. NSString *temStr = [NSString stringWithFormat:@"%@,%@",dic[@"title"],dic[@"code"]];
  117. [couponStr appendAttributedString:[[NSAttributedString alloc]initWithString:temStr]];
  118. if(i != model.couponAry.count-1){
  119. [couponStr appendAttributedString:[[NSAttributedString alloc]initWithString:@"\n"]];
  120. }
  121. }
  122. couponStr.color = [UIColor colorWithHexString:@"#B2B2B2"];
  123. couponStr.font = [UIFont fontWithName:Rob_Regular size:12];
  124. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  125. [paragraphStyle setLineSpacing:8];//设置距离
  126. [couponStr addAttribute:NSParagraphStyleAttributeName
  127. value:paragraphStyle
  128. range:NSMakeRange(0, [couponStr length])];
  129. self.couponDesLab.attributedText = couponStr;
  130. }
  131. #pragma mark - **************** lazy ****************
  132. -(UIView *)bgView{
  133. if(!_bgView){
  134. _bgView = [[UIView alloc]init];
  135. _bgView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  136. _bgView.layer.cornerRadius = 4;
  137. _bgView.clipsToBounds = YES;
  138. }
  139. return _bgView;
  140. }
  141. -(UILabel *)titleLab{
  142. if(!_titleLab){
  143. _titleLab = [[UILabel alloc]init];
  144. _titleLab.text = @"Discount Codes";
  145. _titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  146. _titleLab.font = [UIFont fontWithName:Rob_Bold size:16];
  147. }
  148. return _titleLab;
  149. }
  150. -(UILabel *)priceLab{
  151. if(!_priceLab){
  152. _priceLab = [[UILabel alloc]init];
  153. _priceLab.textAlignment = NSTextAlignmentRight;
  154. _priceLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
  155. _priceLab.font = [UIFont fontWithName:Rob_Bold size:14];
  156. }
  157. return _priceLab;
  158. }
  159. -(TT_CustonTF *)codeTF{
  160. if(!_codeTF){
  161. _codeTF = [[TT_CustonTF alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20-95, 45)];
  162. _codeTF.placeholder = @"Enter Your Coupon Code";
  163. _codeTF.font = [UIFont fontWithName:Rob_Regular size:14];
  164. }
  165. return _codeTF;
  166. }
  167. -(UIButton *)applyBtn{
  168. if(!_applyBtn){
  169. _applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  170. _applyBtn.frame = CGRectMake(0, 0, 95, 45);
  171. [_applyBtn setTitle:@"APPLY" forState:UIControlStateNormal];
  172. [self.applyBtn setTitle:@"CANCEL" forState:UIControlStateSelected];
  173. _applyBtn.backgroundColor = [UIColor colorWithHexString:@"#0B0B0B"];
  174. [_applyBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  175. [_applyBtn addTarget:self action:@selector(handle_ApplyEvent:) forControlEvents:UIControlEventTouchUpInside];
  176. _applyBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  177. _applyBtn.layer.cornerRadius = 4;
  178. }
  179. return _applyBtn;
  180. }
  181. -(QMUILabel *)couponDesLab{
  182. if(!_couponDesLab){
  183. _couponDesLab = [[QMUILabel alloc]init];
  184. _couponDesLab.numberOfLines = 0;
  185. _couponDesLab.font = [UIFont fontWithName:Rob_Regular size:12];
  186. _couponDesLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
  187. _couponDesLab.preferredMaxLayoutWidth =KScreenWidth-40;
  188. }
  189. return _couponDesLab;
  190. }
  191. @end