zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
//
//  PBMateralTableViewCell.m
//  IphoneBIMe
//
//  Created by ZJF on 2022/9/4.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBMateralTableViewCell.h"
#import "PBSiteMechanicalModel.h"
#import "PBSchedulesElementTableViewCell.h"
#import "PBArtifactsInfoModel.h"
 
#define maxTextCount 200
static NSString *const CellID = @"CellID";
@interface PBMateralTableViewCell()<UITextFieldDelegate, UITextViewDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, weak) UILabel *taskNameL; //材料1
@property (nonatomic, weak) UILabel *chooseTaskL; //所选材料类型
@property (nonatomic, weak) UITableView *tableView; //部位
@property (nonatomic, weak) UITextField *specificationTF; //规格
@property (nonatomic, weak) UITextField *materialUnitTF; //单位
@property (nonatomic, weak) UILabel *totalNumL;//材料总量
@property (nonatomic, weak) UITextField *approachTF; //当日进厂量
@property (nonatomic, weak) UILabel *addupNumL; //累计进厂量
@property (nonatomic, weak) UITextView *textView;//生产情况
@property (nonatomic, weak) UILabel *arrivalTimePrL;//预计进场时间
@property (nonatomic, weak) UITextView *remarktextView;// 备注
@property (nonatomic, weak) UILabel *promptL;
@property (nonatomic, weak) UILabel *prompt1L;
//@property (nonatomic, strong) UIToolbar *kbToolbar;
@property (nonatomic, strong) NSMutableArray *elements;
@end
@implementation PBMateralTableViewCell
 
