Files
yinmeng-ios/xplan-ios/Main/Room/View/SendRedPacket/Cell/XPOpenRedPacketCell.m
2022-09-08 11:33:42 +08:00

181 lines
5.8 KiB
Objective-C

//
// XPOpenRedPacketCell.m
// xplan-ios
//
// Created by GreenLand on 2022/9/2.
//
#import "XPOpenRedPacketCell.h"
#import "ThemeColor.h"
#import <Masonry/Masonry.h>
#import "AccountInfoStorage.h"
#import "NetImageView.h"
@interface XPOpenRedPacketCell()
///头像
@property (nonatomic, strong) NetImageView *avatarView;
///用户名
@property (nonatomic, strong) UILabel *userNameLabel;
///时间
@property(nonatomic, strong) UILabel *timeLabel;
///获得红包数
@property (nonatomic, strong) UILabel *amountLabel;
///礼物图
//@property (nonatomic, strong) XYRedPacketResultGiftView *giftView;
///钻号
@property (nonatomic, strong) UIImageView *coinImageView;
///底线
@property (nonatomic, strong) UIView *lineView;
@end
@implementation XPOpenRedPacketCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self initViews];
}
return self;
}
- (void)setModel:(XPRedPacketPersonReceiveModel *)model {
_model = model;
NSString *uid = [AccountInfoStorage instance].getUid;
BOOL isMe = model.userVO.uid == uid.integerValue;
if (isMe) {
self.userNameLabel.text = @"";
self.userNameLabel.textColor = UIColorFromRGB(0xFDCD00);
} else {
NSString *name = model.userVO.nick;
if (model.userVO.nick.length > 6) {
name = [name substringToIndex:6];
name = [name stringByAppendingString:@"..."];
}
self.userNameLabel.text = name;
self.userNameLabel.textColor = UIColorFromRGB(0xFFFFFF);
}
self.avatarView.imageUrl = model.userVO.avatar;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:model.createTime/1000];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"];
self.timeLabel.text = [dateFormatter stringFromDate:date];
self.amountLabel.hidden = NO;
if (model.amount.doubleValue> 0) {
NSString *doubleString = [NSString stringWithFormat:@"%lf", model.amount.doubleValue];
NSDecimalNumber *decNumber = [NSDecimalNumber decimalNumberWithString:doubleString];
self.amountLabel.text = [NSString stringWithFormat:@"%@",decNumber.stringValue];
}else {
self.amountLabel.text = @"0";
}
}
#pragma mark - UI
- (void)initViews {
[self.contentView addSubview:self.avatarView];
[self.contentView addSubview:self.userNameLabel];
[self.contentView addSubview:self.timeLabel];
[self.contentView addSubview:self.amountLabel];
[self.contentView addSubview:self.coinImageView];
[self.contentView addSubview:self.lineView];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make){
make.height.width.mas_equalTo(30);
make.centerY.mas_equalTo(self.mas_centerY);
make.left.mas_equalTo(self.contentView.mas_left).offset(22);
}];
[self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make){
make.left.mas_equalTo(self.avatarView.mas_right).offset(6.5);
make.top.mas_equalTo(self.avatarView.mas_top).offset(2.5);
make.height.mas_equalTo(14);
}];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make){
make.left.mas_equalTo(self.avatarView.mas_right).offset(6.5);
make.bottom.mas_equalTo(self.avatarView.mas_bottom);
}];
[self.coinImageView mas_makeConstraints:^(MASConstraintMaker *make){
make.width.mas_equalTo(22);
make.height.mas_equalTo(22);
make.centerY.mas_equalTo(self.mas_centerY);
make.right.mas_equalTo(self.contentView.mas_right).offset(-22);
}];
[self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make){
make.centerY.mas_equalTo(self.mas_centerY);
make.right.mas_equalTo(self.coinImageView.mas_left).offset(-5);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make){
make.left.mas_equalTo(self.avatarView.mas_left);
make.right.mas_equalTo(self.coinImageView.mas_right);
make.height.mas_equalTo(0.5);
}];
}
#pragma mark - Lazy Load
- (NetImageView *)avatarView {
if (!_avatarView) {
_avatarView = [[NetImageView alloc] init];
_avatarView.layer.masksToBounds = YES;
_avatarView.layer.cornerRadius = 15;
_avatarView.layer.borderWidth = 1;
_avatarView.layer.borderColor = UIColorFromRGB(0xFFFFFF).CGColor;
}
return _avatarView;
}
- (UILabel *)userNameLabel {
if (!_userNameLabel) {
_userNameLabel = [[UILabel alloc] init];
_userNameLabel.text = @"获取红包用户";
_userNameLabel.numberOfLines = 1;
_userNameLabel.font = [UIFont systemFontOfSize:15];
}
return _userNameLabel;
}
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init];
_timeLabel.text = @"00/00/00 00:00";
_timeLabel.font = [UIFont systemFontOfSize:10];
_timeLabel.textColor = UIColorRGBAlpha(0xffffff, 0.5);
_timeLabel.alpha = 0.5;
}
return _timeLabel;
}
- (UILabel *)amountLabel {
if (!_amountLabel) {
_amountLabel = [[UILabel alloc] init];
_amountLabel.text = @"0钻石";
_amountLabel.textAlignment = NSTextAlignmentRight;
_amountLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightMedium];
_amountLabel.textColor = [UIColor whiteColor];
}
return _amountLabel;
}
- (UIImageView *)coinImageView {
if (!_coinImageView) {
_coinImageView = [[UIImageView alloc] init];
[_coinImageView setImage:[UIImage imageNamed:@"common_diamond"]];
}
return _coinImageView;
}
- (UIView *)lineView{
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = UIColorFromRGB(0xE2314D);
}
return _lineView;
}
@end