123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- //
- // ChatNewRowVC.m
- // smartRhino
- //
- // Created by niuzhen on 2019/12/10.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "ChatNewRowVC.h"
- #import "ShowPhotoCameraAlertView.h"
- #import "LYLPhotoTailoringTool.h"
- #import "SendInfoGroupVC.h"
- #import "MailListVC.h"
- #import "AddLookUpUserSecondVC.h"
- #import "TDGroupQrcodeVC.h"
- #import "TDGroupInfoListModel.h"
- #import "NewRowUserCell.h"
- @interface ChatNewRowVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
- @property (strong,nonatomic) IBOutlet UIButton *rightSureBtn;
- @property (weak, nonatomic) IBOutlet UITextField *groupNameTf;
- @property (weak, nonatomic) IBOutlet UITextField *groupIntroTf;
- @property (weak, nonatomic) IBOutlet UIImageView *groupImgView;
- @property (weak, nonatomic) IBOutlet UILabel *avatarTipLab;
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (nonatomic, strong) NSString *groupName ;
- @property (nonatomic, strong) NSString *groupIntroduce ;
- @property (nonatomic, strong) NSString *avatarUrl ;
- @property (nonatomic, strong) NSString *imId ;
- @property (nonatomic, strong) UIImage *groupImage ;
- @property (nonatomic, strong) NSMutableArray * selectArray;
- @property (nonatomic, strong) NSMutableArray * selectIdArray;
- @property (nonatomic, assign) bool isWords;
- @property (nonatomic, assign) bool isAdmin;
- @property (nonatomic, assign) bool isUDisturb ;
- @end
- @implementation ChatNewRowVC
- +(ChatNewRowVC *)initChatNewRowVC{
- ChatNewRowVC *controller = [StoryboardManager.shared.TDGroup instantiateViewControllerWithIdentifier:@"ChatNewRowVC"];
- return controller;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.fd_prefersNavigationBarHidden = YES;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recviveChaoSongRen:) name:NOTIFI_ChaoSongRen object:nil];
- WEAKSELF
- [self.rightSureBtn setAction:^{
- weakSelf.rightSureBtn.enabled = NO;
- [weakSelf createGroupChat];
- }];
- self.groupNameTf.delegate = self;
- self.groupIntroTf.delegate = self;
- self.groupNameTf.returnKeyType = UIReturnKeyDone;
- self.groupIntroTf.returnKeyType = UIReturnKeyDone;
- [self.groupNameTf becomeFirstResponder];
- }
- -(IBAction)userDidUpImgAction:(id)sender{
- WEAKSELF
- [self.groupNameTf resignFirstResponder];
- [self.groupIntroTf resignFirstResponder];
- [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) {
- if(type == ShowPhotoCameraType1){
- [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
- } choosImgBlock:^(UIImage *image) {
- weakSelf.groupImage = image;
- weakSelf.groupImgView.image = image;
- weakSelf.avatarTipLab.text = @"";
- }];
- }else if (type == ShowPhotoCameraType2){
- NSLog(@"相册");
- 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;
- weakSelf.groupImage = image;
- weakSelf.groupImgView.image = image;
- weakSelf.avatarTipLab.text = @"";
- } break;
- case PHAssetMediaTypeAudio:
- break;
- case PHAssetMediaTypeUnknown:
- break;
- default:
- break;
- }
- }];
- [self presentViewController:imagePickerVc animated:YES completion:nil];
- }
- } cancle:^{
- }] showWithAnimation:kAlertAnimationBottom];
- }
- -(IBAction)userDidAddFriendeAction:(id)sender{
- [self.view endEditing:YES];
- Department *defaltGroupSetion = [[Department alloc]init];
- defaltGroupSetion.Name = @"单位通讯录";
- defaltGroupSetion.Id = 0;
-
- Department *myGroupSetion = [[Department alloc]init];
- myGroupSetion.Name = @"自建通讯录";
- defaltGroupSetion.Id = 0;
-
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
- vc.isDefalutPage = 1;
- vc.titleStr = @"添加成员";
- vc.UserIds = self.selectIdArray;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)recviveChaoSongRen:(NSNotification *)notification{
- NSMutableArray <SelectModel *>* array = notification.userInfo[@"selectPeople"];
-
- NSMutableArray <SelectModel *>* array0 = self.selectArray;
- NSMutableArray <SelectModel *>* array1 = notification.userInfo[@"selectPeople"];
- if (array0.count == 0) {
- [self.selectArray addObjectsFromArray:array];
- }else{
- for (NSInteger x = 0; x < array.count; x++) {
- for (NSInteger y = 0 ; y < array0.count; y++) {
- if (array[x].UserId == array0[y].UserId) {
- [array1 removeObjectAtIndex:x];
- }
- }
- }
- NSLog(@"结果数据组%@",array1);
- [self.selectArray addObjectsFromArray:array1];
- }
- if (self.selectArray.count > 0) {
- for (NSInteger i = 0; i < self.selectArray.count; i ++) {
- SelectModel * model = self.selectArray[i];
- [self.selectIdArray addObject:@(model.UserId)];
- }
- [self.tableView reloadData];
- }
- }
- - (void)createGroupChat{
- if (self.groupNameTf.text.length == 0) {
- SHOWERROR(@"请输入小组名称")
- return;
- }else{
- self.groupName = self.groupNameTf.text;
- }
- if (self.groupIntroTf.text.length==0) {
- SHOWERROR(@"请添加小组介绍")
- return;
- }else{
- self.groupIntroduce = self.groupIntroTf.text;
- }
- WEAKSELF
- self.rightSureBtn.enabled = NO;
- if (self.groupImage) {
- [self postGroupAvatar:self.groupImage withCompletion:^(BOOL success, NSString *imageUrl) {
- if (success) {
- weakSelf.avatarUrl = imageUrl;
- [weakSelf postGroupMsg];
- }
- }];
- }else{
- SHOWERROR(@"请上传小组头像");
- self.rightSureBtn.enabled = YES;
- return;
- }
- }
- - (void)postGroupMsg{
- NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
- [dict setValue:self.groupName forKey:@"Name"];
- [dict setValue:self.groupIntroduce forKey:@"Introduce"];
- [dict setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
- [dict setValue:@(self.isWords) forKey:@"IsWords"];
- [dict setValue:@(self.isAdmin) forKey:@"IsAdmin"];
- [dict setValue:self.avatarUrl forKey:@"AvatarUrl"];
- [dict setValue:self.selectIdArray forKey:@"UserIds"];
- [dict setValue:@"" forKey:@"QRCoder"];
- [dict setValue:@(self.isUDisturb) forKey:@"IsUDisturb"];
- [dict setValue:@(self.GroupFolderId) forKey:@"GroupFolderId"];
- WS(weakSelf);
- SHOWLOADING
- [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Group_Insert) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- weakSelf.rightSureBtn.enabled = YES;
- NSLog(@"%@",responseObject);
- dispatch_async(dispatch_get_main_queue(), ^{
- TDGroupQrcodeVC * vc = [TDGroupQrcodeVC initTDGroupQrcodeVC];
- TDGroupInfoListModel * model = [TDGroupInfoListModel modelWithDictionary:responseObject];
- vc.model = model;
- vc.isCreate = YES;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- weakSelf.rightSureBtn.enabled = YES;
- SHOWERROR(@"创建失败")
- }];
- }
- - (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);
- }
- }];
- }
- - (NSMutableArray *)selectArray
- {
- if (!_selectArray) {
- _selectArray = [NSMutableArray array];
- }
- return _selectArray;
- }
- - (NSMutableArray *)selectIdArray
- {
- if (!_selectIdArray) {
- _selectIdArray = [NSMutableArray array];
- }
- return _selectIdArray;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.selectArray.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 65.f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- SelectModel *model = [self.selectArray objectAtIndex:indexPath.row];
- NewRowUserCell *cell = [NewRowUserCell configCell:tableView indexPath:indexPath];
- [cell.imagV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
- cell.nameL.text = model.UserName;
- WS(weakSelf);
- [cell.CloseBtn setAction:^{
- [weakSelf.selectArray removeObjectAtIndex:indexPath.row];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- }];
- return cell;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- if (textField == self.groupNameTf) {
- if (range.length == 1 && string.length == 0) {
- return YES;
- }
- else if (self.groupNameTf.text.length + string.length >= 12) {
- NSMutableString *oldStr = [[NSMutableString alloc]initWithString:textField.text];
- [oldStr insertString:string atIndex:range.location];
- self.groupNameTf.text = [oldStr substringToIndex:12];
- return NO;
- }
- }
- return YES;
- }
- -(void)textFieldDidEndEditing:(UITextField *)textField{
- if (textField.text.length > 12) {
- textField.text = [textField.text substringToIndex:12];
- SHOWERROR(@"文件夹名称最多12个字");
- }
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [textField resignFirstResponder];
- return YES;
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|