ChatNewRowVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //
  2. // ChatNewRowVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/10.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ChatNewRowVC.h"
  9. #import "ShowPhotoCameraAlertView.h"
  10. #import "LYLPhotoTailoringTool.h"
  11. #import "SendInfoGroupVC.h"
  12. #import "MailListVC.h"
  13. #import "AddLookUpUserSecondVC.h"
  14. #import "TDGroupQrcodeVC.h"
  15. #import "TDGroupInfoListModel.h"
  16. #import "NewRowUserCell.h"
  17. @interface ChatNewRowVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  18. @property (strong,nonatomic) IBOutlet UIButton *rightSureBtn;
  19. @property (weak, nonatomic) IBOutlet UITextField *groupNameTf;
  20. @property (weak, nonatomic) IBOutlet UITextField *groupIntroTf;
  21. @property (weak, nonatomic) IBOutlet UIImageView *groupImgView;
  22. @property (weak, nonatomic) IBOutlet UILabel *avatarTipLab;
  23. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  24. @property (nonatomic, strong) NSString *groupName ;
  25. @property (nonatomic, strong) NSString *groupIntroduce ;
  26. @property (nonatomic, strong) NSString *avatarUrl ;
  27. @property (nonatomic, strong) NSString *imId ;
  28. @property (nonatomic, strong) UIImage *groupImage ;
  29. @property (nonatomic, strong) NSMutableArray * selectArray;
  30. @property (nonatomic, strong) NSMutableArray * selectIdArray;
  31. @property (nonatomic, assign) bool isWords;
  32. @property (nonatomic, assign) bool isAdmin;
  33. @property (nonatomic, assign) bool isUDisturb ;
  34. @end
  35. @implementation ChatNewRowVC
  36. +(ChatNewRowVC *)initChatNewRowVC{
  37. ChatNewRowVC *controller = [StoryboardManager.shared.TDGroup instantiateViewControllerWithIdentifier:@"ChatNewRowVC"];
  38. return controller;
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.tableView.delegate = self;
  43. self.tableView.dataSource = self;
  44. self.fd_prefersNavigationBarHidden = YES;
  45. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recviveChaoSongRen:) name:NOTIFI_ChaoSongRen object:nil];
  46. WEAKSELF
  47. [self.rightSureBtn setAction:^{
  48. weakSelf.rightSureBtn.enabled = NO;
  49. [weakSelf createGroupChat];
  50. }];
  51. self.groupNameTf.delegate = self;
  52. self.groupIntroTf.delegate = self;
  53. self.groupNameTf.returnKeyType = UIReturnKeyDone;
  54. self.groupIntroTf.returnKeyType = UIReturnKeyDone;
  55. [self.groupNameTf becomeFirstResponder];
  56. }
  57. -(IBAction)userDidUpImgAction:(id)sender{
  58. WEAKSELF
  59. [self.groupNameTf resignFirstResponder];
  60. [self.groupIntroTf resignFirstResponder];
  61. [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) {
  62. if(type == ShowPhotoCameraType1){
  63. [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  64. } choosImgBlock:^(UIImage *image) {
  65. weakSelf.groupImage = image;
  66. weakSelf.groupImgView.image = image;
  67. weakSelf.avatarTipLab.text = @"";
  68. }];
  69. }else if (type == ShowPhotoCameraType2){
  70. NSLog(@"相册");
  71. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
  72. [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
  73. leftButton.hidden = YES;
  74. }];
  75. imagePickerVc.showSelectBtn = NO;
  76. imagePickerVc.allowCrop = YES;
  77. imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
  78. imagePickerVc.allowTakePicture = NO;
  79. imagePickerVc.allowTakeVideo = NO;
  80. imagePickerVc.allowPickingOriginalPhoto = NO;
  81. imagePickerVc.allowPickingGif = NO;
  82. [imagePickerVc setIsStatusBarDefault:YES];
  83. [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
  84. [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
  85. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  86. PHAsset *asset = assets.firstObject;
  87. switch (asset.mediaType) {
  88. case PHAssetMediaTypeVideo: {
  89. } break;
  90. case PHAssetMediaTypeImage: {
  91. UIImage * image = photos.firstObject;
  92. weakSelf.groupImage = image;
  93. weakSelf.groupImgView.image = image;
  94. weakSelf.avatarTipLab.text = @"";
  95. } break;
  96. case PHAssetMediaTypeAudio:
  97. break;
  98. case PHAssetMediaTypeUnknown:
  99. break;
  100. default:
  101. break;
  102. }
  103. }];
  104. [self presentViewController:imagePickerVc animated:YES completion:nil];
  105. }
  106. } cancle:^{
  107. }] showWithAnimation:kAlertAnimationBottom];
  108. }
  109. -(IBAction)userDidAddFriendeAction:(id)sender{
  110. [self.view endEditing:YES];
  111. Department *defaltGroupSetion = [[Department alloc]init];
  112. defaltGroupSetion.Name = @"单位通讯录";
  113. defaltGroupSetion.Id = 0;
  114. Department *myGroupSetion = [[Department alloc]init];
  115. myGroupSetion.Name = @"自建通讯录";
  116. defaltGroupSetion.Id = 0;
  117. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  118. vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
  119. vc.isDefalutPage = 1;
  120. vc.titleStr = @"添加成员";
  121. vc.UserIds = self.selectIdArray;
  122. [self.navigationController pushViewController:vc animated:YES];
  123. }
  124. - (void)recviveChaoSongRen:(NSNotification *)notification{
  125. NSMutableArray <SelectModel *>* array = notification.userInfo[@"selectPeople"];
  126. NSMutableArray <SelectModel *>* array0 = self.selectArray;
  127. NSMutableArray <SelectModel *>* array1 = notification.userInfo[@"selectPeople"];
  128. if (array0.count == 0) {
  129. [self.selectArray addObjectsFromArray:array];
  130. }else{
  131. for (NSInteger x = 0; x < array.count; x++) {
  132. for (NSInteger y = 0 ; y < array0.count; y++) {
  133. if (array[x].UserId == array0[y].UserId) {
  134. [array1 removeObjectAtIndex:x];
  135. }
  136. }
  137. }
  138. NSLog(@"结果数据组%@",array1);
  139. [self.selectArray addObjectsFromArray:array1];
  140. }
  141. if (self.selectArray.count > 0) {
  142. for (NSInteger i = 0; i < self.selectArray.count; i ++) {
  143. SelectModel * model = self.selectArray[i];
  144. [self.selectIdArray addObject:@(model.UserId)];
  145. }
  146. [self.tableView reloadData];
  147. }
  148. }
  149. - (void)createGroupChat{
  150. if (self.groupNameTf.text.length == 0) {
  151. SHOWERROR(@"请输入小组名称")
  152. return;
  153. }else{
  154. self.groupName = self.groupNameTf.text;
  155. }
  156. if (self.groupIntroTf.text.length==0) {
  157. SHOWERROR(@"请添加小组介绍")
  158. return;
  159. }else{
  160. self.groupIntroduce = self.groupIntroTf.text;
  161. }
  162. WEAKSELF
  163. self.rightSureBtn.enabled = NO;
  164. if (self.groupImage) {
  165. [self postGroupAvatar:self.groupImage withCompletion:^(BOOL success, NSString *imageUrl) {
  166. if (success) {
  167. weakSelf.avatarUrl = imageUrl;
  168. [weakSelf postGroupMsg];
  169. }
  170. }];
  171. }else{
  172. SHOWERROR(@"请上传小组头像");
  173. self.rightSureBtn.enabled = YES;
  174. return;
  175. }
  176. }
  177. - (void)postGroupMsg{
  178. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  179. [dict setValue:self.groupName forKey:@"Name"];
  180. [dict setValue:self.groupIntroduce forKey:@"Introduce"];
  181. [dict setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  182. [dict setValue:@(self.isWords) forKey:@"IsWords"];
  183. [dict setValue:@(self.isAdmin) forKey:@"IsAdmin"];
  184. [dict setValue:self.avatarUrl forKey:@"AvatarUrl"];
  185. [dict setValue:self.selectIdArray forKey:@"UserIds"];
  186. [dict setValue:@"" forKey:@"QRCoder"];
  187. [dict setValue:@(self.isUDisturb) forKey:@"IsUDisturb"];
  188. [dict setValue:@(self.GroupFolderId) forKey:@"GroupFolderId"];
  189. WS(weakSelf);
  190. SHOWLOADING
  191. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Group_Insert) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  192. REMOVESHOW
  193. weakSelf.rightSureBtn.enabled = YES;
  194. NSLog(@"%@",responseObject);
  195. dispatch_async(dispatch_get_main_queue(), ^{
  196. TDGroupQrcodeVC * vc = [TDGroupQrcodeVC initTDGroupQrcodeVC];
  197. TDGroupInfoListModel * model = [TDGroupInfoListModel modelWithDictionary:responseObject];
  198. vc.model = model;
  199. vc.isCreate = YES;
  200. [weakSelf.navigationController pushViewController:vc animated:YES];
  201. });
  202. } failure:^(NSError * _Nonnull error) {
  203. REMOVESHOW
  204. weakSelf.rightSureBtn.enabled = YES;
  205. SHOWERROR(@"创建失败")
  206. }];
  207. }
  208. - (void)postGroupAvatar:(UIImage*)image withCompletion:(void(^)(BOOL success,NSString *imageUrl))completionHandler{
  209. NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post];
  210. [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
  211. if (completionHandler) {
  212. completionHandler(YES,responseObject[@"AbsolutePath"]);
  213. }
  214. } failure:^(NSError * _Nonnull error) {
  215. if (completionHandler) {
  216. completionHandler(NO,nil);
  217. }
  218. }];
  219. }
  220. - (NSMutableArray *)selectArray
  221. {
  222. if (!_selectArray) {
  223. _selectArray = [NSMutableArray array];
  224. }
  225. return _selectArray;
  226. }
  227. - (NSMutableArray *)selectIdArray
  228. {
  229. if (!_selectIdArray) {
  230. _selectIdArray = [NSMutableArray array];
  231. }
  232. return _selectIdArray;
  233. }
  234. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  235. {
  236. return self.selectArray.count;
  237. }
  238. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  239. {
  240. return 65.f;
  241. }
  242. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  243. {
  244. SelectModel *model = [self.selectArray objectAtIndex:indexPath.row];
  245. NewRowUserCell *cell = [NewRowUserCell configCell:tableView indexPath:indexPath];
  246. [cell.imagV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  247. cell.nameL.text = model.UserName;
  248. WS(weakSelf);
  249. [cell.CloseBtn setAction:^{
  250. [weakSelf.selectArray removeObjectAtIndex:indexPath.row];
  251. dispatch_async(dispatch_get_main_queue(), ^{
  252. [weakSelf.tableView reloadData];
  253. });
  254. }];
  255. return cell;
  256. }
  257. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  258. if (textField == self.groupNameTf) {
  259. if (range.length == 1 && string.length == 0) {
  260. return YES;
  261. }
  262. else if (self.groupNameTf.text.length + string.length >= 12) {
  263. NSMutableString *oldStr = [[NSMutableString alloc]initWithString:textField.text];
  264. [oldStr insertString:string atIndex:range.location];
  265. self.groupNameTf.text = [oldStr substringToIndex:12];
  266. return NO;
  267. }
  268. }
  269. return YES;
  270. }
  271. -(void)textFieldDidEndEditing:(UITextField *)textField{
  272. if (textField.text.length > 12) {
  273. textField.text = [textField.text substringToIndex:12];
  274. SHOWERROR(@"文件夹名称最多12个字");
  275. }
  276. }
  277. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  278. {
  279. [textField resignFirstResponder];
  280. return YES;
  281. }
  282. - (void)dealloc
  283. {
  284. [[NSNotificationCenter defaultCenter] removeObserver:self];
  285. }
  286. @end