// // PBSitePerTableViewCell.m // IphoneBIMe // // Created by ZhangJF on 2022/8/30. // Copyright © 2022 ProBIM. All rights reserved. // #import "PBSitePerTableViewCell.h" #import "PBSitePerModel.h" #import "PBSiteMaterialModel.h" @interface PBSitePerTableViewCell() @property (nonatomic, weak) UILabel *chooseTaskL; //所选类型 @property (nonatomic, weak) UILabel *planProportionL; //计划 //@property (nonatomic, weak) UILabel *GrandProportionL; //累计 @property (nonatomic, weak) UIButton *chooseTask;//选择工种 @property (nonatomic, weak) UITextField *todayTF; //增减 @property (nonatomic, weak) UITextField *tomTF; //现场 @property (nonatomic, weak) UILabel *taskNameL; //人员1 @property (nonatomic, weak) UILabel *typeL;//人员类别 自定义 @property (nonatomic, weak) UIView *typeBg;//类别输入背景 @property (nonatomic, weak) UITextField *typeTF;// 人员类别 @property (nonatomic, weak) UILabel *compalte; // 人员总数 //@property (nonatomic, strong) UIToolbar *kbToolbar; @property (nonatomic, weak) UILabel *planunitL; //@property (nonatomic, weak) UILabel *GrandunitL; @property (nonatomic, weak) UILabel *unitL; @property (nonatomic, weak) UILabel *tomunitL; @end @implementation PBSitePerTableViewCell - (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(choosetype) 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 *typeL = [UILabel z_labelWithText:@"人员类别" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:typeL]; [typeL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(chooseTask.mas_bottom).offset(16); make.left.equalTo(chooseTask); }]; UIView *typeBg = [[UIView alloc] init]; typeBg.layer.cornerRadius = 4; typeBg.layer.borderWidth = 1.f; typeBg.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; [self.contentView addSubview:typeBg]; [typeBg mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(typeL.mas_bottom).offset(6); make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.height.equalTo(@44); }]; UITextField *typeTF = [[UITextField alloc] init]; typeTF.placeholder = @"请输入"; typeTF.textAlignment= NSTextAlignmentLeft; typeTF.textColor = PBColor(40, 58, 79); typeTF.font = [UIFont fontWithName:Coarse size:16.0]; typeTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; typeTF.delegate = self; // todayTF.returnKeyType = UIReturnKeyDone; [self.contentView addSubview:typeTF]; [typeTF mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(typeBg).offset(12); make.right.equalTo(typeBg).offset(-12); make.height.equalTo(@44); make.centerY.equalTo(typeBg); }]; 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(typeBg.mas_bottom).offset(16); make.left.equalTo(chooseTask); }]; UILabel *todayNum = [UILabel z_labelWithText:@"今日数量" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:todayNum]; [todayNum mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(compalte); make.right.equalTo(self.contentView).offset(-114); }]; 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.mas_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.centerY.equalTo(PlanBgV); 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(PlanBgV).offset(14); 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(PlanBgV).offset(-14); 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]; [self.contentView addSubview:planProportionL]; [planProportionL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(PlanBgV); 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.centerY.equalTo(PlanBgV); make.right.equalTo(PlanBgV).offset(-12); }]; // UILabel *GrandProportionL = [UILabel z_labelWithText:@"" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:16]; // [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.chooseTask = chooseTask; self.typeL = typeL; self.typeBg = typeBg; self.typeTF = typeTF; self.planProportionL = planProportionL; // self.GrandProportionL = GrandProportionL; self.todayTF = todayTF; self.tomTF = tomTF; self.taskNameL = taskNameL; self.compalte = compalte; // self.todayTF.inputAccessoryView = self.kbToolbar; // self.tomTF.inputAccessoryView = self.kbToolbar; // self.typeTF.inputAccessoryView = self.kbToolbar; self.planunitL = planunitL; // self.GrandunitL = GrandunitL; self.unitL = unitL; self.tomunitL = tomunitL; } - (void)choosetype { if (self.ChooseTypeBlock) { self.ChooseTypeBlock(); } } - (void)deleteAction { if (self.DeleteBlock) { self.DeleteBlock(); } } - (void)setSitePerModel:(PBSitePerModel *)sitePerModel { _sitePerModel = sitePerModel; if ([sitePerModel.MobileUserDetial_Name isEqualToString:@"其他"]) { self.typeL.hidden = NO; self.typeBg.hidden = NO; self.typeTF.hidden = NO; self.typeL.text = @"人员类别"; self.typeTF.text = sitePerModel.MobileUserDetial_type; [self.compalte mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.chooseTask.mas_bottom).offset(106); }]; } else { self.typeL.hidden = YES; self.typeBg.hidden = YES; self.typeTF.hidden = YES; [self.compalte mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.chooseTask.mas_bottom).offset(16); }]; } if (sitePerModel.MobileUserDetial_Name == nil){ self.chooseTaskL.textColor = PBColor(174, 174, 174); self.chooseTaskL.text = @"请选择"; self.planProportionL.text = nil; } else { self.chooseTaskL.textColor = PBColor(51, 51, 51); self.chooseTaskL.text = sitePerModel.MobileUserDetial_Name; self.planProportionL.text = sitePerModel.MobileUserDetial_PlanNum; } self.compalte.text = @"人员总量"; self.planunitL.text = @"人"; // self.GrandunitL.text = @"人"; self.unitL.text = @"人"; self.tomunitL.text = @"人"; // self.GrandProportionL.text = sitePerModel.MobileUserDetial_AddNum; self.todayTF.text = sitePerModel.MobileUserDetial_AdddelNum; self.tomTF.text = sitePerModel.MobileUserDetial_NewNum; } - (void)setSiteMaterialModel:(PBSiteMaterialModel *)siteMaterialModel{ _siteMaterialModel = siteMaterialModel; if ([siteMaterialModel.MaterialsDetial_Name isEqualToString:@"其他"]) { self.typeL.hidden = NO; self.typeBg.hidden = NO; self.typeTF.hidden = NO; self.typeL.text = @"机械类别"; self.typeTF.text = siteMaterialModel.MaterialsDetial_type; [self.compalte mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.chooseTask.mas_bottom).offset(106); }]; } else { self.typeL.hidden = YES; self.typeBg.hidden = YES; self.typeTF.hidden = YES; [self.compalte mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.chooseTask.mas_bottom).offset(16); }]; } if (siteMaterialModel.MaterialsDetial_Name == nil){ self.chooseTaskL.textColor = PBColor(174, 174, 174); self.chooseTaskL.text = @"请选择"; self.planProportionL.text = nil; } else { self.chooseTaskL.textColor = PBColor(51, 51, 51); self.chooseTaskL.text = siteMaterialModel.MaterialsDetial_Name; self.planProportionL.text = siteMaterialModel.MaterialsDetial_PlanNum; } self.compalte.text = @"机械总量"; self.planunitL.text = @"台"; // self.GrandunitL.text = @"台"; self.unitL.text = @"台"; self.tomunitL.text = @"台"; // self.GrandProportionL.text = siteMaterialModel.MaterialsDetial_AddNum; self.todayTF.text = siteMaterialModel.MaterialsDetial_AdddelNum; self.tomTF.text = siteMaterialModel.MaterialsDetial_NewNum; } - (void)setPerIndex:(NSInteger)perIndex { _perIndex = perIndex; self.taskNameL.text = [NSString stringWithFormat:@"人员%zd",perIndex]; } - (void)setMaterialIndex:(NSInteger)materialIndex { _materialIndex = materialIndex; self.taskNameL.text = [NSString stringWithFormat:@"机械%zd",materialIndex]; } //- (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(self.sitePerModel) { if(textField == self.typeTF) { self.sitePerModel.MobileUserDetial_type = textField.text; }else if (textField == self.todayTF){ self.sitePerModel.MobileUserDetial_AdddelNum = textField.text; NSInteger planNum = [self.sitePerModel.MobileUserDetial_PlanNum integerValue]; NSInteger adddelNum = [self.sitePerModel.MobileUserDetial_AdddelNum integerValue]; self.sitePerModel.MobileUserDetial_NewNum = [NSString stringWithFormat:@"%zd", planNum + adddelNum]; self.tomTF.text = self.sitePerModel.MobileUserDetial_NewNum; }else { self.sitePerModel.MobileUserDetial_NewNum = textField.text; NSInteger planNum = [self.sitePerModel.MobileUserDetial_PlanNum integerValue]; NSInteger newNum = [self.sitePerModel.MobileUserDetial_NewNum integerValue]; self.sitePerModel.MobileUserDetial_AdddelNum = [NSString stringWithFormat:@"%zd", newNum - planNum]; self.todayTF.text = self.sitePerModel.MobileUserDetial_AdddelNum; // NSInteger site = [textField.text integerValue]; // NSInteger addNum = [self.sitePerModel.MobileUserDetial_AddNum integerValue]; // self.sitePerModel.MobileUserDetial_AddNum = [NSString stringWithFormat:@"%zd",addNum + site]; // self.GrandProportionL.text = self.sitePerModel.MobileUserDetial_AddNum; } }else { if(textField == self.typeTF) { self.siteMaterialModel.MaterialsDetial_type = textField.text; }else if (textField == self.todayTF){ self.siteMaterialModel.MaterialsDetial_AdddelNum = textField.text; NSInteger planNum = [self.siteMaterialModel.MaterialsDetial_PlanNum integerValue]; NSInteger adddelNum = [self.siteMaterialModel.MaterialsDetial_AdddelNum integerValue]; self.siteMaterialModel.MaterialsDetial_NewNum = [NSString stringWithFormat:@"%zd", planNum + adddelNum]; self.tomTF.text = self.siteMaterialModel.MaterialsDetial_NewNum; }else { self.siteMaterialModel.MaterialsDetial_NewNum = textField.text; NSInteger planNum = [self.siteMaterialModel.MaterialsDetial_PlanNum integerValue]; NSInteger newNum = [self.siteMaterialModel.MaterialsDetial_NewNum integerValue]; self.siteMaterialModel.MaterialsDetial_AdddelNum = [NSString stringWithFormat:@"%zd", newNum - planNum]; self.todayTF.text = self.siteMaterialModel.MaterialsDetial_AdddelNum; // NSInteger site = [textField.text integerValue]; // NSInteger addNum = [self.siteMaterialModel.MaterialsDetial_AddNum integerValue]; // self.siteMaterialModel.MaterialsDetial_AddNum = [NSString stringWithFormat:@"%zd",addNum + site]; // self.GrandProportionL.text = self.siteMaterialModel.MaterialsDetial_AddNum; } } } @end