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
//
//  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()<UITextFieldDelegate, UITextViewDelegate>
@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