Files
peko-ios/YuMi/Modules/YMMine/View/Cell/XPGameOrdersListTableViewCell.m
2024-07-15 11:17:04 +08:00

469 lines
20 KiB
Objective-C

//
// XPGameOrdersListTableViewCell.m
// YuMi
//
// Created by P on 2024/7/9.
//
#import "XPGameOrdersListTableViewCell.h"
#import "XPMineGamePartnerInfoModel.h"
@interface XPGameOrdersListTableViewCell ()
@property (nonatomic, strong) NetImageView *avatarImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *userIDLabel;
@property (nonatomic, strong) UILabel *gameNameLabel;
@property (nonatomic, strong) UILabel *gamePriceLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *orderIDLabel;
@property (nonatomic, strong) UIButton *againButton;
@property (nonatomic, strong) UIButton *messageButton;
@end
@implementation XPGameOrdersListTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self setup];
}
return self;
}
- (void)setModel:(XPMineGameOrderRecoredModel *)model {
_model = model;
self.gameNameLabel.text = model.gameName;
self.timeLabel.text = model.orderTime;
self.orderIDLabel.text = model.orderNo;
self.gamePriceLabel.text = @(self.model.amount).stringValue;
// [self updatePriceContent];
}
- (void)setType:(NSInteger)type {
_type = type;
if (type == 0) {
self.avatarImageView.imageUrl = self.model.toAvatar;
self.nameLabel.text = self.model.toNick;
self.userIDLabel.text = @(self.model.toErBanNo).stringValue;
self.againButton.hidden = NO;
} else {
self.avatarImageView.imageUrl = self.model.fromAvatar;
self.nameLabel.text = self.model.fromNick;
self.userIDLabel.text = @(self.model.fromErBanNo).stringValue;
self.againButton.hidden = YES;
}
}
- (void)updatePriceContent {
NSTextAttachment *coinAttachment = [[NSTextAttachment alloc] init];
coinAttachment.image = kImage(@"mine_game_gold_icon");
coinAttachment.bounds = CGRectMake(4, 0.5, 9, 9);
NSAttributedString *coin = [NSAttributedString attributedStringWithAttachment:coinAttachment];
NSAttributedString *price = [[NSAttributedString alloc] initWithString:@(self.model.amount).stringValue
attributes:@{
NSFontAttributeName: self.gamePriceLabel.font,
NSForegroundColorAttributeName: self.gamePriceLabel.textColor
}];
if (isMSRTL()) {
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:price];
[mutableAttributedString insertAttributedString:coin atIndex:0];
self.gamePriceLabel.attributedText = mutableAttributedString.copy;
} else {
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:coin];
[mutableAttributedString insertAttributedString:price atIndex:0];
self.gamePriceLabel.attributedText = mutableAttributedString.copy;
}
[self.contentView layoutIfNeeded];
}
- (void)updateOrderContent {
NSTextAttachment *coinAttachment = [[NSTextAttachment alloc] init];
coinAttachment.image = kImage(@"user_card_copy_id1");
coinAttachment.bounds = CGRectMake(2, -0.5, 9, 9);
NSAttributedString *coin = [NSAttributedString attributedStringWithAttachment:coinAttachment];
NSAttributedString *price = [[NSAttributedString alloc] initWithString:self.model.orderNo
attributes:@{
NSFontAttributeName: self.orderIDLabel.font,
NSForegroundColorAttributeName: self.orderIDLabel.textColor
}];
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:coin];
[mutableAttributedString insertAttributedString:price atIndex:0];
self.orderIDLabel.attributedText = mutableAttributedString.copy;
[self.contentView layoutIfNeeded];
}
- (void)setup {
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
// UIView *shadowView = [[UIView alloc] init];
// shadowView.backgroundColor = [UIColor clearColor];
// shadowView.layer.shadowColor = [UIColor redColor].CGColor;
// shadowView.layer.shadowOpacity = 0.5;
// shadowView.layer.shadowOffset = CGSizeMake(10, 30);
// shadowView.layer.shadowRadius = 5;
// [self.contentView addSubview:shadowView];
// [shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(0);
// make.left.mas_equalTo(14);
// make.right.mas_equalTo(-14);
// make.bottom.mas_equalTo(-16);
// }];
UIView *container = [[UIView alloc] init];
container.backgroundColor = [UIColor whiteColor];
container.layer.cornerRadius = 10;
container.layer.masksToBounds = YES;
container.layer.shadowColor = UIColorFromRGB(0x272727).CGColor;
[self.contentView addSubview:container];
[container mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(14);
make.right.mas_equalTo(-14);
make.bottom.mas_equalTo(-16);
}];
[container addSubview:self.avatarImageView];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(12.5);
if (isMSRTL()) {
make.right.mas_equalTo(-9);
} else {
make.left.mas_equalTo(9);
}
make.width.height.mas_equalTo(60);
}];
UIStackView *userInfoStack = [[UIStackView alloc] init];
userInfoStack.axis = UILayoutConstraintAxisVertical;
userInfoStack.distribution = UIStackViewDistributionFill;
userInfoStack.alignment = UIStackViewAlignmentTop;
userInfoStack.spacing = 15.5;
[userInfoStack addArrangedSubview:self.nameLabel];
[userInfoStack addArrangedSubview:self.userIDLabel];
[container addSubview:userInfoStack];
[userInfoStack mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.avatarImageView).offset(13.5);
if (isMSRTL()) {
make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-12);
} else {
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(12);
}
}];
UIView *line = [[UIView alloc] init];
line.backgroundColor = UIColorFromRGB(0xf4f4f4);
[container addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(0.5);
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(14);
}];
// UIStackView *nameStack = [self horizontalStack];
// [nameStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_11")]];
// [nameStack addArrangedSubview:self.gameNameLabel];
//
UIStackView *priceStack = [self horizontalStack];
// [priceStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_12")]];
// [priceStack addArrangedSubview:self.gamePriceLabel];
UIImageView *coinIcon = [[UIImageView alloc] initWithImage:kImage(@"mine_game_gold_icon")];
coinIcon.contentMode = UIViewContentModeScaleAspectFit;
[coinIcon setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[coinIcon setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
coinIcon.frame = CGRectMake(0, 0, 10, 10);
[priceStack addArrangedSubview:self.gamePriceLabel];
[priceStack addArrangedSubview:coinIcon];
// UIStackView *orderTimeStack = [self horizontalStack];
// [orderTimeStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_13")]];
// [orderTimeStack addArrangedSubview:self.timeLabel];
//
UIStackView *orderIdStack = [self horizontalStack];
orderIdStack.spacing = 0;
// [orderIdStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_14")]];
UIImageView *copyIcon = [[UIImageView alloc] initWithImage:kImage(@"user_card_copy_id1")];
copyIcon.contentMode = UIViewContentModeScaleAspectFit;
[copyIcon setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[copyIcon setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
copyIcon.frame = CGRectMake(0, 0, 14, 14);
copyIcon.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(didTapOrderLabel)];
[copyIcon addGestureRecognizer:tap];
[orderIdStack addArrangedSubview:self.orderIDLabel];
[orderIdStack addArrangedSubview:copyIcon];
//
// UIStackView *contentStack = [[UIStackView alloc] initWithArrangedSubviews:@[
// nameStack,
// priceStack,
// orderTimeStack,
// orderIdStack
// ]];
// contentStack.axis = UILayoutConstraintAxisVertical;
// contentStack.distribution = UIStackViewDistributionFill;
// contentStack.alignment = UIStackViewAlignmentTop;
// contentStack.spacing = 8;
// [container addSubview:contentStack];
// [contentStack mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(line.mas_bottom).offset(13.5);
// if (isMSRTL()) {
// make.right.mas_equalTo(self.avatarImageView);
// make.left.mas_equalTo(container).offset(11.5 + 6);
// } else {
// make.left.mas_equalTo(self.avatarImageView);
// make.right.mas_equalTo(container).offset(-11.5 - 6);
// }
// }];
UIStackView *titleStack = [[UIStackView alloc] init];
titleStack.axis = UILayoutConstraintAxisVertical;
titleStack.distribution = UIStackViewDistributionFillEqually;
titleStack.alignment = UIStackViewAlignmentLeading;
titleStack.spacing = 15.5;
[titleStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_11")]];
[titleStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_12")]];
[titleStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_13")]];
[titleStack addArrangedSubview:[self titleLabel:YMLocalizedString(@"GameOrderContent_14")]];
[container addSubview:titleStack];
[titleStack mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(line).offset(11.5);
if (isMSRTL()) {
make.right.mas_equalTo(self.avatarImageView).offset(-11.5);
} else {
make.left.mas_equalTo(self.avatarImageView).offset(11.5);
}
}];
UIStackView *informationStack = [[UIStackView alloc] init];
informationStack.axis = UILayoutConstraintAxisVertical;
informationStack.distribution = UIStackViewDistributionFill;
informationStack.alignment = UIStackViewAlignmentLeading;
informationStack.spacing = 15.5;
[informationStack addArrangedSubview:self.gameNameLabel];
[informationStack addArrangedSubview:priceStack];
[informationStack addArrangedSubview:self.timeLabel];
[informationStack addArrangedSubview:orderIdStack];
[container addSubview:informationStack];
[informationStack mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(titleStack);
if (isMSRTL()) {
make.right.mas_equalTo(titleStack.mas_left).offset(-8);
make.left.mas_equalTo(container).offset(8);
} else {
make.left.mas_equalTo(titleStack.mas_right).offset(8);
make.right.mas_equalTo(container).offset(-8);
}
}];
UIView *line_2 = [[UIView alloc] init];
line_2.backgroundColor = UIColorFromRGB(0xF4F4F4);
[container addSubview:line_2];
[line_2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(0.5);
// make.bottom.mas_equalTo(container.mas_bottom).offset(-49);
make.top.mas_equalTo(informationStack.mas_bottom).offset(12.5);
}];
UIStackView *buttonsStack = [[UIStackView alloc] init];
buttonsStack.axis = UILayoutConstraintAxisHorizontal;
buttonsStack.distribution = UIStackViewDistributionFill;
buttonsStack.alignment = UIStackViewAlignmentCenter;
buttonsStack.spacing = 26;
[buttonsStack addArrangedSubview:self.againButton];
[buttonsStack addArrangedSubview:self.messageButton];
[container addSubview:buttonsStack];
[buttonsStack mas_makeConstraints:^(MASConstraintMaker *make) {
if (isMSRTL()) {
make.left.mas_equalTo(13);
} else {
make.right.mas_equalTo(-13);
}
make.top.mas_equalTo(line_2.mas_bottom).offset(10);
// make.bottom.mas_equalTo(container).offset(-13.5);
}];
}
- (UIStackView *)horizontalStack {
UIStackView *stack = [[UIStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 18)];
stack.axis = UILayoutConstraintAxisHorizontal;
stack.distribution = UIStackViewDistributionFill;
stack.alignment = UIStackViewAlignmentCenter;
stack.spacing = 2;
return stack;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)setIsMyOrder:(BOOL)isMyOrder {
self.againButton.hidden = !isMyOrder;
}
- (UILabel *)titleLabel:(NSString *)content {
UILabel *label = [UILabel labelInitWithText:[NSString stringWithFormat:@"%@", content]
font:kFontMedium(13)
textColor:UIColorFromRGB(0x242335)];
[label setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
[label setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
return label;
}
-(IBAction)didTapAgainButton:(id)sender {
if (self.didTapPlayAgain) {
self.didTapPlayAgain(self.model);
}
}
-(IBAction)didTapMessageButton:(id)sender {
if (self.didTapChat) {
self.didTapChat(self.model, self.type);
}
}
- (void)didTapOrderLabel {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:self.model.orderNo];
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"XPShareView0")];
}
#pragma mark -
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = 10;
_avatarImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _avatarImageView;
}
- (UILabel *)nameLabel {
if (!_nameLabel) {
_nameLabel = [UILabel labelInitWithText:@""
font:kFontMedium(14)
textColor:UIColorFromRGB(0x242335)];
}
return _nameLabel;
}
- (UILabel *)userIDLabel {
if (!_userIDLabel) {
_userIDLabel = [UILabel labelInitWithText:@""
font:kFontMedium(12)
textColor:UIColorFromRGB(0x666666)];
}
return _userIDLabel;
}
- (UILabel *)gameNameLabel {
if (!_gameNameLabel) {
_gameNameLabel = [UILabel labelInitWithText:@""
font:kFontMedium(14)
textColor:UIColorFromRGB(0x242335)];
}
return _gameNameLabel;
}
- (UILabel *)gamePriceLabel {
if (!_gamePriceLabel) {
_gamePriceLabel = [UILabel labelInitWithText:@"0"
font:kFontMedium(14)
textColor:UIColorFromRGB(0x242335)];
[_gamePriceLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_gamePriceLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _gamePriceLabel;
}
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [UILabel labelInitWithText:@""
font:kFontMedium(14)
textColor:UIColorFromRGB(0x242335)];
}
return _timeLabel;
}
- (UILabel *)orderIDLabel {
if (!_orderIDLabel) {
_orderIDLabel = [UILabel labelInitWithText:@""
font:kFontMedium(14)
textColor:UIColorFromRGB(0x242335)];
_orderIDLabel.userInteractionEnabled = YES;
_orderIDLabel.adjustsFontSizeToFitWidth = YES;
_orderIDLabel.minimumScaleFactor = 0.5;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(didTapOrderLabel)];
[_orderIDLabel addGestureRecognizer:tap];
}
return _orderIDLabel;
}
- (UIButton *)againButton {
if (!_againButton) {
_againButton = [UIButton buttonWithType:UIButtonTypeCustom];
// _againButton.frame = CGRectMake(0, 0, 65, 26);
[_againButton setTitle:YMLocalizedString(@"GameOrderContent_15") forState:UIControlStateNormal];
[_againButton addTarget:self
action:@selector(didTapAgainButton:)
forControlEvents:UIControlEventTouchUpInside];
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFED118),UIColorFromRGB(0xFDB719)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(65, 26)];
[_againButton setBackgroundImage:image forState:UIControlStateNormal];
_againButton.layer.cornerRadius = 13;
_againButton.layer.masksToBounds = YES;
[_againButton.titleLabel setFont:kFontBold(13)];
[_againButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_againButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
_againButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
_againButton.titleLabel.adjustsFontSizeToFitWidth = YES;
_againButton.titleLabel.minimumScaleFactor = 0.5; // 最小缩放比例
}
return _againButton;
}
- (UIButton *)messageButton {
if (!_messageButton) {
_messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
// _messageButton.frame = CGRectMake(0, 0, 65, 26);
[_messageButton setTitle:YMLocalizedString(@"XPMineUserInfoViewController8") forState:UIControlStateNormal];
[_messageButton addTarget:self
action:@selector(didTapMessageButton:)
forControlEvents:UIControlEventTouchUpInside];
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x70e9e7),UIColorFromRGB(0x41d4f6)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(65, 26)];
[_messageButton setBackgroundImage:image forState:UIControlStateNormal];
_messageButton.layer.cornerRadius = 13;
_messageButton.layer.masksToBounds = YES;
[_messageButton.titleLabel setFont:kFontBold(13)];
[_messageButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_messageButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
_messageButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
_messageButton.titleLabel.adjustsFontSizeToFitWidth = YES;
_messageButton.titleLabel.minimumScaleFactor = 0.5; // 最小缩放比例
}
return _messageButton;
}
@end