// // TFFeedBackViewController.m // TFReader // // Created by 谢腾飞 on 2020/12/22. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFFeedBackViewController.h" #import "WXYZ_FeedbackSubViewController.h" #import "TFFeedBackRecordViewController.h" #import "TFFeedBackHeaderView.h" #import "TFFeedBackViewCellCell.h" #import "TFFeedBackModel.h" @interface TFFeedBackViewController () @property (nonatomic ,strong) TFFeedBackModel *feedbackModel; @property (nonatomic ,assign) NSUInteger selectIndex; // 当前选择位置 @end @implementation TFFeedBackViewController - (void)viewDidLoad { [super viewDidLoad]; [self initialize]; [self createSubviews]; [self netRequest]; } - (void)initialize { [self setNavigationBarTitle:TFLocalizedString(@"首页帮助反馈")]; self.selectIndex = 99999; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deletePhoto:) name:TF_DELETE_PHOTO object:nil]; } - (void)createSubviews { self.mainTableViewGroup.delegate = self; self.mainTableViewGroup.dataSource = self; [self.view addSubview:self.mainTableViewGroup]; WS(weakSelf) TFFeedBackHeaderView *headerView = [[TFFeedBackHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)]; headerView.leftButtonClick = ^{ [weakSelf.navigationController pushViewController:[[TFFeedBackRecordViewController alloc] init] animated:YES]; }; headerView.rightButtonClick = ^{ [weakSelf.navigationController pushViewController:[[WXYZ_FeedbackSubViewController alloc] init] animated:YES]; }; [self.mainTableViewGroup setTableHeaderView:headerView]; [self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(PUB_NAVBAR_HEIGHT); make.width.mas_equalTo(SCREEN_WIDTH); make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT); }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.feedbackModel.help_list.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.feedbackModel.help_list objectAtIndex:section].list.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TFHelpListModel *sectionModel = [self.feedbackModel.help_list objectAtIndex:indexPath.section]; TFQuestionListModel *indexModel = [sectionModel.list objectOrNilAtIndex:indexPath.row]; static NSString *cellName = @"TFFeedBackViewCellCell"; TFFeedBackViewCellCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (!cell) { cell = [[TFFeedBackViewCellCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } cell.questionModel = indexModel; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)]; view.backgroundColor = kGrayViewColor; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kHalfMargin, 0, SCREEN_WIDTH - 2 * kHalfMargin, 40)]; titleLabel.text = [self.feedbackModel.help_list objectAtIndex:section].name ? : @""; titleLabel.textColor = kGrayTextColor; titleLabel.font = kFont15; [view addSubview:titleLabel]; return view; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if (section == self.feedbackModel.help_list.count - 1) { return PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET; } return CGFLOAT_MIN; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)]; view.backgroundColor = [UIColor clearColor]; return view; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { TFFeedBackViewCellCell *cell = [self.mainTableViewGroup cellForRowAtIndexPath:indexPath]; [self.mainTableViewGroup beginUpdates]; if (cell.detailCellShowing) { [cell hiddenDetail]; } else { [cell showDetail]; } [self.mainTableViewGroup endUpdates]; } - (void)netRequest { WS(weakSelf) [TFNetworkTools POST:Answer_List parameters:nil model:TFFeedBackModel.class success:^(BOOL isSuccess, TFFeedBackModel *_Nullable t_model, TFNetworkRequestModel *requestModel) { if (isSuccess) { weakSelf.feedbackModel = t_model; [weakSelf.mainTableViewGroup reloadData]; } } failure:nil]; } - (void)deletePhoto:(NSNotification *)noti { [TFNetworkTools POST:Delete_Upload_Image parameters:@{@"image":[TFUtilsHelper formatStringWithObject:noti.object]} model:nil success:nil failure:nil]; } @end