123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- //
- // MyDetailViewController.m
- // DSH
- //
- // Created by 张毅成 on 2018/9/26.
- // Copyright © 2018 WZX. All rights reserved.
- //
- #import "MyDetailViewController.h"
- #import "MyDetailModel.h"
- #import "MyDetailTableViewCell.h"
- #import <AVFoundation/AVCaptureDevice.h>
- #import <AVFoundation/AVMediaFormat.h>
- #import <AssetsLibrary/AssetsLibrary.h>
- #import "PickerView.h"
- #import "FeedbackViewController.h"
- #import "PersonalCertificationViewController.h"
- @interface MyDetailViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate>
- @property (weak, nonatomic) IBOutlet UIButton *buttonSave;
- @property (strong, nonatomic) UIImage *imageIcon;
- @property (strong, nonatomic) PickerView *pickerView;
- @property (copy, nonatomic) NSString *sex;
- @property (copy, nonatomic) NSString *nickname;
- @property (copy, nonatomic) NSString *imageUrl;
- @end
- @implementation MyDetailViewController
- - (PickerView *)pickerView {
- WeakSelf(self)
- if (!_pickerView) {
- _pickerView = [PickerView new];
- _pickerView.block = ^(NSString *string, NSInteger selectIndex) {
- weakself.sex = string;
- NSIndexPath *patn = [NSIndexPath indexPathForRow:2 inSection:0];
- [weakself.tableView reloadRowsAtIndexPaths:@[patn] withRowAnimation:UITableViewRowAnimationNone];
- [weakself NetworkOfUpdateInfo];
- };
- }
- return _pickerView;
- }
- - (void)NetworkOfUploadIcon {
- SHOWLOADING
- // NSString *URL = @"upload/uploadImage";
- // [NetWorkRequest PostImages:URL post:nil dicImages:@[self.imageIcon].mutableCopy amrFilePath:nil name:@"file" success:^(id result) {
- // NSLog(@"%@",result);
- // REMOVESHOW
- // if ([result[@"code"] integerValue] == 0) {
- //// SHOWSUCCESS(@"修改成功")
- // self.imageUrl = result[@"data"][@"fileUrl"];
- // [self NetworkOfUpdateInfo];
- // }
- // } fail:^(id error) {
- // REMOVESHOW
- // }];
- }
- - (void)NetworkOfUpdateInfo {
- SHOWLOADING
- NSString *URL = @"my/updateMessage";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- parameters[@"sex"] = self.sex;
- parameters[@"nickname"] = self.nickname;
- if (self.imageUrl.length) {
- parameters[@"userLogo"] = self.imageUrl;
- }
- [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject[@"code"] integerValue] == 0) {
- SHOWSUCCESS(@"修改成功")
- NSString *string = [NSString stringWithFormat:@"%@",self.imageUrl];
- USERDEFAULTSSET(string, @"headimgurl");
- // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // [self.navigationController popViewControllerAnimated:true];
- // });
- }else
- SHOWERROR(@"修改失败")
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR(@"修改失败")
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"个人信息";
- self.view.backgroundColor = kBackgroundColor;
- self.sex = self.model.sex;
- self.nickname = self.model.nickname;
- [self.buttonSave setCorner];
- [self createTableView];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMydetail) name:@"reloadMydetail" object:nil];
- }
- - (void)createTableView {
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.tableFooterView = [UIView new];
- self.tableView.rowHeight = UITableViewAutomaticDimension;
- self.tableView.estimatedRowHeight = 60;
- self.tableView.backgroundColor = kBackgroundColor;
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
- [cell setPreservesSuperviewLayoutMargins:NO];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 10;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.01;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [UIView new];
- view.backgroundColor = kBackgroundColor;
- return view;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *view = [UIView new];
- view.backgroundColor = kBackgroundColor;
- return view;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return MyDetailModel.arrayData.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- NSArray *array = MyDetailModel.arrayData[section];
- return array.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- MyDetailTableViewCell *cell = [MyDetailTableViewCell cellWithTableView:tableView];
- [cell setDataWithModel:MyDetailModel.arrayData[indexPath.section][indexPath.row]];
- cell.textFieldDetail.hidden = true;
- cell.textFieldDetail.delegate = self;
- cell.imageViewArrow.hidden = false;
- if (indexPath.section == 0) {
- if (indexPath.row == 1) {
- cell.labelDetail.hidden = cell.imageViewIcon.hidden = true;
- cell.textFieldDetail.hidden = false;
- cell.textFieldDetail.text = self.nickname?:kUserNickName;
- [cell.textFieldDetail addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
- }else if (indexPath.row == 2) {
- cell.labelDetail.text = self.sex?:self.model.sex;
- }
- cell.imageViewArrow.hidden = true;
- if (self.imageIcon) {
- cell.imageViewIcon.image = self.imageIcon;
- }
- }else if (indexPath.section == 2) {
- if (indexPath.row == 0) {
- cell.textFieldDetail.hidden = false;
- cell.textFieldDetail.userInteractionEnabled = false;
- cell.textFieldDetail.text = self.model.mobile;
- cell.imageViewArrow.hidden = true;
- }else if (indexPath.row == 1) {
- cell.imageViewArrow.hidden = true;
- }else if (indexPath.row == 2) {
- /**
- 1已认证 2审核中 3未认证 4认证失败
- */
- cell.textFieldDetail.hidden = false;
- cell.textFieldDetail.userInteractionEnabled = false;
- if ([kisApprove isEqualToString:@"1"]) {
- cell.textFieldDetail.text = @"已认证";
- }else if ([kisApprove isEqualToString:@"2"]) {
- cell.textFieldDetail.text = @"审核中";
- }else if ([kisApprove isEqualToString:@"3"]) {
- cell.textFieldDetail.text = @"未认证";
- }else if ([kisApprove isEqualToString:@"4"]) {
- cell.textFieldDetail.text = @"认证失败";
- }
- }
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- if (indexPath.row == 0) {
- [self getPhoto];
- }else if (indexPath.row == 2) {
- [self.pickerView showView];
- }
- }else if (indexPath.section == 1) {
- FeedbackViewController *controller = [FeedbackViewController new];
- controller.modelMy = self.model;
- controller.URL = @"my/updateMessage";
- if (indexPath.row == 0) {
- controller.controllerType = FeedbackViewControllerTypeSelfIntroduction;
- }else if (indexPath.row == 1) {
- controller.controllerType = FeedbackViewControllerTypeSign;
- }
- [self.navigationController pushViewController:controller animated:true];
- }else if (indexPath.section == 2) {
- if (indexPath.row == 2) {
- PersonalCertificationViewController *controller = [PersonalCertificationViewController new];
- controller.controllerType = [kisApprove integerValue];
- [self.navigationController pushViewController:controller animated:true];
- }
- }
- }
- - (void)getPhoto {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
- picker.delegate = self;
- picker.allowsEditing = YES;//取消白框
- UIAlertAction *camera = [UIAlertAction actionWithTitle:@"相册上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [ZYCTool controller:self AlbumIsAvailable:^{
- picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- [self presentViewController:picker animated:YES completion:^{}];
- } OrNotAvailable:^{}];
- }];
- UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [ZYCTool controller:self CameraIsAvailable:^{
- picker.sourceType = UIImagePickerControllerSourceTypeCamera;
- [self presentViewController:picker animated:YES completion:^{}];
- } OrNotAvailable:^{}];
- }];
- UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"点击了取消按钮");
- }];
- [cancel setValue:[UIColor redColor] forKey:@"titleTextColor"];
- [alert addAction:cancel];
- [alert addAction:camera];
- [alert addAction:photo];
- [self presentViewController:alert animated:YES completion:nil];
- }
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
- UIImage *selectIma = [info objectForKey:UIImagePickerControllerEditedImage];
- // selectIma = [selectIma fixOrientation];
- NSData *Data= UIImageJPEGRepresentation(selectIma, 0.3);
- UIImage *new = [UIImage imageWithData:Data];
- self.imageIcon = new;
- [self.navigationController dismissViewControllerAnimated:YES completion:^{}];
- [self.tableView reloadData];
- [self NetworkOfUploadIcon];
- }
- - (IBAction)didTouchButtonSave:(UIButton *)sender {
- if (self.sex.length == 0) {
- SHOWERROR(@"请选择性别")
- return;
- }else if (self.nickname.length == 0) {
- SHOWERROR(@"请选择性别")
- return;
- }
- // [self NetworkOfUpdateInfo];
- }
- #pragma 判断手机号/密码长度
- - (void)change:(UITextField *)textField {
- // if (textField.text.length >= 11) {
- // textField.text = [textField.text substringToIndex:11];
- // [textField resignFirstResponder];
- // }
- self.nickname = textField.text;
- }
- //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- // if (string.length == 0) return YES;
- // NSInteger existedLength = textField.text.length;
- // NSInteger selectedLength = range.length;
- // NSInteger replaceLength = string.length;
- // if (existedLength - selectedLength + replaceLength > 11) {
- // [textField resignFirstResponder];
- // return NO;
- // }
- // return YES;
- //}
- - (void)textFieldDidEndEditing:(UITextField *)textField {
- [self NetworkOfUpdateInfo];
- }
- - (void)reloadMydetail {
- [self.tableView reloadData];
- }
- @end
|