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

#import "SurveyDetailViewController.h"
#import "ResultDetailViewController.h"
n22's avatar
n22 committed
11
#import "SurveyUser.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "UIImageView+WebCache.h"
n22's avatar
n22 committed
13 14 15 16
#define BottomHeight 50
#define LeftMargin 20
#define LeftWidth 100
#define LeftHeight 30
陈俊俊's avatar
陈俊俊 committed
17
#define TopMargin 15
n22's avatar
n22 committed
18 19 20 21 22 23 24 25 26 27 28 29


typedef enum : NSUInteger {
    DetailTag = 6000,
    EndTag,
} BtnTag;

@interface SurveyDetailViewController ()
{
    UIScrollView *_scrollView;
    UIView *_surveyView;
    UIView *_bottomView;
陈俊俊's avatar
陈俊俊 committed
30
    UIImageView *_chartImageView;
n22's avatar
n22 committed
31
}
n22's avatar
n22 committed
32 33 34 35 36 37 38
@property (nonatomic,strong)UILabel *billNumberLabel;
@property (nonatomic,strong)UILabel *stateLabel;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *productLabel;
@property (nonatomic,strong)UILabel *beginDateLabel;
@property (nonatomic,strong)UILabel *endDateLabel;
@property (nonatomic,strong)UILabel *userLabel;
n22's avatar
n22 committed
39 40 41 42 43 44 45
@property (nonatomic,strong)UILabel *noteLabel;
@end

@implementation SurveyDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
46
     self.title = @"行情调研详情";
n22's avatar
n22 committed
47
    [self bulifLayout];
陈俊俊's avatar
陈俊俊 committed
48 49 50 51
    [self getDataFromServer];
}

- (void)getDataFromServer{
n22's avatar
n22 committed
52 53 54 55 56
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        if (data) {
陈俊俊's avatar
陈俊俊 committed
57 58 59 60 61 62 63 64 65 66 67
            NSInteger success = [data[@"success"] integerValue];
            NSString *message  = data[@"message"] ;
            if (success == 1) {
                NSDictionary *dictData = data[@"data"];
                Survey *survey = [[Survey alloc]init];
                [survey setValuesForKeysWithDictionary:dictData];
                self.survey = survey;
                [strongSelf fetchtSurveyDetail];
            }else{
                [IBTLoadingView showTips:message];
            }
n22's avatar
n22 committed
68
        }else{
陈俊俊's avatar
陈俊俊 committed
69
            [strongSelf fetchtSurveyDetail];
n22's avatar
n22 committed
70
        }
陈俊俊's avatar
陈俊俊 committed
71
        [self createResultChart];
n22's avatar
n22 committed
72 73 74 75 76 77 78 79 80
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController] getResultWithSurveyUuid:self.surveyUuid success:succ failure:fail];
}

