123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- //
- // ChatNewGroupVC.m
- // smartRhino
- //
- // Created by armin on 2019/11/5.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "ChatNewGroupVC.h"
- #import "ShowPhotoCameraAlertView.h"
- #import "LYLPhotoTailoringTool.h"
- #import "SendInfoGroupVC.h"
- #import "MailListVC.h"
- #import "AddLookUpUserSecondVC.h"
- #import "NewRowUserCell.h"
- #import "ChatQrcodeVC.h"
- @interface ChatNewGroupVC ()<UITableViewDelegate,UITableViewDataSource>
- @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 ;
- @end
- @implementation ChatNewGroupVC
- +(ChatNewGroupVC *)initChatNewGroupVC{
- ChatNewGroupVC *controller = [StoryboardManager.shared.chatMsg instantiateViewControllerWithIdentifier:@"ChatNewGroupVC"];
- return controller;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.view.backgroundColor = UIColorHex(#F0EFF4);
- if (self.dataArray.count > 0) {
- [self.selectArray addObjectsFromArray:self.dataArray];
- [self.tableView reloadData];
- }
- self.fd_prefersNavigationBarHidden = YES;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recviveChaoSongRen:) name:NOTIFI_ChaoSongRen object:nil];
- WEAKSELF
- [self.rightSureBtn setAction:^{
- [weakSelf createGroupChat];
- }];
- }
- -(IBAction)userDidUpImgAction:(id)sender{
- WEAKSELF
- [self.groupNameTf resignFirstResponder];
- [self.groupIntroTf resignFirstResponder];
- [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) {
- if(type == ShowPhotoCameraType1){
- NSLog(@"相册");
- [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
- NSLog(@"111111");
- } choosImgBlock:^(UIImage *image) {
- NSLog(@"aaaaaa");
- 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{
- 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.grouperArray = self.dataArray;
- vc.titleStr = @"添加成员";
- [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.Id)];
- // }
- // }
- [self.tableView reloadData];
- }
- //创建群聊
- /*
- {
- "Name": "string",
- "Introduce": "string",
- "AvatarUrl": "string",
- "UserId": 0,
- "ImId": "string",
- "IsWords": true,
- "IsAdmin": true
- }
- */
- - (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
- if (self.groupImage) {
- self.rightSureBtn.enabled = NO;
- [self postGroupAvatar:self.groupImage withCompletion:^(BOOL success, NSString *imageUrl) {
- if (success) {
- weakSelf.avatarUrl = imageUrl;
- [weakSelf postGroupMsg];
- }
- }];
- }else{
- SHOWERROR(@"请上传群聊头像")
- }
- }
- - (void)postGroupMsg{
- [self.selectIdArray removeAllObjects];
- if (self.selectArray.count > 0) {
- for (NSInteger i = 0; i < self.selectArray.count; i ++) {
- SelectModel * model = self.selectArray[i];
- [self.selectIdArray addObject:@(model.UserId)];
- }
- }
- 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"];
- NSString *imid = [self EaseCreatGroupChatWithJoinType:0];
- self.imId = imid;
- [dict setValue:self.imId forKey:@"GroupChatImId"];//创建环信群聊时生成的id
- NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,API_GROUPCHAT_ADD];
- WS(weakSelf);
- SHOWLOADING
- [[HttpManager sharedHttpManager] POSTUrl:urlString parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- SHOWSUCCESS(@"创建成功")
- weakSelf.rightSureBtn.enabled = YES;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- ChatQrcodeVC * vc = [ChatQrcodeVC initChatQrcodeVC];
- vc.dict = responseObject;
- vc.isCreate = YES;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- weakSelf.rightSureBtn.enabled = YES;
- }];
- }
- - (void)postGroupAvatar:(UIImage*)image withCompletion:(void(^)(BOOL success,NSString *imageUrl))completionHandler{
- NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post];
- SHOWLOADING
- [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
- REMOVESHOW
- if (completionHandler) {
- completionHandler(YES,responseObject[@"AbsolutePath"]);
- }
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- if (completionHandler) {
- completionHandler(NO,nil);
- }
- }];
- }
- #pragma mark - 创建群聊
- - (NSString *)EaseCreatGroupChatWithJoinType:(int)type {
- EMGroupOptions *setting = [[EMGroupOptions alloc] init];
- setting.maxUsersCount = 2000;
- if (type == 0) {
- setting.style = EMGroupStylePublicOpenJoin;//公开的 都可以进
- } else {
- setting.style = EMGroupStylePublicJoinNeedApproval;//需要审核
- }
- EMError *error = nil;
- EMGroup *group = [[EMClient sharedClient].groupManager createGroupWithSubject:@"" description:@"" invitees:nil message:nil setting:setting error:&error];
- if (group && !error) {
- return group.groupId;
- } else {
- return @"";
- }
- }
- - (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;
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|