411 lines
17 KiB
Objective-C
411 lines
17 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"
|
||
#import "QXTaskCrystalTagView.h"
|
||
#import "JFRoomWishView.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;
|
||
@property (nonatomic,strong)QXTaskCrystalTagView *shuijingView;
|
||
|
||
@property (nonatomic,assign)NSInteger selectedInex;
|
||
@end
|
||
|
||
@implementation QXTaskViewController
|
||
|
||
- (void)viewDidLoad {
|
||
self.isNoChangeBgImage = YES;
|
||
[super viewDidLoad];
|
||
// Do any additional setup after loading the view.
|
||
self.selectedInex = 0;
|
||
}
|
||
-(void)viewWillAppear:(BOOL)animated{
|
||
[super viewWillAppear:animated];
|
||
[self.navigationController setNavigationBarHidden:NO animated:YES];
|
||
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:RGB16(0xffffff)};
|
||
[self getDayTask];
|
||
|
||
}
|
||
-(void)viewWillDisappear:(BOOL)animated{
|
||
[super viewWillDisappear:animated];
|
||
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:RGB16(0x000000)};
|
||
}
|
||
|
||
-(void)setNavgationItems{
|
||
[super setNavgationItems];
|
||
self.navigationItem.title = QXText(@"每日任务");
|
||
self.navigationTintColor = RGB16(0xffffff);
|
||
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 updateBgImage:@"app_home_bg"];
|
||
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 = [UIColor clearColor];
|
||
[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];
|
||
|
||
// self.shuijingView = [[QXTaskCrystalTagView alloc] init];
|
||
// self.shuijingView.startBlock = ^{
|
||
// [JFRoomWishView show];
|
||
// };
|
||
// [self.view addSubview:self.shuijingView];
|
||
}
|
||
-(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) {
|
||
// for (QXDayTaskTypeModel*md in model.tasks) {
|
||
// [self sortStudentsByScoreRule:md];
|
||
// }
|
||
weakSelf.model = model;
|
||
weakSelf.topView.model = model;
|
||
weakSelf.typeModel = model.tasks[weakSelf.selectedInex];
|
||
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)sortStudentsByScoreRule:(QXDayTaskTypeModel*)typeModel {
|
||
// if (typeModel.task_list.count == 0) return;
|
||
// __block NSInteger count = 0;
|
||
//// wait_draw_num
|
||
// // 自定义排序逻辑:2 > 1 > 3
|
||
// NSArray *array = [typeModel.task_list sortedArrayUsingComparator:^NSComparisonResult(QXDayTaskListModel *obj1, QXDayTaskListModel *obj2) {
|
||
// // 定义优先级:2(高) > 1(中) > 3(低)
|
||
// NSInteger priority1 = [self priorityForScore:obj1.task_status.intValue];
|
||
// NSInteger priority2 = [self priorityForScore:obj1.task_status.intValue];
|
||
// count++;
|
||
// if (priority1 > priority2) {
|
||
// return NSOrderedAscending; // obj1排在前面
|
||
// } else if (priority1 < priority2) {
|
||
// return NSOrderedDescending; // obj2排在前面
|
||
// } else {
|
||
// // 成绩相同,可以按其他条件排序(可选)
|
||
// return NSOrderedSame;
|
||
// }
|
||
// }];
|
||
// typeModel.task_list = array;
|
||
// typeModel.wait_draw_num = count;
|
||
//}
|
||
//- (NSInteger)priorityForScore:(NSInteger)score {
|
||
// // 优先级映射:2(最高) -> 3, 1(中等) -> 2, 3(最低) -> 1
|
||
// switch (score) {
|
||
// case 2: return 3; // 最高优先级
|
||
// case 1: return 2; // 中等优先级
|
||
// case 3: return 1; // 最低优先级
|
||
// default: return 0; // 异常情况
|
||
// }
|
||
//}
|
||
|
||
-(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;
|
||
}
|
||
self.selectedInex = indexPath.row;
|
||
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 = self.typeModel.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;
|
||
}
|
||
if (model.wait_reward_num>0) {
|
||
self.badgeLabel.hidden = NO;
|
||
}else{
|
||
self.badgeLabel.hidden = YES;
|
||
}
|
||
}
|
||
-(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:RGB16A(0xffffff,0.4) forState:(UIControlStateNormal)];
|
||
[self.titleBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateSelected)];
|
||
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;
|
||
|
||
self.badgeLabel = [[UILabel alloc] init];
|
||
self.badgeLabel.hidden = YES;
|
||
self.badgeLabel.backgroundColor = RGB16(0xE36C4A);
|
||
[self.badgeLabel addRoundedCornersWithRadius:4];
|
||
[self addSubview:self.badgeLabel];
|
||
[self.badgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.right.equalTo(self.titleBtn);
|
||
make.top.mas_equalTo(12);
|
||
make.width.height.mas_equalTo(8);
|
||
}];
|
||
}
|
||
|
||
@end
|