//
//  pickerViewController.m
//  Open
//
//  Created by gao on 2016/11/4.
//  Copyright © 2016年 黄江涛 . All rights reserved.
//




#import "pickerViewController.h"
#import "HXProvincialCitiesCountiesPickerview.h"
#import "HXAddressManager.h"
//网络
#import "AFNetworking.h"
//算法AES
#import "SecurityUtil.h"
#import "MyMD5.h"
#import "CityModel.h"
#import "MJExtension.h"
#import "areaModel.h"




//
//static AFHTTPSessionManager *manager = nil;
//  static NSString  *provinceLabel =nil;



@interface pickerViewController ()<UITextFieldDelegate>

//第三方导航的地区选择器
@property (nonatomic,strong) HXProvincialCitiesCountiesPickerview *regionPickerView;
@property(nonatomic,strong)	 UILabel *addressLabel;
@property(nonatomic,strong)	 NSString *numbertag;

//设置重复点击的间隔
@property(nonatomic,assign) NSTimeInterval uxy_acceptEventInterval;



//数组图片
@property(nonatomic,strong)NSArray *allImageNames;

//button和label
@property (weak, nonatomic) IBOutlet UIButton *button1;
@property (weak, nonatomic) IBOutlet UIButton *button2;
@property (weak, nonatomic) IBOutlet UIButton *button3;

@property (weak, nonatomic) IBOutlet UIButton *jumpToPhoto;
//控制button的变量
@property(nonatomic,strong)	 UIButton *changeThreeWithUrbanAndGovern;
@property (weak, nonatomic) IBOutlet UIView *companyViewHide;


//网络
@property(nonatomic,strong)	 AFHTTPSessionManager *manager;
//index
@property(nonatomic)NSInteger	tagForProvince;
//负责接收传过来的数据
@property(nonatomic,strong)	 NSMutableArray *array;
//接受city城市的对象
@property(nonatomic,strong)	 NSMutableArray *arrayForCity;
//接受cityid的对象
@property(nonatomic,strong)	 NSMutableArray *dataArr;

/**设置布局的变量*/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *villageContranst;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightVillageContraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topVillageContraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topVillageCommittee;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightVillageCommitteeContraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topPhoneContraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightPhoneContraint;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLabelCommiteeConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLabelCommitteeConstraint2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightLalCommittee;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightLabelCommittee2;



/**这中间设置布局*/

@end

//static const char *UIControl_acceptEventInterval = "UIControl_acceptEventInterval";
static NSString *static_numberPro;
static NSString *static_numbercity;
static NSString *static_numbercountry;

@implementation pickerViewController




-(void)contraintChangeOne
{
    self.heightVillageContraint.constant = 40;
    self.topVillageContraint.constant =9;
    self.topVillageCommittee.constant =9;
    self.heightVillageCommitteeContraint.constant =40;
    self.topLabelCommiteeConstraint.constant =21;
    self.topLabelCommitteeConstraint2.constant =21;
    self.heightLalCommittee.constant =20;
    self.heightLabelCommittee2.constant =20;
    
    
}


-(void)contraintChangeTwo
{
    self.heightVillageContraint.constant = 0;
    self.topVillageContraint.constant =0;
    self.topVillageCommittee.constant =0;
    self.heightVillageCommitteeContraint.constant =0;
    self.topLabelCommiteeConstraint.constant =0;
    self.topLabelCommitteeConstraint2.constant =0;
    self.heightLalCommittee.constant =0;
    self.heightLabelCommittee2.constant =0;

}


//懒加载
-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr =[NSMutableArray new];
    }
    return _dataArr;
}

//懒加载
-(NSMutableArray *)arrayForCity
{
    if (!_arrayForCity) {
        _arrayForCity =[NSMutableArray new];
        [_arrayForCity removeAllObjects];
    }
    return _arrayForCity;
}


//懒加载
-(NSMutableArray *)array
{
    if (!_array) {
        _array =[NSMutableArray new];
       
    }
    return _array;
}






-(NSMutableArray *)array2
{
    if (!_array2 ) {
        _array2 =[NSMutableArray array];
  
    }
    return _array2;

}
  WEBS
