// // 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