//
//  FirthlyViewController.m
//  Open
//
//  Created by 看看智能 on 2018/1/10.
//  Copyright © 2018年 黄江涛 . All rights reserved.
//

#import "FirthlyViewController.h"

@interface FirthlyViewController ()<UITextFieldDelegate,UIScrollViewDelegate,chooseAddressViewcontrollerDelegate>


@property(nonatomic,strong)UIButton *needJobKKButton;
//@property(nonatomic,strong)UIButton *AddressJobKKButton;
//@property(nonatomic,strong)UIButton *JOBStyleKKButton;
//读取数据库里面的数据
@property(nonatomic,strong)NSMutableArray *dataArr;
//单选
@property(nonatomic,strong)addressGatherModel *addressModel;
@end

@implementation FirthlyViewController
#pragma mark - 初始化
//单选初始化
-(addressGatherModel *)addressModel
{
    if(!_addressModel){
        _addressModel =[[addressGatherModel alloc]initWithViewController:self];
    }
    return _addressModel;
    
}
//所有选择数据
-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr =[NSMutableArray array];
        NSArray *result = [CWSqliteModelTool queryAllModels:[PersonJob class]];
        if (result.count > 0) {
            _dataArr = [NSMutableArray arrayWithArray:result];
        }
        
    }
    return _dataArr;
}






+ (FirthlyViewController *)sharedInstance{
    static FirthlyViewController *p = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        p=[sb instantiateViewControllerWithIdentifier:@"FirthlyViewController"];
    });
    return p;
}
#pragma mark - View
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
//    self.qiuzhi.selected =YES;
    self.locality.selected =NO;
    self.provinceIn.selected =NO;
    self.provinceOut.selected =NO;
//    self.choosePlace.selected =NO;
    
    self.fullTime.selected =NO;
    self.partTime.selected =NO;
    self.internship.selected =NO;
    self.temporaryTime.selected =NO;
    self.isSelectedAddress = NO;//默认为yes
    self.choosePlace.titleLabel.text =@"理想就业地:_____________";
    self.AddressJobKK = 0;
    self.JOBStyle = 0;
    if ([self.chooseThreeDifferent  isEqualToString:@"失业新增"]) {
        self.topImage.image =[UIImage imageNamed:@"5需求信息_失业"];
    }else if([self.chooseThreeDifferent isEqualToString:@"就业新增"]){
self.topImage.image =[UIImage imageNamed:@"5需求信息_就业"];
    }else{
    self.topImage.image =[UIImage imageNamed:@"5需求信息_其他"];
        }
      self. peixunGrank_ = 0;
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //键盘弹起
    [self.view openKeyboardOffsetView];
    self.view.keyboardGap =20;
    //设置高度
    self.employeeScroll.bounces = NO;
    //设置所有为空
    [self makeAllZERO:1];
    self.title =@"需求信息";
    //点击事件
    UITapGestureRecognizer *get =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(asdasd)];
    [self.employeeHeightView addGestureRecognizer:get];
    [self needJobKKButt];
    [self AddressJobKKButt];
    [self JOBStyleButt];
     SVProgressHUD.minimumDismissTimeInterval =1.0;
      self.needJobKK  = 1;
      self.AddressJobKK = 0;
      self.JOBStyle = 0;
      self. choosePlace_ =1;
   
    self.mouthIncomeExtension.keyboardType = UIKeyboardTypeNumberPad;
    
  
}


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.employeeHeightView;
}
//scrollDelegate
- (void)updateViewConstraints {
    [super updateViewConstraints];
    self.scroll_width.constant =751;
}
#pragma mark - 工作交互的三个按钮
//-(void)viewDidLayoutSubviews{
//    [super viewDidLayoutSubviews];
//  self.scroll_width.constant =self.employeeHeightView.frame.origin.y+self.employeeHeightView.bounds.size.height +150;
//
//}