- (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);
        make.height.equalTo(@16);
    }];
    UIButton *addPart = [UIButton z_bgImageButton:[UIImage imageNamed:@"addPart_btn"]];
    [addPart addTarget:self action:@selector(addPart) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:addPart];
    [addPart mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(typeL.mas_bottom).offset(6);
        make.left.right.height.equalTo(chooseTask);
    }];
    UITableView *tableView = [[UITableView alloc] init];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    tableView.showsVerticalScrollIndicator = NO;
    tableView.rowHeight = 44.f;
    [tableView registerClass:[PBSchedulesElementTableViewCell class] forCellReuseIdentifier:CellID];
    [self.contentView addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addPart.mas_bottom).offset(6);
        make.left.right.equalTo(chooseTask);
        make.height.equalTo(@100);
    }];
    
    UILabel *specificationL = [UILabel z_labelWithText:@"规格" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:specificationL];
    [specificationL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tableView.mas_bottom).offset(16);
        make.left.equalTo(chooseTask);
        make.height.equalTo(@16);
    }];
    UITextField *specificationTF = [[UITextField alloc] init];
    specificationTF.placeholder = @"请输入...";
    specificationTF.textAlignment= NSTextAlignmentLeft;
    specificationTF.textColor = PBColor(40, 58, 79);
    specificationTF.font = [UIFont fontWithName:Coarse size:14.0];
    specificationTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    specificationTF.delegate = self;
    specificationTF.layer.cornerRadius = 4;
    specificationTF.layer.borderWidth = 1.f;
    specificationTF.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor];
    specificationTF.leftViewMode = UITextFieldViewModeAlways;
    specificationTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 44)];
    [self.contentView addSubview:specificationTF];
    [specificationTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(specificationL.mas_bottom).offset(6);
        make.left.right.height.equalTo(chooseTask);
    }];
    
    UILabel *materialUnitL = [UILabel z_labelWithText:@"单位" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:materialUnitL];
    [materialUnitL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(specificationTF.mas_bottom).offset(16);
        make.left.equalTo(chooseTask);
        make.height.equalTo(@16);
    }];
    UITextField *materialUnitTF = [[UITextField alloc] init];
    materialUnitTF.placeholder = @"请输入...";
    materialUnitTF.textAlignment= NSTextAlignmentLeft;
    materialUnitTF.textColor = PBColor(40, 58, 79);
    materialUnitTF.font = [UIFont fontWithName:Coarse size:14.0];
    materialUnitTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    materialUnitTF.delegate = self;
    materialUnitTF.layer.cornerRadius = 4;
    materialUnitTF.layer.borderWidth = 1.f;
    materialUnitTF.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor];
    materialUnitTF.leftViewMode = UITextFieldViewModeAlways;
    materialUnitTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 44)];
    [self.contentView addSubview:materialUnitTF];
    [materialUnitTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(materialUnitL.mas_bottom).offset(6);
        make.left.right.height.equalTo(chooseTask);
    }];
    
    UILabel *totalL = [UILabel z_labelWithText:@"材料总量:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:totalL];
    [totalL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(materialUnitTF.mas_bottom).offset(16);
        make.left.height.equalTo(chooseTask);
    }];
    UILabel *totalNumL = [UILabel z_labelWithText:@"  223" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:14];
    totalNumL.backgroundColor = PBColor(243, 243, 244);
    [totalNumL circleViewWithRadius:4];
    [self.contentView addSubview:totalNumL];
    [totalNumL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(totalL);
        make.left.equalTo(self.contentView).offset(100);
        make.right.height.equalTo(chooseTask);
    }];
    
    UILabel *approachL = [UILabel z_labelWithText:@"当日进场量:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:approachL];
    [approachL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(totalNumL.mas_bottom).offset(16);
        make.left.height.equalTo(chooseTask);
    }];
    UITextField *approachTF = [[UITextField alloc] init];
    approachTF.placeholder = @"请输入...";
    approachTF.textAlignment= NSTextAlignmentLeft;
    approachTF.textColor = PBColor(40, 58, 79);
    approachTF.font = [UIFont fontWithName:Coarse size:14.0];
    approachTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    approachTF.delegate = self;
    approachTF.layer.cornerRadius = 4;
    approachTF.layer.borderWidth = 1.f;
    approachTF.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor];
    approachTF.leftViewMode = UITextFieldViewModeAlways;
    approachTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 44)];
    [self.contentView addSubview:approachTF];
    [approachTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(approachL);
        make.left.equalTo(self.contentView).offset(100);
        make.right.height.equalTo(chooseTask);
    }];
    
    UILabel *addupL = [UILabel z_labelWithText:@"累计进场量:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:addupL];
    [addupL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(approachTF.mas_bottom).offset(16);
        make.left.height.equalTo(chooseTask);
    }];
    UILabel *addupNumL = [UILabel z_labelWithText:@"  2123" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:16];
    addupNumL.backgroundColor = PBColor(243, 243, 244);
    [addupNumL circleViewWithRadius:4];
    [self.contentView addSubview:addupNumL];
    [addupNumL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addupL);
        make.left.equalTo(self.contentView).offset(100);
        make.right.height.equalTo(chooseTask);
    }];
    
    UILabel *generationL = [UILabel z_labelWithText:@"生产情况:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:generationL];
    [generationL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addupNumL.mas_bottom).offset(16);
        make.left.height.equalTo(chooseTask);
    }];
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(generationL);
        make.left.equalTo(self.contentView).offset(100);
        make.right.equalTo(chooseTask);
        make.height.equalTo(@132);
    }];
    bgView.layer.cornerRadius = 4;
    bgView.layer.borderWidth = 1;
    bgView.layer.borderColor = PBColor(108, 108, 108).CGColor;
    
    UITextView *textView = [[UITextView alloc] init];
    textView.textColor= PBColor(40, 58, 79);
    textView.font = [UIFont boldSystemFontOfSize:14];
    textView.delegate = self;
    [bgView addSubview:textView];
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(10);
        make.left.equalTo(bgView).offset(10);
        make.right.equalTo(bgView).offset(-10);
        make.bottom.equalTo(bgView).offset(-10);
    }];
