ResultDetailViewController.m 4.75 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  ResultDetailViewController.m
//  XFFruit
//
//  Created by n22 on 15/8/7.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "ResultDetailViewController.h"
#import "SurveyResult.h"
#import "SurveyResultCell.h"
n22's avatar
n22 committed
12
#import "ResultView.h"
n22's avatar
n22 committed
13

n22's avatar
n22 committed
14
#define TableHeight 150
n22's avatar
n22 committed
15 16
#define BeginTag 6000
@interface ResultDetailViewController ()<UITableViewDataSource,UITableViewDelegate,ResultViewDelegate>
n22's avatar
n22 committed
17 18 19
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
n22's avatar
n22 committed
20
    ResultView *_resultView;
n22's avatar
n22 committed
21 22 23 24 25 26 27
}
@end

@implementation ResultDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
28
    self.title = @"行情反馈列表";
n22's avatar
n22 committed
29 30 31 32 33 34
    [self initData];
    [self createTableView];
}

- (void)initData{
    _dataArr = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
35
    
n22's avatar
n22 committed
36
    __weak typeof(self)weakSelf = self;
陈俊俊's avatar
陈俊俊 committed
37 38
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
n22's avatar
n22 committed
39 40
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf fetchtSurveyResultList:data];
陈俊俊's avatar
陈俊俊 committed
41 42 43 44 45 46 47 48 49
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    
    [[ICRHTTPController sharedController] getResultsWithUuid:self.surveyUuid success:succ failure:fail];

n22's avatar
n22 committed
50 51
    for (NSInteger i = 0; i < 4; i++) {
        SurveyResult *survey = [[SurveyResult alloc]init];
陈俊俊's avatar
陈俊俊 committed
52
        survey.unit = @"南汇8424西瓜调研情况";
n22's avatar
n22 committed
53 54 55 56
        survey.place = @"150605000001";
        survey.price = @"南汇842[100213]";
        survey.capacity = @"22222222222";
        survey.quality = @"费卡接口";
陈俊俊's avatar
陈俊俊 committed
57 58
        survey.userName = @"张三";
        survey.feedbackTime = @"2015-04-05 12:04:06";
n22's avatar
n22 committed
59 60 61 62
        [_dataArr addObject:survey];
    }
}

n22's avatar
n22 committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
- (void)fetchtSurveyResultList:(id)data{
    if (data) {
        NSInteger success = [data[@"success"] integerValue];
        NSString *message  = data[@"message"] ;
        if (success == 1) {
            if (_dataArr.count > 0) {
                [_dataArr removeAllObjects];
            }
            NSArray *dataArr = data[ @"data" ];
            for (NSDictionary *surveyDict in dataArr) {
                NSDictionary *resultDict = surveyDict[@"result"];
                SurveyResult *surveyResult = [[SurveyResult alloc]init];
                [surveyResult setValuesForKeysWithDictionary:resultDict];
                [_dataArr addObject:surveyResult];
            }
            [_tableView reloadData];
        }else{
            [IBTLoadingView showTips:message];
        }
    }else{
        [IBTLoadingView showTips:@"      无记录      "];
    }
}


n22's avatar
n22 committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
- (void)createTableView{
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, 0,ScreenSize.width, ScreenSize.height - 64)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}

#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"SurveyResultCell";
    SurveyResultCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SurveyResultCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (_dataArr.count > 0) {
        SurveyResult *survey = _dataArr[indexPath.row];
        cell.surveyResult = survey;
n22's avatar
n22 committed
114 115
        cell.tag = indexPath.row + BeginTag;
        [cell.imageBtn addTarget:self action:@selector(imageClick:) forControlEvents:UIControlEventTouchUpInside];
n22's avatar
n22 committed
116 117 118 119 120 121 122
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return TableHeight;
}

n22's avatar
n22 committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
- (void)imageClick:(UIButton *)btn {
//    SurveyResult *result = _dataArr[btn.tag - BeginTag];
    //创建详情view
    if (_resultView == nil) {
        _resultView = [[ResultView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height)];
        _resultView.delegate = self;
        _resultView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [_resultView setScrollView];
        [AppWindow addSubview:_resultView];
    }
    
}

#pragma mark - resultView协议方法
- (void)clickBackButton{
    if (_resultView) {
        [_resultView removeFromSuperview];
        _resultView = nil;
    }
}

n22's avatar
n22 committed
144 145 146 147 148 149 150 151

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end