-(void)buttonClick_1{    ZHINENGKEFU}
- (void)viewDidLoad {
    [super viewDidLoad];
  
    //ui
//    UIButton * button_2 = [UIButton buttonWithType:UIButtonTypeCustom];        button_2.frame = CGRectMake(0, 0, 0, 49);     button_2.titleLabel.textAlignment =NSTextAlignmentRight;   [button_2 setTitle:@"     帮助" forState:UIControlStateNormal];        [button_2 addTarget:self action:@selector(buttonClick_1) forControlEvents:UIControlEventTouchUpInside];        UIBarButtonItem * backButtonItem_2 = [[UIBarButtonItem alloc] initWithCustomView:button_2];        self.navigationItem.rightBarButtonItem = backButtonItem_2;
    
//    ui
        if ([[[UIDevice currentDevice]deviceModel] isEqualToString:Device_iPhone5S]) {
            self.button1.titleLabel.font =[UIFont systemFontOfSize:12];
            self.button2.titleLabel.font =[UIFont systemFontOfSize:12];
            self.button3.titleLabel.font =[UIFont systemFontOfSize:12];
        }
    if([[UIScreen mainScreen]bounds].size.height == 568)
    {
        self.button1.titleLabel.font =[UIFont systemFontOfSize:13];
        self.button2.titleLabel.font =[UIFont systemFontOfSize:13];
        self.button3.titleLabel.font =[UIFont systemFontOfSize:13];
    }
    
    
    // Do any additional setup after loading the view, typically from a nib.
    self.title = @"选择地址";
    self.province.delegate =self;
    self.downTown.delegate =self;
    self.area.delegate =self;
    self.village.delegate =self;
    self.villageCommittee.delegate =self;
    ice =0;
    //UI
    [self textFieldAddTwoBlackPlaceinTextFiled:self.phoneNumber];
    [self textFieldAddTwoBlackPlaceinTextFiled:self.Company];
    //省
    [self savensuserDefault];
    [self putTheMessageToUserDefault];

    
//    UI
self.jumpToPhoto.userInteractionEnabled =NO;
    self.province.textAlignment = NSTextAlignmentCenter;
    self.downTown.textAlignment =NSTextAlignmentCenter;
    self.area.textAlignment =NSTextAlignmentCenter;
    self.village.textAlignment =NSTextAlignmentCenter;
    self.villageCommittee.textAlignment =NSTextAlignmentCenter;
    self.phoneNumber.textAlignment =NSTextAlignmentCenter;
   
    
    
  self.changeThreeWithUrbanAndGovern =self.button1;
    [self shezhisuoyouweiNill];
    _phoneBool =NO;
    _companyBool =NO;
    _provinceNumber =[static_numberPro copy];
    _CityNumber =[static_numbercity copy];
    _areaNumber =[static_numbercountry copy];
    
 
}











-(void)shezhisuoyouweiNill
{
    //记录省
    self.province.text = [getPeopleID province];
    //记录市
    self.downTown.text =[getPeopleID country];
    //记录区
    self.area.text =[getPeopleID other];
    self.village.text =@"";
    self.villageCommittee.text =@"";
    self.Company.text =@"";
  //  self.phoneNumber.text=@"";


}

-(void)savensuserDefault
{
    //保存省份
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    [userDefaults setObject:self.array2 forKey:@"myArray"];
    
    [userDefaults synchronize];
   
}



-(void)putTheMessageToUserDefault
{



}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    //显示电话号码,并且去取
     AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    if (delegate.isTel == YES) {
            self.phoneNumber.text = self.telStr;
        delegate.isTel =NO;
    }
    
    

    
    
    if (self.button1.selected ==YES) {
           self.companyViewHide.hidden =YES;
    }
    
    
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //键盘向下移动5个距离
    [self.view openKeyboardOffsetView];
    self.view.keyboardGap =5;

}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
    // 关闭键盘补偿视图
    [self.view closeKeyboardOffsetView];
}


-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField{
    
    [self provinceChoose:textField];
    [textField resignFirstResponder];
    return NO;
}


