Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Cell/AgentMessageTableViewCell.m
2025-02-28 19:04:09 +08:00

168 lines
5.2 KiB
Objective-C

//
// AgentMessageTableViewCell.m
// YuMi
//
// Created by P on 2025/2/20.
//
#import "AgentMessageTableViewCell.h"
#import "AgentMessageModel.h"
@interface AgentMessageTableViewCell ()
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *messageLabel;
@property(nonatomic, strong) UIButton *agreeButton;
@property(nonatomic, strong) UIButton *rejectButton;
@property(nonatomic, strong) UIStackView *stackView;
@end
@implementation AgentMessageTableViewCell
- (void)initSubViews {
[super initSubViews];
self.backView.backgroundColor = [UIColor whiteColor];
[self.backView addSubview:self.titleLabel];
[self.backView addSubview:self.messageLabel];
[self.backView addSubview:self.stackView];
[self.stackView addArrangedSubview:self.rejectButton];
[self.stackView addArrangedSubview:self.agreeButton];
}
- (void)initSubViewConstraints {
[super initSubViewConstraints];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.backView);
make.top.mas_equalTo(self.backView).mas_equalTo(10);
make.height.mas_equalTo(22);
}];
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.backView);
make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_equalTo(10);
make.bottom.mas_equalTo(self.backView).offset(-40);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.backView);
make.height.mas_equalTo(30);
make.bottom.mas_equalTo(-8);
}];
[self.rejectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.width.mas_equalTo(94);
}];
[self.agreeButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.width.mas_equalTo(94);
}];
}
- (void)render:(MessageBaseModel *)message {
AgentMessageModel *model = (AgentMessageModel *)message;
switch (model.layoutType) {
case 1: {
self.agreeButton.hidden = NO;
self.rejectButton.hidden = NO;
}
break;
case 2: {
self.agreeButton.hidden = NO;
self.rejectButton.hidden = YES;
}
break;
case 3: {
self.agreeButton.hidden = YES;
self.rejectButton.hidden = NO;
}
break;
default:
break;
}
self.titleLabel.text = model.title;
self.messageLabel.text = model.content;
#if DEBUG
self.messageLabel.text = @"Agency member ID:10087 has applied to quit. Please review it within 24 hours. Otherwise, it will be resolved by the system within 24 hours.";
#endif
}
#pragma mark -
- (void)didTapAgree {
}
- (void)didTapReject {
}
#pragma mark -
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.preferredMaxLayoutWidth = CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2;
_titleLabel.textColor = UIColorFromRGB(0x313131);
_titleLabel.font = kFontSemibold(15);
}
return _titleLabel;
}
- (UILabel *)messageLabel {
if (!_messageLabel) {
_messageLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_messageLabel.textAlignment = NSTextAlignmentCenter;
_messageLabel.preferredMaxLayoutWidth = CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2;
_messageLabel.textColor = UIColorFromRGB(0x313131);
_messageLabel.font = kFontRegular(14);
_messageLabel.numberOfLines = 0;
}
return _messageLabel;
}
- (UIButton *)agreeButton {
if (!_agreeButton) {
_agreeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_agreeButton addGradientBackgroundWithColors:@[
UIColorFromRGB(0xE29030),
UIColorFromRGB(0xFCC074),
] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) cornerRadius:15];
[_agreeButton setTitle:YMLocalizedString(@"XPAnchorPKInviteView7") forState:UIControlStateNormal];
[_agreeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_agreeButton.titleLabel.font = kFontMedium(14);
[_agreeButton addTarget:self action:@selector(didTapAgree) forControlEvents:UIControlEventTouchUpInside];
}
return _agreeButton;
}
- (UIButton *)rejectButton {
if (!_rejectButton) {
_rejectButton = [UIButton buttonWithType:UIButtonTypeCustom];
_rejectButton.backgroundColor = UIColorFromRGB(0xEBEBEB);
[_rejectButton setCornerRadius:15];
[_rejectButton setTitle:YMLocalizedString(@"XPAnchorPKInviteView6") forState:UIControlStateNormal];
[_rejectButton setTitleColor:UIColorFromRGB(0x7b7b7d) forState:UIControlStateNormal];
_rejectButton.titleLabel.font = kFontMedium(14);
[_rejectButton addTarget:self action:@selector(didTapReject) forControlEvents:UIControlEventTouchUpInside];
}
return _rejectButton;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.spacing = 12;
}
return _stackView;
}
@end