//    textView.inputAccessoryView = self.kbToolbar;
 
    UILabel *promptL= [UILabel z_labelWithText:@"请输入..." Color:PBColor(174, 174, 174) isBold:YES Font:14];
    [bgView addSubview:promptL];
    [promptL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(textView).offset(8);
        make.left.equalTo(textView).offset(6);
    }];
    
    UILabel *arrivalTimeL = [UILabel z_labelWithText:@"预计到场:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:arrivalTimeL];
    [arrivalTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(16);
        make.left.height.equalTo(chooseTask);
    }];
    UIButton *arrivalTime = [[UIButton alloc] init];
    [arrivalTime addTarget:self action:@selector(chooseTime) forControlEvents:UIControlEventTouchUpInside];
    arrivalTime.layer.cornerRadius = 4;
    arrivalTime.layer.borderWidth = 1.f;
    arrivalTime.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor];
    [self.contentView addSubview:arrivalTime];
    [arrivalTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(arrivalTimeL);
        make.left.equalTo(self.contentView).offset(100);
        make.right.equalTo(chooseTask);
        make.height.equalTo(@44);
    }];
    UILabel *arrivalTimePrL = [UILabel z_labelWithText:@"请选择" Color:[UIColor z_colorWithR:174 G:174 B:174] isBold:NO Font:14];
    [self.contentView addSubview:arrivalTimePrL];
    [arrivalTimePrL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(arrivalTime).offset(12);
        make.right.equalTo(arrivalTime).offset(-44);
        make.centerY.equalTo(arrivalTime);
    }];
    UIImageView *timeImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"date_btn"]];
    [self.contentView addSubview:timeImageV];
    [timeImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(arrivalTime).offset(10);
        make.right.equalTo(arrivalTime).offset(-10);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    
    UILabel *remarkL = [UILabel z_labelWithText:@"备注:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14];
    [self.contentView addSubview:remarkL];
    [remarkL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(arrivalTimeL.mas_bottom).offset(16);
        make.left.height.equalTo(chooseTask);
    }];
    UIView *remarkbgView = [[UIView alloc] init];
    remarkbgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:remarkbgView];
    [remarkbgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(remarkL);
        make.left.equalTo(self.contentView).offset(100);
        make.right.equalTo(chooseTask);
        make.bottom.equalTo(self.contentView).offset(-20);
        make.height.equalTo(@132);
    }];
    remarkbgView.layer.cornerRadius = 4;
    remarkbgView.layer.borderWidth = 1;
    remarkbgView.layer.borderColor = PBColor(108, 108, 108).CGColor;
    
    UITextView *remarktextView = [[UITextView alloc] init];
    remarktextView.textColor= PBColor(40, 58, 79);
    remarktextView.font = [UIFont boldSystemFontOfSize:14];
    remarktextView.delegate = self;
    [remarkbgView addSubview:remarktextView];
    [remarktextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(remarkbgView).offset(10);
        make.left.equalTo(remarkbgView).offset(10);
        make.right.equalTo(remarkbgView).offset(-10);
        make.bottom.equalTo(remarkbgView).offset(-10);
    }];
//    remarktextView.inputAccessoryView = self.kbToolbar;
 
    UILabel *prompt1L= [UILabel z_labelWithText:@"请输入..." Color:PBColor(174, 174, 174) isBold:YES Font:14];
    [remarkbgView addSubview:prompt1L];
    [prompt1L mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(remarktextView).offset(8);
        make.left.equalTo(remarktextView).offset(6);
    }];
//    specificationTF.inputAccessoryView = self.kbToolbar;
//    materialUnitTF.inputAccessoryView = self.kbToolbar;
//    approachTF.inputAccessoryView = self.kbToolbar;
    self.taskNameL = taskNameL;
    self.chooseTaskL = chooseTaskL;
    self.tableView = tableView;
    self.specificationTF = specificationTF;
    self.materialUnitTF = materialUnitTF;
    self.totalNumL = totalNumL;
    self.approachTF = approachTF;
    self.addupNumL = addupNumL;
    self.textView = textView;
    self.arrivalTimePrL = arrivalTimePrL;
    self.remarktextView = remarktextView;
    self.promptL = promptL;
    self.prompt1L = prompt1L;
 
}
 