//两个网络请求的方法
+ (AFHTTPSessionManager *)sharedAFManager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [AFHTTPSessionManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript", @"text/plain", nil];
    });
    return manager;
}
//+ (id)POST:(NSString *)path parameters:(NSDictionary *)params completionHandler:(void(^)(id responseObj, NSError *error))complete{
//    return [[self sharedAFManager] POST:path parameters:params success:^void(NSURLSessionDataTask * task, id responseObject) {
//        complete(responseObject, nil);
//        NSLog(@"%@",task);
//        
//        
//    } failure:^void(NSURLSessionDataTask * task, NSError * error) {
//      
//        complete(nil, error);
//    }];
//}




#define mark -这里showpicker
- (HXProvincialCitiesCountiesPickerview *)regionPickerView {
    if (!_regionPickerView) {
        _regionPickerView = [[HXProvincialCitiesCountiesPickerview alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        
        __weak typeof(self) wself = self;
        _regionPickerView.completion = ^(NSString *provinceName,NSString *numberSign,NSString *countyName) {
            __strong typeof(wself) self = wself;
            self.addressLabel.text = [NSString stringWithFormat:@"%@",provinceName,nil,nil];
           
            if (indexTag == 1 ){
               
//                _provinceName =provinceName;
                static_numberPro =numberSign;
             _provinceNumber =numberSign;
              self.province.text =provinceName;
//              self.numbertag =numberSign;
                  self.downTown.text =0;
                self.area.text =0;
                self.village.text =0;
                self.villageCommittee.text =0;
              //  self.phoneNumber.text = 0;
                self.Company.text = 0;
            }
            if(indexTag == 2){
//                _CityName =provinceName;
                 static_numbercity =provinceName;
                _CityNumber =numberSign;
            self.downTown.text =provinceName;
            self.area.text =0;
           self.village.text =0;
            self.villageCommittee.text =0;
             //   self.phoneNumber.text = 0;
                self.Company.text = 0;
            }
            if (indexTag == 3) {
                self.area.text =provinceName;
                self->_areaNumber =numberSign;
               static_numbercountry =numberSign;
                self.village.text =0;
                self.villageCommittee.text =0;
             //   self.phoneNumber.text = 0;
                self.Company.text = 0;

            }
            if (indexTag == 4) {
                self.village.text =provinceName;
                self.villageCommittee.text =0;
            //    self.phoneNumber.text = 0;
                self.Company.text = 0;
                self->_TownNumber =numberSign;
                NSLog(@"chengshi:%@",self->_TownNumber);
                NSLog(@"chengshi:%@",self.village.text);
            }
            if (indexTag == 5 ) {
                self.villageCommittee.text =provinceName;
                self->_VillageCoNumber =numberSign;
             //   self.phoneNumber.text = 0;
                self.Company.text = 0;
            }
        };
        [self.navigationController.view addSubview:_regionPickerView];
    }
    return _regionPickerView;
}

- (void)show:(UITextField *)sender {
    NSString *address = _addressLabel.text;
    //用空格来分割字符串
    NSArray *array = [address componentsSeparatedByString:@" "];
    
    provinceLabel = array[0];


          [self.regionPickerView showPickerWithProvinceName:provinceLabel cityName:nil countyName:nil index:1];
    

  
}

#pragma mark - 在此发送第二个数据
static int tagger = 0 ;
static int indexTag =1;
-(void)senderSecondMessage:(NSString *)province_id theSecondMessage:(NSString *)province_name
{
//  [SVProgressHUD show];
    indexTag  = 2;

        NSString *name =@"province_name";
        NSString *ID =@"province_id";
        NSString *IDEn =  [EnercryTool encryptUseDES:province_id  key:@"KkweFace95271124"];
        NSString *NameEn =  [EnercryTool encryptUseDES:province_name key:@"KkweFace95271124"];
        NSString *path =@"";
  path  = [IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/city"];
    NSLog(@"%@",province_id);
    if ([self.province.text isEqualToString:PROVINCE]) {
        IDEn =  [EnercryTool encryptUseDES:@"310"  key:@"KkweFace95271124"];
               NameEn =  [EnercryTool encryptUseDES:@"上海市" key:@"KkweFace95271124"];
    }
        [CityNetManager getMD5Method:name encrypt:NameEn andTheOther:ID twoEncrypt:IDEn andPutThePathForThis:path completionHandle:^(CitytoCityModel *model, NSError *error) {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            if (model.result == nil) {
                SVProgressHUD.minimumDismissTimeInterval =3.0;
                [SVProgressHUD showErrorWithStatus:@"请重新选择省份"];
                return;
            }
             [self.array removeAllObjects];
            [self.arrayForCity removeAllObjects];
            [self.dataArr removeAllObjects];
            [self.array addObjectsFromArray:model.result];
            for (CityToCityResultModel *models in self.array) {
                //保存了city数据
                [self.arrayForCity addObject:models.city_name];
           
                NSData *data =[NSKeyedArchiver archivedDataWithRootObject:models.city_id];
                [self.dataArr addObject:data];
                //保存了city_id的数据
            }
             NSArray * CityNetWorkForID = [NSArray arrayWithArray:self.dataArr];
            NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
            [userDefaults setObject:CityNetWorkForID forKey:@"myCityModelID"];
            [userDefaults synchronize];
            //修改
             NSArray * CityNetWorkArray = [NSArray arrayWithArray:self.arrayForCity];
            //修改
              NSUserDefaults *userDefault =[NSUserDefaults standardUserDefaults];
            [userDefault setObject:CityNetWorkArray forKey:@"myCityModel"];
            [userDefault synchronize];
            NSString *address = _addressLabel.text;
            //用空格来分割字符串
            NSArray *array = [address componentsSeparatedByString:@" "];
            provinceLabel = array[0];
            self.regionPickerView =nil;
//             [SVProgressHUD dismiss];
            dispatch_async(dispatch_get_main_queue(), ^{
          
             if (tagger == 0) {
            [self.regionPickerView showPickerWithProvinceName:provinceLabel cityName:nil countyName:nil index:2];
//                 tagger =1;
             }else
             {
                 [self.regionPickerView showPickerWithProvinceName:province_name cityName:nil countyName:nil index:3];
             }
                NSLog(@"代码在这个线程block----%@",[NSThread currentThread]);
                });
            });
        }];
                  NSLog(@"代码在这个线程3----%@",[NSThread currentThread]);
      

}
#pragma mark - 在此发送第三个数据
-(void)senderCountryMessage:(NSString *)province_id theSecondMessage:(NSString *)province_name
{
//    [SVProgressHUD show];
    indexTag  =3;

    NSString *name =@"city_name";
    NSString *ID =@"city_id";
    NSString *IDEn =  [EnercryTool encryptUseDES:province_id  key:@"KkweFace95271124"];
    NSString *NameEn =  [EnercryTool encryptUseDES:province_name key:@"KkweFace95271124"];
    
    NSString *path =@"";
    path  = [IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/county"];
    NSLog(@"%@",province_id);
    
    if ([self.downTown.text isEqualToString:COUNTRY]) {
       IDEn =  [EnercryTool encryptUseDES:@"310100000000"  key:@"KkweFace95271124"];
    NameEn =  [EnercryTool encryptUseDES:@"市辖区" key:@"KkweFace95271124"];
    }
    
    
    
    [CityNetManager getAreaMethod:name encrypt:NameEn andTheOther:ID twoEncrypt:IDEn andPutThePathForThis:path completionHandle:^(areaModel *model, NSError *error) {
        if (model.result == nil) {
            SVProgressHUD.minimumDismissTimeInterval =3.0;
            [SVProgressHUD showErrorWithStatus:@"请重新选择城市"];
            return;
        }

        [self.array removeAllObjects];
        [self.arrayForCity removeAllObjects];
        [self.dataArr removeAllObjects];
        [self.array addObjectsFromArray:model.result];
 
        for (CityToAreaResultModel *models in self.array) {
            //保存了city数据
            [self.arrayForCity addObject:models.county_name];
 
            NSData *data =[NSKeyedArchiver archivedDataWithRootObject:models.county_id];
            [self.dataArr addObject:data];
            //保存了city_id的数据
        }
        NSArray * CityNetWorkForID = [NSArray arrayWithArray:self.dataArr];
        NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
        [userDefaults setObject:CityNetWorkForID forKey:@"myCityModelID"];
        [userDefaults synchronize];
        //修改
        NSArray * CityNetWorkArray = [NSArray arrayWithArray:self.arrayForCity];
        //修改
        NSUserDefaults *userDefault =[NSUserDefaults standardUserDefaults];
        [userDefault setObject:CityNetWorkArray forKey:@"myCityModel"];
        [userDefault synchronize];
        NSString *address = _addressLabel.text;
        //用空格来分割字符串
        NSArray *array = [address componentsSeparatedByString:@" "];
        provinceLabel = array[0];
        self.regionPickerView =nil;
//        [SVProgressHUD dismiss];
     
            [self.regionPickerView showPickerWithProvinceName:provinceLabel cityName:nil countyName:nil index:2];
       
        NSLog(@"代码在这个线程block----%@",[NSThread currentThread]);
    }];
    NSLog(@"代码在这个线程3----%@",[NSThread currentThread]);
    
}
#pragma mark - 在此发送第四个数据
-(void)senderTownMessage:(NSString *)province_id theSecondMessage:(NSString *)province_name
{
  

//    [SVProgressHUD show];
    indexTag  =4;
    //    dispatch_queue_t  queue= dispatch_queue_create("wendingding", NULL);
    //线程一,串行执行
    //    dispatch_async(queue, ^{
    NSString *name =@"county_name";
    NSString *ID =@"county_id";
    NSString *IDEn =  [EnercryTool encryptUseDES:province_id  key:@"KkweFace95271124"];
    NSString *NameEn =  [EnercryTool encryptUseDES:province_name key:@"KkweFace95271124"];
   
    NSString *path =@"";
    path  = [IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/town"];
    NSLog(@"%@",province_id);
    if ([self.area.text isEqualToString:AREA]) {
           IDEn =  [EnercryTool encryptUseDES:@"310115000000"  key:@"KkweFace95271124"];
        NameEn =  [EnercryTool encryptUseDES:@"浦东新区" key:@"KkweFace95271124"];
    }
    [CityNetManager getTownMethod:name encrypt:NameEn andTheOther:ID twoEncrypt:IDEn andPutThePathForThis:path completionHandle:^(Town *model, NSError *error) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        if (model.result == nil) {
            SVProgressHUD.minimumDismissTimeInterval =3.0;
            [SVProgressHUD showErrorWithStatus:@"请重新选择区"];
            return;
        }

        [self.array removeAllObjects];
        [self.arrayForCity removeAllObjects];
        [self.dataArr removeAllObjects];
        [self.array addObjectsFromArray:model.result];
        
        for (TownResultModel *models in self.array) {
            //保存了city数据
            [self.arrayForCity addObject:models.town_name];
            
            NSData *data =[NSKeyedArchiver archivedDataWithRootObject:models.town_id];
            [self.dataArr addObject:data];
            //保存了city_id的数据
        }
        NSArray * CityNetWorkForID = [NSArray arrayWithArray:self.dataArr];
        NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
        [userDefaults setObject:CityNetWorkForID forKey:@"myCityModelID"];
        [userDefaults synchronize];
        //修改
        NSArray * CityNetWorkArray = [NSArray arrayWithArray:self.arrayForCity];
        //修改
        NSUserDefaults *userDefault =[NSUserDefaults standardUserDefaults];
        [userDefault setObject:CityNetWorkArray forKey:@"myCityModel"];
        [userDefault synchronize];
        NSString *address = _addressLabel.text;
        //用空格来分割字符串
        NSArray *array = [address componentsSeparatedByString:@" "];
        provinceLabel = array[0];
        self.regionPickerView =nil;
//        [SVProgressHUD dismiss];
            dispatch_async(dispatch_get_main_queue(), ^{
    
        [self.regionPickerView showPickerWithProvinceName:provinceLabel cityName:nil countyName:nil index:2];
            });
        });

    }];
    NSLog(@"代码在这个线程3----%@",[NSThread currentThread]);
    
}
#pragma mark -这里第五个数据
-(void)senderVillageMessage:(NSString *)province_id theSecondMessage:(NSString *)province_name
{
//    [SVProgressHUD show];
    indexTag  =5;
    
    //    dispatch_queue_t  queue= dispatch_queue_create("wendingding", NULL);
    //线程一,串行执行
    //    dispatch_async(queue, ^{
    NSString *name =@"town_name";
    NSString *ID =@"town_id";
    NSString *IDEn =  [EnercryTool encryptUseDES:province_id  key:@"KkweFace95271124"];
    NSString *NameEn =  [EnercryTool encryptUseDES:province_name key:@"KkweFace95271124"];
    NSString *path =@"";
    path  = [IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/village"];
    [CityNetManager getVillageMethod:name encrypt:NameEn andTheOther:ID twoEncrypt:IDEn andPutThePathForThis:path completionHandle:^(VillageModel *model, NSError *error) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        });
        if (model.result == nil) {
            SVProgressHUD.minimumDismissTimeInterval =3.0;
            [SVProgressHUD showErrorWithStatus:@"请重新选择乡镇"];
            return;
        }

        [self.array removeAllObjects];
        [self.arrayForCity removeAllObjects];
        [self.dataArr removeAllObjects];
        [self.array addObjectsFromArray:model.result];
        
        for (VillageResultModel *models in self.array) {
            //保存了city数据
            [self.arrayForCity addObject:models.village_name];
            
            NSData *data =[NSKeyedArchiver archivedDataWithRootObject:models.village_id];
            [self.dataArr addObject:data];
            //保存了city_id的数据
        }
        NSArray * CityNetWorkForID = [NSArray arrayWithArray:self.dataArr];
        NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
        [userDefaults setObject:CityNetWorkForID forKey:@"myCityModelID"];
        [userDefaults synchronize];
        //修改
        NSArray * CityNetWorkArray = [NSArray arrayWithArray:self.arrayForCity];
        //修改
        NSUserDefaults *userDefault =[NSUserDefaults standardUserDefaults];
        [userDefault setObject:CityNetWorkArray forKey:@"myCityModel"];
        [userDefault synchronize];
        NSString *address = _addressLabel.text;
        //用空格来分割字符串
        NSArray *array = [address componentsSeparatedByString:@" "];
        provinceLabel = array[0];
        self.regionPickerView =nil;
//        [SVProgressHUD dismiss];
        dispatch_async(dispatch_get_main_queue(), ^{
 
        [self.regionPickerView showPickerWithProvinceName:provinceLabel cityName:nil countyName:nil index:2];
               });
        NSLog(@"代码在这个线程block----%@",[NSThread currentThread]);
    }];
    NSLog(@"代码在这个线程3----%@",[NSThread currentThread]);
    
}
//textField 文本框
//@property (weak, nonatomic) IBOutlet UITextField *province;
//@property (weak, nonatomic) IBOutlet UITextField *downTown;
//@property (weak, nonatomic) IBOutlet UITextField *area;
//@property (weak, nonatomic) IBOutlet UITextField *village;
//@property (weak, nonatomic) IBOutlet UITextField *villageCommittee;
//@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
//@property (weak, nonatomic) IBOutlet UITextField *Company;