-(void)needJobKKButt{

    //1=城市 和 2 =农业
    
    
   
    [self.choosePlace setTitle:@"理想就业地:_____________" forState:0];
    
    NSArray *arr = @[_qiuzhi,_peixun,_chuangye,_xuqiu];
     [self  buttonUse:arr andID:8478];
    __weak __typeof(self)weakSelf = self;
    self.buttonA = ^(CLMarkButton *buttonName_A) {
        _needJobKKButton =buttonName_A;
        dispatch_async(dispatch_get_main_queue(), ^{
            if (_needJobKKButton == weakSelf.qiuzhi) {
                [weakSelf makeAllZERO:2];
                weakSelf.needJobKK =1;
                [weakSelf ALLPlaceHolderNULL];
                //周一在用安卓手机看一下
               
                weakSelf.seondChooseHeight.constant =301;
                weakSelf.thirdChooseHeight.constant =465;
                weakSelf.backGroundOnePointFour.constant = 450;

                weakSelf.extensionAddressHide.hidden =NO;
                weakSelf.extensionHide.hidden =NO;
                weakSelf.jobTypeHide.hidden =NO;
                weakSelf.extasfaggHide.hidden =YES;
                weakSelf.peixunDeleHide.hidden =YES;
                weakSelf.chuangyeHide.hidden =YES;
                weakSelf.jiuyeExtensionHide.hidden = NO;
                weakSelf. entrepreneurialExtension.text =@"";
                weakSelf.WorkTypeExtension.text =@"";//意向工种
            }else if (_needJobKKButton == weakSelf.peixun){
                [weakSelf makeAllZERO:2];
                 weakSelf.isSelectedAddress =YES;
                weakSelf. needJobKK =2;
                [weakSelf ALLPlaceHolderNULL];
                weakSelf.seondChooseHeight.constant =15;
                weakSelf.thirdChooseHeight.constant =301;
            weakSelf.backGroundOnePointFour.constant = 300;
                weakSelf.extensionAddressHide.hidden =YES;
                weakSelf.extensionHide.hidden =YES;
                weakSelf.jobTypeHide.hidden =YES;
                weakSelf.extasfaggHide.hidden =NO;
                weakSelf.peixunDeleHide.hidden =NO;
                weakSelf.chuangyeHide.hidden =YES;
                 weakSelf.jiuyeExtensionHide.hidden = YES;
            }else if (_needJobKKButton == weakSelf.chuangye){
                weakSelf.AddressJobKK = 0;
                [weakSelf makeAllZERO:2];
                 weakSelf.isSelectedAddress =YES;
                 [weakSelf ALLPlaceHolderNULL];
                weakSelf. needJobKK =3;
                weakSelf.seondChooseHeight.constant =15;
                weakSelf.thirdChooseHeight.constant =15;
               weakSelf.backGroundOnePointFour.constant = 300;
                weakSelf.extensionAddressHide.hidden =YES;
                weakSelf.extensionHide.hidden =YES;
                weakSelf.jobTypeHide.hidden =YES;
                weakSelf.extasfaggHide.hidden =YES;
                weakSelf.peixunDeleHide.hidden =YES;
                weakSelf.chuangyeHide.hidden =NO;
                  weakSelf.jiuyeExtensionHide.hidden = YES;
            }else if (_needJobKKButton == weakSelf.xuqiu){
                [weakSelf makeAllZERO:2];
                weakSelf. needJobKK =4;
                [weakSelf ALLPlaceHolderNULL];
                weakSelf.seondChooseHeight.constant =0;
                weakSelf.thirdChooseHeight.constant =0;
        weakSelf.backGroundOnePointFour.constant = 300;
                 weakSelf.isSelectedAddress =YES;
                weakSelf.extensionAddressHide.hidden =YES;
                weakSelf.extensionHide.hidden =YES;
                weakSelf.jobTypeHide.hidden =YES;
                weakSelf.extasfaggHide.hidden =YES;
                weakSelf.peixunDeleHide.hidden =YES;
                weakSelf.chuangyeHide.hidden =YES;
                weakSelf.jiuyeExtensionHide.hidden = YES;
            
                
                

                
            }
        });
    };
}

