zjf
2023-03-13 881f0da670f20c401c1e1d08b36253abb28f72d2
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
//
//  PBListTableViewCell.m
//  IphoneBIMe
//
//  Created by zjf on 2020/8/18.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBListTableViewCell.h"
#import "PBExamineAddModel.h"
#import "PBListDataTableViewCell.h"
#import "PBArtifactsInfoModel.h"
static NSString *const cellID = @"CellID";
@interface PBListTableViewCell()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, weak) UILabel *titleL;
@property (nonatomic, weak) UILabel *descL;
@property (nonatomic, weak) UILabel *promteL;
@property (nonatomic, weak) UIButton *selectBtn;
@end
@implementation PBListTableViewCell
 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    UILabel *titleL = [UILabel z_labelWithText:@"" Color:PromptColor isBold:NO Font:14];
    titleL.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(@20);
        
    }];
//    UILabel *descL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:18];
//    descL.numberOfLines = 0;
//    descL.textAlignment = NSTextAlignmentCenter;
//    [self.contentView addSubview:descL];
//    [descL mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(titleL.mas_bottom).offset(16);
//        make.left.right.equalTo(titleL);
//        make.bottom.equalTo(self.contentView).offset(-16);
//        make.height.mas_greaterThanOrEqualTo(25);
//    }];
    UILabel *promteL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:TitleFontSize];
    [self.contentView addSubview:promteL];
    [promteL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleL.mas_bottom).offset(10);
        make.centerX.equalTo(titleL);
        make.height.equalTo(@25);
    }];
    self.tableView = [[UITableView alloc] init];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.bounces = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[PBListDataTableViewCell class] forCellReuseIdentifier:cellID];
    [self.contentView addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleL.mas_bottom).offset(14);
        make.left.right.bottom.equalTo(self.contentView);
        make.height.equalTo(@1);
//        make.bottom.equalTo(self.contentView).offset(-25);
    }];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.bottom.equalTo(self.tableView.mas_bottom).offset(25);
    }];
    UIButton *selectBtn = [[UIButton alloc] init];
    [selectBtn addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:selectBtn];
    [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-100);
    }];
    self.titleL = titleL;
//    self.descL = descL;
    self.promteL = promteL;
    self.selectBtn = selectBtn;
}
- (void)selectAction {
    if (self.ChooseBlock) {
        self.ChooseBlock();
    }
}
- (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel {
    _examineAddModel = examineAddModel;
    self.titleL.text = examineAddModel.title;
    if (examineAddModel.dataArr.count > 0) {
        self.promteL.hidden = YES;
        CGFloat tableViewH = examineAddModel.dataArr.count * 40.f;
        [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(tableViewH));
        }];
        [self.tableView reloadData];
    }else {
        self.promteL.hidden = NO;
        self.promteL.text = examineAddModel.prompt;
        [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(1));
        }];
    }
    if ([examineAddModel.key isEqualToString:@"Materials"]) {
        self.selectBtn.hidden = YES;
    }else {
        self.selectBtn.hidden = NO;
    }
    
    
    
//    NSMutableString *strM = [[NSMutableString alloc] init];
//    if (examineAddModel.dataArr.count > 0) {
//        self.promteL.hidden = YES;
//        for (NSInteger i = 0 ; i < examineAddModel.dataArr.count; i++) {
//            NSDictionary *obj = examineAddModel.dataArr[i];
//            NSString *str;
//            if ([examineAddModel.key isEqualToString:@"Materials"] || [examineAddModel.key isEqualToString:@"rel_materialjson"]) {
//                str = [obj valueForKey:@"bm_materialname"];
//            }else {
//                str = [obj valueForKey:@"NAME_"];
//            }
//            if (i == examineAddModel.dataArr.count - 1) {
//                [strM appendFormat:@"%@",str];
//            }else {
//                [strM appendFormat:@"%@\n",str];
//            }
//        }
//        self.descL.text = strM.copy;
//    }else {
//        self.descL.text = @"";
//        self.promteL.hidden = NO;
//        self.promteL.text = examineAddModel.prompt;
//    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.examineAddModel.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBListDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    if ([self.examineAddModel.key isEqualToString:@"Materials"] || [self.examineAddModel.key isEqualToString:@"rel_materialjson"]) {
        id obj = self.examineAddModel.dataArr[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;
        NSDictionary *dict = self.examineAddModel.dataArr[indexPath.row];
        cell.title = [dict valueForKey:@"NAME_"];
    }
    cell.deleteBlock = ^{
        if (self.DeleteBlock) {
            self.DeleteBlock(indexPath.row);
        }
    };
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.ToViewBlock) {
        self.ToViewBlock(indexPath.row);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
@end