Files
featherVoice/QXLive/Mine(音域)/Controller/每日任务/QXTaskViewController.m
2025-12-17 11:44:25 +08:00

342 lines
14 KiB
Objective-C

//
// QXTaskViewController.m
// QXLive
//
// Created by 启星 on 2025/5/9.
//
#import "QXTaskViewController.h"
#import "QXDayTaskTopView.h"
#import "QXDayTaskCell.h"
#import "QXDayTaskRuleView.h"
#import "QXMineNetwork.h"
#import "QXTaskGiftRecordVC.h"
#import "QXRealNameViewController.h"
#import "QXUserHomePageViewController.h"
#import "QXGuildViewController.h"
#import "QXWithDrawBindViewController.h"
#import "QXRechargeViewcController.h"
#import "QXSignInAppView.h"
#import "QXCreatPhotosViewController.h"
#import "QXCreateRoomViewController.h"
@interface QXTaskViewController ()<UITableViewDataSource,UITableViewDelegate,QXDayTaskCellDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong)QXDayTaskTopView *topView;
@property (nonatomic,strong)UIView *bottomView;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)QXDayTaskModel *model;
@property (nonatomic,strong)QXDayTaskTypeModel *typeModel;
@property (nonatomic,strong)UIImageView *nodataView;
@end
@implementation QXTaskViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self getDayTask];
}
-(void)setNavgationItems{
[super setNavgationItems];
self.navigationItem.title = QXText(@"每日任务");
UIButton*recordBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[recordBtn setTitle:QXText(@"礼盒记录") forState:(UIControlStateNormal)];
[recordBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)];
recordBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[recordBtn addTarget:self action:@selector(recordAction) forControlEvents:(UIControlEventTouchUpInside)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:recordBtn];
}
- (void)initSubViews{
self.bgImageHidden = YES;
self.view.backgroundColor = RGB16(0xE3FAE4);
[self.view addSubview:self.topView];
self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(16, self.topView.bottom, SCREEN_WIDTH-32, SCREEN_HEIGHT-self.topView.bottom-kSafeAreaBottom)];
self.bottomView.backgroundColor = RGB16(0xffffff);
[self.bottomView addRoundedCornersWithRadius:16];
self.tableView.frame = CGRectMake(0, 48, self.bottomView.width, self.bottomView.height-48);
[self.bottomView addSubview:self.tableView];
[self.view addSubview:self.bottomView];
self.nodataView = [[UIImageView alloc] initWithFrame:self.tableView.frame];
self.nodataView.hidden = YES;
[self.bottomView addSubview:self.nodataView];
[self createTaskTypeView];
}
-(void)createTaskTypeView{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 20;
layout.sectionInset = UIEdgeInsetsMake(0, 14, 0, 16);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerClass:[QXTaskTypeCell class] forCellWithReuseIdentifier:@"QXTaskTypeCell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.bounces = NO;
self.collectionView.pagingEnabled = NO;
self.collectionView.backgroundColor = [UIColor clearColor];
[self.bottomView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.right.mas_equalTo(0);
make.height.mas_equalTo(48);
}];
}
-(void)getDayTask{
MJWeakSelf
[QXMineNetwork getDayTaskListSuccessBlock:^(QXDayTaskModel * _Nonnull model) {
weakSelf.model = model;
weakSelf.topView.model = model;
weakSelf.typeModel = model.tasks.firstObject;
if (weakSelf.typeModel) {
weakSelf.typeModel.isSelected = YES;
[weakSelf.dataArray removeAllObjects];
[weakSelf.dataArray addObjectsFromArray:weakSelf.typeModel.task_list];
[weakSelf.tableView reloadData];
}
[weakSelf.collectionView reloadData];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
-(void)recordAction{
QXTaskGiftRecordVC *vc = [[QXTaskGiftRecordVC alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
-(QXDayTaskTopView *)topView{
if (!_topView) {
_topView = [[QXDayTaskTopView alloc] initWithFrame:CGRectMake(16, NavContentHeight, SCREEN_WIDTH-32, ScaleWidth(285))];
}
return _topView;
}
-(void)didClickFinishTaskWithModel:(QXDayTaskListModel *)taskModel{
if ([taskModel.task_id isEqualToString:@"1"]) {
QXSignInAppView *signView = [[QXSignInAppView alloc] init];
[signView showInView:self.view];
return;
}
if (taskModel.task_status.intValue == 1) {
// if (taskModel.task_id.intValue == 9 || taskModel.task_id.intValue == 10) {
//// QXGlobal.shareGlobal.taskModel = self.model;
// if ([[QXGlobal shareGlobal].roomId isEqualToString:taskModel.from_id]) {
// [[QXGlobal shareGlobal] popToRoomViewController];
// }
// [[QXGlobal shareGlobal] joinRoomWithRoomId:self.model.from_id isRejoin:NO navagationController:self.viewController.navigationController];
// }
if (taskModel.jump_type.intValue == 0) {
return;
}else if (taskModel.jump_type.intValue == 1) {
QXRealNameViewController *vc = [[QXRealNameViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
return;
}else if (taskModel.jump_type.intValue == 2) {
QXCreatPhotosViewController *vc = [[QXCreatPhotosViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
return;
}else if (taskModel.jump_type.intValue == 3) {
QXWithDrawBindViewController *vc = [[QXWithDrawBindViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
return;
}else if (taskModel.jump_type.intValue == 4) {
// if (taskModel.from_id.longLongValue > 0) {
showLoadingInView(self.view);
[QXMineNetwork getRoomTaskJumpRoomWithTaskId:taskModel.task_id successBlock:^(NSString * _Nonnull roomId) {
hideLoadingInView(self.view);
if (roomId.longLongValue > 0) {
NSDictionary *dict = @{@"status":@"1",@"room_id":taskModel.from_id?:@""};
NSString *jsonStr = [dict jsonStringEncoded];
[[QXRoomMessageManager shared] sendC2CMessage:jsonStr messageType:(QXRoomMessageTypeMasterTask) userId:taskModel.student_id];
[QXGlobal.shareGlobal joinRoomWithRoomId:roomId isRejoin:NO navagationController:self.navigationController];
}else{
showToast(@"暂无此类型房间");
}
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
hideLoadingInView(self.view);
showToast(msg);
}];
// }else{
// showToast(@"暂无此类型房间");
// }
return;
}else if (taskModel.jump_type.intValue == 5) {
QXGuildViewController *vc = [[QXGuildViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
return;
}else if (taskModel.jump_type.intValue == 6) {
QXRechargeViewcController *vc = [[QXRechargeViewcController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
return;
}else if (taskModel.jump_type.intValue == 7) {
QXCreateRoomViewController *vc = [[QXCreateRoomViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
return;
}
}else if (taskModel.task_status.intValue == 2) {
MJWeakSelf
[QXMineNetwork dayTaskDrawWithTaskId:taskModel.task_id student_id:taskModel.student_id successBlock:^(NSDictionary * _Nonnull dict) {
showToast(@"领取成功");
[weakSelf getDayTask];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
}
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.model.tasks.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXTaskTypeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXTaskTypeCell" forIndexPath:indexPath];
cell.model = self.model.tasks[indexPath.row];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
QXDayTaskTypeModel *model = self.model.tasks[indexPath.row];
CGFloat itemWidth = [model.task_type_name widthForFont:[UIFont boldSystemFontOfSize:16]];
if (model.is_lock.intValue == 1) {
itemWidth += 21;
}
itemWidth += 5;
return CGSizeMake(itemWidth, 48);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXDayTaskTypeModel *model = self.model.tasks[indexPath.row];
if (model == self.typeModel) {
return;
}
if (self.typeModel) {
self.typeModel.isSelected = NO;
}
model.isSelected = YES;
self.typeModel = model;
[collectionView reloadData];
[self.dataArray removeAllObjects];
[self.dataArray addObjectsFromArray:model.task_list];
[self.tableView reloadData];
if (model.is_lock.intValue == 1) {
if ([model.task_type_name containsString:@"情侣"]) {
self.nodataView.hidden = NO;
self.nodataView.image = [UIImage imageNamed:@"task_cp_no_data"];
}else if ([model.task_type_name containsString:@"师徒"]) {
self.nodataView.hidden = NO;
self.nodataView.image = [UIImage imageNamed:@"task_master_no_data"];
}else{
self.nodataView.hidden = YES;
}
}else{
self.nodataView.hidden = YES;
}
}
#pragma mark - UITableViewDataSource,UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QXDayTaskCell *cell = [QXDayTaskCell cellWithTableView:tableView];
QXDayTaskListModel *taskModel = self.dataArray[indexPath.row];
cell.model = taskModel;
cell.delegate = self;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
QXDayTaskTypeModel *model = self.model.tasks[indexPath.section];
QXDayTaskListModel *taskModel = model.task_list[indexPath.row];
if ([taskModel.task_id isEqualToString:@"1"]) {
QXSignInAppView *signView = [[QXSignInAppView alloc] init];
[signView showInView:self.view];
return;
}
}
-(UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(16, self.topView.bottom+12, SCREEN_WIDTH-32, SCREEN_HEIGHT-self.topView.bottom-12) style:(UITableViewStylePlain)];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.backgroundColor = [UIColor clearColor];
// _tableView.estimatedRowHeight = 60;
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
if (@available(iOS 15.0, *)) {
_tableView.sectionHeaderTopPadding = 0;
} else {
// Fallback on earlier versions
}
}
return _tableView;
}
@end
@implementation QXTaskTypeCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)setModel:(QXDayTaskTypeModel *)model{
_model = model;
[self.titleBtn setTitle:model.task_type_name forState:(UIControlStateNormal)];
if (model.is_lock.intValue == 1) {
[self.titleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self);
make.right.equalTo(self.lockImageBtn.mas_left);
}];
self.lockImageBtn.hidden = NO;
}else{
self.lockImageBtn.hidden = YES;
[self.titleBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self);
make.right.equalTo(self.lockImageBtn.mas_right);
}];
}
if (model.isSelected) {
self.titleBtn.selected = YES;
self.lockImageBtn.selected = YES;
}else{
self.titleBtn.selected = NO;
self.lockImageBtn.selected = NO;
}
}
-(void)initSubviews{
self.lockImageBtn = [[UIButton alloc] init];
[self.lockImageBtn setImage:[UIImage imageNamed:@"task_lock_icon_nor"] forState:(UIControlStateNormal)];
[self.lockImageBtn setImage:[UIImage imageNamed:@"task_lock_icon_sel"] forState:(UIControlStateSelected)];
[self addSubview:self.lockImageBtn];
[self.lockImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self);
make.height.width.mas_equalTo(21);
make.centerY.equalTo(self);
}];
self.lockImageBtn.userInteractionEnabled = NO;
self.titleBtn = [[UIButton alloc] init];
[self.titleBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateSelected)];
[self.titleBtn setTitleColor:RGB16A(0x000000,0.45) forState:(UIControlStateNormal)];
self.titleBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[self addSubview:self.titleBtn];
[self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self);
make.right.equalTo(self.lockImageBtn.mas_left);
}];
self.titleBtn.userInteractionEnabled = NO;
}
@end