MyDetailViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. //
  2. // MyDetailViewController.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/9/26.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "MyDetailViewController.h"
  9. #import "MyDetailModel.h"
  10. #import "MyDetailTableViewCell.h"
  11. #import <AVFoundation/AVCaptureDevice.h>
  12. #import <AVFoundation/AVMediaFormat.h>
  13. #import <AssetsLibrary/AssetsLibrary.h>
  14. #import "PickerView.h"
  15. #import "FeedbackViewController.h"
  16. #import "PersonalCertificationViewController.h"
  17. @interface MyDetailViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate>
  18. @property (weak, nonatomic) IBOutlet UIButton *buttonSave;
  19. @property (strong, nonatomic) UIImage *imageIcon;
  20. @property (strong, nonatomic) PickerView *pickerView;
  21. @property (copy, nonatomic) NSString *sex;
  22. @property (copy, nonatomic) NSString *nickname;
  23. @property (copy, nonatomic) NSString *imageUrl;
  24. @end
  25. @implementation MyDetailViewController
  26. - (PickerView *)pickerView {
  27. WeakSelf(self)
  28. if (!_pickerView) {
  29. _pickerView = [PickerView new];
  30. _pickerView.block = ^(NSString *string, NSInteger selectIndex) {
  31. weakself.sex = string;
  32. NSIndexPath *patn = [NSIndexPath indexPathForRow:2 inSection:0];
  33. [weakself.tableView reloadRowsAtIndexPaths:@[patn] withRowAnimation:UITableViewRowAnimationNone];
  34. [weakself NetworkOfUpdateInfo];
  35. };
  36. }
  37. return _pickerView;
  38. }
  39. - (void)NetworkOfUploadIcon {
  40. SHOWLOADING
  41. // NSString *URL = @"upload/uploadImage";
  42. // [NetWorkRequest PostImages:URL post:nil dicImages:@[self.imageIcon].mutableCopy amrFilePath:nil name:@"file" success:^(id result) {
  43. // NSLog(@"%@",result);
  44. // REMOVESHOW
  45. // if ([result[@"code"] integerValue] == 0) {
  46. //// SHOWSUCCESS(@"修改成功")
  47. // self.imageUrl = result[@"data"][@"fileUrl"];
  48. // [self NetworkOfUpdateInfo];
  49. // }
  50. // } fail:^(id error) {
  51. // REMOVESHOW
  52. // }];
  53. }
  54. - (void)NetworkOfUpdateInfo {
  55. SHOWLOADING
  56. NSString *URL = @"my/updateMessage";
  57. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  58. parameters[@"sex"] = self.sex;
  59. parameters[@"nickname"] = self.nickname;
  60. if (self.imageUrl.length) {
  61. parameters[@"userLogo"] = self.imageUrl;
  62. }
  63. [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  64. REMOVESHOW
  65. NSLog(@"%@",responseObject);
  66. if ([responseObject[@"code"] integerValue] == 0) {
  67. SHOWSUCCESS(@"修改成功")
  68. NSString *string = [NSString stringWithFormat:@"%@",self.imageUrl];
  69. USERDEFAULTSSET(string, @"headimgurl");
  70. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  71. // [self.navigationController popViewControllerAnimated:true];
  72. // });
  73. }else
  74. SHOWERROR(@"修改失败")
  75. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  76. REMOVESHOW
  77. SHOWERROR(@"修改失败")
  78. }];
  79. }
  80. - (void)viewDidLoad {
  81. [super viewDidLoad];
  82. self.title = @"个人信息";
  83. self.view.backgroundColor = kBackgroundColor;
  84. self.sex = self.model.sex;
  85. self.nickname = self.model.nickname;
  86. [self.buttonSave setCorner];
  87. [self createTableView];
  88. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMydetail) name:@"reloadMydetail" object:nil];
  89. }
  90. - (void)createTableView {
  91. self.tableView.delegate = self;
  92. self.tableView.dataSource = self;
  93. self.tableView.tableFooterView = [UIView new];
  94. self.tableView.rowHeight = UITableViewAutomaticDimension;
  95. self.tableView.estimatedRowHeight = 60;
  96. self.tableView.backgroundColor = kBackgroundColor;
  97. }
  98. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  99. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  100. [cell setSeparatorInset:UIEdgeInsetsZero];
  101. }
  102. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  103. [cell setLayoutMargins:UIEdgeInsetsZero];
  104. }
  105. if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  106. [cell setPreservesSuperviewLayoutMargins:NO];
  107. }
  108. }
  109. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  110. return 10;
  111. }
  112. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  113. return 0.01;
  114. }
  115. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  116. UIView *view = [UIView new];
  117. view.backgroundColor = kBackgroundColor;
  118. return view;
  119. }
  120. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  121. UIView *view = [UIView new];
  122. view.backgroundColor = kBackgroundColor;
  123. return view;
  124. }
  125. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  126. return MyDetailModel.arrayData.count;
  127. }
  128. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  129. NSArray *array = MyDetailModel.arrayData[section];
  130. return array.count;
  131. }
  132. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  133. MyDetailTableViewCell *cell = [MyDetailTableViewCell cellWithTableView:tableView];
  134. [cell setDataWithModel:MyDetailModel.arrayData[indexPath.section][indexPath.row]];
  135. cell.textFieldDetail.hidden = true;
  136. cell.textFieldDetail.delegate = self;
  137. cell.imageViewArrow.hidden = false;
  138. if (indexPath.section == 0) {
  139. if (indexPath.row == 1) {
  140. cell.labelDetail.hidden = cell.imageViewIcon.hidden = true;
  141. cell.textFieldDetail.hidden = false;
  142. cell.textFieldDetail.text = self.nickname?:kUserNickName;
  143. [cell.textFieldDetail addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
  144. }else if (indexPath.row == 2) {
  145. cell.labelDetail.text = self.sex?:self.model.sex;
  146. }
  147. cell.imageViewArrow.hidden = true;
  148. if (self.imageIcon) {
  149. cell.imageViewIcon.image = self.imageIcon;
  150. }
  151. }else if (indexPath.section == 2) {
  152. if (indexPath.row == 0) {
  153. cell.textFieldDetail.hidden = false;
  154. cell.textFieldDetail.userInteractionEnabled = false;
  155. cell.textFieldDetail.text = self.model.mobile;
  156. cell.imageViewArrow.hidden = true;
  157. }else if (indexPath.row == 1) {
  158. cell.imageViewArrow.hidden = true;
  159. }else if (indexPath.row == 2) {
  160. /**
  161. 1已认证 2审核中 3未认证 4认证失败
  162. */
  163. cell.textFieldDetail.hidden = false;
  164. cell.textFieldDetail.userInteractionEnabled = false;
  165. if ([kisApprove isEqualToString:@"1"]) {
  166. cell.textFieldDetail.text = @"已认证";
  167. }else if ([kisApprove isEqualToString:@"2"]) {
  168. cell.textFieldDetail.text = @"审核中";
  169. }else if ([kisApprove isEqualToString:@"3"]) {
  170. cell.textFieldDetail.text = @"未认证";
  171. }else if ([kisApprove isEqualToString:@"4"]) {
  172. cell.textFieldDetail.text = @"认证失败";
  173. }
  174. }
  175. }
  176. return cell;
  177. }
  178. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  179. if (indexPath.section == 0) {
  180. if (indexPath.row == 0) {
  181. [self getPhoto];
  182. }else if (indexPath.row == 2) {
  183. [self.pickerView showView];
  184. }
  185. }else if (indexPath.section == 1) {
  186. FeedbackViewController *controller = [FeedbackViewController new];
  187. controller.modelMy = self.model;
  188. controller.URL = @"my/updateMessage";
  189. if (indexPath.row == 0) {
  190. controller.controllerType = FeedbackViewControllerTypeSelfIntroduction;
  191. }else if (indexPath.row == 1) {
  192. controller.controllerType = FeedbackViewControllerTypeSign;
  193. }
  194. [self.navigationController pushViewController:controller animated:true];
  195. }else if (indexPath.section == 2) {
  196. if (indexPath.row == 2) {
  197. PersonalCertificationViewController *controller = [PersonalCertificationViewController new];
  198. controller.controllerType = [kisApprove integerValue];
  199. [self.navigationController pushViewController:controller animated:true];
  200. }
  201. }
  202. }
  203. - (void)getPhoto {
  204. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  205. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  206. picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  207. picker.delegate = self;
  208. picker.allowsEditing = YES;//取消白框
  209. UIAlertAction *camera = [UIAlertAction actionWithTitle:@"相册上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  210. [ZYCTool controller:self AlbumIsAvailable:^{
  211. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  212. [self presentViewController:picker animated:YES completion:^{}];
  213. } OrNotAvailable:^{}];
  214. }];
  215. UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  216. [ZYCTool controller:self CameraIsAvailable:^{
  217. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  218. [self presentViewController:picker animated:YES completion:^{}];
  219. } OrNotAvailable:^{}];
  220. }];
  221. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  222. NSLog(@"点击了取消按钮");
  223. }];
  224. [cancel setValue:[UIColor redColor] forKey:@"titleTextColor"];
  225. [alert addAction:cancel];
  226. [alert addAction:camera];
  227. [alert addAction:photo];
  228. [self presentViewController:alert animated:YES completion:nil];
  229. }
  230. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  231. UIImage *selectIma = [info objectForKey:UIImagePickerControllerEditedImage];
  232. // selectIma = [selectIma fixOrientation];
  233. NSData *Data= UIImageJPEGRepresentation(selectIma, 0.3);
  234. UIImage *new = [UIImage imageWithData:Data];
  235. self.imageIcon = new;
  236. [self.navigationController dismissViewControllerAnimated:YES completion:^{}];
  237. [self.tableView reloadData];
  238. [self NetworkOfUploadIcon];
  239. }
  240. - (IBAction)didTouchButtonSave:(UIButton *)sender {
  241. if (self.sex.length == 0) {
  242. SHOWERROR(@"请选择性别")
  243. return;
  244. }else if (self.nickname.length == 0) {
  245. SHOWERROR(@"请选择性别")
  246. return;
  247. }
  248. // [self NetworkOfUpdateInfo];
  249. }
  250. #pragma 判断手机号/密码长度
  251. - (void)change:(UITextField *)textField {
  252. // if (textField.text.length >= 11) {
  253. // textField.text = [textField.text substringToIndex:11];
  254. // [textField resignFirstResponder];
  255. // }
  256. self.nickname = textField.text;
  257. }
  258. //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  259. // if (string.length == 0) return YES;
  260. // NSInteger existedLength = textField.text.length;
  261. // NSInteger selectedLength = range.length;
  262. // NSInteger replaceLength = string.length;
  263. // if (existedLength - selectedLength + replaceLength > 11) {
  264. // [textField resignFirstResponder];
  265. // return NO;
  266. // }
  267. // return YES;
  268. //}
  269. - (void)textFieldDidEndEditing:(UITextField *)textField {
  270. [self NetworkOfUpdateInfo];
  271. }
  272. - (void)reloadMydetail {
  273. [self.tableView reloadData];
  274. }
  275. @end