-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [SVProgressHUD dismiss];
        [self.view endEditing:YES];
//     AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
//    delegate.buttonS(@"asdasd");
    
    
}


- (IBAction)didend:(UITextField *)sender {
    [self.view endEditing:YES];
}
#pragma mark - 监听所有的texteField
- (IBAction)provinceChoose:(UITextField *)sender {
//     [self show1:sender];
  
    
    
    if (sender == self.province) {
   [self.view endEditing:YES];
          [self  show:sender];
        indexTag =1;
     
    }else if(sender == self.downTown)
    {
        [self.view endEditing:YES];
        [self senderSecondMessage:_provinceNumber theSecondMessage:self.province.text];
        
    }else if (sender == self.area)
    {
      [self.view endEditing:YES];
        [self senderCountryMessage:_CityNumber theSecondMessage:self.downTown.text];
        

    }else if (sender == self.village)
    {[self.view endEditing:YES];
        [self senderTownMessage:_areaNumber theSecondMessage:self.area.text];
    
    }else if (sender ==self.villageCommittee)
    {[self.view endEditing:YES];
        [self senderVillageMessage:_TownNumber theSecondMessage:self.village.text];
        
    }else if(sender == self.phoneNumber)
    {
        self.Company.text = 0;
        NSLog(@"self.phoneNumber:%@",self.phoneNumber.text);
        if (![self.phoneNumber.text isEqualToString:@""]) {
            _phoneBool =YES;
         
            _companyBool =NO;
//            [self.Company addTarget:self action:@selector(put2:) forControlEvents:UIControlEventEditingChanged];
        }else {
            _phoneBool =NO;
        }
    }else
    {
        if (![self.Company.text isEqualToString:@""]) {

            _companyBool =YES;
        }else
        {
            _companyBool =NO;
        }
    }
    if (self.changeThreeWithUrbanAndGovern == self.button1) {
        
    if((self.province.text.length > 0) && (self.downTown.text.length > 0) && (self.area.text.length > 0) && (self.village.text.length > 0))
    {
        
        [self.view reloadInputViews];
        self.jumpToPhoto .backgroundColor =[UIColor colorWithRed:25/255.0 green:149/255.0 blue:109/255.0 alpha:1.0];
        self.jumpToPhoto.userInteractionEnabled =YES;
           [self.jumpToPhoto addTarget:self action:@selector(put_1) forControlEvents:UIControlEventTouchUpInside];
     
    }else
    {
        [self.view reloadInputViews];
    self.jumpToPhoto.backgroundColor =[UIColor colorWithRed:191/255.0 green:191/255.0 blue:191/255.0 alpha:1.0];
         self.jumpToPhoto.userInteractionEnabled =NO;
    }
     
}
     if ((self.changeThreeWithUrbanAndGovern == self.button2)||(self.changeThreeWithUrbanAndGovern == self.button3))
    {
       
        if((self.province.text.length > 0) && (self.downTown.text.length > 0) && (self.area.text.length > 0) &&(_companyBool == YES))
        {
        
                [self.view reloadInputViews];
                self.jumpToPhoto .backgroundColor =[UIColor colorWithRed:25/255.0 green:149/255.0 blue:109/255.0 alpha:1.0];
                self.jumpToPhoto.userInteractionEnabled =YES;
               [self.jumpToPhoto addTarget:self action:@selector(put_1) forControlEvents:UIControlEventTouchUpInside];
   
        }else
        {
            [self.view reloadInputViews];
            self.jumpToPhoto.backgroundColor =[UIColor colorWithRed:191/255.0 green:191/255.0 blue:191/255.0 alpha:1.0];
            self.jumpToPhoto.userInteractionEnabled =NO;
        }
      
    }
}



