MyInfoVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. //
  2. // MyInfoVC.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/1.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyInfoVC.h"
  9. #import "MyInfoCell.h"
  10. #import "ShowPhotoCameraAlertView.h"
  11. #import "LYLPhotoTailoringTool.h"
  12. #import "EditUserNickVC.h"
  13. #import "ShowGenderAlertView.h"
  14. #import "EditMySignOrBriefVC.h"
  15. #import "MyQRCodeVC.h"
  16. #import "EditPhoneOrEmailVC.h"
  17. #import "H5ViewController.h"
  18. #import "H6ViewController.h"
  19. #import "MyUserIconVC.h"
  20. @interface MyInfoVC ()<UITableViewDelegate,UITableViewDataSource>
  21. @property (strong,nonatomic) IBOutlet UITableView *tableView;
  22. @property (strong,nonatomic) UIImageView *showUserTestUserImg;
  23. @property (strong,nonatomic) UILabel *showUserGenderLabel;
  24. @end
  25. @implementation MyInfoVC
  26. +(MyInfoVC *)initMyInfoVC{
  27. MyInfoVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"MyInfoVC"];
  28. return controller;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.fd_prefersNavigationBarHidden = YES;
  33. self.view.backgroundColor = RGB(238, 238, 238);
  34. if (@available(iOS 11.0, *)) {
  35. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  36. } else {
  37. self.automaticallyAdjustsScrollViewInsets = NO;
  38. }
  39. self.tableView.delegate = self;
  40. self.tableView.dataSource = self;
  41. self.tableView.backgroundColor = [UIColor clearColor];
  42. self.tableView.estimatedRowHeight = 0;
  43. self.tableView.estimatedSectionHeaderHeight = 0;
  44. self.tableView.estimatedSectionFooterHeight = 0;
  45. }
  46. - (void)viewWillAppear:(BOOL)animated{
  47. [super viewWillAppear:animated];
  48. [self.tableView reloadData];
  49. }
  50. - (void)viewDidAppear:(BOOL)animated{
  51. [super viewDidAppear:animated];
  52. [self.tableView reloadData];
  53. }
  54. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  55. return 3;
  56. }
  57. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  58. switch (section) {
  59. case 0:{
  60. return 3;
  61. }break;
  62. case 1:{
  63. return 3;
  64. }break;
  65. case 2:{
  66. return 3;
  67. }break;
  68. default:break;
  69. }
  70. return 0;
  71. }
  72. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  73. switch (indexPath.section) {
  74. case 0:{
  75. return [MyInfoCell configCell0Height];
  76. }break;
  77. case 1:{
  78. return [MyInfoCell configCell1Height];
  79. }break;
  80. case 2:{
  81. return [MyInfoCell configCell1Height];
  82. }break;
  83. default:break;
  84. }
  85. return 0;
  86. }
  87. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  88. UIView *headerView = [[UIView alloc]init];
  89. [headerView setBackgroundColor:RGBA(238, 238, 238, 1)];
  90. return headerView;
  91. }
  92. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  93. UIView *headerView = [[UIView alloc]init];
  94. [headerView setBackgroundColor:RGBA(238, 238, 238, 1)];
  95. return headerView;
  96. }
  97. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  98. return 0;
  99. }
  100. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  101. if(section == 0 || section == 1){
  102. return 10;
  103. }
  104. return 0;
  105. }
  106. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  107. WS(weakSelf);
  108. switch (indexPath.section) {
  109. case 0:{
  110. switch (indexPath.row) {
  111. case 0:{
  112. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  113. cell.cell0TitleLabel.text = @"头像";
  114. cell.cell0UserImgView.hidden = NO;
  115. [cell.cell0UserImgView sd_setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].AvatarUrl]];
  116. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  117. MyUserIconVC * vc = [MyUserIconVC initMyUserIconVC];
  118. [weakSelf.navigationController pushViewController:vc animated:YES];
  119. }];
  120. [cell.cell0UserImgView addGestureRecognizer:tap];
  121. cell.cell0UserImgView.userInteractionEnabled = YES;
  122. self.showUserTestUserImg = cell.cell0UserImgView;
  123. return cell;
  124. }break;
  125. case 1:{
  126. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  127. cell.cell0TitleLabel.text = @"昵称";
  128. cell.cell0ValueLabel.text = [self showStringLength:[AppUserModel sharedAppUserModel].Nick];
  129. return cell;
  130. }break;
  131. case 2:{
  132. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  133. cell.cell0TitleLabel.text = @"性别";
  134. cell.cell0ValueLabel.text = [[AppUserModel sharedAppUserModel].Gender isEqualToString:@"Male"] ? @"男":@"女";
  135. cell.cell0LineView.hidden = YES;
  136. self.showUserGenderLabel = cell.cell0ValueLabel;
  137. return cell;
  138. }break;
  139. default:
  140. break;
  141. }
  142. }break;
  143. case 1:{
  144. switch (indexPath.row) {
  145. case 0:{
  146. MyInfoCell *cell = [MyInfoCell configCell1:tableView indexPath:indexPath];
  147. cell.cell1TitleLabel.text = @"单位";
  148. cell.cell1ValueLabel.text = ISEmptyString([AppUserModel sharedAppUserModel].DepartmentName) ? @"暂无单位": [self showStringLength:[AppUserModel sharedAppUserModel].DepartmentName];
  149. return cell;
  150. }break;
  151. case 1:{
  152. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  153. cell.cell0TitleLabel.text = @"自我介绍";
  154. cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].description) ? @"":[self showStringLength:[AppUserModel sharedAppUserModel].Description]
  155. return cell;
  156. }break;
  157. case 2:{
  158. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  159. cell.cell0TitleLabel.text = @"我的签名";
  160. cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].Signature) ? @"广西出版集团撰稿人":[self showStringLength:[AppUserModel sharedAppUserModel].Signature]
  161. cell.cell0LineView.hidden = YES;
  162. return cell;
  163. }break;
  164. default:
  165. break;
  166. }
  167. }break;
  168. case 2:{
  169. switch (indexPath.row) {
  170. case 0:{
  171. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  172. cell.cell0TitleLabel.text = @"二维码";
  173. cell.cell0ErWeiMaImgView.hidden = NO;
  174. cell.cell0ErWeiMaImgView.image = [UIImage imageNamed:@"my_qrcode_code_icon"];
  175. return cell;
  176. }break;
  177. case 1:{
  178. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  179. cell.cell0TitleLabel.text = @"手机号";
  180. cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].Phone) ? @"":[AppUserModel sharedAppUserModel].Phone
  181. return cell;
  182. }break;
  183. case 2:{
  184. MyInfoCell *cell = [MyInfoCell configCell0:tableView indexPath:indexPath];
  185. cell.cell0TitleLabel.text = @"邮箱";
  186. cell.cell0ValueLabel.text = @"";//ISEmptyString([AppUserModel sharedAppUserModel].Email) ? @"":[AppUserModel sharedAppUserModel].Email;
  187. cell.cell0LineView.hidden = YES;
  188. return cell;
  189. }break;
  190. default:
  191. break;
  192. }
  193. }break;
  194. default:break;
  195. }
  196. return nil;
  197. }
  198. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  199. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  200. WS(weakSelf);
  201. switch (indexPath.section) {
  202. case 0:{
  203. switch (indexPath.row) {
  204. case 0:{
  205. [[ShowPhotoCameraAlertView initShowPhotoCameraAlertViewConfirm:^(ShowPhotoCameraType type) {
  206. if(type == ShowPhotoCameraType1){
  207. NSLog(@"相册");
  208. [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  209. NSLog(@"111111");
  210. } choosImgBlock:^(UIImage *image) {
  211. NSLog(@"aaaaaa");
  212. self.showUserTestUserImg.image = image;
  213. SHOWLOADING
  214. [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{@"":@""} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
  215. NSDictionary *dic = responseObject;
  216. NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]);
  217. NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]);
  218. [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) {
  219. REMOVESHOW;
  220. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,UserDetailGet] parameters:@{} success:^(id _Nonnull responseObject) {
  221. NSDictionary *dic = responseObject;
  222. [[AppUserModel sharedAppUserModel] modelSetWithDictionary:dic];
  223. dispatch_async(dispatch_get_main_queue(), ^{
  224. [weakSelf.tableView reloadRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
  225. });
  226. } failure:^(NSError * _Nonnull error) {
  227. }];
  228. } failure:^(NSError * _Nonnull error) {
  229. REMOVESHOW
  230. SHOWERROR([ZYCTool handerResultData:error])
  231. }];
  232. } failure:^(NSError * _Nonnull error) {
  233. REMOVESHOW
  234. SHOWERROR([ZYCTool handerResultData:error])
  235. }];
  236. }];
  237. }else if (type == ShowPhotoCameraType2){
  238. NSLog(@"相机");
  239. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
  240. [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
  241. leftButton.hidden = YES;
  242. }];
  243. imagePickerVc.showSelectBtn = NO;
  244. imagePickerVc.allowCrop = YES;
  245. imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
  246. imagePickerVc.allowTakePicture = NO;
  247. imagePickerVc.allowTakeVideo = NO;
  248. imagePickerVc.allowPickingOriginalPhoto = NO;
  249. imagePickerVc.allowPickingGif = NO;
  250. [imagePickerVc setIsStatusBarDefault:YES];
  251. [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
  252. [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
  253. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  254. PHAsset *asset = assets.firstObject;
  255. switch (asset.mediaType) {
  256. case PHAssetMediaTypeVideo: {
  257. } break;
  258. case PHAssetMediaTypeImage: {
  259. UIImage * image = photos.firstObject;
  260. [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
  261. NSDictionary *dic = responseObject;
  262. NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]);
  263. NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]);
  264. [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) {
  265. REMOVESHOW;
  266. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,UserDetailGet] parameters:@{} success:^(id _Nonnull responseObject) {
  267. NSDictionary *dic = responseObject;
  268. [[AppUserModel sharedAppUserModel] modelSetWithDictionary:dic];
  269. dispatch_async(dispatch_get_main_queue(), ^{
  270. [weakSelf.tableView reloadRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
  271. });
  272. } failure:^(NSError * _Nonnull error) {
  273. }];
  274. } failure:^(NSError * _Nonnull error) {
  275. REMOVESHOW
  276. SHOWERROR([ZYCTool handerResultData:error])
  277. }];
  278. } failure:^(NSError * _Nonnull error) {
  279. REMOVESHOW
  280. SHOWERROR([ZYCTool handerResultData:error])
  281. }];
  282. } break;
  283. case PHAssetMediaTypeAudio:
  284. break;
  285. case PHAssetMediaTypeUnknown:
  286. break;
  287. default: break;
  288. }
  289. }];
  290. [self presentViewController:imagePickerVc animated:YES completion:nil];
  291. // [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  292. // NSLog(@"222222");
  293. //
  294. // } choosImgBlock:^(UIImage *image) {
  295. // NSLog(@"oooooo");
  296. // self.showUserTestUserImg.image = image;
  297. //
  298. // [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{@"":@""} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
  299. //
  300. // NSDictionary *dic = responseObject;
  301. // NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]);
  302. // NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]);
  303. //
  304. // [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) {
  305. // REMOVESHOW;
  306. // SHOWSUCCESS(@"修改成功");
  307. // } failure:^(NSError * _Nonnull error) {
  308. // REMOVESHOW
  309. // SHOWERROR([ZYCTool handerResultData:error])
  310. // }];
  311. //
  312. // } failure:^(NSError * _Nonnull error) {
  313. // REMOVESHOW
  314. // SHOWERROR([ZYCTool handerResultData:error])
  315. // }];
  316. // }];
  317. }
  318. } cancle:^{
  319. }] showWithAnimation:kAlertAnimationBottom];
  320. }break;
  321. case 1:{
  322. EditMySignOrBriefVC *vc = [EditMySignOrBriefVC initEditMySignOrBriefVC];
  323. vc.pagetype = EditMySignOrBriefPageType3;
  324. vc.hidesBottomBarWhenPushed = YES;
  325. [self.navigationController pushViewController:vc animated:YES];
  326. }break;
  327. case 2:{
  328. WS(weakSelf);
  329. [[ShowGenderAlertView initShowGenderAlertViewWithGender:self.showUserGenderLabel.text confirm:^(NSString * _Nonnull gender) {
  330. weakSelf.showUserGenderLabel.text = gender;
  331. NSString *sexType = [gender isEqualToString:@"男"] ? @"Male":@"Female";
  332. SHOWLOADING
  333. [UserManager updateUserInfoDetail:Sex Param:sexType Success:^(id _Nonnull responseObject) {
  334. REMOVESHOW
  335. [UserManager getUserInfoDetail];
  336. } failure:^(NSError * _Nonnull error) {
  337. REMOVESHOW
  338. SHOWERROR([ZYCTool handerResultData:error]);
  339. }];
  340. } cancle:^{
  341. }] showWithAnimation:kAlertAnimationBottom];
  342. }break;
  343. default:
  344. break;
  345. }
  346. }break;
  347. case 1:{
  348. switch (indexPath.row) {
  349. case 0:{
  350. }break;
  351. case 1:{
  352. EditMySignOrBriefVC *vc = [EditMySignOrBriefVC initEditMySignOrBriefVC];
  353. vc.pagetype = EditMySignOrBriefPageType2;
  354. vc.hidesBottomBarWhenPushed = YES;
  355. [self.navigationController pushViewController:vc animated:YES];
  356. }break;
  357. case 2:{
  358. EditMySignOrBriefVC *vc = [EditMySignOrBriefVC initEditMySignOrBriefVC];
  359. vc.pagetype = EditMySignOrBriefPageType1;
  360. vc.hidesBottomBarWhenPushed = YES;
  361. [self.navigationController pushViewController:vc animated:YES];
  362. }break;
  363. default:
  364. break;
  365. }
  366. }break;
  367. case 2:{
  368. switch (indexPath.row) {
  369. case 0:{
  370. MyQRCodeVC *vc = [MyQRCodeVC initMyQRCodeVC];
  371. vc.hidesBottomBarWhenPushed = YES;
  372. [self.navigationController pushViewController:vc animated:YES];
  373. // H5ViewController *vc = [[H5ViewController alloc] init];
  374. // vc.hidesBottomBarWhenPushed = YES;
  375. // [self.navigationController pushViewController:vc animated:YES];
  376. }break;
  377. case 1:{
  378. EditPhoneOrEmailVC *vc = [EditPhoneOrEmailVC initEditPhoneOrEmailVC];
  379. vc.pageType = BindingOrChangePhoneOrEmailPageType1;
  380. [self.navigationController pushViewController:vc animated:YES];
  381. // H6ViewController *vc = [[H6ViewController alloc] init];
  382. // vc.hidesBottomBarWhenPushed = YES;
  383. // [self.navigationController pushViewController:vc animated:YES];
  384. }break;
  385. case 2:{
  386. if (ISEmptyString([AppUserModel sharedAppUserModel].Email)) {
  387. EditPhoneOrEmailVC *vc = [EditPhoneOrEmailVC initEditPhoneOrEmailVC];
  388. vc.pageType = BindingOrChangePhoneOrEmailPageType4;
  389. [self.navigationController pushViewController:vc animated:YES];
  390. }else{
  391. EditPhoneOrEmailVC *vc = [EditPhoneOrEmailVC initEditPhoneOrEmailVC];
  392. vc.pageType = BindingOrChangePhoneOrEmailPageType2;
  393. [self.navigationController pushViewController:vc animated:YES];
  394. }
  395. }break;
  396. default:
  397. break;
  398. }
  399. }break;
  400. default:
  401. break;
  402. }
  403. }
  404. - (void)uploadImage{
  405. }
  406. - (NSString *)showStringLength:(NSString *)str
  407. {
  408. if (str.length >= 20) {
  409. NSString * newStr = [str substringToIndex:10];
  410. return [NSString stringWithFormat:@"%@...",newStr];
  411. }
  412. return str;
  413. }
  414. @end