TDGroupInfoChangeVc.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // TDGroupInfoChangeVc.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/13.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "TDGroupInfoChangeVc.h"
  9. #import "ShowPhotoCameraAlertView.h"
  10. #import "LYLPhotoTailoringTool.h"
  11. @interface TDGroupInfoChangeVc ()
  12. @property (weak, nonatomic) IBOutlet UIImageView *IconImgV;
  13. @property (weak, nonatomic) IBOutlet UITextField *IntreField;
  14. @property (weak, nonatomic) IBOutlet UITextField *NameField;
  15. @property (weak, nonatomic) IBOutlet UIButton *closeBtn;
  16. @property (weak, nonatomic) IBOutlet UIButton *saveBtn;
  17. @property (strong,nonatomic) UIImage *image;
  18. @property (copy,nonatomic) NSString *imageUrl;
  19. @end
  20. @implementation TDGroupInfoChangeVc
  21. +(TDGroupInfoChangeVc *)initTDGroupInfoChangeVc{
  22. TDGroupInfoChangeVc *controller = [StoryboardManager.shared.TDGroupInfo instantiateViewControllerWithIdentifier:@"TDGroupInfoChangeVc"];
  23. return controller;
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.fd_prefersNavigationBarHidden = YES;
  28. self.NameField.text = self.model.Name;
  29. self.IntreField.text = self.model.Introduce;
  30. [self.IconImgV sd_setImageWithURL:[NSURL URLWithString:self.model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  31. WS(weakSelf);
  32. [self.closeBtn setAction:^{
  33. weakSelf.NameField.text = @"";
  34. }];
  35. [self.saveBtn setAction:^{
  36. [weakSelf saveInfo];
  37. }];
  38. }
  39. - (void)saveInfo
  40. {
  41. WEAKSELF
  42. if (self.image) {
  43. [self postGroupAvatar:self.image withCompletion:^(BOOL success, NSString *imageUrl) {
  44. if (success) {
  45. weakSelf.imageUrl = imageUrl;
  46. [weakSelf saveChangeInfo];
  47. }
  48. }];
  49. }else{
  50. [self saveChangeInfo];
  51. }
  52. }
  53. - (void)saveChangeInfo
  54. {
  55. WS(weakSelf);
  56. NSDictionary * dict = @{@"Id":@(self.model.Id),
  57. @"Name":self.NameField.text ? self.NameField.text : @"",
  58. @"Introduce":self.IntreField.text ? self.IntreField.text : @"",
  59. @"AvatarUrl":self.imageUrl.length > 0 ? self.imageUrl : @""
  60. };
  61. SHOWLOADING
  62. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Update) parameters:dict responseStyle:DATA success:^(id _Nonnull responseObject) {
  63. REMOVESHOW
  64. SHOWSUCCESS(@"修改成功");
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66. [weakSelf.navigationController popViewControllerAnimated:YES];
  67. });
  68. } failure:^(NSError * _Nonnull error) {
  69. REMOVESHOW
  70. }];
  71. }
  72. - (void)chatBarDidPhotoAction
  73. {
  74. WS(weakSelf);
  75. [self.view endEditing:YES];
  76. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
  77. [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
  78. leftButton.hidden = YES;
  79. }];
  80. imagePickerVc.showSelectBtn = NO;
  81. imagePickerVc.allowCrop = YES;
  82. imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
  83. imagePickerVc.allowTakePicture = NO;
  84. imagePickerVc.allowTakeVideo = NO;
  85. imagePickerVc.allowPickingOriginalPhoto = NO;
  86. imagePickerVc.allowPickingGif = NO;
  87. [imagePickerVc setIsStatusBarDefault:YES];
  88. [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
  89. [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
  90. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  91. PHAsset *asset = assets.firstObject;
  92. switch (asset.mediaType) {
  93. case PHAssetMediaTypeVideo: {
  94. } break;
  95. case PHAssetMediaTypeImage: {
  96. UIImage * image = photos.firstObject;
  97. dispatch_async(dispatch_get_main_queue(), ^{
  98. weakSelf.image = image;
  99. weakSelf.IconImgV.image = image;
  100. });
  101. } break;
  102. case PHAssetMediaTypeAudio:
  103. break;
  104. case PHAssetMediaTypeUnknown:
  105. break;
  106. default: break;
  107. }
  108. }];
  109. [self presentViewController:imagePickerVc animated:YES completion:nil];
  110. }
  111. - (IBAction)ChangeAction:(id)sender {
  112. WS(weakSelf);
  113. [self.IntreField resignFirstResponder];
  114. [self.NameField resignFirstResponder];
  115. [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) {
  116. if(type == ShowPhotoCameraType1){
  117. NSLog(@"相机");
  118. [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  119. NSLog(@"222222");
  120. } choosImgBlock:^(UIImage *image) {
  121. NSLog(@"oooooo");
  122. weakSelf.image = image;
  123. weakSelf.IconImgV.image = image;
  124. }];
  125. }else if (type == ShowPhotoCameraType2){
  126. NSLog(@"相册");
  127. [weakSelf chatBarDidPhotoAction];
  128. }
  129. } cancle:^{
  130. }] showWithAnimation:kAlertAnimationBottom];
  131. }
  132. - (void)postGroupAvatar:(UIImage*)image withCompletion:(void(^)(BOOL success,NSString *imageUrl))completionHandler{
  133. NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post];
  134. [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
  135. if (completionHandler) {
  136. completionHandler(YES,responseObject[@"AbsolutePath"]);
  137. }
  138. } failure:^(NSError * _Nonnull error) {
  139. if (completionHandler) {
  140. completionHandler(NO,nil);
  141. }
  142. }];
  143. }
  144. @end