// // TDGroupInfoChangeVc.m // smartRhino // // Created by niuzhen on 2019/12/13. // Copyright © 2019 tederen. All rights reserved. // #import "TDGroupInfoChangeVc.h" #import "ShowPhotoCameraAlertView.h" #import "LYLPhotoTailoringTool.h" @interface TDGroupInfoChangeVc () @property (weak, nonatomic) IBOutlet UIImageView *IconImgV; @property (weak, nonatomic) IBOutlet UITextField *IntreField; @property (weak, nonatomic) IBOutlet UITextField *NameField; @property (weak, nonatomic) IBOutlet UIButton *closeBtn; @property (weak, nonatomic) IBOutlet UIButton *saveBtn; @property (strong,nonatomic) UIImage *image; @property (copy,nonatomic) NSString *imageUrl; @end @implementation TDGroupInfoChangeVc +(TDGroupInfoChangeVc *)initTDGroupInfoChangeVc{ TDGroupInfoChangeVc *controller = [StoryboardManager.shared.TDGroupInfo instantiateViewControllerWithIdentifier:@"TDGroupInfoChangeVc"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.NameField.text = self.model.Name; self.IntreField.text = self.model.Introduce; [self.IconImgV sd_setImageWithURL:[NSURL URLWithString:self.model.AvatarUrl] placeholderImage:kUserDefaultHeadImage]; WS(weakSelf); [self.closeBtn setAction:^{ weakSelf.NameField.text = @""; }]; [self.saveBtn setAction:^{ [weakSelf saveInfo]; }]; } - (void)saveInfo { WEAKSELF if (self.image) { [self postGroupAvatar:self.image withCompletion:^(BOOL success, NSString *imageUrl) { if (success) { weakSelf.imageUrl = imageUrl; [weakSelf saveChangeInfo]; } }]; }else{ [self saveChangeInfo]; } } - (void)saveChangeInfo { WS(weakSelf); NSDictionary * dict = @{@"Id":@(self.model.Id), @"Name":self.NameField.text ? self.NameField.text : @"", @"Introduce":self.IntreField.text ? self.IntreField.text : @"", @"AvatarUrl":self.imageUrl.length > 0 ? self.imageUrl : @"" }; SHOWLOADING [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update) parameters:dict responseStyle:DATA success:^(id _Nonnull responseObject) { REMOVESHOW SHOWSUCCESS(@"修改成功"); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }); } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; } - (void)chatBarDidPhotoAction { WS(weakSelf); [self.view endEditing:YES]; TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil]; [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){ leftButton.hidden = YES; }]; imagePickerVc.showSelectBtn = NO; imagePickerVc.allowCrop = YES; imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH); imagePickerVc.allowTakePicture = NO; imagePickerVc.allowTakeVideo = NO; imagePickerVc.allowPickingOriginalPhoto = NO; imagePickerVc.allowPickingGif = NO; [imagePickerVc setIsStatusBarDefault:YES]; [imagePickerVc setNaviTitleColor:[UIColor blackColor]]; [imagePickerVc setBarItemTextColor:[UIColor blackColor]]; [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { PHAsset *asset = assets.firstObject; switch (asset.mediaType) { case PHAssetMediaTypeVideo: { } break; case PHAssetMediaTypeImage: { UIImage * image = photos.firstObject; dispatch_async(dispatch_get_main_queue(), ^{ weakSelf.image = image; weakSelf.IconImgV.image = image; }); } break; case PHAssetMediaTypeAudio: break; case PHAssetMediaTypeUnknown: break; default: break; } }]; [self presentViewController:imagePickerVc animated:YES completion:nil]; } - (IBAction)ChangeAction:(id)sender { WS(weakSelf); [self.IntreField resignFirstResponder]; [self.NameField resignFirstResponder]; [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) { if(type == ShowPhotoCameraType1){ NSLog(@"相机"); [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) { NSLog(@"222222"); } choosImgBlock:^(UIImage *image) { NSLog(@"oooooo"); weakSelf.image = image; weakSelf.IconImgV.image = image; }]; }else if (type == ShowPhotoCameraType2){ NSLog(@"相册"); [weakSelf chatBarDidPhotoAction]; } } cancle:^{ }] showWithAnimation:kAlertAnimationBottom]; } - (void)postGroupAvatar:(UIImage*)image withCompletion:(void(^)(BOOL success,NSString *imageUrl))completionHandler{ NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post]; [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) { if (completionHandler) { completionHandler(YES,responseObject[@"AbsolutePath"]); } } failure:^(NSError * _Nonnull error) { if (completionHandler) { completionHandler(NO,nil); } }]; } @end