// // QXDayTaskTopView.m // QXLive // // Created by 启星 on 2025/5/26. // #import "QXDayTaskTopView.h" #import "QXDayTaskRuleView.h" #import "QXMineNetwork.h" @interface QXDayTaskTopView() @property (nonatomic,strong)UIImageView *topImageView; @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UIButton *ruleBtn; @property (nonatomic,strong)QXDayTaskTopSubView *leftBoxView; @property (nonatomic,strong)QXDayTaskTopSubView *rightBoxView; @end @implementation QXDayTaskTopView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ self.topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"day_task_top"]]; [self addSubview:self.topImageView]; self.topImageView.frame = CGRectMake(0, 0, self.width, ScaleWidth(187)); self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScaleWidth(25), ScaleWidth(22), 250, 21)]; self.titleLabel.textColor = [UIColor whiteColor]; self.titleLabel.font = [UIFont systemFontOfSize:14]; [self addSubview:self.titleLabel]; self.ruleBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-25, 0, 25, 50)]; [self.ruleBtn setTitle:QXText(@"任务规则") forState:(UIControlStateNormal)]; self.ruleBtn.titleLabel.numberOfLines = 0; [self.ruleBtn addRoundedCornersWithRadius:8 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft)]; [self.ruleBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)]; self.ruleBtn.titleLabel.font = [UIFont systemFontOfSize:12]; self.ruleBtn.backgroundColor = RGB16(0xEA927E); [self.ruleBtn addTarget:self action:@selector(ruleAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.ruleBtn]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, ScaleWidth(52), self.width, self.height-ScaleWidth(52)-12)]; [self.bgView addRoundedCornersWithRadius:16]; self.bgView.backgroundColor = [UIColor whiteColor]; [self addSubview:self.bgView]; CGFloat boxWidth = (self.width-16*3)/2; self.leftBoxView = [[QXDayTaskTopSubView alloc] initWithFrame:CGRectMake(16, 16, boxWidth, self.bgView.height-16*2)]; [self.leftBoxView addRoundedCornersWithRadius:8]; self.leftBoxView.backgroundColor = RGB16(0xFCE4ED); self.leftBoxView.type = QXDayTaskTopSubViewTypeLeft; [self.bgView addSubview:self.leftBoxView]; self.rightBoxView = [[QXDayTaskTopSubView alloc] initWithFrame:CGRectMake(self.leftBoxView.right+16, 16, boxWidth, self.leftBoxView.height) ]; self.rightBoxView.backgroundColor = RGB16(0xFDE8AE); [self.rightBoxView addRoundedCornersWithRadius:8]; self.rightBoxView.type = QXDayTaskTopSubViewTypeRight; [self.bgView addSubview:self.rightBoxView]; // self.leftBoxView.progress = 0.4; // self.rightBoxView.progress = 1; // self.titleLabel.text = [NSString stringWithFormat:@"%@:%@",QXText(@"今日累计获得金币"),@"20"]; } -(void)setModel:(QXDayTaskModel *)model{ _model = model; self.titleLabel.text = [NSString stringWithFormat:@"%@:%@",QXText(@"今日累计充值金币"),model.user_gold]; self.leftBoxView.boxModel = model.gift_box_list.firstObject; self.rightBoxView.boxModel = model.gift_box_list.lastObject; } -(void)ruleAction{ QXDayTaskRuleView *ruleView = [[QXDayTaskRuleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; [self.viewController.view addSubview:ruleView]; } @end @implementation QXDayTaskTopSubView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, self.width-20, 24)]; self.titleLabel.font = [UIFont boldSystemFontOfSize:16]; self.titleLabel.textColor = RGB16(0xE24171); self.titleLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:self.titleLabel]; self.subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.titleLabel.bottom, self.width-20, 18)]; self.subTitleLabel.font = [UIFont systemFontOfSize:12]; self.subTitleLabel.textColor = RGB16(0x999999); self.subTitleLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:self.subTitleLabel]; self.iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"day_task_left"]]; self.iconImageView.frame = CGRectMake((self.width-ScaleWidth(60))/2, self.subTitleLabel.bottom, ScaleWidth(60), ScaleWidth(60)); [self addSubview:self.iconImageView]; self.cornLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.iconImageView.bottom, self.width-20, 18)]; self.cornLabel.font = [UIFont systemFontOfSize:12]; self.cornLabel.textColor = RGB16(0x999999); self.cornLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:self.cornLabel]; self.openBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width-ScaleWidth(80))/2, self.height-30-ScaleWidth(10), ScaleWidth(80), 30)]; [self.openBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0xf8b6a8)] forState:(UIControlStateDisabled)]; [self.openBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0xff512c)] forState:(UIControlStateNormal)]; [self.openBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0xf8b6a8)] forState:(UIControlStateSelected)]; [self.openBtn setTitle:QXText(@"未解锁") forState:(UIControlStateDisabled)]; [self.openBtn setTitle:QXText(@"已领取") forState:(UIControlStateSelected)]; [self.openBtn setTitle:QXText(@"已解锁") forState:(UIControlStateNormal)]; [self.openBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)]; self.openBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.openBtn addTarget:self action:@selector(openAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.openBtn addRoundedCornersWithRadius:15]; self.openBtn.enabled = NO; [self addSubview:self.openBtn]; self.progressView = [[QXProgressView alloc] initWithFrame:CGRectMake((self.width-ScaleWidth(70))/2, self.openBtn.top-4-13, ScaleWidth(70), 13)]; self.progressView.bgColor = RGB16(0xFFB8CD); self.progressView.progressColor = RGB16(0xE24272); self.progressView.progressTitleColor = RGB16(0xE24272); [self addSubview:self.progressView]; // self.titleLabel.text = @"初级礼盒"; // self.subTitleLabel.text = @"最高可获得1000金币"; // self.cornLabel.text = @"满200金币"; } -(void)setBoxModel:(QXGiftBoxModel *)boxModel{ _boxModel = boxModel; self.titleLabel.text = boxModel.name; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:boxModel.title]; [attr yy_setColor:RGB16(0xE24171) range:[boxModel.title rangeOfString:boxModel.highest_gain]]; self.subTitleLabel.attributedText = attr; if (boxModel.icon.length > 0 && ([boxModel.icon hasPrefix:@"http"] || [boxModel.icon hasPrefix:@"https"])) { [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:boxModel.icon]]; } self.cornLabel.text = [NSString stringWithFormat:@"满%@金币",boxModel.meet]; self.progressView.progress = boxModel.unlock_progress.doubleValue; if (boxModel.status.intValue == 0) { self.openBtn.enabled = NO; }else if (boxModel.status.intValue == 1) { self.openBtn.selected = NO; self.openBtn.enabled = YES; }else{ self.openBtn.enabled = YES; self.openBtn.selected = YES; } } -(void)openAction{ if (self.openBtn.selected == NO && self.openBtn.enabled == YES) { MJWeakSelf [QXMineNetwork openDayTaskGiftWithGiftBoxId:self.boxModel.id successBlock:^(NSString * _Nonnull giftName) { weakSelf.boxModel.status = @"2"; weakSelf.openBtn.enabled = YES; weakSelf.openBtn.selected = YES; showToast(giftName); } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); }]; } } -(void)setProgress:(double)progress{ _progress = progress; self.progressView.progress = progress; if (progress >= 1) { self.openBtn.enabled = YES; }else{ self.openBtn.enabled = NO; } } -(void)setType:(QXDayTaskTopSubViewType)type{ _type = type; switch (type) { case QXDayTaskTopSubViewTypeLeft:{ self.iconImageView.image = [UIImage imageNamed:@"day_task_left"]; self.progressView.bgColor = RGB16(0xFFB8CD); self.progressView.progressColor = RGB16(0xE24272); self.progressView.progressTitleColor = RGB16(0xE24272); } break; case QXDayTaskTopSubViewTypeRight:{ self.iconImageView.image = [UIImage imageNamed:@"day_task_right"]; self.progressView.bgColor = RGB16(0xFFCFB3); self.progressView.progressColor = RGB16(0xF35F07); self.progressView.progressTitleColor = RGB16(0xF35F07); } break; default: break; } } @end