-(void)AddressJobKKButt{
    //1=城市 和 2 =农业

    NSArray *arr = @[_locality,_provinceIn,_provinceOut];
    
    [self  buttonUse:arr andID:545848];
    
    __weak __typeof(self)weakSelf = self;

    //self.choosePlace.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;// 垂直居中对齐
    
     self.choosePlace.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;// 水平左对齐
    [self.choosePlace addTarget:self action:@selector(clickedButton) forControlEvents:UIControlEventTouchUpInside];
    /**
     * 按照上面的操作 按钮的内容对津贴屏幕左边缘 不美观 可以添加一下代码实现间隔已达到美观
     * UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
     *    top: 为正数：表示向下偏移  为负数：表示向上偏移
     *   left: 为整数：表示向右偏移  为负数：表示向左偏移
     * bottom: 为整数：表示向上偏移  为负数：表示向下偏移
     *  right: 为整数：表示向左偏移  为负数：表示向右偏移
     *
     **/
//    button.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);//
//    button.titleEdgeInsets = UIEdgeInsetsMake(0, button.imageView.frame.size.width, 0, 0);
    self.buttonB = ^(CLMarkButton *buttonName_B) {
        if (buttonName_B == weakSelf.locality) {
            weakSelf.AddressJobKK =1;
        }else if (buttonName_B == weakSelf.provinceIn){
            weakSelf.  AddressJobKK =2;
        }else if (buttonName_B == weakSelf.provinceOut){
            weakSelf.  AddressJobKK =3;
        }else if (buttonName_B == weakSelf.choosePlace){
            weakSelf.   AddressJobKK =3;
//                        [weakSelf.addressModel getProvinceHandle:^(NSString *str1, NSString *str2, NSError *error) {
//                           dispatch_async(dispatch_get_main_queue(), ^{
//                                [weakSelf.choosePlace setTitle:[NSString stringWithFormat:@"选择城市:%@",str1] forState:0];
//                                [weakSelf.choosePlace setTitle:[NSString stringWithFormat:@"选择城市:%@",str1] forState:UIControlStateSelected];
//
//
//
//
//                            });
//
//                        }];

        }
    };
    
    

}
-(void)clickedButton{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    chooseAddressViewController*once  = [sb instantiateViewControllerWithIdentifier:@"chooseAddressViewController"];
    once.delegate =self;
    [self presentViewController:once animated:YES completion:^{
        once.stringChoose =@"stringChoose";
    }];
    
}
-(void)JOBStyleButt{
    //1=城市 和 2 =农业
    
    NSArray *arr = @[_fullTime,_partTime,_internship,_temporaryTime];
    
    [self  buttonUse:arr andID:11209];
    
    __weak __typeof(self)weakSelf = self;
    
    self.buttonS = ^(CLMarkButton *buttonName) {
        if (buttonName == weakSelf.fullTime) {
        weakSelf.    JOBStyle =1;
        }else if (buttonName == weakSelf.partTime){
         weakSelf.   JOBStyle =2;
        }else if (buttonName == weakSelf.internship){
         weakSelf.   JOBStyle =3;
        }else if (buttonName == weakSelf.temporaryTime){
         weakSelf.   JOBStyle =4;
        }
        
    };
}











-(void)makeAllZERO:(NSInteger)type{

    if (type == 1) {
        //main主线程
        [self allDelegateAndAllZero:_employeeExtension];
        [self allDelegateAndAllZero:_entrepreneurialExtension];
        [self allDelegateAndAllZero:_mouthIncomeExtension];
        [self allDelegateAndAllZero:_peixunGrank];
        [self allDelegateAndAllZero:_WorkTypeExtension];
    }else{
         [self makeAllButtUserInfoNo:_employeeExtension andInt:1];
         [self makeAllButtUserInfoNo:_entrepreneurialExtension andInt:1];
         [self makeAllButtUserInfoNo:_mouthIncomeExtension andInt:1];
         [self makeAllButtUserInfoNo:_peixunGrank andInt:1];
         [self makeAllButtUserInfoNo:_WorkTypeExtension andInt:1];
        
    }
    
}

-(void)ALLPlaceHolderNULL{
    self.employeeExtension.placeholder =@"必填";
     self.entrepreneurialExtension.placeholder =@"必填";
     self.mouthIncomeExtension.placeholder =@"必填";
     self.peixunGrank.placeholder =@"必填";
     self.WorkTypeExtension.placeholder =@"必填";
    self.employeeExtension.text =@"";
    self.entrepreneurialExtension.text =@"";
    self.mouthIncomeExtension.text =@"";
    self.peixunGrank.text =@"";
    self.WorkTypeExtension.text =@"";
}

-(void)allDelegateAndAllZero:(UITextField*)textField{
    textField.text =nil;
    //几口请求
    textField.delegate =self;
    textField.placeholder =@"必填";
    textField.userInteractionEnabled = YES;
    textField.textColor =[UIColor blackColor];
    //jiuyeyixiang


  self.seondChooseHeight.constant =301;
    self.thirdChooseHeight.constant =465;
    //1:4 背景
    self.backGroundOnePointFour.constant = 450;

    self.extensionAddressHide.hidden =NO;
    self.extensionHide.hidden =NO;
    self.jobTypeHide.hidden =NO;
    
    self.extasfaggHide.hidden =YES;
    self.peixunDeleHide.hidden =YES;
    self.chuangyeHide.hidden =YES;
   self.jiuyeExtensionHide.hidden = NO;
    
    
    
    [self makeAllButtUserInfoNo:self.peixunGrank andInt:2];
    [self makeAllButtUserInfoNo:self.WorkTypeExtension andInt:2];
    [self makeAllButtUserInfoNo:self.entrepreneurialExtension andInt:2];
    [self textFieldAddTwoBlackPlaceinTextFiled:textField];
    
}
//1代表可以使用 2代表不可以使用
-(void)makeAllButtUserInfoNo:(UITextField *)textfField andInt:(NSInteger)type{
    if (type == 1) {
          textfField.userInteractionEnabled = YES;
    }else{
        textfField.userInteractionEnabled = NO;
        textfField.placeholder =@"非必填";
    }
}





