// // MyInfoVC.m // smartRhino // // Created by armin on 2019/11/1. // Copyright © 2019 tederen. All rights reserved. // #import "MyInfoVC.h" #import "MyInfoCell.h" #import "ShowPhotoCameraAlertView.h" #import "LYLPhotoTailoringTool.h" #import "EditUserNickVC.h" #import "ShowGenderAlertView.h" #import "EditMySignOrBriefVC.h" #import "MyQRCodeVC.h" #import "EditPhoneOrEmailVC.h" #import "H5ViewController.h" #import "H6ViewController.h" #import "MyUserIconVC.h" @interface MyInfoVC () @property (strong,nonatomic) IBOutlet UITableView *tableView; @property (strong,nonatomic) UIImageView *showUserTestUserImg; @property (strong,nonatomic) UILabel *showUserGenderLabel; @end @implementation MyInfoVC +(MyInfoVC *)initMyInfoVC{ MyInfoVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"MyInfoVC"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = RGB(238, 238, 238); if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.estimatedRowHeight = 0; self.tableView.estimatedSectionHeaderHeight = 0; self.tableView.estimatedSectionFooterHeight = 0; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.tableView reloadData]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self.tableView reloadData]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ switch (section) { case 0:{ return 3; }break; case 1:{ return 3; }break; case 2:{ return 3; }break; default:break; } return 0; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ switch (indexPath.section) { case 0:{ return [MyInfoCell configCell0Height]; }break; case 1:{ return [MyInfoCell configCell1Height]; }break; case 2:{ return [MyInfoCell configCell1Height]; }break; default:break; } return 0; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *headerView = [[UIView alloc]init]; [headerView setBackgroundColor:RGBA(238, 238, 238, 1)]; return headerView; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *headerView = [[UIView alloc]init]; [headerView setBackgroundColor:RGBA(238, 238, 238, 1)]; return headerView; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if(section == 0 || section == 1){ return 10; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ WS(weakSelf); switch (indexPath.section) { case 0:{ switch (indexPath.row) { case 0:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"头像"; cell.cell0UserImgView.hidden = NO; [cell.cell0UserImgView sd_setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].AvatarUrl]]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { MyUserIconVC * vc = [MyUserIconVC initMyUserIconVC]; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [cell.cell0UserImgView addGestureRecognizer:tap]; cell.cell0UserImgView.userInteractionEnabled = YES; self.showUserTestUserImg = cell.cell0UserImgView; return cell; }break; case 1:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"昵称"; cell.cell0ValueLabel.text = [self showStringLength:[AppUserModel sharedAppUserModel].Nick]; return cell; }break; case 2:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"性别"; cell.cell0ValueLabel.text = [[AppUserModel sharedAppUserModel].Gender isEqualToString:@"Male"] ? @"男":@"女"; cell.cell0LineView.hidden = YES; self.showUserGenderLabel = cell.cell0ValueLabel; return cell; }break; default: break; } }break; case 1:{ switch (indexPath.row) { case 0:{ MyInfoCell *cell = [MyInfoCell configCell1:tableView indexPath:indexPath]; cell.cell1TitleLabel.text = @"单位"; cell.cell1ValueLabel.text = ISEmptyString([AppUserModel sharedAppUserModel].DepartmentName) ? @"暂无单位": [self showStringLength:[AppUserModel sharedAppUserModel].DepartmentName]; return cell; }break; case 1:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"自我介绍"; cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].description) ? @"":[self showStringLength:[AppUserModel sharedAppUserModel].Description] return cell; }break; case 2:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"我的签名"; cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].Signature) ? @"广西出版集团撰稿人":[self showStringLength:[AppUserModel sharedAppUserModel].Signature] cell.cell0LineView.hidden = YES; return cell; }break; default: break; } }break; case 2:{ switch (indexPath.row) { case 0:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"二维码"; cell.cell0ErWeiMaImgView.hidden = NO; cell.cell0ErWeiMaImgView.image = [UIImage imageNamed:@"my_qrcode_code_icon"]; return cell; }break; case 1:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"手机号"; cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].Phone) ? @"":[AppUserModel sharedAppUserModel].Phone return cell; }break; case 2:{ MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = @"邮箱"; cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].Email) ? @"":[AppUserModel sharedAppUserModel].Email; cell.cell0LineView.hidden = YES; return cell; }break; default: break; } }break; default:break; } return nil; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; WS(weakSelf); switch (indexPath.section) { case 0:{ switch (indexPath.row) { case 0:{ [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) { if(type == ShowPhotoCameraType1){ NSLog(@"相册"); [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) { NSLog(@"111111"); } choosImgBlock:^(UIImage *image) { NSLog(@"aaaaaa"); self.showUserTestUserImg.image = image; SHOWLOADING [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{@"":@""} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) { NSDictionary *dic = responseObject; NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]); NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]); [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) { REMOVESHOW; [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,UserDetailGet] parameters:@{} success:^(id _Nonnull responseObject) { NSDictionary *dic = responseObject; [[AppUserModel sharedAppUserModel] modelSetWithDictionary:dic]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] withRowAnimation:UITableViewRowAnimationAutomatic]; }); } failure:^(NSError * _Nonnull error) { }]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; }]; }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 *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { PHAsset *asset = assets.firstObject; switch (asset.mediaType) { case PHAssetMediaTypeVideo: { } break; case PHAssetMediaTypeImage: { UIImage * image = photos.firstObject; [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) { NSDictionary *dic = responseObject; NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]); NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]); [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) { REMOVESHOW; [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,UserDetailGet] parameters:@{} success:^(id _Nonnull responseObject) { NSDictionary *dic = responseObject; [[AppUserModel sharedAppUserModel] modelSetWithDictionary:dic]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] withRowAnimation:UITableViewRowAnimationAutomatic]; }); } failure:^(NSError * _Nonnull error) { }]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]) }]; } break; case PHAssetMediaTypeAudio: break; case PHAssetMediaTypeUnknown: break; default: break; } }]; [self presentViewController:imagePickerVc animated:YES completion:nil]; // [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) { // NSLog(@"222222"); // // } choosImgBlock:^(UIImage *image) { // NSLog(@"oooooo"); // self.showUserTestUserImg.image = image; // // [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{@"":@""} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) { // // NSDictionary *dic = responseObject; // NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]); // NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]); // // [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) { // REMOVESHOW; // SHOWSUCCESS(@"修改成功"); // } failure:^(NSError * _Nonnull error) { // REMOVESHOW // SHOWERROR([ZYCTool handerResultData:error]) // }]; // // } failure:^(NSError * _Nonnull error) { // REMOVESHOW // SHOWERROR([ZYCTool handerResultData:error]) // }]; // }]; } } cancle:^{ }] showWithAnimation:kAlertAnimationBottom]; }break; case 1:{ EditMySignOrBriefVC *vc = [EditMySignOrBriefVC initEditMySignOrBriefVC]; vc.pagetype = EditMySignOrBriefPageType3; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }break; case 2:{ WS(weakSelf); [[ShowGenderAlertView initShowGenderAlertViewWithGender:self.showUserGenderLabel.text confirm:^(NSString * _Nonnull gender) { weakSelf.showUserGenderLabel.text = gender; NSString *sexType = [gender isEqualToString:@"男"] ? @"Male":@"Female"; SHOWLOADING [UserManager updateUserInfoDetail:Sex Param:sexType Success:^(id _Nonnull responseObject) { REMOVESHOW [UserManager getUserInfoDetail]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]); }]; } cancle:^{ }] showWithAnimation:kAlertAnimationBottom]; }break; default: break; } }break; case 1:{ switch (indexPath.row) { case 0:{ }break; case 1:{ EditMySignOrBriefVC *vc = [EditMySignOrBriefVC initEditMySignOrBriefVC]; vc.pagetype = EditMySignOrBriefPageType2; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }break; case 2:{ EditMySignOrBriefVC *vc = [EditMySignOrBriefVC initEditMySignOrBriefVC]; vc.pagetype = EditMySignOrBriefPageType1; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; }break; default: break; } }break; case 2:{ switch (indexPath.row) { case 0:{ MyQRCodeVC *vc = [MyQRCodeVC initMyQRCodeVC]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; // H5ViewController *vc = [[H5ViewController alloc] init]; // vc.hidesBottomBarWhenPushed = YES; // [self.navigationController pushViewController:vc animated:YES]; }break; case 1:{ EditPhoneOrEmailVC *vc = [EditPhoneOrEmailVC initEditPhoneOrEmailVC]; vc.pageType = BindingOrChangePhoneOrEmailPageType1; [self.navigationController pushViewController:vc animated:YES]; // H6ViewController *vc = [[H6ViewController alloc] init]; // vc.hidesBottomBarWhenPushed = YES; // [self.navigationController pushViewController:vc animated:YES]; }break; case 2:{ if (ISEmptyString([AppUserModel sharedAppUserModel].Email)) { EditPhoneOrEmailVC *vc = [EditPhoneOrEmailVC initEditPhoneOrEmailVC]; vc.pageType = BindingOrChangePhoneOrEmailPageType4; [self.navigationController pushViewController:vc animated:YES]; }else{ EditPhoneOrEmailVC *vc = [EditPhoneOrEmailVC initEditPhoneOrEmailVC]; vc.pageType = BindingOrChangePhoneOrEmailPageType2; [self.navigationController pushViewController:vc animated:YES]; } }break; default: break; } }break; default: break; } } - (void)uploadImage{ } - (NSString *)showStringLength:(NSString *)str { if (str.length >= 20) { NSString * newStr = [str substringToIndex:10]; return [NSString stringWithFormat:@"%@...",newStr]; } return str; } @end