陈俊俊's avatar
陈俊俊 committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
- (void)createResultChart {
    void(^succ)(id) = ^(id data) {
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message  = data[@"message"] ;
            if (success == 1) {
                NSString *dataStr = data[@"data"];
               NSString *urlStr = [NSString stringWithFormat:@"%@/DisplayChart?filename=%@",Server_Url,dataStr];
                [_chartImageView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [[ICRHTTPController sharedController] resultChartWithResultUuid:self.surveyUuid width:[NSNumber numberWithFloat:CGRectGetWidth(_chartImageView.frame)] height:[NSNumber numberWithFloat:CGRectGetHeight(_chartImageView.frame)] success:succ failure:fail];
}



n22's avatar
n22 committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
- (void)fetchtSurveyDetail{
    self.billNumberLabel.text = [IBTCommon checkString:self.survey.billNumber];
    if ([self.survey.state isEqualToString:@"initial"]) {
        self.stateLabel.textColor = [UIColor redColor];
        self.stateLabel.text = @"未提交";
    }else if ([self.survey.state isEqualToString:@"submitted"]) {
        self.stateLabel.textColor = [UIColor greenColor];
        self.stateLabel.text = @"已提交";
    }else if ([self.survey.state isEqualToString:@"insurvey"]) {
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"调研中";
    }else if ([self.survey.state isEqualToString:@"finished"]) {
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"已完成";
    }
    NSString *user = @"";
    for (NSDictionary *userDict  in self.survey.users) {
        SurveyUser *surveyUser = [[SurveyUser alloc]init];
        [surveyUser setValuesForKeysWithDictionary:userDict];
陈俊俊's avatar
陈俊俊 committed
123 124 125 126 127
        if (user.length == 0) {
            user = [user stringByAppendingFormat:@"%@",surveyUser.userName];
        }else{
            user = [user stringByAppendingFormat:@"、%@",surveyUser.userName];
        }
n22's avatar
n22 committed
128 129 130 131 132 133 134 135
    }
    self.titleLabel.text = [IBTCommon checkString:self.survey.title];
    self.productLabel.text = [IBTCommon checkString:self.survey.productName];
    self.beginDateLabel.text = [IBTCommon checkString:self.survey.beginDate];
    self.endDateLabel.text = [IBTCommon checkString:self.survey.endDate];
    self.userLabel.text = [IBTCommon checkString:user];
    self.noteLabel.text = [IBTCommon checkString:self.survey.remark];
    [self setNoteHeight];
n22's avatar
n22 committed
136 137
}

n22's avatar
n22 committed
138 139


n22's avatar
n22 committed
140 141 142 143 144
#pragma mark - 视图初始化
- (void)bulifLayout{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
陈俊俊's avatar
陈俊俊 committed
145
    _scrollView.backgroundColor = HexColor(@"f8f8f8");
n22's avatar
n22 committed
146 147 148 149 150 151
    [self.view addSubview:_scrollView];
    
    
    UIButton *endBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin*2, 40) target:self sel:@selector(btnClick:) tag:EndTag image:nil title:@"结束" titleColor:[UIColor whiteColor] isCorner:YES corner:8 bgColor:HexColor(@"f69100")];
    [self.view addSubview:endBtn];
    
陈俊俊's avatar
陈俊俊 committed
152
    _surveyView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, LeftHeight*9+LeftMargin/2)];
n22's avatar
n22 committed
153 154 155 156 157 158
    _surveyView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_surveyView];
    
    UILabel *tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin/2, 10, LeftWidth*2, LeftHeight)];
    tagLabel.text = @"【调研内容】";
    tagLabel.font =  FontSize(17);
陈俊俊's avatar
陈俊俊 committed
159
    tagLabel.textColor = HexColor(@"7ebf74");
n22's avatar
n22 committed
160 161 162 163 164 165
    [_surveyView addSubview:tagLabel];
    
    NSArray *leftArr = @[@"单号:",@"状态:",@"标题:",@"商品:",@"开始日期:",@"截止日期:",@"调研人员:",@"备注:"];
    for (NSInteger i = 0 ; i < leftArr.count; i++) {
        UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin, CGRectGetMaxY(tagLabel.frame) + LeftHeight *i, LeftWidth, LeftHeight)];
        leftLabel.font = FontSize(17);
n22's avatar
n22 committed
166
        leftLabel.text = leftArr[i];
陈俊俊's avatar
陈俊俊 committed
167
        leftLabel.textColor = HexColor(@"888888");
n22's avatar
n22 committed
168 169 170 171
        [_surveyView addSubview:leftLabel];
        
        UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), CGRectGetMaxY(tagLabel.frame) + LeftHeight *i, _surveyView.frame.size.width - LeftMargin - LeftWidth, LeftHeight)];
        rightLabel.font = FontSize(17);
陈俊俊's avatar
陈俊俊 committed
172
        rightLabel.textColor = HexColor(@"888888");
n22's avatar
n22 committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
        if (i == 0) {
            self.billNumberLabel = rightLabel;
        }else if (i == 1) {
            self.stateLabel = rightLabel;
        }else if(i == 2){
            self.titleLabel = rightLabel;
        }else if(i == 3){
            self.productLabel = rightLabel;
        }else if(i == 4){
            self.beginDateLabel = rightLabel;
        }else if(i == 5){
            self.endDateLabel = rightLabel;
        }else if(i == 6){
            self.userLabel = rightLabel;
        }else if(i == 7){
n22's avatar
n22 committed
188 189 190 191 192
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
        }
        [_surveyView addSubview:rightLabel];
    }
n22's avatar
n22 committed
193

n22's avatar
n22 committed
194
    
n22's avatar
n22 committed
195
    _bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_surveyView.frame) + TopMargin, ScreenSize.width, 300)];