#pragma mark - 收起按钮
-(void)asdasd{
    [self.view endEditing:YES];
      [SVProgressHUD dismiss];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}

-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField{
    if (textField ==  self.peixunGrank
        ){
        [self NotUseButton:textField];
        [textField resignFirstResponder];
        return NO;
    }else{
        return YES;
    }
    
}
#pragma mark - 所有不能手输的按钮
- (void)NotUseButton:(UITextField *)sender {
        [self.view endEditing:YES];
     if (sender == self.peixunGrank ) {
            __block NSArray *   array = @[@"初级",@"中级",@"高级",@"技师",@"高级技师"];
         __weak typeof(self) weakSelf = self;
         [self.addressModel onlySelect:array Handle:^(NSString *str1, NSString *str2, NSError *error) {
         weakSelf.  peixunGrank_   =  (int)[JobUtil chooseEmployeeFamilyRelation:[array copy] andSelectedString:str1];
             weakSelf.peixunGrank.text = str1;
         }];
     }
    
    
    
}
#pragma mark - 选择地址协议
-(void)sendCityToFirstInfornation:(chooseAddressViewController *)avc senderProvince:(NSString *)province senderDownTown:(NSString *)downTown senderArea:(NSString *)area senderVillage:(NSString *)village senderVillageCommit:(NSString *)villageCommite senderDoor:(NSString *)door
{
    if (![villageCommite isEqualToString:@""]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.choosePlace setTitle:[NSString stringWithFormat:@"%@%@%@%@%@%@",province,downTown,area,village,villageCommite,door] forState:0];
            [self.choosePlace setTitleColor:[UIColor blackColor] forState:0];
            [self.choosePlace setTitle:[NSString stringWithFormat:@"%@%@%@%@%@%@",province,downTown,area,village,villageCommite,door]forState:UIControlStateSelected];
            self.isSelectedAddress =YES;
            [self.view setNeedsLayout];
        });
    }
    
    
}


#pragma mark -logicRun
- (IBAction)pageNext:(id)sender {
    if (self.needJobKK == 1) {
        if ([self.employeeExtension.text isEqualToString:@""]) {
            [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
            return ;
            
        }
        if ([self.mouthIncomeExtension.text isEqualToString:@""]) {
            [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
            return ;
            
        }

        //    self.choosePlace.selected =NO;
        

        
        if (self.locality.selected == NO &&
            self.provinceIn.selected ==NO &&
            self.provinceOut.selected ==NO) {
            [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
            return ;
        }
        if (self.fullTime.selected == NO &&
            self.partTime.selected ==NO &&
            self.internship.selected ==NO &&
            self.temporaryTime.selected == NO
            ) {
            [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
            return ;
        }
        
    }else if (self.needJobKK == 2){
        if ([self.peixunGrank.text isEqualToString:@""]) {

            
        }
        if ([self.WorkTypeExtension.text isEqualToString:@""]) {
            [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
            return ;
            
        }
 
        
    }else if (self.needJobKK == 3){
        if ([self.entrepreneurialExtension.text isEqualToString:@""]) {
            [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
            return ;
            
        }
        
    }else{
        
    }
    

    
    
    
    
    
    
    
 
    [self makeAllZERO:2];
//    JobUtil *jobUtil =[[JobUtil alloc]init];


    if ([self.chooseThreeDifferent  isEqualToString:@"失业新增"]) {
        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        signatureNameViewController *name =[sb instantiateViewControllerWithIdentifier:@"signatureNameViewController"];
        name.selfSignation =@"本人签字";
        name.shiye =@"失业";
        if(![self.navigationController.topViewController isKindOfClass:[name class]]) {
            [self.navigationController  pushViewController:name animated:YES];
        }
    }else if([self.chooseThreeDifferent isEqualToString:@"就业新增"]){
        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        signatureNameViewController *name =[sb instantiateViewControllerWithIdentifier:@"signatureNameViewController"];
        name.selfSignation =@"本人签字";
        if(![self.navigationController.topViewController isKindOfClass:[name class]]) {
            [self.navigationController  pushViewController:name animated:YES];
        }
        
    }else{
        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        signatureNameViewController *name =[sb instantiateViewControllerWithIdentifier:@"signatureNameViewController"];
        name.selfSignation =@"本人签字";
        name.shiye =@"其他";
        name.asdasdasfdsg=self.employeeOther_;
        if(![self.navigationController.topViewController isKindOfClass:[name class]]) {
            [self.navigationController  pushViewController:name animated:YES];
        }
      
    }
    
    
        


    
}


@end
