CNLiveCommuntInformViewController.m
30.8 KB
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
//
// CNLiveCommuntInformViewController.m
// CNLiveCommunitModule
//
// Created by open on 2022/2/3.
//
#import "CNLiveCommuntInformViewController.h"
@interface CNLiveCommuntInformViewController ()<UITableViewDelegate,UITableViewDataSource,CNLiveCommuntSubInputTableViewDelegate,CNTZImagePickerControllerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property (nonatomic, strong) NSMutableArray * dataSource;
@property (nonatomic, strong) NSMutableArray * dataArray;
@property (nonatomic, strong) NSMutableArray * imageArray;
@property (nonatomic, strong) NSMutableArray * assetArray;
@property (nonatomic, strong) MBProgressHUD * progressHud;
@property (nonatomic, strong) NSMutableArray * cameraArray;
@property (nonatomic, strong) NSMutableArray * cameraAssetArray;
@property (nonatomic, strong) NSMutableArray * photoArray;
@property (nonatomic, strong) NSMutableArray * photoAssetArray;
@property (nonatomic, strong) NSMutableArray * videoArray;
@property (nonatomic, strong) NSMutableArray * videoAssetArray;
@property (nonatomic, strong) CNLiveCommuntSubAlertTableView * typeView;
@property (nonatomic, strong) CNLiveCommuntSubAlertTableView * dateView;
@property (nonatomic, copy) NSString *project;
@property (nonatomic, copy) NSString *projectString;
@property (nonatomic, copy) NSString *timeString;
@property (nonatomic, copy) NSString *nbhdId;
@end
@implementation CNLiveCommuntInformViewController
- (instancetype)initWithNBhdId:(NSString *)nbhdId
{
self = [super init];
if (self) {
_nbhdId = nbhdId;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"填写信息";
self.imageArray = [[NSMutableArray alloc] init];
self.assetArray = [[NSMutableArray alloc] init];
self.cameraArray = [[NSMutableArray alloc] init];
self.photoArray = [[NSMutableArray alloc] init];
self.videoArray = [[NSMutableArray alloc] init];
self.cameraAssetArray = [[NSMutableArray alloc] init];
self.photoAssetArray = [[NSMutableArray alloc] init];
self.videoAssetArray = [[NSMutableArray alloc] init];
UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[rightBtn setTitle:@"报修记录" forState:UIControlStateNormal];
[rightBtn setTitleColor:UIColorHex(#F97723) forState:UIControlStateNormal];
rightBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[rightBtn addTarget:self action:@selector(rightMothodAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
weakself
self.dataArray = [[NSMutableArray alloc] init];
NSString * nb_info = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@",kCNLiveCommuntyNBhdInfoIdentifier,[CNUserInfoManager manager].userInfoModel.uid]];
if ([nb_info isNotBlank]) {
[QMUITips showLoadingInView:self.view];
CNLiveCommuntyHomeListModel * listModel = [CNLiveCommuntyHomeListModel mj_objectWithKeyValues:nb_info];
[CNLiveCommuntViewModel requestWithCommuntyHomeMaintenForNBHdId:listModel.propertyId CompleterBlock:^(NSArray * _Nonnull dataArray) {
[QMUITips hideAllTipsInView:weakSelf.view];
[weakSelf.dataArray addObjectsFromArray:dataArray];
}];
}
}
-(void)initTableView
{
[super initTableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// self.tableView.tableFooterView = [self setTableViewFooterView];
UIView * footerView = [self setTableViewFooterView];
[self.view addSubview:footerView];
self.tableView.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kNavigationBarHeight);
}
-(void)layoutTableView
{
[super layoutTableView];
}
-(void)rightMothodAction
{
CNLiveCommuntActiviRepairViewController * repairView = [[CNLiveCommuntActiviRepairViewController alloc] init];
[[self displayViewController] dsPushViewController:repairView animated:YES];
}
-(NSMutableArray *)dataSource
{
if (!_dataSource) {
_dataSource = [[NSMutableArray alloc] initWithArray:@[
@{@"name":@"联系人",@"placeholder":@"请输入姓名",@"isClick":@NO,@"isTextField":@YES,@"isTextView":@NO,@"isImage":@NO,@"isChick":@NO},
@{@"name":@"联系地址",@"placeholder":@"请输入联系地址",@"isClick":@NO,@"isTextField":@YES,@"isTextView":@NO,@"isImage":@NO,@"isChick":@NO},
@{@"name":@"联系电话",@"placeholder":@"请输入联系电话",@"isClick":@NO,@"isTextField":@YES,@"isTextView":@NO,@"isImage":@NO,@"isChick":@NO},
@{@"name":@"报修项目",@"placeholder":@"请选择报修项目",@"isClick":@YES,@"isTextField":@NO,@"isTextView":@NO,@"isImage":@NO,@"isChick":@NO},
@{@"name":@"上门时间",@"placeholder":@"请选择上门时间",@"isClick":@YES,@"isTextField":@NO,@"isTextView":@NO,@"isImage":@NO,@"isChick":@NO},
@{@"name":@"问题描述",@"placeholder":@"您遇到什么问题,请留言",@"isClick":@NO,@"isTextField":@NO,@"isTextView":@YES,@"isImage":@NO,@"isChick":@NO},
@{@"name":@"",@"placeholder":@"",@"isClick":@NO,@"isTextField":@NO,@"isTextView":@NO,@"isImage":@YES,@"isChick":@NO},
]];
NSArray * array = (NSArray *)[CNLiveRespCacheManager objectCacheWithFileName:[NSString stringWithFormat:@"CNLiveCommunityRepirContentKey_%@",[CNUserInfoManager manager].userInfoModel.uid]];
if (array && array.count > 0) {
for (int i = 0; i < array.count; i++) {
NSString * content = array[i];
NSMutableDictionary * tempDict = [[_dataSource objectAtIndex:i] mutableCopy];
[tempDict setObject:content forKey:@"content"];
[_dataSource replaceObjectAtIndex:i withObject:tempDict];
}
}
}
return _dataSource;
}
-(UIView *)setTableViewFooterView
{
NSString * nb_info = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@",kCNLiveCommuntyNBhdInfoIdentifier,[CNUserInfoManager manager].userInfoModel.uid]];
self.tableView.contentInset = UIEdgeInsetsMake(kNavigationBarHeight, 0, [nb_info isNotBlank]?90:70, 0);
UIView * footerView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - ([nb_info isNotBlank]?90:70), kScreenWidth, [nb_info isNotBlank]?90:70)];
footerView.backgroundColor = [UIColor whiteColor];
if ([nb_info isNotBlank]) {
CNLiveCommuntyHomeListModel * listModel = [CNLiveCommuntyHomeListModel mj_objectWithKeyValues:nb_info];
YYLabel * phoneLabel = [[YYLabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, 20)];
phoneLabel.textColor = UIColorHex(#B4B4B4);
phoneLabel.textAlignment = NSTextAlignmentCenter;
phoneLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
phoneLabel.numberOfLines = 0;
phoneLabel.hidden = ![listModel.propertyPhone isNotBlank];
phoneLabel.backgroundColor = [UIColor whiteColor];
NSString * string = [NSString stringWithFormat:@"您也可以拨打物业电话 %@",listModel.propertyPhone];
NSMutableAttributedString *textAttributedString = [[NSMutableAttributedString alloc] initWithString:string];
textAttributedString.yy_font = [UIFont systemFontOfSize:10];
textAttributedString.yy_color = UIColorHex(#B4B4B4);
textAttributedString.yy_alignment = NSTextAlignmentCenter;
[textAttributedString yy_setTextHighlightRange:[string rangeOfString:listModel.propertyPhone]
color:[UIColor qmui_colorWithHexString:@"0091FF"]
backgroundColor:[UIColor qmui_colorWithHexString:@"0091FF"]
tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:listModel.propertyPhone style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"tel:%@",listModel.propertyPhone];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:NULL];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:NULL]];
[[self displayViewController] presentViewController:alert animated:YES completion:nil];
}];
phoneLabel.attributedText = textAttributedString;
[footerView addSubview:phoneLabel];
UILabel * lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, kScreenWidth - 20, 0.5)];
lineLabel.backgroundColor = UIColorHex(#E6E6E6);
[footerView addSubview:lineLabel];
}
UIButton * submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
submitBtn.backgroundColor = UIColorHex(#CD0302);
submitBtn.frame = CGRectMake(10, [nb_info isNotBlank]?40:20, kScreenWidth - 20, 40);
submitBtn.layer.cornerRadius = 20;
submitBtn.layer.masksToBounds = YES;
[submitBtn setTitle:@"提交" forState:UIControlStateNormal];
submitBtn.titleLabel.font = [UIFont systemFontOfSize:16];
submitBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[submitBtn addTarget:self action:@selector(submitRequestAction:) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:submitBtn];
return footerView;
}
-(void)submitRequestAction:(UIButton *)button
{
NSArray * names = @[@"userName",@"address",@"phone",@"repairProject",@"time",@"remark",@""];
NSMutableDictionary * paramDict = [[NSMutableDictionary alloc] init];
for (int i = 0; i < self.dataSource.count; i++) {
NSString * tempContent = [self.dataSource[i] stringValueForKey:@"content" default:@""];
NSString * name = names[i];
if ([name isEqualToString:@""]) break;
if ([name isEqualToString:@"time"]) {
NSString * timeString = [self.timeString isNotBlank]?self.timeString:@"";
NSString * dayString = [timeString componentsSeparatedByString:@" "].firstObject;
NSString * startString = [[timeString componentsSeparatedByString:@" "].lastObject componentsSeparatedByString:@"~"].firstObject;
NSString * endString = [[timeString componentsSeparatedByString:@" "].lastObject componentsSeparatedByString:@"~"].lastObject;
if ([startString isNotBlank] && [endString isNotBlank]) {
NSString * temp_start_time = [NSString stringWithFormat:@"%@ %@:00",dayString,startString];
NSString * temp_end_time = [NSString stringWithFormat:@"%@ %@:00",dayString,endString];
[paramDict addString:[temp_start_time isNotBlank]?temp_start_time:@"" forKey:@"beginTime"];
[paramDict addString:[temp_end_time isNotBlank]?temp_end_time:@"" forKey:@"endTime"];
}else{
[paramDict addString:@"" forKey:@"beginTime"];
[paramDict addString:@"" forKey:@"endTime"];
}
}else if ([name isEqualToString:@"repairProject"]) {
[paramDict addString:[self.project isNotBlank]?self.project:@"" forKey:@"repairProject"];
}else if ([name isEqualToString:@"phone"]) {
if ([tempContent isNotBlank] && tempContent.length == 11) {
[paramDict addString:tempContent forKey:@"phone"];
}else{
[QMUITips showWithText:tempContent.length == 0 ? @"联系电话不能为空" : @"联系电话填写错误"];
return;
}
}else{
[paramDict setObject:tempContent forKey:name];
}
}
NSString * userName = [paramDict stringValueForKey:@"userName" default:@""];
if (![userName isNotBlank]) {
[QMUITips showWithText:@"联系人不能为空"];
return;
}
NSString * address = [paramDict stringValueForKey:@"address" default:@""];
if (![address isNotBlank]) {
[QMUITips showWithText:@"联系地址不能为空"];
return;
}
NSString * phone = [paramDict stringValueForKey:@"phone" default:@""];
if (![phone isNotBlank]) {
[QMUITips showWithText:@"联系电话不能为空"];
return;
}
NSString * repairProject = [paramDict stringValueForKey:@"repairProject" default:@""];
if (![repairProject isNotBlank]) {
[QMUITips showWithText:@"报修项目不能为空"];
return;
}
NSString * beginTime = [paramDict stringValueForKey:@"beginTime" default:@""];
if (![beginTime isNotBlank]) {
[QMUITips showWithText:@"请选择上门时间"];
return;
}
NSString * endTime = [paramDict stringValueForKey:@"endTime" default:@""];
if (![endTime isNotBlank]) {
[QMUITips showWithText:@"请选择上门时间"];
return;
}
NSArray * array = @[[paramDict stringValueForKey:@"userName" default:@""],[paramDict stringValueForKey:@"address" default:@""],[paramDict stringValueForKey:@"phone" default:@""]];
[CNLiveRespCacheManager cachePathWithObject:array FileName:[NSString stringWithFormat:@"CNLiveCommunityRepirContentKey_%@",[CNUserInfoManager manager].userInfoModel.uid]];
__weak typeof(self) weakSelf = self;
if (self.imageArray.count == 0) {
[paramDict addString:@"" forKey:@"img"];
[CNLiveCommuntViewModel requestWithCommuntyHomeMaintenPushWithParamDict:paramDict nbhdId:self.nbhdId CompleterBlock:^(CNLiveCommuntyActivityMaintainsCreateModel * _Nonnull createModel) {
if (createModel) {
CNLiveCommuntyOrderViewController * vc = [[CNLiveCommuntyOrderViewController alloc] initWithShowType:CNLiveCommuntyOrderShowTypeListYetOrder CreateModel:createModel];
[weakSelf.navigationController pushViewController:vc animated:YES];
#ifdef DEBUG
[[NSUserDefaults standardUserDefaults] setObject:createModel.idStr forKey:@"cmnt_id"];
[[NSUserDefaults standardUserDefaults] synchronize];
#else
#endif
}
}];
}else{
[self uploadImageWithCompleterBlock:^(NSString *imageUrl) {
[paramDict addString:imageUrl forKey:@"img"];
[CNLiveCommuntViewModel requestWithCommuntyHomeMaintenPushWithParamDict:paramDict nbhdId:self.nbhdId CompleterBlock:^(CNLiveCommuntyActivityMaintainsCreateModel * _Nonnull createModel) {
if (createModel) {
CNLiveCommuntyOrderViewController * vc = [[CNLiveCommuntyOrderViewController alloc] initWithShowType:CNLiveCommuntyOrderShowTypeListYetOrder CreateModel:createModel];
[weakSelf.navigationController pushViewController:vc animated:YES];
#ifdef DEBUG
[[NSUserDefaults standardUserDefaults] setObject:createModel.idStr forKey:@"cmnt_id"];
[[NSUserDefaults standardUserDefaults] synchronize];
#else
#endif
}
}];
}];
}
}
-(void)uploadImageWithCompleterBlock:(void(^)(NSString * imageUrl))completerBlock
{
__weak typeof(self) weakSelf = self;
NSDictionary *param = @{@"appId":AppId,
@"verb":@"POST",
@"storageType":@"2",
@"bucket":API_BucketName
};
self.progressHud.hidden = NO;
self.progressHud.mode = MBProgressHUDModeIndeterminate;
self.progressHud.bezelView.backgroundColor = [UIColor blackColor];
[CNLiveUploadManager uploadRequestType:CNLiveUploadTypeQN url:CNUploadAuthForApp dic:param imageArray:self.imageArray assetArray:self.assetArray isOriginal:NO limitType:AppPhototLimitTypeFriendsCircle progress:^(float progress) {
NSLog(@"上传进度测试:%.2f",progress);
weakSelf.progressHud.mode = MBProgressHUDModeDeterminate;
weakSelf.progressHud.label.text = @"上传图片中...";
weakSelf.progressHud.bezelView.color = [UIColor colorWithWhite:0.95f alpha:0.6f];
weakSelf.progressHud.detailsLabel.text = [NSString stringWithFormat:@"%.2f %%",(progress * 100)];
} success:^(NSMutableArray *fileArray) {
NSLog(@"输出结果测试:%@",fileArray);
__block NSMutableString *picString = [[NSMutableString alloc] init];
[fileArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
CNLiveUploadModel *model = fileArray[idx];
if ([model.code isEqualToString:@"200"]) {
[picString appendString:model.imageUrl];
if (fileArray.count != idx + 1) [picString appendString:@","];
}else {
weakSelf.progressHud.hidden = YES;
weakSelf.progressHud = nil;
[QMUITips showError:model.info.error.localizedDescription inView:weakSelf.view hideAfterDelay:1.5f];
}
}];
weakSelf.progressHud.hidden = YES;
weakSelf.progressHud = nil;
if (completerBlock) completerBlock(picString);
} failure:^(NSMutableArray *errorArray, NSError *error) {
weakSelf.progressHud.hidden = YES;
weakSelf.progressHud = nil;
NSLog(@"输出结果测试:%@,错误:%@---%ld",errorArray,error,error.code);
if (error.code == 0) {
[QMUITips showError:@"上传失败" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5f];
}else {
[QMUITips showWithText:error.localizedDescription inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
}
}];
}
#pragma mark =
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
__weak typeof(self) weakSelf = self;
CNLiveCommuntSubInputTableView * inpView = [CNLiveCommuntSubInputTableView setTableView:tableView SubDict:self.dataSource[indexPath.row] indexs:indexPath.row UserInfo:@{} ReloadBlock:^(NSDictionary * _Nonnull paramDict, NSString * _Nonnull contentString) {
NSMutableDictionary * tempDict = [paramDict mutableCopy];
[tempDict setObject:contentString forKey:@"content"];
if ([[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"联系地址"] || [[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"联系人"] || [[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"联系电话"] || [[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"问题描述"]) {
NSInteger index = 0;
if ([[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"联系地址"]) index = 1;
if ([[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"联系电话"]) index = 2;
if ([[paramDict stringValueForKey:@"name" default:@""] isEqualToString:@"问题描述"]) index = 5;
[weakSelf.dataSource replaceObjectAtIndex:index withObject:tempDict];
}
}];
inpView.delegate = self;
inpView.imageArray = self.imageArray;
return inpView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row < 5) return 50.0f;
if (indexPath.row == 5) return 150.0f;
if (indexPath.row == 6) return 140.0f;
return 0.001f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MJWeakSelf
if (indexPath.row == 3) {
if (self.dataArray.count > 0) {
[CNLiveCommuntSubAlertTableView showAlertViewDataSource:self.dataArray isTime:NO CompleterBlock:^(NSString * _Nonnull idStr, NSString * _Nonnull content) {
CNLiveCommuntSubInputTableView * inpView = [tableView cellForRowAtIndexPath:indexPath];
inpView.moreButton.titleLabel.font = [UIFont systemFontOfSize:15];
inpView.moreButton.titleLabel.font = [UIFont boldSystemFontOfSize:15];
[inpView.moreButton setTitle:content forState:UIControlStateNormal];
[inpView.moreButton setTitleColor:UIColorHex(#333333) forState:UIControlStateNormal];
weakSelf.project = idStr;
weakSelf.projectString = content;
NSMutableDictionary * tempDict = [[weakSelf.dataSource objectAtIndex:3] mutableCopy];
[tempDict setObject:content forKey:@"content"];
[weakSelf.dataSource replaceObjectAtIndex:3 withObject:tempDict];
}];
}else{
NSString * nb_info = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@",kCNLiveCommuntyNBhdInfoIdentifier,[CNUserInfoManager manager].userInfoModel.uid]];
if ([nb_info isNotBlank]) {
CNLiveCommuntyHomeListModel * listModel = [CNLiveCommuntyHomeListModel mj_objectWithKeyValues:nb_info];
[CNLiveCommuntViewModel requestWithCommuntyHomeMaintenForNBHdId:listModel.propertyId CompleterBlock:^(NSArray * _Nonnull dataArray) {
[QMUITips hideAllTipsInView:weakSelf.view];
[weakSelf.dataArray addObjectsFromArray:dataArray];
}];
}
}
}
if (indexPath.row == 4) {
[CNLiveCommuntViewModel requestWithCommuntyHomeMaintenForTimeInterval:7 CompleterBlock:^(NSArray * _Nonnull dataArray) {
[CNLiveCommuntSubAlertTableView showAlertViewDataSource:dataArray isTime:YES CompleterBlock:^(NSString * _Nonnull idStr, NSString * _Nonnull content) {
CNLiveCommuntSubInputTableView * inpView = [tableView cellForRowAtIndexPath:indexPath];
inpView.moreButton.titleLabel.font = [UIFont systemFontOfSize:15];
inpView.moreButton.titleLabel.font = [UIFont boldSystemFontOfSize:15];
[inpView.moreButton setTitle:content forState:UIControlStateNormal];
[inpView.moreButton setTitleColor:UIColorHex(#333333) forState:UIControlStateNormal];
weakSelf.timeString = content;
NSMutableDictionary * tempDict = [[weakSelf.dataSource objectAtIndex:4] mutableCopy];
[tempDict setObject:content forKey:@"content"];
[weakSelf.dataSource replaceObjectAtIndex:4 withObject:tempDict];
}];
}];
}
}
#pragma mark = CNLiveCommuntSubInputTableViewDelegate 下面是选择图片视频逻辑
-(void)setCommuntSubInputTableViewWithDelectForImage:(UIImage *)image
{
if ([self.imageArray containsObject:image]) {
[self.assetArray removeObjectAtIndex:[self.imageArray indexOfObject:image]];
[self.imageArray removeObject:image];
[self.tableView reloadData];
}
}
-(void)setCommuntSubInputTableViewWithPreviewForIndex:(NSInteger)index ImageViews:(nonnull NSArray *)imageViews
{
[CNLivePhotoBrowser photoBrowserForDefultWithSourceViews:imageViews MediaURLArray:self.imageArray CurrentIndex:index ShowType:CNLivePhotoBrowserShowTypeImage Sheet:nil CompleterBlock:NULL];
}
/// 点击选择图片视频
/// @param index 点击的位置
-(void)setCommuntSubInputTableViewWithSelectForIndex:(NSInteger)index
{
__weak typeof(self) weakSelf = self;
[self.view createAlertViewTitleArray:@[@"拍摄",@"从手机相册选择"] subTitleArr:@[@"",@""] textColor:UIColorMake(40, 40, 40) subTitleColor:UIColorMake(152, 152, 152) font:UIFontMake(15) subFont:UIFontMake(12) actionBlock:^(UIButton *button, NSInteger didRow) {
switch (didRow) {
case 0:
{
if (IOS14_SDK_ALLOWED) {
[weakSelf requestCNLiveALAssetsLibraryAuthorizationWithCompletion:^(BOOL isAuth) {
if (isAuth) {
dispatch_async_on_main_queue(^{
[weakSelf takeToXFPhoto:index];
});
}
}];
}else{
[weakSelf takeToXFPhoto:index];
}
}
break;
case 1:
{
[self pushTZImagePickerController:index];
}
break;
default:
break;
}
}];
}
-(void)requestCNLiveALAssetsLibraryAuthorizationWithCompletion:(void(^)(BOOL isAuth))requestAssetsLibraryAuthCompletion
{
PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];
if (authStatus != PHAuthorizationStatusAuthorized) {//未授权
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status != PHAuthorizationStatusAuthorized) {//已授权
if (requestAssetsLibraryAuthCompletion) {
requestAssetsLibraryAuthCompletion(NO);
}
} else {
if (requestAssetsLibraryAuthCompletion) {
requestAssetsLibraryAuthCompletion(YES);
}
}
}];
} else {
if (requestAssetsLibraryAuthCompletion) {
requestAssetsLibraryAuthCompletion(YES);
}
}
}
- (void)takeToXFPhoto:(NSInteger)index
{
__weak typeof(self) weakSelf = self;
XFCameraController *cameraController = [[XFCameraController alloc] init];
cameraController.isCanShootVideo = NO;
cameraController.modalPresentationStyle = UIModalPresentationFullScreen;
__weak XFCameraController *weakCameraController = cameraController;
// cameraController.zxshootCompletionBlock = ^(PHAsset *asset, NSURL *videoUrl, CGFloat videoTimeLength, UIImage *thumbnailImage, NSError *error) {
// if (!error) {
// dispatch_async_on_main_queue(^{
// [weakCameraController dismissViewControllerAnimated:YES completion:^{
// [weakSelf.videoArray removeAllObjects];
// [weakSelf.videoAssetArray removeAllObjects];
// [weakSelf.videoArray addObject:thumbnailImage];
// [weakSelf.videoAssetArray addObject:asset];
// [weakSelf.tableView reloadData];
// }];
// });
// }
// };
cameraController.takePhotosCompletionBlock = ^(UIImage *image, NSError *error) {
if (!error) {
NSMutableArray *imageIds = [NSMutableArray array];
[weakCameraController dismissViewControllerAnimated:YES completion:^{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
//写入图片到相册
PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
//记录本地标识,等待完成后取到相册中的图片对象
[imageIds addObject:req.placeholderForCreatedAsset.localIdentifier];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
if (success) {
PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:imageIds options:nil];
[result enumerateObjectsUsingBlock:^(PHAsset * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
dispatch_async_on_main_queue(^{
// [weakSelf.imageArray removeObject:weakSelf.cameraArray.firstObject];
// [weakSelf.assetArray removeObject:weakSelf.cameraAssetArray.firstObject];
//
// [weakSelf.cameraAssetArray removeAllObjects];
// [weakSelf.cameraArray removeAllObjects];
// [weakSelf.cameraAssetArray addObject:obj];
// [weakSelf.cameraArray addObject:image];
//
// [weakSelf.imageArray addObject:image];
// [weakSelf.assetArray addObject:obj];
[weakSelf.imageArray addObjectsFromArray:@[image]];
[weakSelf.assetArray addObjectsFromArray:@[obj]];
[weakSelf.tableView reloadData];
});
}];
}
}];
}];
}
};
[self presentViewController:cameraController animated:YES completion:NULL];
}
- (void)pushTZImagePickerController:(NSInteger)index
{
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:3 columnNumber:3 delegate:self pushPhotoPickerVc:YES];
imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
// [imagePickerVc configTZImagePicker];//配置
imagePickerVc.isSelectOriginalPhoto = NO;//是否选择原图
// 1.设置目前已经选中的图片数组
imagePickerVc.selectedAssets = self.assetArray;
// imagePickerVc.maxEditVideoTime = 0;//编辑长度
// imagePickerVc.maxVideoDuration = 0;//编辑视频最大长度
// 3. Set allow picking video & photo & originalPhoto or not
// 3. 设置是否可以选择视频/图片/原图
imagePickerVc.allowPickingVideo = NO;
/// 5. Single selection mode, valid when maxImagesCount = 1
/// 5. 单选模式,maxImagesCount为1时才生效
// 设置竖屏下的裁剪尺寸
NSInteger left = 30;
NSInteger widthHeight = KScreenWidth - 2 * left;
NSInteger top = (KScreenHeight - widthHeight) / 2;
imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
[self presentViewController:imagePickerVc animated:YES completion:NULL];
}
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto
{
[self.imageArray removeAllObjects];
[self.assetArray removeAllObjects];
[self.imageArray addObjectsFromArray:photos];
[self.assetArray addObjectsFromArray:assets];
[self.tableView reloadData];
}
- (MBProgressHUD *)progressHud {
if (!_progressHud) {
_progressHud= [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
_progressHud.mode = MBProgressHUDModeDeterminate;
_progressHud.animationType = MBProgressHUDAnimationZoomIn;
_progressHud.bezelView.backgroundColor = [UIColor blackColor];
}
return _progressHud;
}
@end