- (void)choosetype {
    if (self.ChooseTypeBlock) {
        self.ChooseTypeBlock();
    }
}
- (void)chooseTime {
    if (self.ChooseTimeBlock) {
        self.ChooseTimeBlock();
    }
}
- (void)addPart {
    if(self.AddElementBlock) {
        self.AddElementBlock();
    }
}
- (void)deleteAction {
    if (self.DeleteBlock) {
        self.DeleteBlock();
    }
}
- (void)setSiteMechanicalModel:(PBSiteMechanicalModel *)siteMechanicalModel {
    _siteMechanicalModel = siteMechanicalModel;
    if (siteMechanicalModel.MachineDetial_Name == nil) {
        self.chooseTaskL.textColor = PBColor(174, 174, 174);
        self.chooseTaskL.text = @"请选择";
    }else {
        self.chooseTaskL.textColor = PBColor(51, 51, 51);
        self.chooseTaskL.text = siteMechanicalModel.MachineDetial_Name;
    }
    
    self.elements = siteMechanicalModel.elementList.mutableCopy;
    NSInteger tableH = 44 * self.elements.count;
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(tableH));
    }];
    [self.tableView reloadData];
    
 
    self.specificationTF.text = siteMechanicalModel.MachineDetial_Size;
    self.materialUnitTF.text = siteMechanicalModel.MachineDetial_Unit;
    if (siteMechanicalModel.MachineDetial_Sum==nil){
        siteMechanicalModel.MachineDetial_Sum = @"";
    }
    self.totalNumL.text = [NSString stringWithFormat:@"  %@",siteMechanicalModel.MachineDetial_Sum];
    self.approachTF.text = siteMechanicalModel.MachineDetial_Approcach;
    if (siteMechanicalModel.MachineDetial_Add==nil){
        siteMechanicalModel.MachineDetial_Add = @"";
    }
    self.addupNumL.text = [NSString stringWithFormat:@"  %@",siteMechanicalModel.MachineDetial_Add];
    self.textView.text = siteMechanicalModel.MachineDetial_Product;
    if (self.textView.text.length == 0) {
        self.promptL.hidden = NO;
    }else {
        self.promptL.hidden = YES;
    }
    
    if (siteMechanicalModel.MachineDetial_Estimated == nil) {
        self.arrivalTimePrL.textColor = PBColor(174, 174, 174);
        self.arrivalTimePrL.text = @"请选择日期";
    }else {
        self.arrivalTimePrL.textColor = PBColor(51, 51, 51);
        self.arrivalTimePrL.text = siteMechanicalModel.MachineDetial_Estimated;
    }
    
    self.remarktextView.text = siteMechanicalModel.MachineDetial_Remark;
    if (self.remarktextView.text.length == 0) {
        self.prompt1L.hidden = NO;
    }else {
        self.prompt1L.hidden = YES;
    }
}
 
