InformViewController.m 7.24 KB
//
//  InformViewController.m
//  IVTMeLive
//
//  Created by xrg on 16/5/13.
//  Copyright © 2016年 Joky. All rights reserved.
//

#import "InformViewController.h"
#import "Masonry.h"
#import "UIFont+IVTMeFont.h"
#import "UIColor+IVTMeColor.h"
#import "SVProgressHUD.h"
#import "AFNetworking.h"
#import "AFURLSessionManager.h"

//#define kINFORMURL [NSString stringWithFormat:@"%@%@",@"http://api.me.cnlive.com/",@"live/report.json"]

@interface InformViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *juBaoContentArray;
    NSInteger currentSelectedRow;
}

@property (nonatomic, strong) UITableView *informTabelView;
@property (nonatomic, retain) NSIndexPath *selectedIndexPath;


@end

@implementation InformViewController


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    juBaoContentArray = [NSArray arrayWithObjects:@"色情低俗",@"政治敏感",@"谣言",@"欺诈骗钱",@"违法(暴力恐怖、违禁品等)",@"未成年",@"其他", nil];
    currentSelectedRow = 0;
    
    [self initNavView];
    
    [self creatTableView];
    
//    _stateDic = [[NSMutableDictionary alloc] initWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"state"]];
    
//    NSInteger row =  [[[NSUserDefaults standardUserDefaults] objectForKey:@"lastRow"] integerValue];
    
//    self.selectedIndexPath = [NSIndexPath indexPathForRow:row inSection:0];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)initNavView{
    
    __unsafe_unretained typeof (self) wself = self;
    //整体背景nav view
    UIView* navBgView = [[UIView alloc] init];
    [self.view addSubview:navBgView];
    navBgView.backgroundColor = [UIColor IVTLightRedColor];
    [navBgView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(wself.view.mas_left);
        make.right.equalTo(wself.view.mas_right);
        make.top.equalTo(@0);
        make.height.equalTo(@0);
    }];
    
    
    UILabel *message = [[UILabel alloc]init];
    [navBgView addSubview:message];
    message.text =@"举报";
    message.textColor = [UIColor IVTTitleColor];
    message.font = [UIFont YXFontOfSize:19];
    [message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(navBgView.mas_centerX);
        make.top.equalTo(wself.view.mas_top).with.offset(29);
        make.size.mas_equalTo(CGSizeMake(50.0f, 19.0f));
    }];
    
    
    //背景nav 返回上级页面按钮
    UIButton* backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [navBgView addSubview:backButton];
    UIImage* navImage = [UIImage imageNamed:@"返回键全局"];
    [backButton mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(wself.view);
        make.top.equalTo(wself.view.mas_top).with.offset(18);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        
    }];
    [backButton setImage:navImage forState:UIControlStateNormal];
    backButton.imageEdgeInsets = UIEdgeInsetsMake(5,5,5,5);
    [backButton addTarget:self action:@selector(backToTopPage:) forControlEvents:UIControlEventTouchUpInside];
    

    
    
    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [navBgView addSubview:okBtn];
    [okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [okBtn setTitle:@"确定" forState:UIControlStateNormal];
    [okBtn addTarget:self action:@selector(sendInform:) forControlEvents:UIControlEventTouchUpInside];
    okBtn.titleLabel.font = [UIFont YXFontOfSize:15];
    [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(40, 15.0f));
        make.top.equalTo(navBgView.mas_top).with.offset(32);
        make.trailing.equalTo(navBgView.mas_trailing).with.offset(-10);
    }];
    
}


- (void)creatTableView
{
    _informTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,kScreenWidth ,kScreenHeight) style:UITableViewStyleGrouped];
    _informTabelView.delegate = self;
    _informTabelView.dataSource = self;
    
    _informTabelView.backgroundColor = [UIColor IVTBackgroundColor];
    [self.view addSubview:_informTabelView];
}

#pragma mark - tableview代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    if (indexPath.row == currentSelectedRow) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.textLabel.text = [juBaoContentArray objectAtIndex:indexPath.row];
    
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (currentSelectedRow != indexPath.row) {
        NSIndexPath *oldSelectedIndexPath = [NSIndexPath indexPathForRow:currentSelectedRow inSection:0];
        currentSelectedRow = indexPath.row;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:oldSelectedIndexPath,indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"请选择举报原因";
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

- (void)sendInform:(id)sender
{
//    dic = @{@"Membership_Id1":@(10016)} 

    UIImage *imagePicker = [UIImage imageNamed:@"返回键"];
    NSData *imageData = UIImageJPEGRepresentation(imagePicker, 0.4);
//    UIImage *image = [UIImage imageWithData:imageData];
        NSDictionary *dict1 = @{@"userId":@([[IVTAccountTool getUserId] intValue]),@"liveId":@([self.liveId intValue]),@"reason":juBaoContentArray[currentSelectedRow],@"type":[NSString stringWithFormat:@"%ld",(long)currentSelectedRow]};
    
//    [[IVTNetworkAPIClient sharedClient] sendReprot:imageData success:^(NSDictionary *successData) {
//        LRLog(@"~");
//    } error:^(NSDictionary *successData) {
//        LRLog(@"~");
//    } failure:^(NSError *failureError) {
//        LRLog(@"~");
//    }];
    
    [[IVTNetworkAPIClient sharedClient] sendReprot:imageData paramDict:dict1 success:^(NSDictionary *successData) {
     LRLog(@"~");
} error:^(NSDictionary *successData) {
     LRLog(@"~");
} failure:^(NSError *failureError) {
     LRLog(@"~");
}];
}



//取消按钮点击
-(void)backToTopPage:(id)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end