// // 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" @interface QXTaskViewController () @property (nonatomic,strong)QXDayTaskTopView *topView; @property (nonatomic,strong)UITableView *tableView; @property (nonatomic,strong)QXDayTaskModel *model; @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(0xD7CDFF); self.tableView.tableHeaderView = self.topView; [self.view addSubview:self.tableView]; } -(void)getDayTask{ MJWeakSelf [QXMineNetwork getDayTaskListSuccessBlock:^(QXDayTaskModel * _Nonnull model) { weakSelf.model = model; weakSelf.topView.model = model; [weakSelf.tableView 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(0, 0, SCREEN_WIDTH-32, ScaleWidth(285)+12)]; } return _topView; } #pragma mark - UITableViewDataSource,UITableViewDelegate -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ if (self.model == nil) { return 0; } return 3; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section == 0) { return self.model.tasks.daily_tasks.count; }else if(section == 1){ return self.model.tasks.daily_tasks_special.count; }else{ return self.model.tasks.usual_tasks.count; } } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ QXDayTaskCell *cell = [QXDayTaskCell cellWithTableView:tableView]; QXDayTaskListModel *model; if (indexPath.section == 0) { model = self.model.tasks.daily_tasks[indexPath.row]; }else if(indexPath.section == 1){ model = self.model.tasks.daily_tasks_special[indexPath.row]; }else{ model = self.model.tasks.usual_tasks[indexPath.row]; } cell.model = model; return cell; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-32, 35)]; header.backgroundColor = [UIColor whiteColor]; [header addRoundedCornersWithRadius:17.5 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 12, SCREEN_WIDTH-32*2, 23)]; titleLabel.font = [UIFont boldSystemFontOfSize:16]; titleLabel.textColor = QXConfig.textColor; if (section == 0) { titleLabel.text = QXText(@"每日任务"); }else if(section == 1){ titleLabel.text = QXText(@"特殊任务"); }else{ titleLabel.text = QXText(@"平台任务"); } [header addSubview:titleLabel]; return header; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 35; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-32, 35)]; footer.backgroundColor = [UIColor clearColor]; UIView *roundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-32, 25)]; roundView.backgroundColor = [UIColor whiteColor]; [roundView addRoundedCornersWithRadius:17.5 byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)]; [footer addSubview:roundView]; return footer; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 35; } -(UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(16, NavContentHeight, SCREEN_WIDTH-32, SCREEN_HEIGHT-NavContentHeight) style:(UITableViewStyleGrouped)]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.backgroundColor = [UIColor clearColor]; _tableView.rowHeight = 60; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } else { // Fallback on earlier versions } } return _tableView; } @end