zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  PBProjectInfoView.m
//  IphoneBIMe
//
//  Created by zjf on 2020/5/25.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBProjectInfoView.h"
#import "PBProjectModel.h"
@interface PBProjectInfoView()
@property (nonatomic, weak) UILabel *projectNameL;
@property (nonatomic, weak) UIImageView *privacyImageV;
@property (nonatomic, weak) UIImageView *dataIamgeV;
@property (nonatomic, weak) UILabel *dataL;
@property (nonatomic, weak) UIView *linV;
@property (nonatomic, weak) UILabel *companyL;
@property (nonatomic, weak) UILabel *managerL;
@property (nonatomic, weak) UIButton * collectionBtn;
@property (nonatomic, weak) UILabel *collectionL;
@property (nonatomic, weak) UIButton *intoProjectBtn;
@end
@implementation PBProjectInfoView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
 
- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    UIButton *barBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"bar"]];
    [barBtn addTarget:self action:@selector(barSelectAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:barBtn];
    [barBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(2);
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(28, 20));
    }];
    
    UILabel *projectNameL = [UILabel z_labelWithText:@"塔里木油田试用项目" Color:PBColor(40, 58, 79) isBold:YES Font:18];
    [self addSubview:projectNameL];
    [projectNameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(26);
        make.left.equalTo(self).offset(15);
        make.height.equalTo(@24);
        make.right.equalTo(self.mas_right).offset(-60);
    }];
    
    UIButton *packupBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"arrow"]];
    [packupBtn addTarget:self action:@selector(packupBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:packupBtn];
    [packupBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(projectNameL);
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.right.equalTo(self).offset(-16);
    }];
 
    UIImageView *dataIamgeV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"time"]];
    [self addSubview:dataIamgeV];
    [dataIamgeV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(projectNameL.mas_bottom).offset(12);
        make.left.equalTo(self).offset(15);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    UILabel *dataL = [UILabel z_labelWithText:@"2020年12月23日 到期" Color:PBColor(166, 174, 182) isBold:YES Font:13];
    [self addSubview:dataL];
    [dataL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(dataIamgeV);
        make.left.equalTo(dataIamgeV.mas_right).offset(8);
        make.height.equalTo(@16);
    }];
 
    UIView *linV = [[UIView alloc] init];
    linV.backgroundColor = PBColor(244, 21, 21);
    [self addSubview:linV];
    [linV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(dataL);
        make.left.equalTo(dataL);
        make.right.equalTo(dataL);
        make.height.equalTo(@1);
    }];
    UIImageView *privacyImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"public"]];
    [self addSubview:privacyImageV];
    [privacyImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 20));
        make.top.equalTo(dataL.mas_bottom).offset(11);
        make.right.equalTo(self).offset(-15);
    }];
    UILabel *managerL = [UILabel z_labelWithText:@"薛友松" Color:PBColor(166, 174, 182) isBold:YES Font:13];
    [self addSubview:managerL];
    [managerL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dataIamgeV.mas_bottom).offset(12);
        make.left.equalTo(self.mas_right).offset(-142);
        make.right.equalTo(privacyImageV.mas_left).offset(-20);
        make.height.equalTo(@18);
    }];
    UIImageView *separatedImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"l"]];
    [self addSubview:separatedImageV];
    [separatedImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(managerL);
        make.right.equalTo(managerL.mas_left).offset(-10);
        make.size.mas_equalTo(CGSizeMake(2, 10));
    }];
    
    UILabel *companyL = [UILabel z_labelWithText:@"北京东晨工元科技发展有限公司" Color:PBColor(166, 174, 182) isBold:YES Font:13];
    [self addSubview:companyL];
    [companyL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dataIamgeV.mas_bottom).offset(12);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(separatedImageV.mas_left).offset(-10);
        make.height.equalTo(@18);
    }];
    UIImageView *bottomLin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"line"]];
    [self addSubview:bottomLin];
    [bottomLin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(companyL.mas_bottom).offset(12);
        make.left.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-10);
        make.height.equalTo(@1);
    }];
    
    UIButton * collectionBtn = [UIButton z_bgNormalImage:[UIImage imageNamed:@"star"] bgSelectedImage:[UIImage imageNamed:@"star_fill"]];
    [collectionBtn addTarget:self action:@selector(collectionAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:collectionBtn];
    [collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.top.equalTo(bottomLin.mas_bottom).offset(19);
        make.left.equalTo(self).offset(25);
    }];
    
    UILabel *collectionL = [UILabel z_labelWithText:@"收藏" Color:PBColor(40, 58, 79) isBold:YES Font:13];
    [self addSubview:collectionL];
    [collectionL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(collectionBtn.mas_right).offset(8);
        make.centerY.equalTo(collectionBtn);
    }];
    UIButton *intoProjectBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"goitm"]];
    [intoProjectBtn addTarget:self action:@selector(intoProjectAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:intoProjectBtn];
    [intoProjectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(companyL.mas_bottom).offset(23);
        make.right.equalTo(self).offset(-25);
        make.size.mas_equalTo(CGSizeMake(142, 41));
    }];
    
    self.projectNameL = projectNameL;
    self.dataIamgeV = dataIamgeV;
    self.dataL = dataL;
    self.companyL = companyL;
    self.managerL = managerL;
    self.collectionBtn = collectionBtn;
    self.collectionL = collectionL;
    self.intoProjectBtn = intoProjectBtn;
    self.linV = linV;
    self.privacyImageV = privacyImageV;
}
- (void)barSelectAction:(UIButton *)sender {
    
}
- (void)intoProjectAction {
    if (self.IntoProjectBlock) {
        self.IntoProjectBlock(self.projectModel);
    }
}
- (void)collectionAction:(UIButton *)sender {
    [YJProgressHUD showProgress:@"" inView:self];
    NSString *flag = @"";
    if (!sender.selected) {
        flag = @"1";
    }
    [[PBNetworkTools sharedTools] editFavoriteWithOrganizeId:self.projectModel.organizeid andAddOrRm:flag andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
            [YJProgressHUD showMessage:@"收藏失败" inView:self];
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        NSLog(@"%@",str);
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1) {
            [YJProgressHUD hide];
            sender.selected = !sender.selected;
            if (sender.selected) {
                self.collectionL.text = @"已收藏";
                self.collectionL.textColor = PBColor(0, 122, 255);
                self.projectModel.isFavorite = YES;
            }else {
                self.collectionL.text = @"收藏";
                self.collectionL.textColor = PBColor(40, 58, 79);
                self.projectModel.isFavorite = NO;
            }
            if (self.SetCollectionState) {
                self.SetCollectionState(self.projectModel);
            }
        }else {
            [YJProgressHUD showMessage:@"收藏失败" inView:self];
        }
    }];
}
- (void)packupBtnAction {
    if (self.packupBlock) {
        self.packupBlock();
    }
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
    self.projectNameL.text = projectModel.fullname;
    if ([projectModel.com_FullName isEqualToString:@""] || projectModel.com_FullName == nil) {
        self.companyL.text = @"<无隶属单位>";
    }else {
        self.companyL.text = projectModel.com_FullName;
    }
    if ([projectModel.endTime isEqualToString:@""] || projectModel.endTime == nil) {
        self.dataIamgeV.image = [UIImage imageNamed:@"time"];
        self.dataL.text = @"<未定义到期日期>";
        self.dataL.textColor = PBColor(97, 111, 125);
        self.linV.hidden = YES;
    }else {
        NSRange tRange = [projectModel.endTime rangeOfString:@" "];
        NSString *endTime = [projectModel.endTime substringToIndex:tRange.location];
        self.dataL.text = [NSString stringWithFormat:@"%@ 到期",endTime];
        NSInteger num = [self compareWithDate:endTime];
        if (num == 1) {
            self.dataIamgeV.image = [UIImage imageNamed:@"time_1"];
            self.dataL.textColor = PBColor(244, 21, 21);
            self.linV.hidden = NO;
        }else {
            self.dataIamgeV.image = [UIImage imageNamed:@"time"];
            self.dataL.textColor = PBColor(97, 111, 125);
            self.linV.hidden = YES;
        }
    }
    self.managerL.text = projectModel.manager;
    if (projectModel.ispublic) {
        self.privacyImageV.image = [UIImage imageNamed:@"public"];
    }else {
        self.privacyImageV.image = [UIImage imageNamed:@"unpublic"];
    }
    if (projectModel.isFavorite) {
        self.collectionBtn.selected = YES;
        self.collectionL.text = @"已收藏";
        self.collectionL.textColor = PBColor(0, 122, 255);
    }else {
        self.collectionBtn.selected = NO;
        self.collectionL.text = @"收藏";
        self.collectionL.textColor = PBColor(40, 58, 79);
    }
}
//比较时间大小
- (NSInteger)compareWithDate:(NSString*)bDate{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString*aDate = [formatter stringFromDate:[NSDate date]];
    NSDateFormatter *dateformater = [[NSDateFormatter alloc] init];
    [dateformater setDateFormat:@"yyyy-MM-dd"];
    NSDate*dta = [[NSDate alloc]init];
    NSDate*dtb = [[NSDate alloc]init];
    dta = [dateformater dateFromString:aDate];
    dtb = [dateformater dateFromString:bDate];
    NSComparisonResult result = [dta compare:dtb];
    if (result == NSOrderedDescending) {
    //指定时间 已过期
       return 1;
    }else if(result == NSOrderedAscending){
    //指定时间 没过期
       return -1;
    }else{
    //刚好时间一样.
       return 0;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
 
@end