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
//
// InspectionResultDetailsModel.m
// patrol
//
// Created by 曹云霄 on 16/9/5.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "InspectionResultDetailsModel.h"
#define DEFAULT 17
@implementation InspectionResultDetailsModel
+ (BOOL)propertyIsOptional:(NSString *)propertyName
{
return YES;
}
+ (NSDictionary *)objectClassInArray{
return @{@"answers" : [NewAnswers class]};
}
@end
@implementation NewAnswers
+ (NSDictionary *)objectClassInArray{
return @{@"details" : [NewDetails class]};
}
+ (BOOL)propertyIsOptional:(NSString *)propertyName
{
return YES;
}
- (CGFloat)questionHeight
{
if (_questionHeight) {
return _questionHeight;
}
_questionHeight = [self calculateStringHeight:self.questionTitle size:CGSizeMake(ScreenSize.width-56-30, CGFLOAT_MAX)];
return _questionHeight;
}
- (CGFloat)remarkHeight
{
if (!self.answered) {
return 0;
}
if (_remarkHeight) {
return _remarkHeight;
}
if (!self.remark.length) {
self.remark = nil;
return 0;
}
_remarkHeight = [self calculateStringHeight:self.remark size:CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
return _remarkHeight;
}
/// DEFAULT表示默认高度
- (CGFloat)contentHeight
{
if (!self.answered) {
return DEFAULT;
}
if (_contentHeight) {
return _contentHeight;
}
switch (self.questionType) {
case kICRQestionTypeSingleSel://0单选
{
NewDetails *detail = [self.details firstObject];
_contentHeight = [self calculateStringHeight:detail.questionValue size:CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
}
break;
case kICRQestionTypeMultipleSel://1多选
{
NSMutableString *mutableString = [NSMutableString string];
for (NewDetails *detail in self.details) {
[mutableString appendString:[NSString stringWithFormat:@"%@ ",detail.stringValue]];
}
_contentHeight = [self calculateStringHeight:mutableString size:CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
}
break;
case kICRQestionTypeReply://2回复类
{
NewDetails *detail = [self.details firstObject];
_contentHeight = [self calculateStringHeight:detail.questionValue size:CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
}
break;
case kICRQestionTypeScore://3评分类
{
_contentHeight = [self calculateStringHeight:[NSString stringWithFormat:@"%@%@",self.score,@"分"] size: CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
}
break;
case kICRQestionTypeStoreInv://4库存调查类
{
NSMutableArray *tempArray = [NSMutableArray array];
for (NewDetails *detail in self.details) {
[tempArray addObject:@(detail.numberValue)];
}
NSSet *set = [NSSet setWithArray:tempArray];
//40表格高度
_contentHeight = ([set allObjects].count+1) * 40;
}
break;
case kICRQestionTypeSpeciesInv://5品类调查类
{
NSMutableArray *tempArray = [NSMutableArray array];
for (NewDetails *detail in self.details) {
[tempArray addObject:@(detail.numberValue)];
}
NSSet *set = [NSSet setWithArray:tempArray];
//40表格高度
_contentHeight = ([set allObjects].count+1) * 40;
}
break;
case kICRQestionTypeStarNum://6星数类
{
_contentHeight = DEFAULT;
}
break;
case kICRQestionTypeSingleScore://7单选打分
{
NewDetails *detail = [self.details firstObject];
_contentHeight = [self calculateStringHeight:[NSString stringWithFormat:@"%@ %@分",detail.questionValue,self.score] size: CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
}
break;
case kICRQestionTypeYesOrNO://8是非题
{
NewDetails *detail = [self.details firstObject];
_contentHeight = [self calculateStringHeight:[NSString stringWithFormat:@"%ld",detail.numberValue] size:CGSizeMake(ScreenSize.width-72-15, CGFLOAT_MAX)];
}
break;
default:
break;
}
return (_contentHeight < DEFAULT)?DEFAULT:_contentHeight;
}
- (CGFloat)resultAttachmentsHeight
{
if (!self.answered) {/// 未回答情况
return 0;
}
if (_resultAttachmentsHeight) {
return _resultAttachmentsHeight;
}
_resultAttachmentsHeight = [self calculateResultAttachmentsHeight:_resultAttachments.count lineNumber:3];
return _resultAttachmentsHeight;
}
#pragma mark - 计算字符串高度
- (CGFloat)calculateStringHeight:(NSString *)textString size:(CGSize)size
{
/// 72为左边距 15为右边距
CGFloat stringHeight = [textString boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height;
return stringHeight;
}
#pragma mark - 计算附件高度
- (CGFloat)calculateResultAttachmentsHeight:(NSInteger)arrayCount lineNumber:(NSInteger)number
{
CGFloat attachmentHeight = (ScreenSize.width-72-15-20)/3;//附件高度
CGFloat intervalWidth = 10;//附件间隔
CGFloat cellHeight = 0;
if (arrayCount == 0) {
return arrayCount;
}
if (arrayCount %number == 0) {
cellHeight += attachmentHeight * arrayCount/number + (arrayCount/number - 1) * intervalWidth;
}else if (arrayCount %number == 1){
cellHeight += attachmentHeight * (arrayCount + 2)/number + ((arrayCount + 2)/number -1) * intervalWidth;
}else{
cellHeight += attachmentHeight * (arrayCount + 1)/number + ((arrayCount + 1)/number -1) * intervalWidth;
}
return cellHeight;
}
@end
@implementation NewDetails
+ (BOOL)propertyIsOptional:(NSString *)propertyName
{
return YES;
}
@end
@implementation RealStore
@end