SurveyDetailViewController.m 12.2 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
#define BottomHeight 50
#define LeftMargin 20
#define LeftWidth 100
陈俊俊's avatar
陈俊俊 committed
16
#define LeftHeight 20
陈俊俊's avatar
陈俊俊 committed
17
#define TopMargin 15
陈俊俊's avatar
陈俊俊 committed
18
#define ContentMargin 10
n22's avatar
n22 committed
19 20 21 22 23 24

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

陈俊俊's avatar
陈俊俊 committed
25
@interface SurveyDetailViewController ()<UIAlertViewDelegate>
n22's avatar
n22 committed
26 27 28 29
{
    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
@property (nonatomic,strong)UILabel *noteLabel;
陈俊俊's avatar
陈俊俊 committed
40 41
@property (nonatomic,strong)UILabel *lefeNoteLabel;

n22's avatar
n22 committed
42 43 44 45 46 47
@end

@implementation SurveyDetailViewController

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

- (void)getDataFromServer{
n22's avatar
n22 committed
54 55 56 57 58
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        if (data) {
陈俊俊's avatar
陈俊俊 committed
59 60 61 62 63 64 65 66 67 68 69
            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
70
        }else{
陈俊俊's avatar
陈俊俊 committed
71
            [strongSelf fetchtSurveyDetail];
n22's avatar
n22 committed
72
        }
陈俊俊's avatar
陈俊俊 committed
73
        [self createResultChart];
n22's avatar
n22 committed
74 75 76 77 78 79 80 81 82
    };
    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
83 84 85 86 87 88 89
- (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"];
陈俊俊's avatar
陈俊俊 committed
90
               NSString *urlStr = [NSString stringWithFormat:@"%@/DisplayChart?filename=%@",@"http://122.224.171.126:7280/cruiser-server",dataStr];
陈俊俊's avatar
陈俊俊 committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
                [_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
106 107
- (void)fetchtSurveyDetail{
    self.billNumberLabel.text = [IBTCommon checkString:self.survey.billNumber];
n22's avatar
n22 committed
108
    if ([self.survey.state isEqualToString:SURVEY_STATE_INITIAL]) {
n22's avatar
n22 committed
109 110
        self.stateLabel.textColor = [UIColor redColor];
        self.stateLabel.text = @"未提交";
n22's avatar
n22 committed
111
    }else if ([self.survey.state isEqualToString:SURVEY_STATE_SUBMITTED]) {
n22's avatar
n22 committed
112 113
        self.stateLabel.textColor = [UIColor greenColor];
        self.stateLabel.text = @"已提交";
n22's avatar
n22 committed
114
    }else if ([self.survey.state isEqualToString:SURVEY_STATE_INSURVEY]) {
n22's avatar
n22 committed
115 116
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"调研中";
n22's avatar
n22 committed
117
    }else if ([self.survey.state isEqualToString:SURVEY_STATE_FINISHED]) {
n22's avatar
n22 committed
118 119 120 121 122 123 124
        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
125 126 127 128 129
        if (user.length == 0) {
            user = [user stringByAppendingFormat:@"%@",surveyUser.userName];
        }else{
            user = [user stringByAppendingFormat:@"、%@",surveyUser.userName];
        }
n22's avatar
n22 committed
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];
陈俊俊's avatar
陈俊俊 committed
136
    self.noteLabel.text = [NSString stringWithFormat:@"%@",self.survey.remark?self.survey.remark : @"无"];
n22's avatar
n22 committed
137
    [self setNoteHeight];
n22's avatar
n22 committed
138 139
}

n22's avatar
n22 committed
140 141


n22's avatar
n22 committed
142 143 144 145 146
#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
147
    _scrollView.backgroundColor = XXFBgColor;
n22's avatar
n22 committed
148 149 150
    [self.view addSubview:_scrollView];
    
    
陈俊俊's avatar
陈俊俊 committed
151
    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:GXF_COMMIT_COLOR];
n22's avatar
n22 committed
152 153
    [self.view addSubview:endBtn];
    
陈俊俊's avatar
陈俊俊 committed
154 155
    
    
陈俊俊's avatar
陈俊俊 committed
156
    _surveyView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, LeftHeight * 9+ ContentMargin * 10)];
n22's avatar
n22 committed
157 158 159
    _surveyView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_surveyView];
    
陈俊俊's avatar
陈俊俊 committed
160
    UILabel *tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin/2, ContentMargin, LeftWidth*2, LeftHeight)];
n22's avatar
n22 committed
161
    tagLabel.text = @"【调研内容】";
陈俊俊's avatar
陈俊俊 committed
162
    tagLabel.font =  GXF_SEVENTEENTH_SIZE;
陈俊俊's avatar
陈俊俊 committed
163
    tagLabel.textColor = HexColor(@"7ebf74");
n22's avatar
n22 committed
164 165 166 167
    [_surveyView addSubview:tagLabel];
    
    NSArray *leftArr = @[@"单号:",@"状态:",@"标题:",@"商品:",@"开始日期:",@"截止日期:",@"调研人员:",@"备注:"];
    for (NSInteger i = 0 ; i < leftArr.count; i++) {
陈俊俊's avatar
陈俊俊 committed
168
        UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin, CGRectGetMaxY(tagLabel.frame) + ContentMargin+ (LeftHeight + ContentMargin) *i, LeftWidth, LeftHeight)];
陈俊俊's avatar
陈俊俊 committed
169
        leftLabel.font = GXF_SEVENTEENTH_SIZE;
n22's avatar
n22 committed
170
        leftLabel.text = leftArr[i];
