123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // 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<UIImage *> *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
|