Files
featherVoice/QXLive/Mine(音域)/View/QXMineServiceCell.m

335 lines
12 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXMineServiceCell.m
// QXLive
//
// Created by on 2025/5/9.
//
#import "QXMineServiceCell.h"
2025-11-06 13:04:04 +08:00
2025-10-30 00:45:15 +08:00
@class QXMineServiceSubCell;
@interface QXMineServiceCell()<UICollectionViewDelegate,UICollectionViewDataSource>
2025-08-08 10:49:36 +08:00
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UILabel *titleLabel;
2025-10-30 00:45:15 +08:00
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *serviceArray;
2025-11-06 13:04:04 +08:00
@property (nonatomic,strong)NSMutableArray *moreArray;
@property (nonatomic,strong)QXServiceModel *inviteModel;
2025-12-04 14:11:00 +08:00
@property (nonatomic,strong)QXServiceModel *singerAuthModel;
@property (nonatomic,strong)QXServiceModel *songListModel;
2025-08-08 10:49:36 +08:00
@end
@implementation QXMineServiceCell
+(instancetype)cellWithTableView:(UITableView *)tableView{
static NSString *cellId = @"QXMineServiceCell";
QXMineServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[QXMineServiceCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
}
return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
[self createViews];
}
return self;
}
-(void)createViews{
self.bgView = [[UIView alloc] init];
2025-11-06 13:04:04 +08:00
self.bgView.backgroundColor = RGB16(0x231F2C);
2025-08-08 10:49:36 +08:00
[self.bgView addRoundedCornersWithRadius:10];
[self.contentView addSubview:self.bgView];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.right.mas_equalTo(-16);
2025-11-06 13:04:04 +08:00
make.top.mas_equalTo(6);
make.bottom.mas_equalTo(-6);
2025-08-08 10:49:36 +08:00
}];
self.titleLabel = [[UILabel alloc] init];
2025-11-06 13:04:04 +08:00
self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
self.titleLabel.textColor = RGB16(0x929196);
2025-08-08 10:49:36 +08:00
self.titleLabel.text = QXText(@"更多服务");
[self.bgView addSubview:self.titleLabel];;
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.mas_equalTo(12);
make.right.mas_equalTo(-12);
2025-11-06 13:04:04 +08:00
make.height.mas_equalTo(16);
2025-08-08 10:49:36 +08:00
}];
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
NSInteger maxCount = 4;
2025-10-30 00:45:15 +08:00
CGFloat btnWith = (int)(SCREEN_WIDTH-32-1)/maxCount;
2025-08-08 10:49:36 +08:00
CGFloat btnHeight = 44;
2025-10-30 00:45:15 +08:00
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(btnWith, btnHeight);
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 0;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerClass:[QXMineServiceSubCell class] forCellWithReuseIdentifier:@"QXMineServiceSubCell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
2025-11-06 13:04:04 +08:00
self.collectionView.scrollEnabled = NO;
2025-10-30 00:45:15 +08:00
self.collectionView.backgroundColor = UIColor.clearColor;
[self.bgView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.bgView);
2025-11-06 13:04:04 +08:00
make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
make.bottom.mas_equalTo(-12);
2025-10-30 00:45:15 +08:00
}];
// for (int i = 0; i < self.serviceArray.count; i++) {
// NSInteger col = i / maxCount;
// NSInteger line = i % maxCount;
// UIButton *btn = [[UIButton alloc] init];
// [self.bgView addSubview:btn];
// [btn setTitle:self.serviceArray[i] forState:(UIControlStateNormal)];
// [btn setTitleColor:[UIColor clearColor] forState:(UIControlStateNormal)];
// [btn addTarget:self action:@selector(serviceClick:) forControlEvents:(UIControlEventTouchUpInside)];
// [btn mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.mas_equalTo(line*btnWith);
// make.top.equalTo(self.titleLabel.mas_bottom).offset(13+col*(btnHeight+13));
// make.height.mas_equalTo(btnHeight);
// make.width.mas_equalTo(btnWith);
// }];
//
//
//
// }
2025-08-08 10:49:36 +08:00
}
2025-11-06 13:04:04 +08:00
-(void)setIsMore:(BOOL)isMore{
_isMore = isMore;
self.titleLabel.text = isMore?@"更多":@"常用服务";
if (isMore) {
if ([self.moreArray containsObject:self.inviteModel]) {
2025-12-04 14:11:00 +08:00
}else{
if (QXGlobal.shareGlobal.isOpenRecharge) {
[self.moreArray insertObject:self.inviteModel atIndex:1];
}
2025-11-06 13:04:04 +08:00
}
2025-12-04 14:11:00 +08:00
if (self.singerIsAuth) {
if ([self.moreArray containsObject:self.singerAuthModel]) {
[self.moreArray removeObject:self.singerAuthModel];
}
if ([self.moreArray containsObject:self.songListModel]) {
}else{
NSInteger index = self.moreArray.count-1;
[self.moreArray insertObject:self.songListModel atIndex:index];
}
}else{
if ([self.moreArray containsObject:self.songListModel]) {
[self.moreArray removeObject:self.songListModel];
}
if ([self.moreArray containsObject:self.singerAuthModel]) {
}else{
NSInteger index = self.moreArray.count-1;
[self.moreArray insertObject:self.singerAuthModel atIndex:index];
}
2025-11-06 13:04:04 +08:00
}
2025-08-08 10:49:36 +08:00
}
2025-11-21 16:17:05 +08:00
[self.collectionView reloadData];
2025-08-08 10:49:36 +08:00
}
2025-12-04 14:11:00 +08:00
-(void)setSingerIsAuth:(BOOL)singerIsAuth{
_singerIsAuth = singerIsAuth;
}
2025-10-30 00:45:15 +08:00
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
2025-11-06 13:04:04 +08:00
return self.isMore?self.moreArray.count:self.serviceArray.count;
2025-10-30 00:45:15 +08:00
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXMineServiceSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMineServiceSubCell" forIndexPath:indexPath];
2025-11-06 13:04:04 +08:00
QXServiceModel *model = self.isMore?self.moreArray[indexPath.row]:self.serviceArray[indexPath.row];
cell.model = model;
2025-10-30 00:45:15 +08:00
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
2025-11-06 13:04:04 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickServiceWithType:)]) {
QXServiceModel *model = self.isMore?self.moreArray[indexPath.row]:self.serviceArray[indexPath.row];
[self.delegate didClickServiceWithType:model.type];
2025-10-30 00:45:15 +08:00
}
}
-(void)cellReload{
2025-11-03 09:55:25 +08:00
// if (QXGlobal.shareGlobal.isOpenRecharge){
// if ([self.serviceArray containsObject:QXText(@"每日任务")]) {
// return;
// }
// [self.serviceArray addObject:QXText(@"每日任务")];
// [self.serviceImageArray addObject:@"service_task"];
// [self.collectionView reloadData];
// }
2025-10-30 00:45:15 +08:00
}
-(NSMutableArray *)serviceArray{
2025-08-08 10:49:36 +08:00
if (!_serviceArray) {
2025-11-06 13:04:04 +08:00
QXServiceModel *md1 = [[QXServiceModel alloc] init];
md1.title = @"等级";
md1.icon = @"service_level";
md1.type = QXMineServiceTypeLevel;
QXServiceModel *md2 = [[QXServiceModel alloc] init];
md2.title = @"个性装扮";
md2.icon = @"service_dress";
md2.type = QXMineServiceTypeDress;
QXServiceModel *md3 = [[QXServiceModel alloc] init];
md3.title = @"我的背包";
md3.icon = @"service_bag";
md3.type = QXMineServiceTypeBackpack;
2025-12-04 14:11:00 +08:00
QXServiceModel *md4 = [[QXServiceModel alloc] init];
md4.title = @"家族";
md4.icon = @"service_my_family";
md4.type = QXMineServiceTypeFamily;
2025-11-06 13:04:04 +08:00
2025-10-30 00:45:15 +08:00
_serviceArray = [NSMutableArray arrayWithArray:@[
2025-12-04 14:11:00 +08:00
md4,
2025-11-06 13:04:04 +08:00
md1,
md2,
md3,
2025-10-30 00:45:15 +08:00
]];
2025-08-08 10:49:36 +08:00
}
return _serviceArray;
}
2025-11-06 13:04:04 +08:00
-(NSMutableArray *)moreArray{
if (!_moreArray) {
QXServiceModel *md1 = [[QXServiceModel alloc] init];
md1.title = @"帮助中心";
md1.icon = @"service_help";
md1.type = QXMineServiceTypeHelp;
QXServiceModel *md2 = [[QXServiceModel alloc] init];
md2.title = @"每日任务";
md2.icon = @"service_task";
md2.type = QXMineServiceTypeDayTask;
QXServiceModel *md3 = [[QXServiceModel alloc] init];
md3.title = @"意见反馈";
2025-11-11 17:19:21 +08:00
md3.icon = @"service_report";
2025-11-06 13:04:04 +08:00
md3.type = QXMineServiceTypeReport;
QXServiceModel *md4 = [[QXServiceModel alloc] init];
md4.title = @"个税客服";
md4.icon = @"service_customer_service";
md4.type = QXMineServiceTypeCustomerService;
2025-12-04 14:11:00 +08:00
// QXServiceModel *md5 = [[QXServiceModel alloc] init];
// md5.title = @"歌手认证";
// md5.icon = @"service_singer_auth";
// md5.type = QXMineServiceTypeSingerAuth;
//
// QXServiceModel *md6 = [[QXServiceModel alloc] init];
// md6.title = @"我的歌单";
// md6.icon = @"service_songlist";
// md6.type = QXMineServiceTypeSongList;
2025-11-21 16:17:05 +08:00
2025-12-04 14:11:00 +08:00
QXServiceModel *md7 = [[QXServiceModel alloc] init];
md7.title = @"设置";
md7.icon = @"service_setting";
md7.type = QXMineServiceTypeSetting;
2025-11-21 16:17:05 +08:00
2025-11-06 13:04:04 +08:00
_moreArray = [NSMutableArray arrayWithArray:@[
md1,
md2,
md3,
md4,
2025-12-04 14:11:00 +08:00
// md5,
// md6,
md7
2025-10-30 00:45:15 +08:00
]];
2025-08-08 10:49:36 +08:00
}
2025-11-06 13:04:04 +08:00
return _moreArray;
}
-(QXServiceModel *)inviteModel{
if (!_inviteModel) {
_inviteModel = [[QXServiceModel alloc] init];
_inviteModel.title = @"邀请";
_inviteModel.icon = @"service_invite";
_inviteModel.type = QXMineServiceTypeInvite;
}
return _inviteModel;
2025-08-08 10:49:36 +08:00
}
2025-12-04 14:11:00 +08:00
-(QXServiceModel *)singerAuthModel{
if (!_singerAuthModel) {
_singerAuthModel = [[QXServiceModel alloc] init];
_singerAuthModel.title = @"歌手认证";
_singerAuthModel.icon = @"service_singer_auth";
_singerAuthModel.type = QXMineServiceTypeSingerAuth;
}
return _singerAuthModel;
}
-(QXServiceModel *)songListModel{
if (!_songListModel) {
_songListModel = [[QXServiceModel alloc] init];
_songListModel.title = @"我的歌单";
_songListModel.icon = @"service_songlist";
_songListModel.type = QXMineServiceTypeSongList;
}
return _songListModel;
}
2025-08-08 10:49:36 +08:00
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
2025-10-30 00:45:15 +08:00
@implementation QXMineServiceSubCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
2025-11-06 13:04:04 +08:00
-(void)setModel:(QXServiceModel *)model{
_model = model;
self.imageView.image = [UIImage imageNamed:model.icon];
self.titleLabel.text = model.title;
}
2025-10-30 00:45:15 +08:00
-(void)initSubviews{
UIImageView *imageView = [[UIImageView alloc] init];
[self.contentView addSubview:imageView];
self.imageView = imageView;
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.centerX.equalTo(self.contentView);
2025-11-06 13:04:04 +08:00
make.height.width.mas_equalTo(ScaleWidth(24));
2025-10-30 00:45:15 +08:00
}];
UILabel *titleLabel = [[UILabel alloc] init];
2025-11-06 13:04:04 +08:00
titleLabel.textColor = RGB16(0x929196);
2025-10-30 00:45:15 +08:00
titleLabel.font = [UIFont systemFontOfSize:12];
[self.contentView addSubview:titleLabel];
self.titleLabel = titleLabel;
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(imageView.mas_bottom).offset(3);
make.centerX.equalTo(self.contentView);
make.height.mas_equalTo(17);
}];
}
@end