// // PBArtifactsListTableViewCell.m // IphoneBIMe // // Created by zjf on 2020/12/8. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBArtifactsListTableViewCell.h" #import "PBAritifactsTableViewCell.h" #import "PBExamineAddModel.h" #import "PBArtifactsInfoModel.h" #import "PBETaskInfoModel.h" static NSString *const cellId = @"cellId"; @interface PBArtifactsListTableViewCell() @property (nonatomic,strong) UITableView *tableView; @property (nonatomic,strong) NSMutableArray *data; //@property (nonatomic,copy) selectedHandler handler; @property (nonatomic, weak) UILabel *titleL; @property (nonatomic, weak) UILabel *dataL; @property (nonatomic, weak) UIButton *chooseBtn; @property (nonatomic, weak) UIButton *totalNumberBtn; @end @implementation PBArtifactsListTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupUI]; } return self; } - (void)setupUI { UIButton *btn = [[UIButton alloc] init]; [btn addTarget:self action:@selector(chooseTime) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:btn]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.equalTo(self.contentView); }]; UILabel *titleL = [UILabel z_labelWithText:@"构件" Color:PBColor(102, 102, 102) isBold:NO Font:15]; [self.contentView addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(15); make.left.equalTo(self.contentView).offset(15); make.height.equalTo(@18); }]; UILabel *dataL = [UILabel z_labelWithText:@"请选择构件" Color:PBColor(79, 40, 58) isBold:NO Font:15]; [self.contentView addSubview:dataL]; [dataL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(116); make.right.equalTo(self.contentView).offset(-15); make.centerY.equalTo(titleL); make.height.equalTo(@18); }]; UIButton *chooseBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"set_arrow_right"]]; [chooseBtn addTarget:self action:@selector(chooseTime) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:chooseBtn]; [chooseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(titleL); make.size.mas_equalTo(CGSizeMake(16, 16)); make.right.equalTo(self.contentView).offset(-15); }]; self.titleL = titleL; self.dataL = dataL; self.chooseBtn = chooseBtn; self.tableView = [[UITableView alloc] init]; self.tableView.backgroundColor = [UIColor whiteColor]; self.tableView.dataSource = self; self.tableView.delegate = self; // self.tableView.rowHeight = UITableViewAutomaticDimension; // self.tableView.estimatedRowHeight = 100.f; self.tableView.rowHeight = 42.f; self.tableView.scrollEnabled = NO; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; [self.tableView registerClass:[PBAritifactsTableViewCell class] forCellReuseIdentifier:cellId]; [self.contentView addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleL.mas_bottom).offset(10); make.left.right.equalTo(dataL); make.height.equalTo(@1); make.bottom.equalTo(self.contentView).offset(-15); }]; UIButton *totalNumberBtn = [[UIButton alloc] init]; [totalNumberBtn addTarget:self action:@selector(totalNumberBtnAction) forControlEvents:UIControlEventTouchUpInside]; [totalNumberBtn setTitle:@"查看全部" forState:UIControlStateNormal]; [totalNumberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; totalNumberBtn.backgroundColor = PBColor(0, 122, 255); [self.contentView addSubview:totalNumberBtn]; [totalNumberBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tableView.mas_bottom).offset(6); make.left.equalTo(dataL); make.height.equalTo(@32); }]; totalNumberBtn.layer.cornerRadius = 2; totalNumberBtn.layer.masksToBounds = YES; self.totalNumberBtn = totalNumberBtn; } - (void)totalNumberBtnAction { NSLog(@"查看全部构件"); if (self.LookAllBlock) { self.LookAllBlock(); } } - (void)chooseTime { if (self.ChooseBlock) { self.ChooseBlock(); } } - (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel { _examineAddModel = examineAddModel; self.titleL.text = examineAddModel.title; if (examineAddModel.dataArr.count > 0) { self.dataL.textColor = PBColor(40, 58, 79); self.dataL.text = [NSString stringWithFormat:@"已关联%zd个", examineAddModel.dataArr.count]; }else { self.dataL.textColor = PBColor(204, 204, 204); self.dataL.text = examineAddModel.prompt; } self.data = examineAddModel.dataArr.mutableCopy; [self.tableView reloadData]; [self.tableView layoutIfNeeded]; CGFloat botton; CGFloat height; if (self.examineAddModel.dataArr.count > 10) { botton = 15.f + 32.f; height = 42 * 10; self.totalNumberBtn.hidden = NO; [self.totalNumberBtn setTitle:[NSString stringWithFormat:@"查看全部%zd个%@", self.examineAddModel.dataArr.count, self.examineAddModel.title] forState:UIControlStateNormal]; }else { botton = 15.f; height = 42 * examineAddModel.dataArr.count; self.totalNumberBtn.hidden = YES; } [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.contentView).offset(-(botton)); make.height.equalTo(@(height)); }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (self.data.count > 10) { return 10; }else { return self.data.count; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PBAritifactsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath]; if ([self.examineAddModel.key isEqualToString:@"Materials"] || [self.examineAddModel.key isEqualToString:@"rel_materialjson"]) { id obj = self.data[indexPath.row]; if ([obj isKindOfClass:[PBArtifactsInfoModel class]]) { PBArtifactsInfoModel *model = (PBArtifactsInfoModel *)obj; // cell.isNotEdit = NO; cell.title = model.bm_materialname; }else { PBArtifactsInfoModel *model = [PBArtifactsInfoModel yy_modelWithDictionary:obj]; // cell.isNotEdit = YES; cell.title = model.bm_materialname; } }else { // cell.isNotEdit = YES; id obj = self.data[indexPath.row]; if ([obj isKindOfClass:[PBETaskInfoModel class]]) { PBETaskInfoModel *taskInfoModel = (PBETaskInfoModel *)obj; cell.title = taskInfoModel.NAME_; }else { NSDictionary *dict = self.examineAddModel.dataArr[indexPath.row]; cell.title = [dict valueForKey:@"NAME_"]; } } // cell.deleteBlock = ^{ // if (self.DeleteBlock) { // self.DeleteBlock(indexPath.row); // } // }; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.ToViewBlock) { self.ToViewBlock(indexPath.row); } } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end