// // PBPlanTaskTableViewCell.m // IphoneBIMe // // Created by ZhangJF on 2022/8/24. // Copyright © 2022 ProBIM. All rights reserved. // #import "PBPlanTaskTableViewCell.h" #import "PBImageCollectionViewCell.h" #import "PBTaskScheduleModel.h" #import "PBSchedulePlanModel.h" static NSString *const cellID = @"cellID"; @interface PBPlanTaskTableViewCell() @property (nonatomic, weak) UILabel *chooseTaskL; //所选任务 @property (nonatomic, weak) UILabel *planTimeL; //计划时间 @property (nonatomic, weak) UILabel *statusL; //任务状态 @property (nonatomic, weak) UILabel *reasonL; @property (nonatomic, weak) UIView *reasonLBgView; @property (nonatomic, weak) UITextView *textView; @property (nonatomic, weak) UILabel *promptL; @property (nonatomic, weak) UILabel *compalte; @property (nonatomic, weak) UILabel *planProportionL; //计划比例 @property (nonatomic, weak) UILabel *GrandProportionL; //累计比例 @property (nonatomic, weak) UITextField *todayTF; //今日 @property (nonatomic, weak) UITextField *tomTF; //明日 @property (nonatomic, weak) UILabel *taskNameL; //@property (nonatomic, strong) UIToolbar *kbToolbar; @end @implementation PBPlanTaskTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupUI]; } return self; } - (void)setupUI { UIButton *deleteBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"delete_task"]]; [deleteBtn addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:deleteBtn]; [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(6); make.left.equalTo(self.contentView).offset(12); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; UILabel *taskNameL = [UILabel z_labelWithText:@"任务1" Color:[UIColor z_colorWithR:95 G:158 B:249] isBold:YES Font:14]; [self.contentView addSubview:taskNameL]; [taskNameL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(deleteBtn); make.left.equalTo(deleteBtn.mas_right).offset(8); }]; UIButton *chooseTask = [[UIButton alloc] init]; [chooseTask addTarget:self action:@selector(chooseTask) forControlEvents:UIControlEventTouchUpInside]; chooseTask.layer.cornerRadius = 4; chooseTask.layer.borderWidth = 1.f; chooseTask.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; [self.contentView addSubview:chooseTask]; [chooseTask mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(deleteBtn.mas_bottom).offset(6); make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.height.equalTo(@44); }]; UILabel *chooseTaskL = [UILabel z_labelWithText:@"请选择" Color:[UIColor z_colorWithR:174 G:174 B:174] isBold:NO Font:14]; [self.contentView addSubview:chooseTaskL]; [chooseTaskL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(chooseTask).offset(12); make.right.equalTo(chooseTask).offset(-44); make.centerY.equalTo(chooseTask); }]; UIImageView *chooseImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chooseTask_icon"]]; [self.contentView addSubview:chooseImageV]; [chooseImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(chooseTask).offset(18); make.right.equalTo(chooseTask).offset(-14); make.size.mas_equalTo(CGSizeMake(12, 10)); }]; UILabel *planTime = [UILabel z_labelWithText:@"计划时间" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:planTime]; [planTime mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(chooseTask.mas_bottom).offset(16); make.left.equalTo(chooseTask); }]; UILabel *planTimeL = [UILabel z_labelWithText:@"2022-04-30 ~ 2022-11-29" Color:[UIColor z_colorWithR:174 G:174 B:174] isBold:NO Font:14]; [self.contentView addSubview:planTimeL]; [planTimeL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(planTime.mas_bottom).offset(6); make.left.equalTo(planTime).offset(12); make.right.equalTo(chooseTask); make.height.equalTo(@44); }]; UILabel *status = [UILabel z_labelWithText:@"任务状态: " Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:status]; [status mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(planTimeL.mas_bottom).offset(16); make.left.equalTo(chooseTask); make.height.equalTo(@44); }]; UILabel *statusL = [UILabel z_labelWithText:@"滞后" Color:[UIColor z_colorWithR:255 G:107 B:80] isBold:YES Font:14]; [self.contentView addSubview:statusL]; [statusL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.equalTo(status); make.left.equalTo(status.mas_right).offset(12); }]; UILabel *reasonL = [UILabel z_labelWithText:@"滞后原因及措施" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:reasonL]; [reasonL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(statusL.mas_bottom).offset(16); make.left.equalTo(chooseTask); }]; UIView *reasonLBgView = [[UIView alloc] init]; reasonLBgView.backgroundColor = [UIColor whiteColor]; [self.contentView addSubview:reasonLBgView]; [reasonLBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(reasonL.mas_bottom).offset(6); make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.height.equalTo(@81); }]; reasonLBgView.layer.cornerRadius = 4; reasonLBgView.layer.borderWidth = 1; reasonLBgView.layer.borderColor = PBColor(108, 108, 108).CGColor; UITextView *textView = [[UITextView alloc] init]; textView.textColor= PBColor(40, 58, 79); textView.font = [UIFont boldSystemFontOfSize:15]; // [textView becomeFirstResponder]; textView.delegate = self; // textView.text = _text; [reasonLBgView addSubview:textView]; [textView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(reasonLBgView).offset(12); make.left.equalTo(reasonLBgView).offset(12); make.right.equalTo(reasonLBgView).offset(-12); make.bottom.equalTo(reasonLBgView).offset(-12); }]; // textView.inputAccessoryView = self.kbToolbar; UILabel *promptL= [UILabel z_labelWithText:@"请输入" Color:PBColor(97, 111, 125) isBold:YES Font:15]; [reasonLBgView addSubview:promptL]; [promptL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(textView).offset(8); make.left.equalTo(textView).offset(6); }]; UILabel *compalte = [UILabel z_labelWithText:@"完成比例" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:compalte]; [compalte mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(statusL.mas_bottom).offset(16); make.left.equalTo(chooseTask); }]; UIView *PlanBgV = [[UIView alloc] init]; PlanBgV.backgroundColor = PBColor(243, 243, 243); PlanBgV.layer.cornerRadius = 4; PlanBgV.layer.borderWidth = 1.f; PlanBgV.layer.borderColor = PBColor(108, 108, 108).CGColor; [self.contentView addSubview:PlanBgV]; [PlanBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(compalte.mas_bottom).offset(16); make.left.equalTo(compalte).offset(44); make.size.mas_equalTo(CGSizeMake(112, 88)); make.bottom.equalTo(self.contentView).offset(-20); }]; UIView *planBgLine = [[UIView alloc] init]; planBgLine.backgroundColor = PBColor(51, 51, 51); [self.contentView addSubview:planBgLine]; [planBgLine mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(PlanBgV).offset(43); make.height.equalTo(@2); make.left.right.equalTo(PlanBgV); }]; UILabel *planL = [UILabel z_labelWithText:@"计划: " Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:planL]; [planL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(PlanBgV).offset(14); make.left.equalTo(compalte); }]; UILabel *grandL = [UILabel z_labelWithText:@"累计: " Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:grandL]; [grandL mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(PlanBgV).offset(-14); make.left.equalTo(compalte); }]; UILabel *todayL = [UILabel z_labelWithText:@"今日: " Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:todayL]; [todayL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(planL); make.left.equalTo(PlanBgV.mas_right).offset(35); }]; UILabel *tomL = [UILabel z_labelWithText:@"明日: " Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:tomL]; [tomL mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(grandL); make.left.equalTo(todayL); }]; UIView *actualBgV = [[UIView alloc] init]; actualBgV.layer.cornerRadius = 4; actualBgV.layer.borderWidth = 1.f; actualBgV.layer.borderColor = PBColor(108, 108, 108).CGColor; [self.contentView addSubview:actualBgV]; [actualBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(PlanBgV); make.left.equalTo(PlanBgV.mas_right).offset(81); make.size.mas_equalTo(CGSizeMake(112, 88)); }]; UIView *actualBgLine = [[UIView alloc] init]; actualBgLine.backgroundColor = PBColor(51, 51, 51); [self.contentView addSubview:actualBgLine]; [actualBgLine mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(actualBgV).offset(43); make.height.equalTo(@2); make.left.right.equalTo(actualBgV); }]; UILabel *planProportionL = [UILabel z_labelWithText:@"" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:16]; planProportionL.text = @"60%"; [self.contentView addSubview:planProportionL]; [planProportionL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(PlanBgV); make.bottom.equalTo(planBgLine.mas_top); make.left.equalTo(PlanBgV).offset(12); make.right.equalTo(PlanBgV).offset(-28); }]; UILabel *planunitL = [UILabel z_labelWithText:@"%" Color:[UIColor z_colorWithR:108 G:108 B:108] isBold:YES Font:14]; [self.contentView addSubview:planunitL]; [planunitL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(planL); make.right.equalTo(PlanBgV).offset(-12); }]; UILabel *GrandProportionL = [UILabel z_labelWithText:@"" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:16]; GrandProportionL.text = @"80%"; [self.contentView addSubview:GrandProportionL]; [GrandProportionL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(planBgLine.mas_bottom); make.bottom.equalTo(PlanBgV); make.left.equalTo(PlanBgV).offset(12); make.right.equalTo(PlanBgV).offset(-28); }]; UILabel *GrandunitL = [UILabel z_labelWithText:@"%" Color:[UIColor z_colorWithR:108 G:108 B:108] isBold:YES Font:14]; [self.contentView addSubview:GrandunitL]; [GrandunitL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(grandL); make.right.equalTo(PlanBgV).offset(-12); }]; UITextField *todayTF = [[UITextField alloc] init]; todayTF.placeholder = @"请输入"; todayTF.textAlignment= NSTextAlignmentLeft; todayTF.textColor = PBColor(40, 58, 79); todayTF.font = [UIFont fontWithName:Coarse size:16.0]; todayTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; todayTF.delegate = self; // todayTF.returnKeyType = UIReturnKeyDone; [self.contentView addSubview:todayTF]; [todayTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(actualBgV); make.bottom.equalTo(actualBgLine.mas_top); make.left.equalTo(actualBgV).offset(12); make.right.equalTo(actualBgV).offset(-28); }]; UILabel *unitL = [UILabel z_labelWithText:@"%" Color:[UIColor z_colorWithR:108 G:108 B:108] isBold:YES Font:14]; [self.contentView addSubview:unitL]; [unitL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(todayL); make.right.equalTo(actualBgV).offset(-12); }]; UITextField *tomTF = [[UITextField alloc] init]; tomTF.placeholder = @"请输入"; tomTF.textAlignment= NSTextAlignmentLeft; tomTF.textColor = PBColor(40, 58, 79); tomTF.font = [UIFont fontWithName:Coarse size:16.0]; tomTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; // todayTF.delegate = self; // todayTF.returnKeyType = UIReturnKeyDone; tomTF.delegate = self; [self.contentView addSubview:tomTF]; [tomTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(actualBgLine.mas_bottom); make.bottom.equalTo(actualBgV); make.left.equalTo(actualBgV).offset(12); make.right.equalTo(actualBgV).offset(-28); }]; UILabel *tomunitL = [UILabel z_labelWithText:@"%" Color:[UIColor z_colorWithR:108 G:108 B:108] isBold:YES Font:14]; [self.contentView addSubview:tomunitL]; [tomunitL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(tomL); make.right.equalTo(actualBgV).offset(-12); }]; self.chooseTaskL = chooseTaskL; self.planTimeL = planTimeL; self.statusL = statusL; self.reasonL = reasonL; self.reasonLBgView = reasonLBgView; self.textView = textView; self.promptL = promptL; self.compalte = compalte; self.planProportionL = planProportionL; self.GrandProportionL = GrandProportionL; self.todayTF = todayTF; self.tomTF = tomTF; self.taskNameL = taskNameL; // self.todayTF.inputAccessoryView = self.kbToolbar; // self.tomTF.inputAccessoryView = self.kbToolbar; } - (void)chooseTask { if (self.ChooseTaskBlock) { self.ChooseTaskBlock(); } } - (void)deleteAction { if (self.DeleteBlock) { self.DeleteBlock(); } } - (void)setTaskScheduleModel:(PBTaskScheduleModel *)taskScheduleModel { _taskScheduleModel = taskScheduleModel; if (taskScheduleModel.Progress_Name == nil) { self.chooseTaskL.textColor = PBColor(174, 174, 174); self.chooseTaskL.text = @"请选择"; }else { self.chooseTaskL.textColor = PBColor(51, 51, 51); self.chooseTaskL.text = taskScheduleModel.Progress_Name; } if (taskScheduleModel.Progress_planstarttime != nil && taskScheduleModel.Progress_plannendtime != nil) { self.planTimeL.text = [NSString stringWithFormat:@"%@ ~ %@", taskScheduleModel.Progress_planstarttime, taskScheduleModel.Progress_plannendtime]; }else { self.planTimeL.text = @"请先选择任务"; } if ([taskScheduleModel.Progress_state isEqualToString:@"滞后"]) { self.reasonL.hidden = NO; self.reasonLBgView.hidden = NO; self.textView.hidden = NO; self.promptL.hidden = NO; self.textView.text = taskScheduleModel.Progress_MobileReason; if (self.textView.text.length == 0) { self.promptL.hidden = NO; }else { self.promptL.hidden = YES; } [self.compalte mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.statusL.mas_bottom).offset(146); }]; }else { self.reasonL.hidden = YES; self.reasonLBgView.hidden = YES; self.textView.hidden = YES; self.promptL.hidden = YES; taskScheduleModel.Progress_MobileReason = @""; self.textView.text = taskScheduleModel.Progress_MobileReason; self.promptL.hidden = NO; [self.compalte mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.statusL.mas_bottom).offset(16); }]; } self.statusL.text = taskScheduleModel.Progress_state; self.planProportionL.text = taskScheduleModel.Progress_planratio; self.GrandProportionL.text = taskScheduleModel.Progress_MobileAddratio == nil? @"0": taskScheduleModel.Progress_MobileAddratio; self.todayTF.text = taskScheduleModel.Progress_actualratio; self.tomTF.text = taskScheduleModel.Progress_MobileTomorrowratio; } - (void)setTaskIndex:(NSInteger)taskIndex { _taskIndex = taskIndex; self.taskNameL.text = [NSString stringWithFormat:@"任务%zd",taskIndex]; } //- (UIToolbar *) kbToolbar { // if (_kbToolbar == nil) { // _kbToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 44)]; // UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(closeKeyboard)]; // _kbToolbar.items = @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], doneItem]; // } // return _kbToolbar; //} //- (void)closeKeyboard { // [self endEditing:YES]; //} #pragma mark - UITextFieldDelegate - (void)textFieldDidEndEditing:(UITextField *)textField{ if (textField == self.todayTF){ self.taskScheduleModel.Progress_actualratio = textField.text; NSInteger added = [self.taskScheduleModel.MobileAddratio integerValue]; NSInteger total = [self.taskScheduleModel.Progress_actualratio integerValue]; self.taskScheduleModel.Progress_MobileAddratio = [NSString stringWithFormat:@"%zd",added + total]; self.GrandProportionL.text = [NSString stringWithFormat:@"%@", self.taskScheduleModel.Progress_MobileAddratio]; }else { self.taskScheduleModel.Progress_MobileTomorrowratio = textField.text; } } #pragma mark - UITextViewDelegate - (void)textViewDidChange:(UITextView *)textView{ if (textView.text.length == 0) { self.promptL.hidden = NO; }else { self.promptL.hidden = YES; } self.taskScheduleModel.Progress_MobileReason = textView.text; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end