Files
peko-ios/YuMi/Modules/YMRoom/View/SendRedPacket/PIReceiveRedPacketSuccessView.m
2023-10-31 18:02:12 +08:00

260 lines
12 KiB
Objective-C

//
// PIReceiveRedPacketSuccessView.m
// YuMi
//
// Created by duoban on 2023/10/20.
//
#import "PIReceiveRedPacketSuccessView.h"
#import "XPOpenRedPacketCell.h"
@interface PIReceiveRedPacketSuccessView()<UITableViewDelegate, UITableViewDataSource>
///关闭
@property (nonatomic, strong) UIButton *closeBtn;
///背景
@property (nonatomic, strong) UIImageView *bgImageView;
///钻石数
@property(nonatomic,strong) UILabel *getDiamondView;
///提示
@property(nonatomic,strong) UILabel *pi_tipsView;
///发送者头像
@property (nonatomic, strong) NetImageView *sendAvatar;
///发送者昵称
@property (nonatomic, strong) UILabel *sendNickLabel;
///收到的祝福语
@property (nonatomic, strong) UILabel *sendWishLabel;
///领取个数
@property(nonatomic,strong) UILabel *openSituationLabel;
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation PIReceiveRedPacketSuccessView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
[self addSubview:self.bgImageView];
[self addSubview:self.closeBtn];
[self.bgImageView addSubview:self.getDiamondView];
[self.bgImageView addSubview:self.pi_tipsView];
[self.bgImageView addSubview:self.sendAvatar];
[self.bgImageView addSubview:self.sendNickLabel];
[self.bgImageView addSubview:self.sendWishLabel];
[self.bgImageView addSubview:self.tableView];
[self.bgImageView addSubview:self.openSituationLabel];
NSMutableAttributedString *numText = [[NSMutableAttributedString alloc]initWithString:@"0" attributes:@{NSFontAttributeName:kFontMedium(32),NSForegroundColorAttributeName:UIColorFromRGB(0xFF285C)}];
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
UIImage *iconImage = [UIImage imageNamed:@"mine_noble_center__diamond"];;
attachment.bounds = CGRectMake(0, roundf(kFontMedium(32).capHeight - iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height);
attachment.image =iconImage;
NSAttributedString * starAttribute = [NSMutableAttributedString attributedStringWithAttachment:(NSTextAttachment *)attachment];
[numText insertAttributedString:starAttribute atIndex:0];
self.getDiamondView.attributedText = numText;
}
-(void)installConstraints{
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(327));
make.height.mas_equalTo(kGetScaleWidth(466));
make.center.equalTo(self);
}];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(28));
make.trailing.equalTo(self.bgImageView.mas_trailing).mas_offset(-kGetScaleWidth(8));
make.top.equalTo(self.bgImageView.mas_top).mas_offset(kGetScaleWidth(39));
}];
[self.getDiamondView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kGetScaleWidth(34));
make.centerX.equalTo(self.bgImageView);
make.top.mas_equalTo(kGetScaleWidth(89));
}];
[self.sendNickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.bgImageView.mas_centerX).mas_offset(kGetScaleWidth(14));
make.centerY.equalTo(self.sendAvatar);
make.height.mas_equalTo(kGetScaleWidth(20));
}];
[self.sendAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(24));
make.top.mas_equalTo(kGetScaleWidth(177));
make.trailing.equalTo(self.sendNickLabel.mas_leading).mas_offset(-kGetScaleWidth(4));
}];
[self.sendWishLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.sendAvatar.mas_bottom).mas_offset(kGetScaleWidth(4));
make.height.mas_equalTo(kGetScaleWidth(20));
make.centerX.equalTo(self.bgImageView);
make.width.mas_equalTo(kGetScaleWidth(223));
}];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.sendWishLabel.mas_bottom).mas_offset(kGetScaleWidth(8));
make.width.mas_equalTo(kGetScaleWidth(223));
make.height.mas_equalTo(kGetScaleWidth(160));
make.centerX.equalTo(self.bgImageView);
}];
[self.openSituationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(60));
make.bottom.mas_equalTo(-kGetScaleWidth(54));
make.height.mas_equalTo(kGetScaleWidth(14));
}];
}
#pragma mark - tableviewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.resultModel.redEnvelopeItemVOs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
XPOpenRedPacketCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPOpenRedPacketCell class]) forIndexPath:indexPath];
XPRedPacketPersonReceiveModel *model = [self.resultModel.redEnvelopeItemVOs safeObjectAtIndex1:indexPath.row];
cell.model = model;
return cell;
}
#pragma mark - action
- (void)onCloseButtonClick:(UIButton *)sender {
if(self.delegate && [self.delegate respondsToSelector:@selector(closeedPacketSuccessView)]){
[self.delegate closeedPacketSuccessView];
}
}
-(void)setResultModel:(XPRedPacketResultModel *)resultModel{
_resultModel = resultModel;
if (_resultModel.redEnvelopeState == RedPacketState_Success) {//抢到红包
NSMutableAttributedString *numText = [[NSMutableAttributedString alloc]initWithString:_resultModel.currentUserAmount attributes:@{NSFontAttributeName:kFontMedium(32),NSForegroundColorAttributeName:UIColorFromRGB(0xFF285C)}];
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
UIImage *iconImage = [UIImage imageNamed:@"mine_noble_center__diamond"];;
attachment.bounds = CGRectMake(0, roundf(kFontMedium(32).capHeight - iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height);
attachment.image =iconImage;
NSAttributedString * starAttribute = [NSMutableAttributedString attributedStringWithAttachment:(NSTextAttachment *)attachment];
[numText insertAttributedString:starAttribute atIndex:0];
self.getDiamondView.attributedText = numText;
self.pi_tipsView.text = YMLocalizedString(@"XPReceiveRedPacketView1");
[self.pi_tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(129));
make.centerX.equalTo(self.bgImageView);
make.height.mas_equalTo(kGetScaleWidth(17));
}];
self.bgImageView.image = kImage(@"pi_red_packet_receive_success_bg");
} else if (_resultModel.redEnvelopeState == RedPacketState_Remain_Zero) {//抢光了
self.getDiamondView.hidden = YES;
self.pi_tipsView.text = YMLocalizedString(@"XPReceiveRedPacketView2");
[self.pi_tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(110));
make.centerX.equalTo(self.bgImageView);
make.height.mas_equalTo(kGetScaleWidth(17));
}];
self.bgImageView.image = kImage(@"pi_red_packet_receive_success_no_bg");
}
self.sendAvatar.imageUrl = _resultModel.redEnvelopeVO.userVO.avatar;
NSString *nick = resultModel.redEnvelopeVO.userVO.nick;
if (resultModel.redEnvelopeVO.userVO.nick.length > 6) {
nick = [NSString stringWithFormat:@"%@...", [resultModel.redEnvelopeVO.userVO.nick substringToIndex:6]];
}
nick = [NSString stringWithFormat:@"%@%@",nick,YMLocalizedString(@"XPReceiveRedPacketView8")];
self.sendWishLabel.text = _resultModel.redEnvelopeVO.message;
self.openSituationLabel.text = [NSString stringWithFormat:YMLocalizedString(@"XPReceiveRedPacketView4"), resultModel.redEnvelopeVO.pickNum, resultModel.redEnvelopeVO.totalNum];
// NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] init];
// NSMutableAttributedString *nickAttr = [[NSMutableAttributedString alloc] initWithString:nick attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xFDCD00)}];
// NSMutableAttributedString *redPacketStr = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPReceiveRedPacketView3") attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
// [attribute appendAttributedString:nickAttr];
// [attribute appendAttributedString:redPacketStr];
// self.sendNickLabel.attributedText = attribute;
// self.sendWishLabel.text = resultModel.redEnvelopeVO.message;
// self.openSituationLabel.text = [NSString stringWithFormat:YMLocalizedString(@"XPReceiveRedPacketView4"), resultModel.redEnvelopeVO.pickNum, resultModel.redEnvelopeVO.totalNum];
[self.tableView reloadData];
}
#pragma mark - 懒加载
- (UIImageView *)bgImageView {
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pi_red_packet_receive_success_bg"]];
_bgImageView.userInteractionEnabled = YES;
}
return _bgImageView;
}
- (UIButton *)closeBtn {
if (!_closeBtn) {
_closeBtn = [[UIButton alloc] init];
[_closeBtn setImage:[UIImage imageNamed:@"pi_red_packet_receive_colse"] forState:UIControlStateNormal];
[_closeBtn addTarget:self action:@selector(onCloseButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (NetImageView *)sendAvatar {
if (!_sendAvatar) {
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_sendAvatar = [[NetImageView alloc] initWithConfig:config];
_sendAvatar.layer.masksToBounds = YES;
_sendAvatar.layer.cornerRadius = kGetScaleWidth(24)/2;
_sendAvatar.layer.borderWidth = 1;
_sendAvatar.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _sendAvatar;
}
- (UIView *)sendNickLabel {
if (!_sendNickLabel) {
UILabel *label = [[UILabel alloc] init];
label.font = kFontMedium(14);
label.textColor = [UIColor whiteColor];
_sendNickLabel = label;
}
return _sendNickLabel;
}
- (UILabel *)sendWishLabel {
if (!_sendWishLabel) {
UILabel *label = [[UILabel alloc] init];
label.textAlignment = NSTextAlignmentCenter;
_sendWishLabel = label;
_sendWishLabel.font = kFontRegular(11);
_sendWishLabel.textColor = [UIColor colorWithWhite:1 alpha:0.9];
}
return _sendWishLabel;
}
- (UILabel *)pi_tipsView{
if(!_pi_tipsView){
_pi_tipsView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:UIColorFromRGB(0x767585)];
}
return _pi_tipsView;
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] init];
[_tableView registerClass:[XPOpenRedPacketCell class] forCellReuseIdentifier:NSStringFromClass([XPOpenRedPacketCell class])];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.rowHeight = kGetScaleWidth(48);
_tableView.layer.cornerRadius = kGetScaleWidth(20);
_tableView.layer.masksToBounds = YES;
_tableView.backgroundColor = UIColorFromRGB(0xE03654);
}
return _tableView;
}
- (UILabel *)getDiamondView{
if(!_getDiamondView){
_getDiamondView = [UILabel new];
}
return _getDiamondView;
}
- (UILabel *)openSituationLabel{
if(!_openSituationLabel){
_openSituationLabel = [UILabel labelInitWithText:@"" font:kFontMedium(10) textColor:[UIColor colorWithWhite:1 alpha:0.8]];
}
return _openSituationLabel;
}
@end