//
//  SSCardCollectOtherInfoController.m
//  Open
//
//  Created by 雷俊博 on 2019/11/22.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "SSCardCollectOtherInfoController.h"
#import "SSCardCollectBasicInfoCell.h"
#import "SSCardCollectOtherInfoCell.h"
#import "UIView+frameAdjust.h"

#import "CYAddressSelectedView.h"

@interface SSCardCollectOtherInfoController ()<UITextFieldDelegate,SSCardCollectOtherInfoCellDelegate>
{
    //记录位置
    CGFloat currentMaxY;
    
    //记录选中的工作状态
    NSString *jobState;
}

@property (nonatomic, strong)UIScrollView *scrollView;

@property (nonatomic, strong)UIView *backView;

@property (nonatomic, strong)NSArray *departmentArray;

@property (nonatomic, strong)NSArray *bankArray;

@property (nonatomic, strong)NSArray *industryArray;

@property (nonatomic, strong)NSArray *occupationArray;

@end

@implementation SSCardCollectOtherInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view addSubview:self.scrollView];
    
    [self confirmNavBav];
    [self setupUI];
}

- (void)confirmNavBav
{
    UIButton *btn_back = [UIButton buttonWithType:UIButtonTypeCustom];
    btn_back.frame = CGRectMake(0, 0, 60, 40);
    
    [btn_back setTitle:@"返回" forState:UIControlStateNormal];
    [btn_back setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
    btn_back.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn_back setImage:[[UIImage imageNamed:@"back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    [btn_back addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [btn_back layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btn_back];
    if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=7) {
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSpacer.width = -15;
        self.navigationItem.leftBarButtonItems = @[negativeSpacer, backItem];
    }else{
        self.navigationItem.leftBarButtonItem = backItem;
    }
    
}

- (void)setupUI
{
    NSArray *titleArray = @[@"*所属机构",@"*服务银行",@"*工作状态",@"所属行业",@"所属职业"];
    
    NSArray *placeArray = @[@"请选择所属机构",@"请选择服务银行",@"",@"请选择所属行业",@"请选择所属职业"];
    
    for (int i = 0; i < titleArray.count; i++) {
        
        if (i == 2) {
            currentMaxY = [self creatLine2WithLeftStr:titleArray[i] height:58 index:i];
        }else{
            currentMaxY = [self creatLineWithLeftStr:titleArray[i] right:placeArray[i] height:58 index:i];
        }
       
    }
    
    [self creatBtn];
          
}


- (CGFloat)creatLineWithLeftStr:(NSString *)leftName right:(NSString *)rightName height:(CGFloat)height index:(NSInteger)index
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"SSCardCollectBasicInfoCell" owner:self options:nil];
    SSCardCollectBasicInfoCell *view = [Bundle objectAtIndex:0];
    
    view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
     [self.backView addSubview:view];
    
    view.lb_left.text = leftName;
    view.tf_right.placeholder = rightName;
    
    view.tf_right.delegate = self;
    
    
    view.tf_right.tag = 200 + index;
    
    
    
        view.img_arrow.hidden = NO;

    
    
    self.backView.height = view.maxY + 50;
    self.scrollView.contentSize = CGSizeMake(ScreenWidth, self.backView.height);
    
    
    
     return view.maxY;
}

- (CGFloat)creatLine2WithLeftStr:(NSString *)leftName  height:(CGFloat)height index:(NSInteger)index
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"SSCardCollectOtherInfoCell" owner:self options:nil];
       SSCardCollectOtherInfoCell *view = [Bundle objectAtIndex:0];
       
       view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
    view.delegate = self;
       
        [self.backView addSubview:view];
    
    [view clickBtn];
    
    self.backView.height = view.maxY + 80;
    self.scrollView.contentSize = CGSizeMake(ScreenWidth, self.backView.height);
    
    return view.maxY;
}

- (CGFloat)creatBtn
{
    UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    
    [nextBtn setBackgroundColor:K_MainColor];
    
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    nextBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    nextBtn.frame = CGRectMake(10, currentMaxY + 50, ScreenWidth - 20, 45);
    
    nextBtn.layer.cornerRadius = 5;
    
    [nextBtn addTarget:self action:@selector(goToNextVC:) forControlEvents:UIControlEventTouchUpInside];
    
   
    
    [self.backView addSubview:nextBtn];
    
    
    self.backView.height = nextBtn.maxY + 50;
    self.scrollView.contentSize = CGSizeMake(ScreenWidth, self.backView.height);
    
    return nextBtn.maxY;
}

#pragma mark - SSCardCollectOtherInfoCellDelegate
- (void)btnClickWithButton:(UIButton *)button
{
    NSLog(@"点击%@按钮",button.titleLabel.text);
    
    jobState = button.titleLabel.text;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    if (textField.tag == 201) {
        [ CYAddressSelectedView show2AddressPickerWithTitle:@"请选择服务银行" data:self.bankArray addressType:AddressTypeNational resultBlock2:^(NSString * _Nonnull selectValue) {
            textField.text = selectValue;
        }];
    }else if (textField.tag == 203){
        [ CYAddressSelectedView show2AddressPickerWithTitle:@"请选择所属行业" data:self.industryArray addressType:AddressTypeNational resultBlock2:^(NSString * _Nonnull selectValue) {
            textField.text = selectValue;
        }];
    }else if (textField.tag == 204){
        [ CYAddressSelectedView show2AddressPickerWithTitle:@"请选择所属职业" data:self.occupationArray addressType:AddressTypeNational resultBlock2:^(NSString * _Nonnull selectValue) {
            textField.text = selectValue;
        }];
    }
    
    return NO;
}



#pragma mark - event response
- (void)backClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)goToNextVC:(UIButton *)sender
{
    
}


#pragma mark - getters and setters

- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    }
    return _backView;
}

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight);
        
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        
        
        
        [_scrollView addSubview:self.backView];
    }
    return _scrollView;
}

- (NSArray *)departmentArray
{
    if (!_departmentArray) {
        _departmentArray = @[];
    }
    return _departmentArray;
}

- (NSArray *)bankArray
{
    if (!_bankArray) {
        _bankArray = @[@"朝阳银行",@"建设银行",@"工商银行"];
    }
    return _bankArray;
}

- (NSArray *)industryArray
{
    if (!_industryArray) {
        _industryArray = @[@"邮电通讯行业",@"房地产行业",@"交通运输业",@"法律/司法行业",@"文化/娱乐/体育",@"媒介/广告行业",@"科研/教育业",@"医疗行业",@"计算机/网络行业",@"商业贸易行业",@"财政行业",@"税务行业",@"咨询行业",@"社会服务行业",@"旅游/饭店行业",@"部队系统",@"证券行业",@"银行业",@"保险业",@"其他金融行业",@"采矿业",@"建筑业",@"工业",@"制造业",@"水电气工供应机关团队",@"农林牧渔",@"其他"];
    }
    return _industryArray;
}

- (NSArray *)occupationArray
{
    if (!_occupationArray) {
        _occupationArray = @[@"公务员",@"企业单位员工",@"公司员工",@"军人警察",@"工人",@"农民",@"管理人员",@"技术人员",@"私营业主",@"文体明星",@"自由职业者",@"无业"];
    }
    return _occupationArray;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
