YOUPAILCFinishMsgVC.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. //
  2. // YOUPAILCFinishMsgVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/4/8.
  6. // Copyright © 2018年 DaTongIntelligent. All rights reserved.
  7. //
  8. #import "YOUPAILCFinishMsgVC.h"
  9. #import "YOUPAILCCommonCell.h"
  10. #import "YOUPAILCUpdateNickVC.h"
  11. #import "YOUPAILCUpdateCityVC.h"
  12. #import "YOUPAILCUpdateRecomIdVC.h"
  13. #import "PGDatePickManager.h"
  14. #import "YOUPAILCBindPhoneAccountVC.h"
  15. #import "YOUPAIZYSelectSexWindow.h"
  16. #import "UIViewController+TFPresent.h"
  17. @interface YOUPAILCFinishMsgVC ()<UITableViewDataSource,UITableViewDelegate,PGDatePickerDelegate,ZYSelectSexWindowDelegate>
  18. @property(nonatomic,strong)YOUPAILCUserModel* youpaipuserModel;
  19. @property(nonatomic,strong)UITableView* youpaiptableView;
  20. @property (strong ,nonatomic) UIView *youpaipheaderView;
  21. @property (strong, nonatomic) UIView *youpaipfooterView;
  22. @property(nonatomic,strong)UIButton* youpaipstartBtn;
  23. @end
  24. @implementation YOUPAILCFinishMsgVC
  25. - (UITableView *)youpaiptableView{
  26. if (!_youpaiptableView) {
  27. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(50, NavBarHeight, KScreenWidth-100, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
  28. _youpaiptableView.showsVerticalScrollIndicator = NO;
  29. // _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  30. _youpaiptableView.backgroundColor = LCWhiteColor;
  31. _youpaiptableView.separatorInset = UIEdgeInsetsMake(0,65, 0,15);
  32. _youpaiptableView.separatorColor = [UIColor whiteColor];
  33. _youpaiptableView.delegate = self;
  34. _youpaiptableView.dataSource = self;
  35. if (@available(iOS 15.0, *)) {
  36. _youpaiptableView.sectionHeaderTopPadding = 0;
  37. }
  38. }
  39. return _youpaiptableView;
  40. }
  41. - (void)viewWillAppear:(BOOL)animated{
  42. [super viewWillAppear:animated];
  43. self.sx_disableInteractivePop = YES;
  44. }
  45. - (void)viewWillDisappear:(BOOL)animated{
  46. [super viewWillDisappear:animated];
  47. self.sx_disableInteractivePop = NO;
  48. }
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. self.view.backgroundColor = LCWhiteColor;
  52. self.youpaipuserModel = [LCSaveModel getUserModel];
  53. if(self.youpaipinviteCodeStr == nil)
  54. {
  55. self.youpaipinviteCodeStr = @"";
  56. }
  57. [self youpaifsetupView];
  58. }
  59. -(UIView *)youpaipheaderView{
  60. if (!_youpaipheaderView) {
  61. _youpaipheaderView = [[UIView alloc]initWithFrame:CGRectMake(50, 0, KScreenWidth-100, 80)];
  62. UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0,25, KScreenWidth-100, 21)];
  63. label.textColor = HexColorFromRGB(0x333333);
  64. label.font = LCFont(17);
  65. label.textAlignment = NSTextAlignmentCenter;
  66. label.text = @"Hi,请完善你的资料哦~";
  67. [_youpaipheaderView addSubview:label];
  68. }
  69. return _youpaipheaderView;
  70. }
  71. -(UIView *)youpaipfooterView{
  72. if (!_youpaipfooterView) {
  73. _youpaipfooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-100, 130)];
  74. UIButton* startBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 62, KScreenWidth-120, 48)];
  75. startBtn.userInteractionEnabled = NO;
  76. startBtn.backgroundColor = LCGray;
  77. startBtn.layer.cornerRadius = 24.0;
  78. startBtn.layer.masksToBounds = YES;
  79. startBtn.titleLabel.font = LCFont17;
  80. [startBtn setTitle:@"开始交友" forState:(UIControlStateNormal)];
  81. [startBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  82. [startBtn addTarget:self action:@selector(youpaifstartGameClick) forControlEvents:(UIControlEventTouchUpInside)];
  83. self.youpaipstartBtn = startBtn;
  84. [_youpaipfooterView addSubview:startBtn];
  85. [self youpaifupdateStartBtnStatu];
  86. }
  87. return _youpaipfooterView;
  88. }
  89. - (void)youpaifsetupView{
  90. [self.view addSubview:self.youpaiptableView];
  91. self.youpaiptableView.tableHeaderView = self.youpaipheaderView;
  92. self.youpaiptableView.tableFooterView = self.youpaipfooterView;
  93. [self youpaifupdateStartBtnStatu];
  94. }
  95. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  96. if (self.youpaipuserModel.youpaipuserinfo.youpaipinvite_code == 0||self.youpaipinviteCodeStr.length ==0) {
  97. return 5;
  98. }else{
  99. return 4;
  100. }
  101. }
  102. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  103. return 55;
  104. }
  105. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  106. return 0.0001;
  107. }
  108. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  109. return 0.0001;
  110. }
  111. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  112. YOUPAILCCommonCell* cell = [[YOUPAILCCommonCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"commonCell"];
  113. if (indexPath.row==0) {
  114. cell.youpaipheadLabel.text = @"昵称";
  115. if ([self.youpaipuserModel.youpaipuserinfo.youpaipnickname isEqualToString:@""]) {
  116. cell.youpaipdataLabel.text = @"请输入昵称";
  117. cell.youpaipdataLabel.textColor = LCGray;
  118. }else{
  119. cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipnickname;
  120. cell.youpaipdataLabel.textColor = LCTextBlack;
  121. }
  122. }else if (indexPath.row==1){
  123. cell.youpaipheadLabel.text = @"性别";
  124. if (self.youpaipuserModel.youpaipuserinfo.youpaipgender ==0) {
  125. cell.youpaipdataLabel.text = @"性别选择后不可更改";
  126. cell.youpaipdataLabel.textColor = LCGray;
  127. }else{
  128. NSString* sexStr;
  129. if(self.youpaipuserModel.youpaipuserinfo.youpaipgender==1){
  130. sexStr = @"女";
  131. }else{
  132. sexStr = @"男";
  133. }
  134. cell.youpaipdataLabel.text = sexStr;
  135. cell.youpaipdataLabel.textColor = LCTextBlack;
  136. }
  137. }else if (indexPath.row==2){
  138. cell.youpaipheadLabel.text = @"城市";
  139. if ([self.youpaipuserModel.youpaipuserinfo.youpaipcity isEqualToString:@""]) {
  140. [[LCLocationManager shareInstance]getLocationCity:^(NSString *city) {
  141. if (![city isEqualToString:@""]) {
  142. for (NSString* dictCity in [[LCSaveData getCityDict] allValues]) {
  143. if ([city containsString:dictCity]) {
  144. self.youpaipuserModel.youpaipuserinfo.youpaipcity = dictCity;
  145. cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  146. cell.youpaipdataLabel.textColor = LCTextBlack;
  147. [self youpaifupdateStartBtnStatu];
  148. }
  149. }
  150. }else{
  151. cell.youpaipdataLabel.text = @"请选择城市";
  152. cell.youpaipdataLabel.textColor = LCGray;
  153. }
  154. }];
  155. }else{
  156. cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  157. cell.youpaipdataLabel.textColor = LCTextBlack;
  158. }
  159. }else if (indexPath.row==3){
  160. cell.youpaipheadLabel.text = @"年龄";
  161. if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]) {
  162. cell.youpaipdataLabel.text = @"请选择日期";
  163. cell.youpaipdataLabel.textColor = LCGray;
  164. }else{
  165. cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  166. cell.youpaipdataLabel.textColor = LCTextBlack;
  167. }
  168. }else if(indexPath.row==4){
  169. cell.youpaipheadLabel.text = @"推荐";
  170. if ([self.youpaipinviteCodeStr isEqualToString:@""]) {
  171. cell.youpaipdataLabel.text = @"请输入推荐人花舞号(选填)";
  172. cell.youpaipdataLabel.textColor = LCGray;
  173. }else{
  174. cell.youpaipdataLabel.text = self.youpaipinviteCodeStr;
  175. cell.youpaipdataLabel.textColor = LCTextBlack;
  176. }
  177. }
  178. [cell bottomLineforViewHeight:55];
  179. return cell;
  180. }
  181. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  182. if (indexPath.row==0) {
  183. YOUPAILCUpdateNickVC* nickVC = [[YOUPAILCUpdateNickVC alloc]init];
  184. nickVC.youpaipnickName = self.youpaipuserModel.youpaipuserinfo.youpaipnickname;
  185. nickVC.youpaipblock = ^(NSString *nickname) {
  186. self.youpaipuserModel.youpaipuserinfo.youpaipnickname = nickname;
  187. [self youpaifupdateStartBtnStatu];
  188. };
  189. [self.navigationController pushViewController:nickVC animated:YES];
  190. }else if (indexPath.row==1){
  191. // ZCAlertAction* action1 = [ZCAlertAction actionWithTitle:@"男" andblock:^{
  192. // self.userModel.userinfo.gender = 2;
  193. // [self youpaifupdateStartBtnStatu];
  194. // }];
  195. // ZCAlertAction* action2 = [ZCAlertAction actionWithTitle:@"女" andblock:^{
  196. // self.userModel.userinfo.gender = 1;
  197. // [self youpaifupdateStartBtnStatu];
  198. // }];
  199. // ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:@"性别选择后不可更改" andShowCancelButton:YES andAction:@[action1,action2]];
  200. // alertSheet.alertWindow.hidden = NO;
  201. // [alertSheet show];
  202. YOUPAIZYSelectSexWindow *vc= [[YOUPAIZYSelectSexWindow alloc]init];
  203. vc.vWidth = KScreenWidth -68;
  204. vc.vHeight = 171;
  205. vc.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender;
  206. vc.youpaipdelegate = self;
  207. vc.isTouchDismiss = YES;
  208. [self TFPresentVC:vc completion:^{}];
  209. }else if (indexPath.row==2){
  210. YOUPAILCUpdateCityVC* cityVC = [[YOUPAILCUpdateCityVC alloc]init];
  211. cityVC.youpaipcityName = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  212. cityVC.youpaipblock = ^(NSString *cityName) {
  213. self.youpaipuserModel.youpaipuserinfo.youpaipcity = cityName;
  214. [self youpaifupdateStartBtnStatu];
  215. };
  216. [self.navigationController pushViewController:cityVC animated:YES];
  217. }else if (indexPath.row==3){
  218. PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  219. datePickManager.isShadeBackground = true;
  220. datePickManager.cancelButtonFont = LCFont(15);
  221. datePickManager.confirmButtonFont = LCFont(15);
  222. datePickManager.cancelButtonTextColor = HexColorFromRGB(0x333333);
  223. datePickManager.confirmButtonTextColor = HexColorFromRGB(0x333333);
  224. datePickManager.headerViewBackgroundColor = LCWhiteColor;
  225. datePickManager.headerHeight = 50;
  226. PGDatePicker *datePicker = datePickManager.datePicker;
  227. datePicker.rowHeight = 35;
  228. datePicker.textColorOfSelectedRow = HexColorFromRGB(0x333333);
  229. datePicker.textColorOfOtherRow = HexColorFromRGB(0xD6D6D6);
  230. datePicker.textFontOfSelectedRow = LCFont(17);
  231. datePicker.textFontOfOtherRow = LCFont(17);
  232. datePicker.lineBackgroundColor = [UIColor clearColor];
  233. // PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  234. // datePickManager.isShadeBackgroud = true;
  235. // PGDatePicker *datePicker = datePickManager.datePicker;
  236. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  237. NSDate* currentDate = [NSDate date];
  238. [dateFormatter setDateFormat:@"yyyy"];
  239. NSString* currentYear=[dateFormatter stringFromDate:currentDate] ;
  240. [dateFormatter setDateFormat:@"MM"];
  241. NSString* currentMonth=[dateFormatter stringFromDate:currentDate];
  242. [dateFormatter setDateFormat:@"dd"];
  243. NSString* currentDay=[dateFormatter stringFromDate:currentDate] ;
  244. NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-18,currentMonth,currentDay];
  245. NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-50,currentMonth,currentDay];
  246. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  247. NSString* defaultDateStr;
  248. if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@""]) {
  249. defaultDateStr = @"1999-03-15";
  250. }else{
  251. defaultDateStr = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  252. }
  253. NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期
  254. [datePicker setDate:date];
  255. datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr];
  256. datePicker.minimumDate = [dateFormatter dateFromString:minDateStr];
  257. datePicker.delegate = self;
  258. datePicker.datePickerType = PGDatePickerTypeLine;
  259. datePicker.isHiddenMiddleText = false;
  260. datePicker.datePickerMode = PGDatePickerModeDate;
  261. [self presentViewController:datePickManager animated:false completion:nil];
  262. }else if (indexPath.row==4){
  263. YOUPAILCUpdateRecomIdVC* recomVC = [[YOUPAILCUpdateRecomIdVC alloc]init];
  264. if (![self.youpaipinviteCodeStr isEqualToString:@""]) {
  265. recomVC.youpaiprecomId = self.youpaipinviteCodeStr;
  266. }
  267. recomVC.youpaipblock = ^(NSString *RecomId) {
  268. self.youpaipinviteCodeStr = RecomId;
  269. [self youpaifupdateStartBtnStatu];
  270. };
  271. [self.navigationController pushViewController:recomVC animated:YES];
  272. }
  273. }
  274. - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
  275. NSLog(@"dateComponents = %@", dateComponents);
  276. NSInteger year=[dateComponents year];
  277. NSInteger month=[dateComponents month];
  278. NSInteger day=[dateComponents day];
  279. NSString* birthday = [NSString stringWithFormat:@"%zd-%zd-%zd",year,month,day];
  280. self.youpaipuserModel.youpaipuserinfo.youpaipbirthday = birthday;
  281. [self youpaifupdateStartBtnStatu];
  282. }
  283. - (void)youpaifupdateStartBtnStatu{
  284. if (![self.youpaipuserModel.youpaipuserinfo.youpaipnickname isEqualToString:@""] && self.youpaipuserModel.youpaipuserinfo.youpaipgender != 0 &&
  285. ![self.youpaipuserModel.youpaipuserinfo.youpaipcity isEqualToString:@""]&&
  286. ![self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]) {
  287. [self.youpaipstartBtn setBackgroundImage:[LCTools ColorImage:self.youpaipstartBtn.frame.size FromColors:@[LCGradientOneColor,LCGradientTwoColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  288. self.youpaipstartBtn.userInteractionEnabled = YES;;
  289. }else{
  290. self.youpaipstartBtn.backgroundColor = LCGray;
  291. [self.youpaipstartBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  292. self.youpaipstartBtn.userInteractionEnabled = NO;
  293. }
  294. [self.youpaiptableView reloadData];
  295. }
  296. - (void)youpaifstartGameClick{
  297. UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:nil message:@"性别确定后将无法修改,如性别不符将导致功能不能正常使用" preferredStyle:UIAlertControllerStyleAlert];
  298. UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  299. [LCHttpHelper requestWithURLString:UpdateUserMsg parameters:@{@"gender":@(self.youpaipuserModel.youpaipuserinfo.youpaipgender),@"birthday":self.youpaipuserModel.youpaipuserinfo.youpaipbirthday,@"cityId":[LCTools getCityIDWithCityName:[LCTools getbindData]?[LCTools getbindData]:@""],@"invite_code":self.youpaipinviteCodeStr} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  300. NSDictionary* dict = (NSDictionary*)responseObject;
  301. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  302. if (code==0) {//成功
  303. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  304. if(userModel.youpaipuserinfo.youpaipmobile!=nil&&userModel.youpaipuserinfo.youpaipmobile.length>9)
  305. {
  306. userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender;
  307. userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  308. userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  309. [LCSaveModel saveUserModel:userModel];
  310. // [LCSaveData saveLoginMark:YES];
  311. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  312. // [LCTools changeRootToTabbar];
  313. }
  314. else
  315. {
  316. //不做强制绑定
  317. /*
  318. userModel.userinfo.gender = self.userModel.userinfo.gender;
  319. userModel.userinfo.birthday = self.userModel.userinfo.birthday;
  320. userModel.userinfo.city = self.userModel.userinfo.city;
  321. [LCSaveModel saveUserModel:userModel];
  322. YOUPAILCBindPhoneAccountVC *bind = [[YOUPAILCBindPhoneAccountVC alloc]init];
  323. bind.inLogin = YES;
  324. [self.navigationController pushViewController:bind animated:YES];
  325. */
  326. userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender;
  327. userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  328. userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  329. [LCSaveModel saveUserModel:userModel];
  330. // [LCSaveData saveLoginMark:YES];
  331. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  332. // [LCTools changeRootToTabbar];
  333. }
  334. }
  335. } failure:^(NSError *error) {
  336. }];
  337. }];
  338. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
  339. [systemAlert addAction:action2];
  340. [systemAlert addAction:action1];
  341. [self presentViewController:systemAlert animated:YES completion:nil];
  342. }
  343. #pragma mark ZYSelectSexWindowDelegate
  344. -(void)youpaifSelectSexWindowAction:(NSInteger)gender
  345. {
  346. self.youpaipuserModel.youpaipuserinfo.youpaipgender = gender;//1 女。2 男
  347. [self youpaifupdateStartBtnStatu];
  348. }
  349. @end