n22's avatar
n22 committed
196 197 198
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
    
n22's avatar
n22 committed
199
    
n22's avatar
n22 committed
200 201 202
    UILabel *resultLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin/2, 10, LeftWidth*2, LeftHeight)];
    resultLabel.text = @"【行情反馈】";
    resultLabel.font =  FontSize(17);
陈俊俊's avatar
陈俊俊 committed
203
    resultLabel.textColor = HexColor(@"7ebf74");
n22's avatar
n22 committed
204 205
    [_bottomView addSubview:resultLabel];
    
陈俊俊's avatar
陈俊俊 committed
206 207 208
    _chartImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(resultLabel.frame) + 10, CGRectGetWidth(_bottomView.frame) - 20, CGRectGetHeight(_bottomView.frame) - LeftHeight - 20)];
    [_bottomView addSubview:_chartImageView];
    
陈俊俊's avatar
陈俊俊 committed
209
    UIButton *btn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetWidth(_bottomView.frame) - 100, 10, 100, LeftHeight) target:self sel:@selector(btnClick:) tag:DetailTag image:nil title:@">>查看详情" titleColor:HexColor(@"7ebf74") isCorner:NO corner:0 bgColor:nil];
n22's avatar
n22 committed
210 211
    [_bottomView addSubview:btn];
    
陈俊俊's avatar
陈俊俊 committed
212 213 214 215 216 217 218
    
    if ([self.survey.state isEqualToString:@"finished"]) {
        endBtn.hidden = YES;
        CGRect scrollViewFrame = _scrollView.frame;
        scrollViewFrame.size.height = ScreenSize.height - 64;
        _scrollView.frame = scrollViewFrame;
    }
n22's avatar
n22 committed
219

陈俊俊's avatar
陈俊俊 committed
220
    
n22's avatar
n22 committed
221 222
    
}
n22's avatar
n22 committed
223 224 225
- (void)btnClick:(UIButton *)btn{
    if (btn.tag == DetailTag) {
        ResultDetailViewController *rvc = [ResultDetailViewController new];
陈俊俊's avatar
陈俊俊 committed
226
        rvc.surveyUuid = self.surveyUuid;
n22's avatar
n22 committed
227 228
        [self PushViewController:rvc animated:YES];
    }else if (btn.tag == EndTag){
陈俊俊's avatar
陈俊俊 committed
229
        [self finishSurveyRequest];
n22's avatar
n22 committed
230 231 232
    }
}

陈俊俊's avatar
陈俊俊 committed
233 234 235 236 237 238 239 240
#pragma mark - 结束行情调研
- (void)finishSurveyRequest{
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message  = data[@"message"] ;
            if (success == 1) {
n22's avatar
n22 committed
241
                [self backSurvey];
陈俊俊's avatar
陈俊俊 committed
242 243 244 245 246 247 248 249 250 251 252 253
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"返回异常"];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
n22's avatar
n22 committed
254 255 256 257 258 259
    [[ICRHTTPController sharedController] surveyFinishWithUuid:self.surveyUuid version:self.survey.version success:succ failure:fail];
}
//返回列表
- (void)backSurvey{
    [ICRUserUtil sharedInstance].needFresh = YES;
    [self PopViewControllerAnimated:YES];
陈俊俊's avatar
陈俊俊 committed
260 261
}

n22's avatar
n22 committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
- (void)setNoteHeight
{
    CGFloat height =  [self.noteLabel calculateHeight];
    
    CGRect noteFrame = self.noteLabel.frame;
    noteFrame.size.height = height;
    self.noteLabel.frame = noteFrame;
    
    CGFloat totalHeight = height + LeftHeight*9;
    CGRect surveyFrame = _surveyView.frame;
    surveyFrame.size.height = totalHeight;
    _surveyView.frame = surveyFrame;
    
    
    CGRect bottomFrame = _bottomView.frame;
陈俊俊's avatar
陈俊俊 committed
277
    bottomFrame.origin.y = CGRectGetMaxY(_surveyView.frame) + TopMargin;
n22's avatar
n22 committed
278 279
    _bottomView.frame = bottomFrame;
    
陈俊俊's avatar
陈俊俊 committed
280
    _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_bottomView.frame) + TopMargin*2);
n22's avatar
n22 committed
281 282 283 284 285 286 287
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end