// // YOUPAILCFinishMsgVC.m // LiveChat // // Created by 张灿 on 2018/4/8. // Copyright © 2018年 DaTongIntelligent. All rights reserved. // #import "YOUPAILCFinishMsgVC.h" #import "YOUPAILCCommonCell.h" #import "YOUPAILCUpdateNickVC.h" #import "YOUPAILCUpdateCityVC.h" #import "YOUPAILCUpdateRecomIdVC.h" #import "PGDatePickManager.h" #import "YOUPAILCBindPhoneAccountVC.h" #import "YOUPAIZYSelectSexWindow.h" #import "UIViewController+TFPresent.h" @interface YOUPAILCFinishMsgVC () @property(nonatomic,strong)YOUPAILCUserModel* youpaipuserModel; @property(nonatomic,strong)UITableView* youpaiptableView; @property (strong ,nonatomic) UIView *youpaipheaderView; @property (strong, nonatomic) UIView *youpaipfooterView; @property(nonatomic,strong)UIButton* youpaipstartBtn; @end @implementation YOUPAILCFinishMsgVC - (UITableView *)youpaiptableView{ if (!_youpaiptableView) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(50, NavBarHeight, KScreenWidth-100, KScreenHeight-NavBarHeight) style:UITableViewStylePlain]; _youpaiptableView.showsVerticalScrollIndicator = NO; // _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; _youpaiptableView.backgroundColor = LCWhiteColor; _youpaiptableView.separatorInset = UIEdgeInsetsMake(0,65, 0,15); _youpaiptableView.separatorColor = [UIColor whiteColor]; _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } } return _youpaiptableView; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.sx_disableInteractivePop = YES; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; self.sx_disableInteractivePop = NO; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = LCWhiteColor; self.youpaipuserModel = [LCSaveModel getUserModel]; if(self.youpaipinviteCodeStr == nil) { self.youpaipinviteCodeStr = @""; } [self youpaifsetupView]; } -(UIView *)youpaipheaderView{ if (!_youpaipheaderView) { _youpaipheaderView = [[UIView alloc]initWithFrame:CGRectMake(50, 0, KScreenWidth-100, 80)]; UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0,25, KScreenWidth-100, 21)]; label.textColor = HexColorFromRGB(0x333333); label.font = LCFont(17); label.textAlignment = NSTextAlignmentCenter; label.text = @"Hi,请完善你的资料哦~"; [_youpaipheaderView addSubview:label]; } return _youpaipheaderView; } -(UIView *)youpaipfooterView{ if (!_youpaipfooterView) { _youpaipfooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-100, 130)]; UIButton* startBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 62, KScreenWidth-120, 48)]; startBtn.userInteractionEnabled = NO; startBtn.backgroundColor = LCGray; startBtn.layer.cornerRadius = 24.0; startBtn.layer.masksToBounds = YES; startBtn.titleLabel.font = LCFont17; [startBtn setTitle:@"开始交友" forState:(UIControlStateNormal)]; [startBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [startBtn addTarget:self action:@selector(youpaifstartGameClick) forControlEvents:(UIControlEventTouchUpInside)]; self.youpaipstartBtn = startBtn; [_youpaipfooterView addSubview:startBtn]; [self youpaifupdateStartBtnStatu]; } return _youpaipfooterView; } - (void)youpaifsetupView{ [self.view addSubview:self.youpaiptableView]; self.youpaiptableView.tableHeaderView = self.youpaipheaderView; self.youpaiptableView.tableFooterView = self.youpaipfooterView; [self youpaifupdateStartBtnStatu]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (self.youpaipuserModel.youpaipuserinfo.youpaipinvite_code == 0||self.youpaipinviteCodeStr.length ==0) { return 5; }else{ return 4; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 55; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.0001; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.0001; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILCCommonCell* cell = [[YOUPAILCCommonCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"commonCell"]; if (indexPath.row==0) { cell.youpaipheadLabel.text = @"昵称"; if ([self.youpaipuserModel.youpaipuserinfo.youpaipnickname isEqualToString:@""]) { cell.youpaipdataLabel.text = @"请输入昵称"; cell.youpaipdataLabel.textColor = LCGray; }else{ cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipnickname; cell.youpaipdataLabel.textColor = LCTextBlack; } }else if (indexPath.row==1){ cell.youpaipheadLabel.text = @"性别"; if (self.youpaipuserModel.youpaipuserinfo.youpaipgender ==0) { cell.youpaipdataLabel.text = @"性别选择后不可更改"; cell.youpaipdataLabel.textColor = LCGray; }else{ NSString* sexStr; if(self.youpaipuserModel.youpaipuserinfo.youpaipgender==1){ sexStr = @"女"; }else{ sexStr = @"男"; } cell.youpaipdataLabel.text = sexStr; cell.youpaipdataLabel.textColor = LCTextBlack; } }else if (indexPath.row==2){ cell.youpaipheadLabel.text = @"城市"; if ([self.youpaipuserModel.youpaipuserinfo.youpaipcity isEqualToString:@""]) { [[LCLocationManager shareInstance]getLocationCity:^(NSString *city) { if (![city isEqualToString:@""]) { for (NSString* dictCity in [[LCSaveData getCityDict] allValues]) { if ([city containsString:dictCity]) { self.youpaipuserModel.youpaipuserinfo.youpaipcity = dictCity; cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity; cell.youpaipdataLabel.textColor = LCTextBlack; [self youpaifupdateStartBtnStatu]; } } }else{ cell.youpaipdataLabel.text = @"请选择城市"; cell.youpaipdataLabel.textColor = LCGray; } }]; }else{ cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity; cell.youpaipdataLabel.textColor = LCTextBlack; } }else if (indexPath.row==3){ cell.youpaipheadLabel.text = @"年龄"; if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]) { cell.youpaipdataLabel.text = @"请选择日期"; cell.youpaipdataLabel.textColor = LCGray; }else{ cell.youpaipdataLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday; cell.youpaipdataLabel.textColor = LCTextBlack; } }else if(indexPath.row==4){ cell.youpaipheadLabel.text = @"推荐"; if ([self.youpaipinviteCodeStr isEqualToString:@""]) { cell.youpaipdataLabel.text = @"请输入推荐人花舞号(选填)"; cell.youpaipdataLabel.textColor = LCGray; }else{ cell.youpaipdataLabel.text = self.youpaipinviteCodeStr; cell.youpaipdataLabel.textColor = LCTextBlack; } } [cell bottomLineforViewHeight:55]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row==0) { YOUPAILCUpdateNickVC* nickVC = [[YOUPAILCUpdateNickVC alloc]init]; nickVC.youpaipnickName = self.youpaipuserModel.youpaipuserinfo.youpaipnickname; nickVC.youpaipblock = ^(NSString *nickname) { self.youpaipuserModel.youpaipuserinfo.youpaipnickname = nickname; [self youpaifupdateStartBtnStatu]; }; [self.navigationController pushViewController:nickVC animated:YES]; }else if (indexPath.row==1){ // ZCAlertAction* action1 = [ZCAlertAction actionWithTitle:@"男" andblock:^{ // self.userModel.userinfo.gender = 2; // [self youpaifupdateStartBtnStatu]; // }]; // ZCAlertAction* action2 = [ZCAlertAction actionWithTitle:@"女" andblock:^{ // self.userModel.userinfo.gender = 1; // [self youpaifupdateStartBtnStatu]; // }]; // ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:@"性别选择后不可更改" andShowCancelButton:YES andAction:@[action1,action2]]; // alertSheet.alertWindow.hidden = NO; // [alertSheet show]; YOUPAIZYSelectSexWindow *vc= [[YOUPAIZYSelectSexWindow alloc]init]; vc.vWidth = KScreenWidth -68; vc.vHeight = 171; vc.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender; vc.youpaipdelegate = self; vc.isTouchDismiss = YES; [self TFPresentVC:vc completion:^{}]; }else if (indexPath.row==2){ YOUPAILCUpdateCityVC* cityVC = [[YOUPAILCUpdateCityVC alloc]init]; cityVC.youpaipcityName = self.youpaipuserModel.youpaipuserinfo.youpaipcity; cityVC.youpaipblock = ^(NSString *cityName) { self.youpaipuserModel.youpaipuserinfo.youpaipcity = cityName; [self youpaifupdateStartBtnStatu]; }; [self.navigationController pushViewController:cityVC animated:YES]; }else if (indexPath.row==3){ PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init]; datePickManager.isShadeBackground = true; datePickManager.cancelButtonFont = LCFont(15); datePickManager.confirmButtonFont = LCFont(15); datePickManager.cancelButtonTextColor = HexColorFromRGB(0x333333); datePickManager.confirmButtonTextColor = HexColorFromRGB(0x333333); datePickManager.headerViewBackgroundColor = LCWhiteColor; datePickManager.headerHeight = 50; PGDatePicker *datePicker = datePickManager.datePicker; datePicker.rowHeight = 35; datePicker.textColorOfSelectedRow = HexColorFromRGB(0x333333); datePicker.textColorOfOtherRow = HexColorFromRGB(0xD6D6D6); datePicker.textFontOfSelectedRow = LCFont(17); datePicker.textFontOfOtherRow = LCFont(17); datePicker.lineBackgroundColor = [UIColor clearColor]; // PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init]; // datePickManager.isShadeBackgroud = true; // PGDatePicker *datePicker = datePickManager.datePicker; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDate* currentDate = [NSDate date]; [dateFormatter setDateFormat:@"yyyy"]; NSString* currentYear=[dateFormatter stringFromDate:currentDate] ; [dateFormatter setDateFormat:@"MM"]; NSString* currentMonth=[dateFormatter stringFromDate:currentDate]; [dateFormatter setDateFormat:@"dd"]; NSString* currentDay=[dateFormatter stringFromDate:currentDate] ; NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-18,currentMonth,currentDay]; NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-50,currentMonth,currentDay]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSString* defaultDateStr; if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@""]) { defaultDateStr = @"1999-03-15"; }else{ defaultDateStr = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday; } NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期 [datePicker setDate:date]; datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr]; datePicker.minimumDate = [dateFormatter dateFromString:minDateStr]; datePicker.delegate = self; datePicker.datePickerType = PGDatePickerTypeLine; datePicker.isHiddenMiddleText = false; datePicker.datePickerMode = PGDatePickerModeDate; [self presentViewController:datePickManager animated:false completion:nil]; }else if (indexPath.row==4){ YOUPAILCUpdateRecomIdVC* recomVC = [[YOUPAILCUpdateRecomIdVC alloc]init]; if (![self.youpaipinviteCodeStr isEqualToString:@""]) { recomVC.youpaiprecomId = self.youpaipinviteCodeStr; } recomVC.youpaipblock = ^(NSString *RecomId) { self.youpaipinviteCodeStr = RecomId; [self youpaifupdateStartBtnStatu]; }; [self.navigationController pushViewController:recomVC animated:YES]; } } - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{ NSLog(@"dateComponents = %@", dateComponents); NSInteger year=[dateComponents year]; NSInteger month=[dateComponents month]; NSInteger day=[dateComponents day]; NSString* birthday = [NSString stringWithFormat:@"%zd-%zd-%zd",year,month,day]; self.youpaipuserModel.youpaipuserinfo.youpaipbirthday = birthday; [self youpaifupdateStartBtnStatu]; } - (void)youpaifupdateStartBtnStatu{ if (![self.youpaipuserModel.youpaipuserinfo.youpaipnickname isEqualToString:@""] && self.youpaipuserModel.youpaipuserinfo.youpaipgender != 0 && ![self.youpaipuserModel.youpaipuserinfo.youpaipcity isEqualToString:@""]&& ![self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]) { [self.youpaipstartBtn setBackgroundImage:[LCTools ColorImage:self.youpaipstartBtn.frame.size FromColors:@[LCGradientOneColor,LCGradientTwoColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; self.youpaipstartBtn.userInteractionEnabled = YES;; }else{ self.youpaipstartBtn.backgroundColor = LCGray; [self.youpaipstartBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaipstartBtn.userInteractionEnabled = NO; } [self.youpaiptableView reloadData]; } - (void)youpaifstartGameClick{ UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:nil message:@"性别确定后将无法修改,如性别不符将导致功能不能正常使用" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [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) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 YOUPAILCUserModel* userModel = [LCSaveModel getUserModel]; if(userModel.youpaipuserinfo.youpaipmobile!=nil&&userModel.youpaipuserinfo.youpaipmobile.length>9) { userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender; userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday; userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity; [LCSaveModel saveUserModel:userModel]; // [LCSaveData saveLoginMark:YES]; [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token]; // [LCTools changeRootToTabbar]; } else { //不做强制绑定 /* userModel.userinfo.gender = self.userModel.userinfo.gender; userModel.userinfo.birthday = self.userModel.userinfo.birthday; userModel.userinfo.city = self.userModel.userinfo.city; [LCSaveModel saveUserModel:userModel]; YOUPAILCBindPhoneAccountVC *bind = [[YOUPAILCBindPhoneAccountVC alloc]init]; bind.inLogin = YES; [self.navigationController pushViewController:bind animated:YES]; */ userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender; userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday; userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity; [LCSaveModel saveUserModel:userModel]; // [LCSaveData saveLoginMark:YES]; [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token]; // [LCTools changeRootToTabbar]; } } } failure:^(NSError *error) { }]; }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]; [systemAlert addAction:action2]; [systemAlert addAction:action1]; [self presentViewController:systemAlert animated:YES completion:nil]; } #pragma mark ZYSelectSexWindowDelegate -(void)youpaifSelectSexWindowAction:(NSInteger)gender { self.youpaipuserModel.youpaipuserinfo.youpaipgender = gender;//1 女。2 男 [self youpaifupdateStartBtnStatu]; } @end