-(void)dosomethingBeforeTimego
{
       [self performSelector:@selector(todoSomething) withObject:nil afterDelay:3.0f];
 
    
}
-(void)geta{
    if((self.province.text.length > 0) && (self.downTown.text.length > 0) && (self.area.text.length > 0) &&(_companyBool == YES))
    {
        
        [self.view reloadInputViews];
        self.jumpToPhoto .backgroundColor =[UIColor colorWithRed:25/255.0 green:149/255.0 blue:109/255.0 alpha:1.0];
        self.jumpToPhoto.userInteractionEnabled =YES;
 
    }else
    {
        [self.view reloadInputViews];
        self.jumpToPhoto.backgroundColor =[UIColor colorWithRed:191/255.0 green:191/255.0 blue:191/255.0 alpha:1.0];
        self.jumpToPhoto.userInteractionEnabled =NO;
    }

}
-(void)todoSomething
{

   [self.jumpToPhoto addTarget:self action:@selector(put_1) forControlEvents:UIControlEventTouchUpInside];
}
//UI

- (IBAction)button_1:(UIButton *)sender {
     ice = 0 ;
  self.button1.selected=YES;
    self.button2.selected =NO;
    self.button3.selected =NO;
    self.villageCommittee.enabled=YES;
    self.village.enabled=YES;
    self.village.placeholder =@"";
    self.villageCommittee.placeholder =@"";
    self.companyViewHide.hidden =YES;
    [self shezhisuoyouweiNill];
   self.changeThreeWithUrbanAndGovern =sender;
    [self contraintChangeOne];

}
//UI
- (IBAction)button_2:(id)sender {
     ice = 1;
    self.button1.selected =NO;
    self.button2.selected =YES;
    self.button3.selected =NO;
        self.village.selected =NO;
//        self.village.textColor =[UIColor redColor];
        self.village.enabled=NO;
        self.village.placeholder =@" 不用填写";
        [self.village setText:nil];
        self.villageCommittee.enabled=NO;
        [self.villageCommittee setText:nil];
        self.villageCommittee.placeholder =@" 不用填写";
      self.companyViewHide.hidden =NO;
    [self shezhisuoyouweiNill];
    self.changeThreeWithUrbanAndGovern =sender;
    [self contraintChangeTwo];
    [self geta];
  
}

