// // BGEditInfoController.m // BuguLive // // Created by 丁凯 on 2017/6/12. // Copyright © 2017年 xfg. All rights reserved. // #import "BGEditInfoController.h" #import "BGEditTCell.h" #import "UserModel.h" #import "GetHeadImgViewController.h" #import "ChangeNameViewController.h" #import "SexViewController.h" #import "emotionView.h" #import "birthdayView.h" #import "areaView.h" #import "BDView.h" //#import "BGOssManager.h" #import "BRDatePickerView.h" #import "UIImage+STCommon.h" @interface BGEditInfoController () { // BGOssManager *_ossManager; NSString *_uploadFilePath; NSString *_urlString; NSString *_timeString;//时间戳的字符串 NSString * _urlStr; UIButton *_rightButton; //保存 UITableView *_tableView; NSMutableArray *_dataArray; BGEditTCell *_TXCell; BGEditTCell *_NCCell; BGEditTCell *_ZHCell; BGEditTCell *_XBCell; BGEditTCell *_GXQMCell; BGEditTCell *_RZCell; BGEditTCell *_SRCell; BGEditTCell *_QGZTCell; BGEditTCell *_JXCell; BGEditTCell *_ZYCell; int _isNeedLoad; UserModel *_model; NSString *_sexString; //性别的字符串 emotionView *_emotionViewVC; //情感的view areaView *_areaViewVC; //地区的view BDView *_datePicker; NSString *_provinceString; //省份 NSString *_cityString; //城市 UIView *_halfClearView; //底部透明的view NSString *_nick_info; UILabel * signTFLabel; BRDatePickerView *_datePickerView; } @property (nonatomic,strong) UIImageView * blurImageView; @property (nonatomic,strong) UIImageView * headerImageView; @end @implementation BGEditInfoController - (void)viewDidLoad { [super viewDidLoad]; _urlStr = @""; if (self.BuguLive.appModel.open_sts == 1) { // _ossManager = [[BGOssManager alloc]initWithDelegate:self]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (_isNeedLoad) { [self loadNetData]; } self.navigationController.navigationBar.hidden = YES; } - (void)initFWUI { [super initFWUI]; _blurImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 375)]; [self.view addSubview:self.blurImageView]; _headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 90)/2, NavigationHeight + 30, 90, 90)]; self.headerImageView.layer.cornerRadius = self.headerImageView.width/2.0; self.headerImageView.layer.masksToBounds = YES; [self.view addSubview:self.headerImageView]; self.headerImageView.userInteractionEnabled = YES; self.blurImageView.userInteractionEnabled = YES; WeakSelf [self.headerImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { GetHeadImgViewController *headVC =[[GetHeadImgViewController alloc]init]; headVC.clickHeadImageBlock = ^(UIImage *image) { [weakSelf saveHeadImageWithImage:image]; }; headVC.headImgView.image = self.headerImageView.image; headVC.userId = _model.user_id; [[AppDelegate sharedAppDelegate]pushViewController:headVC animated:YES]; }]]; UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.headerImageView.width, 20)]; headerLabel.centerX = self.headerImageView.centerX; headerLabel.centerY = self.headerImageView.centerY; headerLabel.text = ASLocalizedString(@"点击更换"); headerLabel.textColor = UIColor.whiteColor; headerLabel.font = [UIFont systemFontOfSize:14]; headerLabel.textAlignment = NSTextAlignmentCenter; [self.view addSubview:headerLabel]; UILabel * tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.headerImageView.bottom + 20, SCREEN_WIDTH - 30, 20)]; tipLabel.text = ASLocalizedString(@"数据填写越完善,为您推荐更精准哦。"); tipLabel.textColor = [UIColor.whiteColor colorWithAlphaComponent:0.6]; tipLabel.font = [UIFont systemFontOfSize:10]; tipLabel.textAlignment = NSTextAlignmentCenter; [self.view addSubview:tipLabel]; UIImageView * navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationHeight)]; // navView.image = [UIImage imageNamed:@"mine_navbg"]; navView.userInteractionEnabled = YES; [self.view addSubview:navView]; UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [backBtn setImage:[UIImage imageNamed:@"back_w"] forState:UIControlStateNormal]; backBtn.frame = CGRectMake(10, StatusBarHeight, 44, 44); [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:backBtn]; _rightButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW-60, backBtn.top, 44, 44)]; [_rightButton setTitle:ASLocalizedString(@"保存")forState:UIControlStateNormal]; [_rightButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _rightButton.titleLabel.font = [UIFont systemFontOfSize:15]; [_rightButton addTarget:self action:@selector(saveEditButton) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:_rightButton]; UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)]; titleLabel.centerX = SCREEN_WIDTH/2; titleLabel.centerY = backBtn.centerY; titleLabel.text = ASLocalizedString(@"编辑资料"); titleLabel.textColor = UIColor.whiteColor; titleLabel.font = [UIFont boldSystemFontOfSize:18]; titleLabel.textAlignment = NSTextAlignmentCenter; [navView addSubview:titleLabel]; UIImageView * midredImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.blurImageView.height - 116, SCREEN_WIDTH, 116)]; midredImageView.image = [UIImage imageNamed:@"editorInfoMidBg"]; midredImageView.userInteractionEnabled = YES; [self.blurImageView addSubview:midredImageView]; UILabel * signtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 30, 200, 30)]; signtitleLabel.text = ASLocalizedString(@"个性签名"); signtitleLabel.textColor = UIColor.blackColor; signtitleLabel.font = [UIFont boldSystemFontOfSize:16]; [midredImageView addSubview:signtitleLabel]; UIView * signTFbaseView = [[UIView alloc] initWithFrame:CGRectMake(15, midredImageView.height - 10 - 50, SCREEN_WIDTH - 30, 50)]; signTFbaseView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"]; signTFbaseView.layer.cornerRadius = 10; signTFbaseView.layer.masksToBounds = YES; [midredImageView addSubview:signTFbaseView]; signTFLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, SCREEN_WIDTH - 30, 20)]; signTFLabel.text = ASLocalizedString(@"快留下一句话,向別人展示自己吧。"); signTFLabel.textColor = [UIColor colorWithHexString:@"#999999"]; signTFLabel.font = [UIFont systemFontOfSize:14]; [signTFbaseView addSubview:signTFLabel]; [signTFbaseView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(signTFbaseViewAction)]]; UILabel * basicInfoTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.blurImageView.bottom, 200, 30)]; basicInfoTitleLabel.text = ASLocalizedString(@"基础信息"); basicInfoTitleLabel.textColor = UIColor.blackColor; basicInfoTitleLabel.font = [UIFont boldSystemFontOfSize:16]; [self.view addSubview:basicInfoTitleLabel]; _dataArray = [[NSMutableArray alloc]init]; // self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"]; // self.navigationItem.title = ASLocalizedString(@"编辑资料"); // // UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_rightButton]; // self.navigationItem.rightBarButtonItem = rightBarButtonItem; _tableView = [[UITableView alloc]initWithFrame:CGRectMake(15, basicInfoTitleLabel.bottom + 10, kScreenW - 30, 45*kAppRowHScale*6) style:UITableViewStylePlain]; // [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight)]; _tableView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.layer.cornerRadius = 10; _tableView.layer.masksToBounds = YES; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } _tableView.delegate = self; _tableView.dataSource = self; _tableView.bounces = YES; [_tableView registerNib:[UINib nibWithNibName:@"BGEditTCell" bundle:nil] forCellReuseIdentifier:@"BGEditTCell"]; [self.view addSubview:_tableView]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ if (![[self getVersionsNum] isEqualToString:self.BuguLive.appModel.region_versions] || ![[self getMyAreaDataArr] count]) { [self loadMyAreaData]; } }); } - (void)reloadHeaderImageWithUrl:(NSString *)url { [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:kDefaultPreloadHeadImg]; [self.blurImageView sd_setImageWithURL:[NSURL URLWithString:url] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { self.blurImageView.image = [UIImage boxblurImage:image withBlurNumber:1]; }]; } #pragma mark 创建或者销毁halfClearView - (void)isCreatHaldClearViewWithCount:(int)count { if (count == 1)//创建_halfClearView { if (!_halfClearView) { _halfClearView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)]; _halfClearView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5]; [[UIApplication sharedApplication].keyWindow addSubview:_halfClearView]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; tap.delegate = self; [_halfClearView addGestureRecognizer:tap]; } }else//销毁_halfClearView { [_halfClearView removeFromSuperview]; _halfClearView = nil; _emotionViewVC = nil; _areaViewVC = nil; _datePicker = nil; } } - (void)tap:(UITapGestureRecognizer *)tap { [self isCreatHaldClearViewWithCount:0]; } #pragma mark comeBack - (void)backClick { if ([GlobalVariables sharedInstance].isUserInfoCheck) { WeakSelf [FanweMessage alertController:ASLocalizedString(@"当前资料未保存,是否放弃编辑")viewController:self destructiveAction:^{ [[AppDelegate sharedAppDelegate]popViewController]; } cancelAction:^{ }]; return; } [[AppDelegate sharedAppDelegate]popViewController]; } - (void)initFWData { [super initFWData]; [self showMyHud]; [self loadNetData]; } #pragma mark 网络加载 - (void)loadNetData { NSMutableDictionary *parmDict = [NSMutableDictionary dictionary]; [parmDict setObject:@"user_center" forKey:@"ctl"]; [parmDict setObject:@"user_edit" forKey:@"act"]; FWWeakify(self) [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) { FWStrongify(self) [self hideMyHud]; if ([responseJson toInt:@"status"] == 1) { _model = [UserModel mj_objectWithKeyValues:[responseJson objectForKey:@"user"]]; _urlString = _model.head_image; _nick_info = [responseJson toString:@"nick_info"]; _sexString = _model.sex; signTFLabel.text = _model.signature; [_tableView reloadData]; [self reloadHeaderImageWithUrl:_urlString]; }else { [BGHUDHelper alert:[responseJson toString:@"error"]]; } } FailureBlock:^(NSError *error) { FWStrongify(self) [self hideMyHud]; }]; } #pragma mark -- dataSource/Delegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ETab_Count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == ERZSection) { return 0; }else { return 1; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == ERZSection || indexPath.section == EJXSection) { return 0; }else { return 45*kAppRowHScale; } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == ETXSection || section == ENCSection || section == ESRSection) { return kRealValue(0); // 10*kAppRowHScale; }else { return 0; } } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(10))]; view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"]; // [UIColor colorWithRed:245 green:245 blue:245 alpha:1]; return view; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == ETXSection) { _TXCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_TXCell creatCellWithStr:_model.head_image andSection:(int)indexPath.section]; return _TXCell; }else if (indexPath.section == ENCSection) { _NCCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_NCCell creatCellWithStr:_model.nick_name andSection:(int)indexPath.section]; return _NCCell; } else if (indexPath.section == EZHSection) { _ZHCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_ZHCell creatCellWithStr:_model.user_id andSection:(int)indexPath.section]; return _ZHCell; } else if (indexPath.section == EXBSection) { _XBCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_XBCell creatCellWithStr:_model.sex andSection:(int)indexPath.section]; return _XBCell; } else if (indexPath.section == EGXQMSection) { _GXQMCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_GXQMCell creatCellWithStr:_model.signature andSection:(int)indexPath.section]; return _GXQMCell; } else if (indexPath.section == ERZSection) { _RZCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; return _RZCell; } else if (indexPath.section == ESRSection) { _SRCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_SRCell creatCellWithStr:_model.birthday andSection:(int)indexPath.section]; return _SRCell; }else if (indexPath.section == EQGZTSection) { _QGZTCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_QGZTCell creatCellWithStr:_model.emotional_state andSection:(int)indexPath.section]; return _QGZTCell; } else if (indexPath.section == EJXSection) { _JXCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; if (!_model.city.length) { _model.city = ASLocalizedString(@"火星"); } [_JXCell creatCellWithStr:_model.city andSection:(int)indexPath.section]; _JXCell.hidden = YES; return _JXCell; } else { _ZYCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath]; [_ZYCell creatCellWithStr:_model.job andSection:(int)indexPath.section]; _ZYCell.lineView.hidden = YES; return _ZYCell; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { switch (indexPath.section) { case ETXSection: { // _isNeedLoad = YES; 04-29 17:39 GetHeadImgViewController *headVC =[[GetHeadImgViewController alloc]init]; WeakSelf headVC.clickHeadImageBlock = ^(UIImage *image) { [weakSelf saveHeadImageWithImage:image]; }; headVC.headImgView.image = _TXCell.headImgView.image; headVC.userId = _model.user_id; [[AppDelegate sharedAppDelegate]pushViewController:headVC animated:YES]; } break; case ENCSection: { [self pushToChangeNameViewWithType:1 andStr:_model.nick_name]; } break; case EZHSection: { UIPasteboard *pasteboard=[UIPasteboard generalPasteboard]; pasteboard.string = _model.user_id; [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"复制成功")]; } break; case EXBSection: { _isNeedLoad = NO; if ([_model.is_edit_sex intValue] == 0) { [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"性别不可编辑")]; return; } FDActionSheet *actionSheet = [[FDActionSheet alloc] initWithTitle:@"" message:@""]; [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"男") type:FDActionTypeDefault CallBack:^{ [self changeSexWithString:@"1"]; }]]; [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"女") type:FDActionTypeDefault CallBack:^{ [self changeSexWithString:@"2"]; }]]; [actionSheet show:[UIApplication sharedApplication].keyWindow]; // SexViewController *sexVC = [[SexViewController alloc]init]; // sexVC.sexType = _sexString; // sexVC.delgate = self; // [self.navigationController pushViewController:sexVC animated:YES]; } break; case EGXQMSection: { [self pushToChangeNameViewWithType:2 andStr:_model.signature]; } break; case ERZSection: { //to do } break; case ESRSection: { [BRDatePickerView showDatePickerWithMode:BRDatePickerModeYMD title:ASLocalizedString(@"生日") selectValue:SafeStr(_model.birthday) resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) { _SRCell.rightLabel.text = selectValue; _model.birthday = selectValue; }]; // NSLog(@"1111111"); // [self isCreatHaldClearViewWithCount:1]; // if (!_datePicker)//生日 // { // _datePicker = [[[NSBundle mainBundle]loadNibNamed:@"BDView" owner:self options:nil]lastObject]; // _datePicker.frame = CGRectMake(0,kScreenH ,kScreenW,260); // if(_model.birthday.length>0) // { // [_datePicker creatMinTime:_model.birthday]; // } // [_halfClearView addSubview:_datePicker]; // [UIView animateWithDuration:0.5 animations:^{ // CGRect rect = _datePicker.frame; // rect.origin.y = kScreenH - 260; // _datePicker.frame = rect; // }]; // FWWeakify(self) // [_datePicker setBDViewBlock:^(int tagIndex){ // FWStrongify(self) // if (tagIndex == 0) // { // [self isCreatHaldClearViewWithCount:0]; // }else if (tagIndex == 1) // { // [self handleToSelectTime]; // } // }]; // } } break; case EQGZTSection: { [self isCreatHaldClearViewWithCount:1]; if (!_emotionViewVC)//情感状态 { _emotionViewVC = [[emotionView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, 160) withName:_model.emotional_state]; _emotionViewVC.delegate = self; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickEmotion:)]; [_emotionViewVC addGestureRecognizer:tap]; [_halfClearView addSubview:_emotionViewVC]; [UIView animateWithDuration:0.5 animations:^{ CGRect rect = _emotionViewVC.frame; rect.origin.y = kScreenH-160; _emotionViewVC.frame = rect; }]; } } break; case EJXSection: { [self isCreatHaldClearViewWithCount:1]; if (!_areaViewVC)//家乡 { _areaViewVC = [[areaView alloc]initWithDelegate:self withCity:_model.city]; _areaViewVC.frame = CGRectMake(0, kScreenH, kScreenW, 190); [_halfClearView addSubview:_areaViewVC]; [UIView animateWithDuration:0.5 animations:^{ CGRect rect = _areaViewVC.frame; rect.origin.y = kScreenH-190; _areaViewVC.frame = rect; }]; } } break; case EZYSection: { [self pushToChangeNameViewWithType:3 andStr:_model.job]; } break; default: break; } } - (void)signTFbaseViewAction { [self pushToChangeNameViewWithType:2 andStr:_model.signature]; } -(void)clickEmotion:(UITapGestureRecognizer *)sender{ } #pragma mark - 上传头像相关 -(void)saveHeadImageWithImage:(UIImage *)image{ // [_TXCell creatCellWithStr:image andSection:0]; [_TXCell.headImgView setImage:image]; // if (self.BuguLive.appModel.open_sts == 0) { // if ([_ossManager isSetRightParameter]) { // [self saveImage:image withName:@"1.png"]; // [self showMyHud]; // _timeString = [_ossManager getObjectKeyString]; // [_ossManager asyncPutImage:_timeString localFilePath:_uploadFilePath]; // } // }else { NSLog(@"image.size.height==%f,image.size.height==%f",image.size.height,image.size.height); NSData *data=UIImageJPEGRepresentation(image, 1); UIImage *image = [UIImage imageWithData:data]; [self saveImage:image withName:@"image_head.jpg"]; [self performSelector:@selector(uploadAvatar) withObject:nil afterDelay:0.8]; } } #pragma mark 使用流文件上传头像 - (void)uploadAvatar { [self showMyHud]; NSString *imageFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *photoName=[imageFile stringByAppendingPathComponent:@"image_head.jpg"]; NSURL *fileUrl = [NSURL URLWithString:[NSString stringWithFormat:@"file:%@",photoName]]; NSMutableDictionary *parmDict = [NSMutableDictionary dictionary]; [parmDict setObject:@"avatar" forKey:@"ctl"]; [parmDict setObject:@"uploadImage" forKey:@"act"]; [parmDict setObject:_model.user_id forKey:@"id"]; FWWeakify(self) [self.httpsManager POSTWithDict:parmDict andFileUrl:fileUrl SuccessBlock:^(NSDictionary *responseJson) { FWStrongify(self) if ([responseJson toInt:@"status"] == 1) { _urlString = [responseJson toString:@"server_full_path"]; _model.head_image = _urlString; [self hideMyHud]; [self updateHeadImage]; [self reloadHeaderImageWithUrl:_urlString]; }else { [BGHUDHelper alert:[responseJson toString:@"error"]]; } } FailureBlock:^(NSError *error) { [self hideMyHud]; }]; } - (void)updateHeadImage { NSMutableDictionary *parmDict = [NSMutableDictionary dictionary]; [parmDict setObject:@"login" forKey:@"ctl"]; [parmDict setObject:@"do_update" forKey:@"act"]; [parmDict setObject:_model.user_id forKey:@"id"]; if (_urlString.length < 1 && [_urlString isEqualToString:@""]) { [parmDict setObject:@"" forKey:@"normal_head_path"]; }else { [parmDict setObject:_urlString forKey:@"normal_head_path"]; } [parmDict setObject:@"1" forKey:@"type"]; [self showMyHud]; [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) { [self hideMyHud]; } FailureBlock:^(NSError *error) { [self hideMyHud]; }]; } - (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName { NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5); NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; [imageData writeToFile:fullPath atomically:NO]; _uploadFilePath = fullPath; NSLog(@"uploadFilePath : %@", _uploadFilePath); } #pragma mark 代理回调 - (void)uploadImageWithUrlStr:(NSString *)imageUrlStr withUploadStateCount:(int)stateCount { [self hideMyHud]; if (stateCount == 0) { _urlString = [NSString stringWithFormat:@"./%@",_timeString]; }else { [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"oss上传头像失败")]; } _model.head_image = _urlString; } #pragma mark -- 日历确定按钮点击事件 - (void)handleToSelectTime { _SRCell.rightLabel.text = _datePicker.timeLabel.text; [UIView animateWithDuration:0.5 animations:^{ } completion:^(BOOL finished) { [self isCreatHaldClearViewWithCount:0]; }]; } #pragma mark 修改情感状态 - (void)changeEmotionStatuWithString:(NSString *)emoyionString { _model.emotional_state = _QGZTCell.rightLabel.text = emoyionString; // [self isCreatHaldClearViewWithCount:0]; [GlobalVariables sharedInstance].isUserInfoCheck = YES; } #pragma mark 修改性别 - (void)changeSexWithString:(NSString *)sexString { _sexString = sexString; if ([sexString isEqualToString:@"1"]) { _XBCell.sexImgView.image = [UIImage imageNamed:@"com_male_selected"]; }else if ([sexString isEqualToString:@"2"]) { _XBCell.sexImgView.image = [UIImage imageNamed:@"com_female_selected"]; } [GlobalVariables sharedInstance].isUserInfoCheck = YES; // isUserInfoCheck } #pragma mark 修改生日 - (void)confrmCallBack:(NSInteger)Year month:(NSInteger)month day:(NSInteger)day andtag:(int)tagIndex { if (tagIndex == 12) { _SRCell.rightLabel.text = [NSString stringWithFormat:@"%d-%d-%d",(int)Year,(int)month,(int)day]; } [self isCreatHaldClearViewWithCount:0]; [GlobalVariables sharedInstance].isUserInfoCheck = YES; } #pragma mark 地区的代理 - (void)confrmCallBack:(NSString *)provice withCity:(NSString *)city andtagIndex:(int)tagIndex { if (tagIndex == 12) { _provinceString = provice; _cityString = city; if (city.length < 1 || provice.length < 1) { _JXCell.rightLabel.text = @""; }else { _model.city = _JXCell.rightLabel.text = [NSString stringWithFormat:@"%@ %@",provice,city]; } } [self isCreatHaldClearViewWithCount:0]; [GlobalVariables sharedInstance].isUserInfoCheck = YES; } #pragma mark 修改昵称之类的 - (void)pushToChangeNameViewWithType:(int)type andStr:(NSString *)str { _isNeedLoad = NO; ChangeNameViewController *nameVC =[[ChangeNameViewController alloc]init]; if (type == 1) { nameVC.nickInfo = _nick_info; } nameVC.textFiledName = str; nameVC.viewType = [NSString stringWithFormat:@"%d",type]; nameVC.delegate = self; [self.navigationController pushViewController:nameVC animated:YES]; } - (void)changeNameWithString:(NSString *)name withType:(NSString *)type { if ([type isEqualToString:@"1"]) { _NCCell.rightLabel.text = name; _model.nick_name = name; }else if ([type isEqualToString:@"2"]) { _GXQMCell.rightLabel.text = name; _model.signature = name; signTFLabel.text = name; }else if ([type isEqualToString:@"3"]) { _ZYCell.rightLabel.text = name; _model.job = name; } [GlobalVariables sharedInstance].isUserInfoCheck = YES; } #pragma mark 保存的按钮 - (void)saveEditButton { [self updateHeadImage]; NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; [dict setObject:@"user_center" forKey:@"ctl"]; [dict setObject:@"user_save" forKey:@"act"]; if (_NCCell.rightLabel.text.length > 0)//名字 { [dict setObject:_NCCell.rightLabel.text forKey:@"nick_name"]; } if (_sexString.length > 0)//性别 { [dict setObject:_sexString forKey:@"sex"]; } if (signTFLabel.text.length > 0)//个性签名 { [dict setObject:signTFLabel.text forKey:@"signature"]; } if (_SRCell.rightLabel.text.length > 0)//生日 { [dict setObject:_SRCell.rightLabel.text forKey:@"birthday"]; } if (_QGZTCell.rightLabel.text.length > 0)//情感状态 { [dict setObject:_QGZTCell.rightLabel.text forKey:@"emotional_state"]; } if (_provinceString.length > 0)//省份 { [dict setObject:_provinceString forKey:@"province"]; } if (_cityString.length > 0)//城市 { [dict setObject:_cityString forKey:@"city"]; } if (_ZYCell.rightLabel.text.length > 0)//工作 { [dict setObject:_ZYCell.rightLabel.text forKey:@"job"]; } FWWeakify(self) [self showMyHud]; [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) { FWStrongify(self) [self hideMyHud]; if ([responseJson toInt:@"status"] == 1) { [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"编辑成功")]; [GlobalVariables sharedInstance].isUserInfoCheck = NO; [self.navigationController popViewControllerAnimated:YES]; }else { [BGHUDHelper alert:[responseJson toString:@"error"]]; } } FailureBlock:^(NSError *error) { FWStrongify(self) [self hideMyHud]; }]; } #pragma mark =============================================家乡数据的获取和存储============================================================ - (NSString *)getVersionsNum { NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]; NSString *filePath = [cachePath stringByAppendingPathComponent:@"versions.plist"]; NSMutableDictionary *dict1 = [NSMutableDictionary dictionaryWithContentsOfFile:filePath]; return [dict1 objectForKey:@"versions"]; } - (NSMutableArray *)getMyAreaDataArr { //获取Documents目录 NSString *docPath2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; //还要指定存储文件的文件名称,仍然使用字符串拼接 NSString *filePath2 = [docPath2 stringByAppendingPathComponent:@"Province.plist"]; return [NSMutableArray arrayWithContentsOfFile:filePath2]; } - (void)loadMyAreaData { NSMutableDictionary *parmDict = [NSMutableDictionary dictionary]; [parmDict setObject:@"user_center" forKey:@"ctl"]; [parmDict setObject:@"region_list" forKey:@"act"]; [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) { if ([responseJson toInt:@"status"] == 1) { //存版本 NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]; NSString *filePath = [cachePath stringByAppendingPathComponent:@"versions.plist"]; NSMutableDictionary *dict1 = [NSMutableDictionary dictionary]; [dict1 setObject:[responseJson toString:@"region_versions"] forKey:@"versions"]; [dict1 writeToFile:filePath atomically:YES]; NSArray *areaArray = [responseJson objectForKey:@"region_list"]; if (areaArray) { if (areaArray.count > 0 && [areaArray isKindOfClass:[NSArray class]]) { //获取Documents目录 NSString *docPath2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; //还要指定存储文件的文件名称,仍然使用字符串拼接 NSString *filePath2 = [docPath2 stringByAppendingPathComponent:@"Province.plist"]; NSLog(@"filePath2==%@",filePath2); [areaArray writeToFile:filePath2 atomically:YES]; } } } } FailureBlock:^(NSError *error) { }]; } @end