123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- //
- // MyCartCouponCell.m
- // Asteria
- //
- // Created by 王猛 on 2024/2/1.
- //
- #import "MyCartCouponCell.h"
- @implementation MyCartCouponCellData
- @end
- @interface MyCartCouponCell ()
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UILabel *titleLab;
- @property (nonatomic, strong) UILabel *priceLab;
- @property (nonatomic, strong) TT_CustonTF *codeTF;
- @property (nonatomic, strong) UIButton *applyBtn;
- @property (nonatomic, strong) QMUILabel *couponDesLab;
- @end
- @implementation MyCartCouponCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)setupSubviewS{ //height 200
- self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
- [self.contentView addSubview:self.bgView];
- [self.bgView addSubview:self.titleLab];
- [self.bgView addSubview:self.priceLab];
-
- UIView *applyTmpV = [[UIView alloc]init];
- applyTmpV.layer.borderColor = [UIColor colorWithHexString:@"#0B0B0B"].CGColor;
- applyTmpV.layer.cornerRadius = 4;
- applyTmpV.layer.borderWidth = 1;
- applyTmpV.clipsToBounds = YES;
- [self.bgView addSubview:applyTmpV];
- [applyTmpV addSubview:self.codeTF];
- [applyTmpV addSubview:self.applyBtn];
-
- [self.bgView addSubview:self.couponDesLab];
-
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.bottom.mas_equalTo(0);
- }];
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(20);
- make.height.mas_equalTo(20);
- make.width.mas_equalTo(150);
- }];
- [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.titleLab.mas_right).offset(20);
- make.right.mas_equalTo(-10);
- make.top.mas_equalTo(20);
- make.height.mas_equalTo(20);
- }];
-
- [applyTmpV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLab.mas_bottom).offset(20);
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.height.mas_equalTo(45);
- }];
- [self.codeTF mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.equalTo(applyTmpV);
- make.width.mas_equalTo(self.codeTF.mj_w);
- }];
- [self.applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.bottom.equalTo(applyTmpV);
- make.width.mas_equalTo(self.applyBtn.mj_w);
- }];
-
- [self.couponDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.width.mas_equalTo(KScreenWidth-40);
- make.top.equalTo(applyTmpV.mas_bottom).offset(10);
- make.bottom.mas_equalTo(-20);
- }];
-
- }
- #pragma mark - **************** handle_ApplyEvent ****************
- -(void)handle_ApplyEvent:(UIButton *)btn{
- if( self.codeTF.text.length == 0){
- [[Current_normalTool topViewController].view makeToast:@"Please fill in the coupon code first" duration:2 position:CSToastPositionCenter];
- return;
- }
- if(btn.selected == NO){
- self.cellData.coupon_code = self.codeTF.text;
- if(self.currencyparameterClose){
- self.currencyparameterClose(0,self.cellData);
- }
- }else{
- self.cellData.coupon_code = @"";
- if(self.currencyparameterClose){
- self.currencyparameterClose(1, self.cellData);
- }
- }
- }
- - (void)configData:(id)Data{
- MyCartCouponCellData *model = (MyCartCouponCellData *)Data;
- self.cellData = model;
- NSString *disountStr = @"";
- if([model.discount_amount floatValue] <0.00){
- CGFloat temF =fabsf([model.discount_amount floatValue]);
- disountStr = [NSString stringWithFormat:@"-%@%.2f",model.currency_symbol,temF];
- }
- self.priceLab.text = disountStr;
- if(![model.coupon_code isEmpty] && model.coupon_code.length>0){
- self.codeTF.text = MM_str(model.coupon_code);
- self.applyBtn.selected = YES;
- }else{
- self.codeTF.text = @"";
- self.applyBtn.selected = NO;
- }
- NSMutableAttributedString *couponStr = [[NSMutableAttributedString alloc]init];
- for (int i=0; i<model.couponAry.count; i++) {
- NSDictionary *dic = model.couponAry[i];
- NSString *temStr = [NSString stringWithFormat:@"%@,%@",dic[@"title"],dic[@"code"]];
- [couponStr appendAttributedString:[[NSAttributedString alloc]initWithString:temStr]];
- if(i != model.couponAry.count-1){
- [couponStr appendAttributedString:[[NSAttributedString alloc]initWithString:@"\n"]];
- }
- }
-
- couponStr.color = [UIColor colorWithHexString:@"#B2B2B2"];
- couponStr.font = [UIFont fontWithName:Rob_Regular size:12];
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:8];//设置距离
- [couponStr addAttribute:NSParagraphStyleAttributeName
- value:paragraphStyle
- range:NSMakeRange(0, [couponStr length])];
- self.couponDesLab.attributedText = couponStr;
- }
- #pragma mark - **************** lazy ****************
- -(UIView *)bgView{
- if(!_bgView){
- _bgView = [[UIView alloc]init];
- _bgView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
- _bgView.layer.cornerRadius = 4;
- _bgView.clipsToBounds = YES;
- }
- return _bgView;
- }
- -(UILabel *)titleLab{
- if(!_titleLab){
- _titleLab = [[UILabel alloc]init];
- _titleLab.text = @"Discount Codes";
- _titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
- _titleLab.font = [UIFont fontWithName:Rob_Bold size:16];
- }
- return _titleLab;
- }
- -(UILabel *)priceLab{
- if(!_priceLab){
- _priceLab = [[UILabel alloc]init];
- _priceLab.textAlignment = NSTextAlignmentRight;
- _priceLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
- _priceLab.font = [UIFont fontWithName:Rob_Bold size:14];
- }
- return _priceLab;
- }
- -(TT_CustonTF *)codeTF{
- if(!_codeTF){
- _codeTF = [[TT_CustonTF alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20-95, 45)];
- _codeTF.placeholder = @"Enter Your Coupon Code";
- _codeTF.font = [UIFont fontWithName:Rob_Regular size:14];
- }
- return _codeTF;
- }
- -(UIButton *)applyBtn{
- if(!_applyBtn){
- _applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _applyBtn.frame = CGRectMake(0, 0, 95, 45);
- [_applyBtn setTitle:@"APPLY" forState:UIControlStateNormal];
- [self.applyBtn setTitle:@"CANCEL" forState:UIControlStateSelected];
- _applyBtn.backgroundColor = [UIColor colorWithHexString:@"#0B0B0B"];
- [_applyBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
- [_applyBtn addTarget:self action:@selector(handle_ApplyEvent:) forControlEvents:UIControlEventTouchUpInside];
- _applyBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
- _applyBtn.layer.cornerRadius = 4;
-
- }
- return _applyBtn;
- }
- -(QMUILabel *)couponDesLab{
- if(!_couponDesLab){
- _couponDesLab = [[QMUILabel alloc]init];
- _couponDesLab.numberOfLines = 0;
- _couponDesLab.font = [UIFont fontWithName:Rob_Regular size:12];
- _couponDesLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
- _couponDesLab.preferredMaxLayoutWidth =KScreenWidth-40;
- }
- return _couponDesLab;
- }
- @end
|