//UI
- (IBAction)button_3:(id)sender {
     ice = 2;
    self.button1.selected =NO;
    self.button2.selected =NO;
    self.button3.selected =YES;
      self.village.selected =NO;
//    self.village.textColor =[UIColor redColor];
    self.village.enabled=NO;
    self.village.placeholder =@" 不用填写";
    [self.village setText:nil];
    self.villageCommittee.enabled=NO;
    [self.villageCommittee setText:nil];
    self.villageCommittee.placeholder =@" 不用填写";
        self.companyViewHide.hidden =NO;
    [self shezhisuoyouweiNill];
    self.changeThreeWithUrbanAndGovern =sender;
 [self contraintChangeTwo];
    [self geta];
}


//方法
#pragma mark - 封装好的用来在textField前面加两个空格
-(void)textFieldAddTwoBlackPlaceinTextFiled:(UITextField *)textField
{
    UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(textField.frame.origin.x,textField.frame.origin.y,5.0, textField.frame.size.height)];
    textField.leftView = blankView;
    textField.leftViewMode =UITextFieldViewModeAlways;
}

//单例
+ (pickerViewController *)sharedInstance{
    static pickerViewController *p = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        p=[sb instantiateViewControllerWithIdentifier:@"pickerViewController"];
    });
    return p;
}