陈俊俊's avatar
陈俊俊 committed
171
        leftLabel.textColor = GXF_DETAIL_COLOR;
n22's avatar
n22 committed
172 173
        [_surveyView addSubview:leftLabel];
        
陈俊俊's avatar
陈俊俊 committed
174
        UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), CGRectGetMaxY(tagLabel.frame) + ContentMargin+ (LeftHeight + ContentMargin) *i, _surveyView.frame.size.width - LeftMargin - LeftWidth, LeftHeight)];
陈俊俊's avatar
陈俊俊 committed
175 176
        rightLabel.font = GXF_SEVENTEENTH_SIZE;
        rightLabel.textColor = GXF_DETAIL_COLOR;
n22's avatar
n22 committed
177 178 179 180 181 182 183 184 185 186 187 188 189
        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){
陈俊俊's avatar
陈俊俊 committed
190
            rightLabel.numberOfLines = 0;
n22's avatar
n22 committed
191 192
            self.userLabel = rightLabel;
        }else if(i == 7){
n22's avatar
n22 committed
193 194
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
陈俊俊's avatar
陈俊俊 committed
195
            self.lefeNoteLabel = leftLabel;
n22's avatar
n22 committed
196 197 198
        }
        [_surveyView addSubview:rightLabel];
    }
n22's avatar
n22 committed
199

n22's avatar
n22 committed
200
    
n22's avatar
n22 committed
201
    _bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_surveyView.frame) + TopMargin, ScreenSize.width, 300)];
n22's avatar
n22 committed
202 203 204
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
    
n22's avatar
n22 committed
205
    
n22's avatar
n22 committed
206 207
    UILabel *resultLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin/2, 10, LeftWidth*2, LeftHeight)];
    resultLabel.text = @"【行情反馈】";
陈俊俊's avatar
陈俊俊 committed
208
    resultLabel.font =  GXF_SEVENTEENTH_SIZE;
陈俊俊's avatar
陈俊俊 committed
209
    resultLabel.textColor = HexColor(@"7ebf74");
n22's avatar
n22 committed
210 211
    [_bottomView addSubview:resultLabel];
    
陈俊俊's avatar
陈俊俊 committed
212 213 214
    _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
215
    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
216 217
    [_bottomView addSubview:btn];
    
陈俊俊's avatar
陈俊俊 committed
218 219 220 221 222 223 224
    
    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
225

陈俊俊's avatar
陈俊俊 committed
226
    
n22's avatar
n22 committed
227 228
    
}
n22's avatar
n22 committed
229 230 231
- (void)btnClick:(UIButton *)btn{
    if (btn.tag == DetailTag) {
        ResultDetailViewController *rvc = [ResultDetailViewController new];
陈俊俊's avatar
陈俊俊 committed
232
        rvc.surveyUuid = self.surveyUuid;
n22's avatar
n22 committed
233 234
        [self PushViewController:rvc animated:YES];
    }else if (btn.tag == EndTag){
陈俊俊's avatar
陈俊俊 committed
235 236 237
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认结束" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
        alertView.delegate = self;
        [alertView show];
n22's avatar
n22 committed
238 239 240
    }
}

陈俊俊's avatar
陈俊俊 committed
241 242 243 244 245 246 247 248
#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
249
                [self backSurvey];
陈俊俊's avatar
陈俊俊 committed
250 251 252 253 254 255 256 257 258 259 260 261
            }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
262 263 264 265 266 267
    [[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
268 269
}

n22's avatar
n22 committed
270 271
- (void)setNoteHeight
{
陈俊俊's avatar
陈俊俊 committed
272 273 274 275 276 277 278
    CGFloat personHeight = [self.userLabel calculateHeight];
    
    CGRect personFrame = self.userLabel.frame;
    personFrame.size.height = personHeight;
    self.userLabel.frame = personFrame;
    
    CGFloat noteHeight =  [self.noteLabel calculateHeight];
n22's avatar
n22 committed
279 280
    
    CGRect noteFrame = self.noteLabel.frame;
陈俊俊's avatar
陈俊俊 committed
281 282
    noteFrame.size.height = noteHeight;
    noteFrame.origin.y = CGRectGetMaxY(self.userLabel.frame)+ ContentMargin;
n22's avatar
n22 committed
283 284
    self.noteLabel.frame = noteFrame;
    
陈俊俊's avatar
陈俊俊 committed
285 286 287 288 289
    CGRect leftNoteFrame = self.lefeNoteLabel.frame;
    leftNoteFrame.origin.y = CGRectGetMaxY(self.userLabel.frame)+ ContentMargin;
    self.lefeNoteLabel.frame = leftNoteFrame;
    
    CGFloat totalHeight = noteHeight + (LeftHeight * 7+ ContentMargin*10) + personHeight;
n22's avatar
n22 committed
290 291 292 293 294 295
    CGRect surveyFrame = _surveyView.frame;
    surveyFrame.size.height = totalHeight;
    _surveyView.frame = surveyFrame;
    
    
    CGRect bottomFrame = _bottomView.frame;
陈俊俊's avatar
陈俊俊 committed
296
    bottomFrame.origin.y = CGRectGetMaxY(_surveyView.frame) + TopMargin;
n22's avatar
n22 committed
297 298
    _bottomView.frame = bottomFrame;
    
陈俊俊's avatar
陈俊俊 committed
299
    _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_bottomView.frame) + TopMargin*2);
n22's avatar
n22 committed
300 301
}

陈俊俊's avatar
陈俊俊 committed
302 303 304 305 306
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [self finishSurveyRequest];//结束
    }
}
n22's avatar
n22 committed
307 308 309 310 311

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