287 lines
10 KiB
Objective-C
287 lines
10 KiB
Objective-C
//
|
|
// QXMineServiceCell.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/5/9.
|
|
//
|
|
|
|
#import "QXMineServiceCell.h"
|
|
|
|
@class QXMineServiceSubCell;
|
|
@interface QXMineServiceCell()<UICollectionViewDelegate,UICollectionViewDataSource>
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
@property (nonatomic,strong)NSMutableArray *serviceArray;
|
|
@property (nonatomic,strong)NSMutableArray *moreArray;
|
|
@property (nonatomic,strong)QXServiceModel *inviteModel;
|
|
@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];
|
|
self.bgView.backgroundColor = RGB16(0x231F2C);
|
|
[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);
|
|
make.top.mas_equalTo(6);
|
|
make.bottom.mas_equalTo(-6);
|
|
}];
|
|
|
|
self.titleLabel = [[UILabel alloc] init];
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
|
|
self.titleLabel.textColor = RGB16(0x929196);
|
|
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);
|
|
make.height.mas_equalTo(16);
|
|
}];
|
|
|
|
|
|
NSInteger maxCount = 4;
|
|
CGFloat btnWith = (int)(SCREEN_WIDTH-32-1)/maxCount;
|
|
CGFloat btnHeight = 44;
|
|
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;
|
|
self.collectionView.scrollEnabled = NO;
|
|
self.collectionView.backgroundColor = UIColor.clearColor;
|
|
[self.bgView addSubview:self.collectionView];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self.bgView);
|
|
make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
|
|
make.bottom.mas_equalTo(-12);
|
|
}];
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
// }];
|
|
//
|
|
//
|
|
//
|
|
// }
|
|
}
|
|
|
|
-(void)setIsMore:(BOOL)isMore{
|
|
_isMore = isMore;
|
|
self.titleLabel.text = isMore?@"更多":@"常用服务";
|
|
if (isMore) {
|
|
if ([self.moreArray containsObject:self.inviteModel]) {
|
|
return;
|
|
}
|
|
if (QXGlobal.shareGlobal.isOpenRecharge) {
|
|
[self.moreArray insertObject:self.inviteModel atIndex:1];
|
|
}
|
|
}
|
|
[self.collectionView reloadData];
|
|
}
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.isMore?self.moreArray.count:self.serviceArray.count;
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXMineServiceSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMineServiceSubCell" forIndexPath:indexPath];
|
|
QXServiceModel *model = self.isMore?self.moreArray[indexPath.row]:self.serviceArray[indexPath.row];
|
|
cell.model = model;
|
|
return cell;
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
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];
|
|
}
|
|
}
|
|
|
|
-(void)cellReload{
|
|
// if (QXGlobal.shareGlobal.isOpenRecharge){
|
|
// if ([self.serviceArray containsObject:QXText(@"每日任务")]) {
|
|
// return;
|
|
// }
|
|
// [self.serviceArray addObject:QXText(@"每日任务")];
|
|
// [self.serviceImageArray addObject:@"service_task"];
|
|
// [self.collectionView reloadData];
|
|
// }
|
|
}
|
|
-(NSMutableArray *)serviceArray{
|
|
if (!_serviceArray) {
|
|
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;
|
|
|
|
QXServiceModel *md4 = [[QXServiceModel alloc] init];
|
|
md4.title = @"设置";
|
|
md4.icon = @"service_setting";
|
|
md4.type = QXMineServiceTypeSetting;
|
|
|
|
QXServiceModel *md5 = [[QXServiceModel alloc] init];
|
|
md5.title = @"家族";
|
|
md5.icon = @"service_setting";
|
|
md5.type = QXMineServiceTypeFamily;
|
|
|
|
_serviceArray = [NSMutableArray arrayWithArray:@[
|
|
md1,
|
|
md2,
|
|
md3,
|
|
md4,
|
|
md5
|
|
]];
|
|
}
|
|
return _serviceArray;
|
|
}
|
|
-(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 = @"意见反馈";
|
|
md3.icon = @"service_report";
|
|
md3.type = QXMineServiceTypeReport;
|
|
|
|
QXServiceModel *md4 = [[QXServiceModel alloc] init];
|
|
md4.title = @"个税客服";
|
|
md4.icon = @"service_customer_service";
|
|
md4.type = QXMineServiceTypeCustomerService;
|
|
|
|
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;
|
|
|
|
_moreArray = [NSMutableArray arrayWithArray:@[
|
|
md1,
|
|
md2,
|
|
md3,
|
|
md4,
|
|
md5,
|
|
md6,
|
|
]];
|
|
}
|
|
|
|
return _moreArray;
|
|
}
|
|
-(QXServiceModel *)inviteModel{
|
|
if (!_inviteModel) {
|
|
_inviteModel = [[QXServiceModel alloc] init];
|
|
_inviteModel.title = @"邀请";
|
|
_inviteModel.icon = @"service_invite";
|
|
_inviteModel.type = QXMineServiceTypeInvite;
|
|
}
|
|
return _inviteModel;
|
|
}
|
|
- (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
|
|
|
|
|
|
@implementation QXMineServiceSubCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)setModel:(QXServiceModel *)model{
|
|
_model = model;
|
|
self.imageView.image = [UIImage imageNamed:model.icon];
|
|
self.titleLabel.text = model.title;
|
|
}
|
|
-(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);
|
|
make.height.width.mas_equalTo(ScaleWidth(24));
|
|
}];
|
|
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|
titleLabel.textColor = RGB16(0x929196);
|
|
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
|