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