BGEditInfoController.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. //
  2. // BGEditInfoController.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/6/12.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGEditInfoController.h"
  9. #import "BGEditTCell.h"
  10. #import "UserModel.h"
  11. #import "GetHeadImgViewController.h"
  12. #import "ChangeNameViewController.h"
  13. #import "SexViewController.h"
  14. #import "emotionView.h"
  15. #import "birthdayView.h"
  16. #import "areaView.h"
  17. #import "BDView.h"
  18. //#import "BGOssManager.h"
  19. #import "BRDatePickerView.h"
  20. #import "UIImage+STCommon.h"
  21. @interface BGEditInfoController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,changeNameDelegate,changeSexDelegate,changeEmotionStatuDelegate,LZDateDelegate,AreaDelegate>
  22. {
  23. // BGOssManager *_ossManager;
  24. NSString *_uploadFilePath;
  25. NSString *_urlString;
  26. NSString *_timeString;//时间戳的字符串
  27. NSString * _urlStr;
  28. UIButton *_rightButton; //保存
  29. UITableView *_tableView;
  30. NSMutableArray *_dataArray;
  31. BGEditTCell *_TXCell;
  32. BGEditTCell *_NCCell;
  33. BGEditTCell *_ZHCell;
  34. BGEditTCell *_XBCell;
  35. BGEditTCell *_GXQMCell;
  36. BGEditTCell *_RZCell;
  37. BGEditTCell *_SRCell;
  38. BGEditTCell *_QGZTCell;
  39. BGEditTCell *_JXCell;
  40. BGEditTCell *_ZYCell;
  41. int _isNeedLoad;
  42. UserModel *_model;
  43. NSString *_sexString; //性别的字符串
  44. emotionView *_emotionViewVC; //情感的view
  45. areaView *_areaViewVC; //地区的view
  46. BDView *_datePicker;
  47. NSString *_provinceString; //省份
  48. NSString *_cityString; //城市
  49. UIView *_halfClearView; //底部透明的view
  50. NSString *_nick_info;
  51. UILabel * signTFLabel;
  52. BRDatePickerView *_datePickerView;
  53. }
  54. @property (nonatomic,strong) UIImageView * blurImageView;
  55. @property (nonatomic,strong) UIImageView * headerImageView;
  56. @end
  57. @implementation BGEditInfoController
  58. - (void)viewDidLoad
  59. {
  60. [super viewDidLoad];
  61. _urlStr = @"";
  62. if (self.BuguLive.appModel.open_sts == 1)
  63. {
  64. // _ossManager = [[BGOssManager alloc]initWithDelegate:self];
  65. }
  66. }
  67. - (void)viewWillAppear:(BOOL)animated
  68. {
  69. [super viewWillAppear:animated];
  70. if (_isNeedLoad)
  71. {
  72. [self loadNetData];
  73. }
  74. self.navigationController.navigationBar.hidden = YES;
  75. }
  76. - (void)initFWUI
  77. {
  78. [super initFWUI];
  79. self.view.backgroundColor = UIColor.whiteColor;
  80. _blurImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 375)];
  81. [self.view addSubview:self.blurImageView];
  82. _headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 90)/2, NavigationHeight + 30, 90, 90)];
  83. self.headerImageView.layer.cornerRadius = self.headerImageView.width/2.0;
  84. self.headerImageView.layer.masksToBounds = YES;
  85. [self.view addSubview:self.headerImageView];
  86. self.headerImageView.userInteractionEnabled = YES;
  87. self.blurImageView.userInteractionEnabled = YES;
  88. WeakSelf
  89. [self.headerImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  90. GetHeadImgViewController *headVC =[[GetHeadImgViewController alloc]init];
  91. headVC.clickHeadImageBlock = ^(UIImage *image) {
  92. [weakSelf saveHeadImageWithImage:image];
  93. };
  94. headVC.headImgView.image = self.headerImageView.image;
  95. headVC.userId = _model.user_id;
  96. [[AppDelegate sharedAppDelegate]pushViewController:headVC animated:YES];
  97. }]];
  98. UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.headerImageView.width, 20)];
  99. headerLabel.centerX = self.headerImageView.centerX;
  100. headerLabel.centerY = self.headerImageView.centerY;
  101. headerLabel.text = ASLocalizedString(@"点击更换");
  102. headerLabel.textColor = UIColor.whiteColor;
  103. headerLabel.font = [UIFont systemFontOfSize:14];
  104. headerLabel.textAlignment = NSTextAlignmentCenter;
  105. [self.view addSubview:headerLabel];
  106. UILabel * tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.headerImageView.bottom + 20, SCREEN_WIDTH - 30, 20)];
  107. tipLabel.text = ASLocalizedString(@"数据填写越完善,为您推荐更精准哦。");
  108. tipLabel.textColor = [UIColor.whiteColor colorWithAlphaComponent:0.6];
  109. tipLabel.font = [UIFont systemFontOfSize:10];
  110. tipLabel.textAlignment = NSTextAlignmentCenter;
  111. [self.view addSubview:tipLabel];
  112. UIImageView * navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationHeight)];
  113. // navView.image = [UIImage imageNamed:@"mine_navbg"];
  114. navView.userInteractionEnabled = YES;
  115. [self.view addSubview:navView];
  116. UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  117. [backBtn setImage:[UIImage imageNamed:@"back_w"] forState:UIControlStateNormal];
  118. backBtn.frame = CGRectMake(10, StatusBarHeight, 44, 44);
  119. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  120. [navView addSubview:backBtn];
  121. _rightButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW-60, backBtn.top, 44, 44)];
  122. [_rightButton setTitle:ASLocalizedString(@"保存")forState:UIControlStateNormal];
  123. [_rightButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  124. _rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
  125. [_rightButton addTarget:self action:@selector(saveEditButton) forControlEvents:UIControlEventTouchUpInside];
  126. [navView addSubview:_rightButton];
  127. UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
  128. titleLabel.centerX = SCREEN_WIDTH/2;
  129. titleLabel.centerY = backBtn.centerY;
  130. titleLabel.text = ASLocalizedString(@"编辑资料");
  131. titleLabel.textColor = UIColor.whiteColor;
  132. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  133. titleLabel.textAlignment = NSTextAlignmentCenter;
  134. [navView addSubview:titleLabel];
  135. UIImageView * midredImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.blurImageView.height - 116, SCREEN_WIDTH, 116)];
  136. midredImageView.image = [UIImage imageNamed:@"editorInfoMidBg"];
  137. midredImageView.userInteractionEnabled = YES;
  138. [self.blurImageView addSubview:midredImageView];
  139. UILabel * signtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 30, 200, 30)];
  140. signtitleLabel.text = ASLocalizedString(@"个性签名");
  141. signtitleLabel.textColor = UIColor.blackColor;
  142. signtitleLabel.font = [UIFont boldSystemFontOfSize:16];
  143. [midredImageView addSubview:signtitleLabel];
  144. UIView * signTFbaseView = [[UIView alloc] initWithFrame:CGRectMake(15, midredImageView.height - 10 - 50, SCREEN_WIDTH - 30, 50)];
  145. signTFbaseView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  146. signTFbaseView.layer.cornerRadius = 10;
  147. signTFbaseView.layer.masksToBounds = YES;
  148. [midredImageView addSubview:signTFbaseView];
  149. signTFLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, SCREEN_WIDTH - 30, 20)];
  150. signTFLabel.text = ASLocalizedString(@"快留下一句话,向別人展示自己吧。");
  151. signTFLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  152. signTFLabel.font = [UIFont systemFontOfSize:14];
  153. [signTFbaseView addSubview:signTFLabel];
  154. [signTFbaseView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(signTFbaseViewAction)]];
  155. UILabel * basicInfoTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.blurImageView.bottom, 200, 30)];
  156. basicInfoTitleLabel.text = ASLocalizedString(@"基础信息");
  157. basicInfoTitleLabel.textColor = UIColor.blackColor;
  158. basicInfoTitleLabel.font = [UIFont boldSystemFontOfSize:16];
  159. [self.view addSubview:basicInfoTitleLabel];
  160. _dataArray = [[NSMutableArray alloc]init];
  161. // self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  162. // self.navigationItem.title = ASLocalizedString(@"编辑资料");
  163. //
  164. // UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_rightButton];
  165. // self.navigationItem.rightBarButtonItem = rightBarButtonItem;
  166. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(15, basicInfoTitleLabel.bottom + 10, kScreenW - 30, 45*kAppRowHScale*6) style:UITableViewStylePlain];
  167. // [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight)];
  168. _tableView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  169. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  170. _tableView.layer.cornerRadius = 10;
  171. _tableView.layer.masksToBounds = YES;
  172. if (@available(iOS 15.0, *)) {
  173. _tableView.sectionHeaderTopPadding = 0;
  174. }
  175. _tableView.delegate = self;
  176. _tableView.dataSource = self;
  177. _tableView.bounces = YES;
  178. [_tableView registerNib:[UINib nibWithNibName:@"BGEditTCell" bundle:nil] forCellReuseIdentifier:@"BGEditTCell"];
  179. [self.view addSubview:_tableView];
  180. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  181. if (![[self getVersionsNum] isEqualToString:self.BuguLive.appModel.region_versions] || ![[self getMyAreaDataArr] count])
  182. {
  183. [self loadMyAreaData];
  184. }
  185. });
  186. }
  187. - (void)reloadHeaderImageWithUrl:(NSString *)url {
  188. [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:kDefaultPreloadHeadImg];
  189. [self.blurImageView sd_setImageWithURL:[NSURL URLWithString:url] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  190. self.blurImageView.image = [UIImage boxblurImage:image withBlurNumber:1];
  191. }];
  192. }
  193. #pragma mark 创建或者销毁halfClearView
  194. - (void)isCreatHaldClearViewWithCount:(int)count
  195. {
  196. if (count == 1)//创建_halfClearView
  197. {
  198. if (!_halfClearView)
  199. {
  200. _halfClearView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  201. _halfClearView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
  202. [[UIApplication sharedApplication].keyWindow addSubview:_halfClearView];
  203. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
  204. tap.delegate = self;
  205. [_halfClearView addGestureRecognizer:tap];
  206. }
  207. }else//销毁_halfClearView
  208. {
  209. [_halfClearView removeFromSuperview];
  210. _halfClearView = nil;
  211. _emotionViewVC = nil;
  212. _areaViewVC = nil;
  213. _datePicker = nil;
  214. }
  215. }
  216. - (void)tap:(UITapGestureRecognizer *)tap
  217. {
  218. [self isCreatHaldClearViewWithCount:0];
  219. }
  220. #pragma mark comeBack
  221. - (void)backClick
  222. {
  223. if ([GlobalVariables sharedInstance].isUserInfoCheck) {
  224. WeakSelf
  225. [FanweMessage alertController:ASLocalizedString(@"当前资料未保存,是否放弃编辑")viewController:self destructiveAction:^{
  226. [[AppDelegate sharedAppDelegate]popViewController];
  227. } cancelAction:^{
  228. }];
  229. return;
  230. }
  231. [[AppDelegate sharedAppDelegate]popViewController];
  232. }
  233. - (void)initFWData
  234. {
  235. [super initFWData];
  236. [self showMyHud];
  237. [self loadNetData];
  238. }
  239. #pragma mark 网络加载
  240. - (void)loadNetData
  241. {
  242. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  243. [parmDict setObject:@"user_center" forKey:@"ctl"];
  244. [parmDict setObject:@"user_edit" forKey:@"act"];
  245. FWWeakify(self)
  246. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  247. {
  248. FWStrongify(self)
  249. [self hideMyHud];
  250. if ([responseJson toInt:@"status"] == 1)
  251. {
  252. _model = [UserModel mj_objectWithKeyValues:[responseJson objectForKey:@"user"]];
  253. _urlString = _model.head_image;
  254. _nick_info = [responseJson toString:@"nick_info"];
  255. _sexString = _model.sex;
  256. signTFLabel.text = _model.signature;
  257. [_tableView reloadData];
  258. [self reloadHeaderImageWithUrl:_urlString];
  259. }else
  260. {
  261. [BGHUDHelper alert:[responseJson toString:@"error"]];
  262. }
  263. } FailureBlock:^(NSError *error)
  264. {
  265. FWStrongify(self)
  266. [self hideMyHud];
  267. }];
  268. }
  269. #pragma mark -- dataSource/Delegate
  270. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  271. {
  272. return ETab_Count;
  273. }
  274. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  275. {
  276. if (section == ERZSection)
  277. {
  278. return 0;
  279. }else
  280. {
  281. return 1;
  282. }
  283. }
  284. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  285. {
  286. if (indexPath.section == ERZSection || indexPath.section == EJXSection)
  287. {
  288. return 0;
  289. }else
  290. {
  291. return 45*kAppRowHScale;
  292. }
  293. }
  294. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  295. {
  296. if (section == ETXSection || section == ENCSection || section == ESRSection)
  297. {
  298. return kRealValue(0);
  299. // 10*kAppRowHScale;
  300. }else
  301. {
  302. return 0;
  303. }
  304. }
  305. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  306. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(10))];
  307. view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
  308. // [UIColor colorWithRed:245 green:245 blue:245 alpha:1];
  309. return view;
  310. }
  311. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  312. {
  313. if (indexPath.section == ETXSection)
  314. {
  315. _TXCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  316. [_TXCell creatCellWithStr:_model.head_image andSection:(int)indexPath.section];
  317. return _TXCell;
  318. }else if (indexPath.section == ENCSection)
  319. {
  320. _NCCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  321. [_NCCell creatCellWithStr:_model.nick_name andSection:(int)indexPath.section];
  322. return _NCCell;
  323. }
  324. else if (indexPath.section == EZHSection)
  325. {
  326. _ZHCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  327. [_ZHCell creatCellWithStr:_model.user_id andSection:(int)indexPath.section];
  328. return _ZHCell;
  329. }
  330. else if (indexPath.section == EXBSection)
  331. {
  332. _XBCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  333. [_XBCell creatCellWithStr:_model.sex andSection:(int)indexPath.section];
  334. return _XBCell;
  335. }
  336. else if (indexPath.section == EGXQMSection)
  337. {
  338. _GXQMCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  339. [_GXQMCell creatCellWithStr:_model.signature andSection:(int)indexPath.section];
  340. return _GXQMCell;
  341. }
  342. else if (indexPath.section == ERZSection)
  343. {
  344. _RZCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  345. return _RZCell;
  346. }
  347. else if (indexPath.section == ESRSection)
  348. {
  349. _SRCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  350. [_SRCell creatCellWithStr:_model.birthday andSection:(int)indexPath.section];
  351. return _SRCell;
  352. }else if (indexPath.section == EQGZTSection)
  353. {
  354. _QGZTCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  355. [_QGZTCell creatCellWithStr:_model.emotional_state andSection:(int)indexPath.section];
  356. return _QGZTCell;
  357. }
  358. else if (indexPath.section == EJXSection)
  359. {
  360. _JXCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  361. if (!_model.city.length)
  362. {
  363. _model.city = ASLocalizedString(@"火星");
  364. }
  365. [_JXCell creatCellWithStr:_model.city andSection:(int)indexPath.section];
  366. _JXCell.hidden = YES;
  367. return _JXCell;
  368. }
  369. else
  370. {
  371. _ZYCell = [tableView dequeueReusableCellWithIdentifier:@"BGEditTCell" forIndexPath:indexPath];
  372. [_ZYCell creatCellWithStr:_model.job andSection:(int)indexPath.section];
  373. _ZYCell.lineView.hidden = YES;
  374. return _ZYCell;
  375. }
  376. }
  377. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  378. {
  379. switch (indexPath.section)
  380. {
  381. case ETXSection:
  382. {
  383. // _isNeedLoad = YES; 04-29 17:39
  384. GetHeadImgViewController *headVC =[[GetHeadImgViewController alloc]init];
  385. WeakSelf
  386. headVC.clickHeadImageBlock = ^(UIImage *image) {
  387. [weakSelf saveHeadImageWithImage:image];
  388. };
  389. headVC.headImgView.image = _TXCell.headImgView.image;
  390. headVC.userId = _model.user_id;
  391. [[AppDelegate sharedAppDelegate]pushViewController:headVC animated:YES];
  392. }
  393. break;
  394. case ENCSection:
  395. {
  396. [self pushToChangeNameViewWithType:1 andStr:_model.nick_name];
  397. }
  398. break;
  399. case EZHSection:
  400. {
  401. UIPasteboard *pasteboard=[UIPasteboard generalPasteboard];
  402. pasteboard.string = _model.user_id;
  403. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"复制成功")];
  404. }
  405. break;
  406. case EXBSection:
  407. {
  408. _isNeedLoad = NO;
  409. if ([_model.is_edit_sex intValue] == 0)
  410. {
  411. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"性别不可编辑")];
  412. return;
  413. }
  414. FDActionSheet *actionSheet = [[FDActionSheet alloc] initWithTitle:@"" message:@""];
  415. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"男") type:FDActionTypeDefault CallBack:^{
  416. [self changeSexWithString:@"1"];
  417. }]];
  418. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"女") type:FDActionTypeDefault CallBack:^{
  419. [self changeSexWithString:@"2"];
  420. }]];
  421. [actionSheet show:[UIApplication sharedApplication].keyWindow];
  422. // SexViewController *sexVC = [[SexViewController alloc]init];
  423. // sexVC.sexType = _sexString;
  424. // sexVC.delgate = self;
  425. // [self.navigationController pushViewController:sexVC animated:YES];
  426. }
  427. break;
  428. case EGXQMSection:
  429. {
  430. [self pushToChangeNameViewWithType:2 andStr:_model.signature];
  431. }
  432. break;
  433. case ERZSection:
  434. {
  435. //to do
  436. }
  437. break;
  438. case ESRSection:
  439. {
  440. [BRDatePickerView showDatePickerWithMode:BRDatePickerModeYMD title:ASLocalizedString(@"生日") selectValue:SafeStr(_model.birthday) resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
  441. _SRCell.rightLabel.text = selectValue;
  442. _model.birthday = selectValue;
  443. }];
  444. // NSLog(@"1111111");
  445. // [self isCreatHaldClearViewWithCount:1];
  446. // if (!_datePicker)//生日
  447. // {
  448. // _datePicker = [[[NSBundle mainBundle]loadNibNamed:@"BDView" owner:self options:nil]lastObject];
  449. // _datePicker.frame = CGRectMake(0,kScreenH ,kScreenW,260);
  450. // if(_model.birthday.length>0)
  451. // {
  452. // [_datePicker creatMinTime:_model.birthday];
  453. // }
  454. // [_halfClearView addSubview:_datePicker];
  455. // [UIView animateWithDuration:0.5 animations:^{
  456. // CGRect rect = _datePicker.frame;
  457. // rect.origin.y = kScreenH - 260;
  458. // _datePicker.frame = rect;
  459. // }];
  460. // FWWeakify(self)
  461. // [_datePicker setBDViewBlock:^(int tagIndex){
  462. // FWStrongify(self)
  463. // if (tagIndex == 0)
  464. // {
  465. // [self isCreatHaldClearViewWithCount:0];
  466. // }else if (tagIndex == 1)
  467. // {
  468. // [self handleToSelectTime];
  469. // }
  470. // }];
  471. // }
  472. }
  473. break;
  474. case EQGZTSection:
  475. {
  476. [self isCreatHaldClearViewWithCount:1];
  477. if (!_emotionViewVC)//情感状态
  478. {
  479. _emotionViewVC = [[emotionView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, 160) withName:_model.emotional_state];
  480. _emotionViewVC.delegate = self;
  481. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickEmotion:)];
  482. [_emotionViewVC addGestureRecognizer:tap];
  483. [_halfClearView addSubview:_emotionViewVC];
  484. [UIView animateWithDuration:0.5 animations:^{
  485. CGRect rect = _emotionViewVC.frame;
  486. rect.origin.y = kScreenH-160;
  487. _emotionViewVC.frame = rect;
  488. }];
  489. }
  490. }
  491. break;
  492. case EJXSection:
  493. {
  494. [self isCreatHaldClearViewWithCount:1];
  495. if (!_areaViewVC)//家乡
  496. {
  497. _areaViewVC = [[areaView alloc]initWithDelegate:self withCity:_model.city];
  498. _areaViewVC.frame = CGRectMake(0, kScreenH, kScreenW, 190);
  499. [_halfClearView addSubview:_areaViewVC];
  500. [UIView animateWithDuration:0.5 animations:^{
  501. CGRect rect = _areaViewVC.frame;
  502. rect.origin.y = kScreenH-190;
  503. _areaViewVC.frame = rect;
  504. }];
  505. }
  506. }
  507. break;
  508. case EZYSection:
  509. {
  510. [self pushToChangeNameViewWithType:3 andStr:_model.job];
  511. }
  512. break;
  513. default:
  514. break;
  515. }
  516. }
  517. - (void)signTFbaseViewAction {
  518. [self pushToChangeNameViewWithType:2 andStr:_model.signature];
  519. }
  520. -(void)clickEmotion:(UITapGestureRecognizer *)sender{
  521. }
  522. #pragma mark - 上传头像相关
  523. -(void)saveHeadImageWithImage:(UIImage *)image{
  524. // [_TXCell creatCellWithStr:image andSection:0];
  525. [_TXCell.headImgView setImage:image];
  526. // if (self.BuguLive.appModel.open_sts == 0) {
  527. // if ([_ossManager isSetRightParameter]) {
  528. // [self saveImage:image withName:@"1.png"];
  529. // [self showMyHud];
  530. // _timeString = [_ossManager getObjectKeyString];
  531. // [_ossManager asyncPutImage:_timeString localFilePath:_uploadFilePath];
  532. // }
  533. // }else
  534. {
  535. NSLog(@"image.size.height==%f,image.size.height==%f",image.size.height,image.size.height);
  536. NSData *data=UIImageJPEGRepresentation(image, 1);
  537. UIImage *image = [UIImage imageWithData:data];
  538. [self saveImage:image withName:@"image_head.jpg"];
  539. [self performSelector:@selector(uploadAvatar) withObject:nil afterDelay:0.8];
  540. }
  541. }
  542. #pragma mark 使用流文件上传头像
  543. - (void)uploadAvatar
  544. {
  545. [self showMyHud];
  546. NSString *imageFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  547. NSString *photoName=[imageFile stringByAppendingPathComponent:@"image_head.jpg"];
  548. NSURL *fileUrl = [NSURL URLWithString:[NSString stringWithFormat:@"file:%@",photoName]];
  549. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  550. [parmDict setObject:@"avatar" forKey:@"ctl"];
  551. [parmDict setObject:@"uploadImage" forKey:@"act"];
  552. [parmDict setObject:_model.user_id forKey:@"id"];
  553. FWWeakify(self)
  554. [self.httpsManager POSTWithDict:parmDict andFileUrl:fileUrl SuccessBlock:^(NSDictionary *responseJson)
  555. {
  556. FWStrongify(self)
  557. if ([responseJson toInt:@"status"] == 1)
  558. {
  559. _urlString = [responseJson toString:@"server_full_path"];
  560. _model.head_image = _urlString;
  561. [self hideMyHud];
  562. [self updateHeadImage];
  563. [self reloadHeaderImageWithUrl:_urlString];
  564. }else
  565. {
  566. [BGHUDHelper alert:[responseJson toString:@"error"]];
  567. }
  568. } FailureBlock:^(NSError *error)
  569. {
  570. [self hideMyHud];
  571. }];
  572. }
  573. - (void)updateHeadImage
  574. {
  575. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  576. [parmDict setObject:@"login" forKey:@"ctl"];
  577. [parmDict setObject:@"do_update" forKey:@"act"];
  578. [parmDict setObject:_model.user_id forKey:@"id"];
  579. if (_urlString.length < 1 && [_urlString isEqualToString:@""])
  580. {
  581. [parmDict setObject:@"" forKey:@"normal_head_path"];
  582. }else
  583. {
  584. [parmDict setObject:_urlString forKey:@"normal_head_path"];
  585. }
  586. [parmDict setObject:@"1" forKey:@"type"];
  587. [self showMyHud];
  588. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  589. {
  590. [self hideMyHud];
  591. } FailureBlock:^(NSError *error)
  592. {
  593. [self hideMyHud];
  594. }];
  595. }
  596. - (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName
  597. {
  598. NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
  599. NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
  600. [imageData writeToFile:fullPath atomically:NO];
  601. _uploadFilePath = fullPath;
  602. NSLog(@"uploadFilePath : %@", _uploadFilePath);
  603. }
  604. #pragma mark 代理回调
  605. - (void)uploadImageWithUrlStr:(NSString *)imageUrlStr withUploadStateCount:(int)stateCount
  606. {
  607. [self hideMyHud];
  608. if (stateCount == 0)
  609. {
  610. _urlString = [NSString stringWithFormat:@"./%@",_timeString];
  611. }else
  612. {
  613. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"oss上传头像失败")];
  614. }
  615. _model.head_image = _urlString;
  616. }
  617. #pragma mark -- 日历确定按钮点击事件
  618. - (void)handleToSelectTime
  619. {
  620. _SRCell.rightLabel.text = _datePicker.timeLabel.text;
  621. [UIView animateWithDuration:0.5 animations:^{
  622. } completion:^(BOOL finished) {
  623. [self isCreatHaldClearViewWithCount:0];
  624. }];
  625. }
  626. #pragma mark 修改情感状态
  627. - (void)changeEmotionStatuWithString:(NSString *)emoyionString
  628. {
  629. _model.emotional_state = _QGZTCell.rightLabel.text = emoyionString;
  630. // [self isCreatHaldClearViewWithCount:0];
  631. [GlobalVariables sharedInstance].isUserInfoCheck = YES;
  632. }
  633. #pragma mark 修改性别
  634. - (void)changeSexWithString:(NSString *)sexString
  635. {
  636. _sexString = sexString;
  637. if ([sexString isEqualToString:@"1"])
  638. {
  639. _XBCell.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  640. }else if ([sexString isEqualToString:@"2"])
  641. {
  642. _XBCell.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  643. }
  644. [GlobalVariables sharedInstance].isUserInfoCheck = YES;
  645. // isUserInfoCheck
  646. }
  647. #pragma mark 修改生日
  648. - (void)confrmCallBack:(NSInteger)Year month:(NSInteger)month day:(NSInteger)day andtag:(int)tagIndex
  649. {
  650. if (tagIndex == 12)
  651. {
  652. _SRCell.rightLabel.text = [NSString stringWithFormat:@"%d-%d-%d",(int)Year,(int)month,(int)day];
  653. }
  654. [self isCreatHaldClearViewWithCount:0];
  655. [GlobalVariables sharedInstance].isUserInfoCheck = YES;
  656. }
  657. #pragma mark 地区的代理
  658. - (void)confrmCallBack:(NSString *)provice withCity:(NSString *)city andtagIndex:(int)tagIndex
  659. {
  660. if (tagIndex == 12)
  661. {
  662. _provinceString = provice;
  663. _cityString = city;
  664. if (city.length < 1 || provice.length < 1)
  665. {
  666. _JXCell.rightLabel.text = @"";
  667. }else
  668. {
  669. _model.city = _JXCell.rightLabel.text = [NSString stringWithFormat:@"%@ %@",provice,city];
  670. }
  671. }
  672. [self isCreatHaldClearViewWithCount:0];
  673. [GlobalVariables sharedInstance].isUserInfoCheck = YES;
  674. }
  675. #pragma mark 修改昵称之类的
  676. - (void)pushToChangeNameViewWithType:(int)type andStr:(NSString *)str
  677. {
  678. _isNeedLoad = NO;
  679. ChangeNameViewController *nameVC =[[ChangeNameViewController alloc]init];
  680. if (type == 1)
  681. {
  682. nameVC.nickInfo = _nick_info;
  683. }
  684. nameVC.textFiledName = str;
  685. nameVC.viewType = [NSString stringWithFormat:@"%d",type];
  686. nameVC.delegate = self;
  687. [self.navigationController pushViewController:nameVC animated:YES];
  688. }
  689. - (void)changeNameWithString:(NSString *)name withType:(NSString *)type
  690. {
  691. if ([type isEqualToString:@"1"])
  692. {
  693. _NCCell.rightLabel.text = name;
  694. _model.nick_name = name;
  695. }else if ([type isEqualToString:@"2"])
  696. {
  697. _GXQMCell.rightLabel.text = name;
  698. _model.signature = name;
  699. signTFLabel.text = name;
  700. }else if ([type isEqualToString:@"3"])
  701. {
  702. _ZYCell.rightLabel.text = name;
  703. _model.job = name;
  704. }
  705. [GlobalVariables sharedInstance].isUserInfoCheck = YES;
  706. }
  707. #pragma mark 保存的按钮
  708. - (void)saveEditButton
  709. {
  710. [self updateHeadImage];
  711. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  712. [dict setObject:@"user_center" forKey:@"ctl"];
  713. [dict setObject:@"user_save" forKey:@"act"];
  714. if (_NCCell.rightLabel.text.length > 0)//名字
  715. {
  716. [dict setObject:_NCCell.rightLabel.text forKey:@"nick_name"];
  717. }
  718. if (_sexString.length > 0)//性别
  719. {
  720. [dict setObject:_sexString forKey:@"sex"];
  721. }
  722. if (signTFLabel.text.length > 0)//个性签名
  723. {
  724. [dict setObject:signTFLabel.text forKey:@"signature"];
  725. }
  726. if (_SRCell.rightLabel.text.length > 0)//生日
  727. {
  728. [dict setObject:_SRCell.rightLabel.text forKey:@"birthday"];
  729. }
  730. if (_QGZTCell.rightLabel.text.length > 0)//情感状态
  731. {
  732. [dict setObject:_QGZTCell.rightLabel.text forKey:@"emotional_state"];
  733. }
  734. if (_provinceString.length > 0)//省份
  735. {
  736. [dict setObject:_provinceString forKey:@"province"];
  737. }
  738. if (_cityString.length > 0)//城市
  739. {
  740. [dict setObject:_cityString forKey:@"city"];
  741. }
  742. if (_ZYCell.rightLabel.text.length > 0)//工作
  743. {
  744. [dict setObject:_ZYCell.rightLabel.text forKey:@"job"];
  745. }
  746. FWWeakify(self)
  747. [self showMyHud];
  748. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson)
  749. {
  750. FWStrongify(self)
  751. [self hideMyHud];
  752. if ([responseJson toInt:@"status"] == 1)
  753. {
  754. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"编辑成功")];
  755. [GlobalVariables sharedInstance].isUserInfoCheck = NO;
  756. [self.navigationController popViewControllerAnimated:YES];
  757. }else
  758. {
  759. [BGHUDHelper alert:[responseJson toString:@"error"]];
  760. }
  761. } FailureBlock:^(NSError *error)
  762. {
  763. FWStrongify(self)
  764. [self hideMyHud];
  765. }];
  766. }
  767. #pragma mark =============================================家乡数据的获取和存储============================================================
  768. - (NSString *)getVersionsNum
  769. {
  770. NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
  771. NSString *filePath = [cachePath stringByAppendingPathComponent:@"versions.plist"];
  772. NSMutableDictionary *dict1 = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
  773. return [dict1 objectForKey:@"versions"];
  774. }
  775. - (NSMutableArray *)getMyAreaDataArr
  776. {
  777. //获取Documents目录
  778. NSString *docPath2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
  779. //还要指定存储文件的文件名称,仍然使用字符串拼接
  780. NSString *filePath2 = [docPath2 stringByAppendingPathComponent:@"Province.plist"];
  781. return [NSMutableArray arrayWithContentsOfFile:filePath2];
  782. }
  783. - (void)loadMyAreaData
  784. {
  785. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  786. [parmDict setObject:@"user_center" forKey:@"ctl"];
  787. [parmDict setObject:@"region_list" forKey:@"act"];
  788. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  789. {
  790. if ([responseJson toInt:@"status"] == 1)
  791. {
  792. //存版本
  793. NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
  794. NSString *filePath = [cachePath stringByAppendingPathComponent:@"versions.plist"];
  795. NSMutableDictionary *dict1 = [NSMutableDictionary dictionary];
  796. [dict1 setObject:[responseJson toString:@"region_versions"] forKey:@"versions"];
  797. [dict1 writeToFile:filePath atomically:YES];
  798. NSArray *areaArray = [responseJson objectForKey:@"region_list"];
  799. if (areaArray)
  800. {
  801. if (areaArray.count > 0 && [areaArray isKindOfClass:[NSArray class]])
  802. {
  803. //获取Documents目录
  804. NSString *docPath2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
  805. //还要指定存储文件的文件名称,仍然使用字符串拼接
  806. NSString *filePath2 = [docPath2 stringByAppendingPathComponent:@"Province.plist"];
  807. NSLog(@"filePath2==%@",filePath2);
  808. [areaArray writeToFile:filePath2 atomically:YES];
  809. }
  810. }
  811. }
  812. } FailureBlock:^(NSError *error)
  813. {
  814. }];
  815. }
  816. @end