//
//  ForumTypeViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2017/3/7.
//  Copyright © 2017年 上海勾芒科技有限公司. All rights reserved.
//

#import "ForumTypeViewController.h"
#import "ForumTypeTableViewCell.h"
#import "ForumViewController.h"

@interface ForumTypeViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) ForumTypeResponse *typeResult;

@end

@implementation ForumTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpForumTableView];
}

#pragma mark - UITableView
- (void)setUpForumTableView
{
    self.tableView.rowHeight = 90;
}

#pragma mark -加载数据
- (void)loadWebDataSource
{
    WS(weakSelf);
    [self getForumAllTypeActionCompleted:^(ForumTypeResponse *result) {
        [weakSelf endRefresh:EndRefreshNotData];
    }];
}

#pragma mark - 获取论坛项Type
- (void)getForumAllTypeActionCompleted:(void(^)(ForumTypeResponse *result))completed
{
    WS(weakSelf);
    [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(FORUMTYPS) withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
        if (RESULT(returnValue)) {
            weakSelf.typeResult = [[ForumTypeResponse alloc] initWithDictionary:RESPONSE(returnValue) error:nil];
            completed(weakSelf.typeResult);
            [weakSelf.tableView reloadData];
        }else{
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
        }
    } withFailureBlock:^(NSError *error) {
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ForumTypeTableViewCell *forumCell = [tableView dequeueReusableCellWithIdentifier:@"ForumTypeTableViewCell" forIndexPath:indexPath];
    forumCell.entity = self.typeResult.list[indexPath.row];
    return forumCell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.typeResult.list.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ForumViewController *itemCategoryVc = [ForumViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_LEARNINGCENTER];
    itemCategoryVc.typeId = [self.typeResult.list[indexPath.row] fid];
    [self pushViewController:itemCategoryVc animated:YES];
}


@end