-(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 (textField == self.specificationTF) {
        self.siteMechanicalModel.MachineDetial_Size = textField.text;
    }else if (textField == self.materialUnitTF){
        self.siteMechanicalModel.MachineDetial_Unit =  textField.text;
    }else {
        self.siteMechanicalModel.MachineDetial_Approcach = textField.text;
        NSInteger approcach = [self.siteMechanicalModel.MachineDetial_Approcach integerValue];
        NSInteger total = [self.siteMechanicalModel.MachineDetialAdd integerValue];
        self.siteMechanicalModel.MachineDetial_Add = [NSString stringWithFormat:@"%zd",approcach + total];
        self.addupNumL.text = [NSString stringWithFormat:@"  %@", self.siteMechanicalModel.MachineDetial_Add];
    }
}
#pragma mark - UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)text {
    NSLog(@"%zd",textView.text.length);
    NSLog(@"===shouldChangeText");
    UITextRange *selectedRange = [textView markedTextRange];
    //获取高亮部分
    UITextPosition *pos = [textView positionFromPosition:selectedRange.start offset:0];
    //获取高亮部分内容
    //NSString * selectedtext = [textView textInRange:selectedRange];
    //如果有高亮且当前字数开始位置小于最大限制时允许输入
    if (selectedRange && pos) {
        NSInteger startOffset = [textView offsetFromPosition:textView.beginningOfDocument toPosition:selectedRange.start];
        NSInteger endOffset = [textView offsetFromPosition:textView.beginningOfDocument toPosition:selectedRange.end];
        NSRange offsetRange = NSMakeRange(startOffset, endOffset - startOffset);
        if (offsetRange.location < maxTextCount) {
            return YES;
        }
        else{
            return NO;
        }
    }
    NSString *comcatstr = [textView.text stringByReplacingCharactersInRange:range withString:text];
    NSInteger caninputlen = maxTextCount - comcatstr.length;
    if (caninputlen >= 0){
        return YES;
    }else{
        NSInteger len = text.length + caninputlen;
        //防止当text.length + caninputlen < 0时,使得rg.length为一个非法最大正数出错
        NSRange rg = {0,MAX(len,0)};
        if (rg.length > 0){
            NSString *s = @"";
            //判断是否只普通的字符或asc码(对于中文和表情返回NO)
            BOOL asc = [text canBeConvertedToEncoding:NSASCIIStringEncoding];
            if (asc) {
                s = [text substringWithRange:rg];//因为是ascii码直接取就可以了不会错
            }else{
                __block NSInteger idx = 0;
                __block NSString  *trimString = @"";//截取出的字串
                //使用字符串遍历,这个方法能准确知道每个emoji是占一个unicode还是两个
                [text enumerateSubstringsInRange:NSMakeRange(0, [text length])
                                         options:NSStringEnumerationByComposedCharacterSequences
                                      usingBlock: ^(NSString* substring, NSRange substringRange, NSRange enclosingRange, BOOL* stop) {
                                          if (idx >= rg.length) {
                                              *stop = YES; //取出所需要就break,提高效率
                                              return ;
                                          }
                                          trimString = [trimString stringByAppendingString:substring];
                                          idx++;
                                      }];
                s = trimString;
            }
            //rang是指从当前光标处进行替换处理(注意如果执行此句后面返回的是YES会触发didchange事件)
            [textView setText:[textView.text stringByReplacingCharactersInRange:range withString:s]];
            //既然是超出部分截取了,哪一定是最大限制了。
//            self.textLengthL.text = [NSString stringWithFormat:@"%d/%ld",0,(long)maxTextCount];
        }
        return NO;
    }
}
- (void)textViewDidChange:(UITextView *)textView{
    if (textView == self.textView) {
        if (textView.text.length == 0) {
            self.promptL.hidden = NO;
        }else {
            self.promptL.hidden = YES;
        }
    }else {
        if (textView.text.length == 0) {
            self.prompt1L.hidden = NO;
        }else {
            self.prompt1L.hidden = YES;
        }
    }
    
    NSLog(@"===DidChangeText");
    UITextRange *selectedRange = [textView markedTextRange];
    //获取高亮部分
    UITextPosition *pos = [textView positionFromPosition:selectedRange.start offset:0];
    //如果在变化中是高亮部分在变,就不要计算字符了
    if (selectedRange && pos) {
        return;
    }
    NSString  *nsTextContent = textView.text;
    NSInteger existTextNum = nsTextContent.length;
    if (existTextNum > maxTextCount){
        //截取到最大位置的字符(由于超出截部分在should时被处理了所在这里这了提高效率不再判断)
        NSString *s = [nsTextContent substringToIndex:maxTextCount];
        [textView setText:s];
    }
    if (textView == self.textView) {
        self.siteMechanicalModel.MachineDetial_Product =  textView.text;
    }else {
        self.siteMechanicalModel.MachineDetial_Remark = textView.text;
    }
 
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.elements.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBSchedulesElementTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    PBArtifactsInfoModel *model = self.elements[indexPath.row];
    cell.artifactsModel = model;
    cell.DeleteBlock = ^{
        [self.elements removeObjectAtIndex:indexPath.row];
        [self updateTableViewWithDate:self.elements.copy];
    };
    return cell;
}
- (void)updateTableViewWithDate:(NSArray *)element {
//    self.siteMechanicalModel.elementList = element;
//    NSInteger tableH = 44 * self.siteMechanicalModel.elementList.count;
//    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.equalTo(@(tableH));
//    }];
//    [self.tableView reloadData];
    if (self.DeleteElementBlock) {
        self.DeleteElementBlock(element);
    }
}
- (NSMutableArray *)elements {
    if (_elements == nil) {
        _elements = [[NSMutableArray alloc] init];
    }
    return _elements;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
@end