#pragma mark - 这里传过去最后一个值

-(void)put_1{
    self.jumpToPhoto.userInteractionEnabled =NO;
    self.jumpToPhoto.selected =YES;
    [SVProgressHUD shows];
    indexTag  =6;
    
    
    NSUserDefaults* userDefault=[NSUserDefaults standardUserDefaults];
    NSString *names =[userDefault objectForKey:@"name"];
    NSString *identifity =[userDefault objectForKey:@"identityNumber"];
    NSString *u =[userDefault objectForKey:@"bak"];
    NSLog(@"%@,%@",names,identifity);
    if ([u isEqualToString:@""]) {
        u =nil;
    }
    NSString *path =@"";
    path  = [IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/verifyAddress"];
    
    [[NSUserDefaults standardUserDefaults]setObject:self.downTown.text forKey:@"asrgergvrg"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    [CityNetManager getVeriftAdressNameToThePath:path FortheName:names encrypt:[EnercryTool A:names] theIdentityNumberPara:identifity twoEncrypt:[EnercryTool A:identifity] theProvince_namePara:self.province.text theCity_namePara:self.downTown.text theCounty_namePara:self.area.text theTown_namePara:self.village.text theVillageNameThPara:self.villageCommittee.text thePhoneNumber:self.phoneNumber.text companyName:self.Company.text verifyType:ice idName:u youP:self.OCRData youP:self.OCRData_ completionHandle:^(verifyAdressModel *model, NSError *error) {
        [SVProgressHUD doneShow];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            if (model.code != 0) {
                NSLog(@"code:%ld",model.code);
                NSLog(@"bak:%@",model.bak);
                
                
                SVProgressHUD.minimumDismissTimeInterval =3.0;
                [SVProgressHUD showErrorWithStatus:@"输入的信息不正确,请检查"];
                self.jumpToPhoto.userInteractionEnabled =YES;
                return;
            }
            
            NSLog(@"code:%ld",(long)model.code);
            
            
            NSLog(@" 数据访问成功");
            
            [userDefault setObject:model.bak forKey:@"bak"];
            
            UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            ShowPicker *receive = [sb instantiateViewControllerWithIdentifier:@"ShowPicker"];
            receive.address_relation =ice;
            receive.city =self.area.text;
            receive.province =self.province.text;
            receive.county =self.downTown.text;
            
            [[NSUserDefaults standardUserDefaults] setObject:self.province.text forKey:@"successProvinceKankan"];
             [[NSUserDefaults standardUserDefaults] setObject:self.area.text forKey:@"successareaKankan"];
             [[NSUserDefaults standardUserDefaults] setObject:self.downTown.text forKey:@"successdowntownKankan"];
            
             [[NSUserDefaults standardUserDefaults] synchronize];
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.navigationController pushViewController:receive animated:YES];
            });
        });
        
        [SVProgressHUD dismiss];
        self.jumpToPhoto.userInteractionEnabled =YES;
    }];
    
    
    
    
    
}

@end
