1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//
// SurveyDetailViewController.m
// XFFruit
//
// Created by 陈俊俊 on 15/8/7.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "SurveyDetailViewController.h"
#import "ResultDetailViewController.h"
#import "SurveyUser.h"
#import "UIImageView+WebCache.h"
#define BottomHeight 50
#define LeftMargin 20
#define LeftWidth 100
#define LeftHeight 30
#define TopMargin 15
typedef enum : NSUInteger {
DetailTag = 6000,
EndTag,
} BtnTag;
@interface SurveyDetailViewController ()
{
UIScrollView *_scrollView;
UIView *_surveyView;
UIView *_bottomView;
UIImageView *_chartImageView;
}
@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;
@property (nonatomic,strong)UILabel *noteLabel;
@end
@implementation SurveyDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"行情调研详情";
[self bulifLayout];
__weak typeof(self)weakSelf = self;
void(^succ)(id) = ^(id data) {
[IBTLoadingView hideHUDWithText:nil];
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (data) {
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];
}
}else{
[strongSelf fetchtSurveyDetail];
}
[self createResultChart];
};
void(^fail)(id) = ^(id data) {
[IBTLoadingView hideHUDWithText:nil];
[IBTLoadingView showTips:data];
};
[IBTLoadingView showProgressLabel:@"正在加载..."];
[[ICRHTTPController sharedController] getResultWithSurveyUuid:self.surveyUuid success:succ failure:fail];
}
- (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];
}
- (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];
if (user.length == 0) {
user = [user stringByAppendingFormat:@"%@",surveyUser.userName];
}else{
user = [user stringByAppendingFormat:@"、%@",surveyUser.userName];
}
}
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];
}
#pragma mark - 视图初始化
- (void)bulifLayout{
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.backgroundColor = HexColor(@"f8f8f8");
[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];
_surveyView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, LeftHeight*9+LeftMargin/2)];
_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);
tagLabel.textColor = [UIColor blueColor];
[_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);
leftLabel.text = leftArr[i];
[_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);
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){
rightLabel.numberOfLines = 0;
self.noteLabel = rightLabel;
}
[_surveyView addSubview:rightLabel];
}
_bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_surveyView.frame) + TopMargin, ScreenSize.width, 200)];
_bottomView.backgroundColor = [UIColor whiteColor];
[_scrollView addSubview:_bottomView];
UILabel *resultLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin/2, 10, LeftWidth*2, LeftHeight)];
resultLabel.text = @"【行情反馈】";
resultLabel.font = FontSize(17);
resultLabel.textColor = [UIColor blueColor];
[_bottomView addSubview:resultLabel];
_chartImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(resultLabel.frame) + 10, CGRectGetWidth(_bottomView.frame) - 20, CGRectGetHeight(_bottomView.frame) - LeftHeight - 20)];
[_bottomView addSubview:_chartImageView];
UIButton *btn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetWidth(_bottomView.frame) - 100, 10, 100, LeftHeight) target:self sel:@selector(btnClick:) tag:DetailTag image:nil title:@">>查看详情" titleColor:[UIColor blueColor] isCorner:NO corner:0 bgColor:nil];
[_bottomView addSubview:btn];
if ([self.survey.state isEqualToString:@"finished"]) {
endBtn.hidden = YES;
CGRect scrollViewFrame = _scrollView.frame;
scrollViewFrame.size.height = ScreenSize.height - 64;
_scrollView.frame = scrollViewFrame;
}
}
- (void)btnClick:(UIButton *)btn{
if (btn.tag == DetailTag) {
ResultDetailViewController *rvc = [ResultDetailViewController new];
rvc.surveyUuid = self.surveyUuid;
[self PushViewController:rvc animated:YES];
}else if (btn.tag == EndTag){
[self finishSurveyRequest];
}
}
#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) {
[self backSurvey];
}else{
[IBTLoadingView showTips:message];
}
}else{
[IBTLoadingView showTips:@"返回异常"];
}
};
void(^fail)(id) = ^(id data) {
[IBTLoadingView hideHUDWithText:nil];
[IBTLoadingView showTips:data];
};
[IBTLoadingView showProgressLabel:@"正在加载..."];
[[ICRHTTPController sharedController] surveyFinishWithUuid:self.surveyUuid version:self.survey.version success:succ failure:fail];
}
//返回列表
- (void)backSurvey{
[ICRUserUtil sharedInstance].needFresh = YES;
[self PopViewControllerAnimated:YES];
}
- (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;
bottomFrame.origin.y = CGRectGetMaxY(_surveyView.frame) + TopMargin;
_bottomView.frame = bottomFrame;
_scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_bottomView.frame) + TopMargin*2);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end