//
//  AddressAlertView.m
//  Open
//
//  Created by 雷俊博 on 2019/12/3.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "AddressAlertView.h"
#import "Constants.h"
#import "UIView+frameAdjust.h"
#import "AddressBasicView.h"
#import "AddressBasic2View.h"
#import "AddressPrizeNameBasicView.h"
#import "ShoeStyleSelectView.h"

#import "ChooseLocationView.h"
#import "CitiesDataTool.h"
#import "Tools.h"

#import <IQKeyboardManager.h>
#import "UIScrollView+UITouch.h"

@interface AddressAlertView ()<UIGestureRecognizerDelegate,UITextFieldDelegate,UITextViewDelegate>
{
    CGFloat basicViewHeigth;
    UITextField* tf_name;
    UITextField* tf_phone;
    UITextField* tf_address;
    UITextView* tv_detailAddress;
    
    UIButton* closeBtn;
    
    ShoeStyleSelectView* _selectView;
}

/** 弹窗主内容view */
@property (nonatomic,strong) UIView   *contentView;

@property (nonatomic,strong) ChooseLocationView *chooseLocationView;
@property (nonatomic,strong) UIView  *cover;

@property(nonatomic ,strong) UITextField * firstResponderTextF;//记录将要编辑的输入框

@property (nonatomic, assign)CTListPrizeType type;


@end

@implementation AddressAlertView
#pragma mark - 构造方法
- (instancetype)initWithType:(CTListPrizeType)type
{
    self = [super init];
    if (self) {
        self.type = type;
        //UI搭建
        [self setupUI];
        
        
        
        
    }
    return self;
}

- (void)setupUI
{
    self.frame = [UIScreen mainScreen].bounds;
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapBackClcik:)];
    tap.delegate = self;
    [self addGestureRecognizer:tap];
    
    
    
    
     //------- 弹窗主内容 -------//
    self.contentView = [[UIView alloc] init];
    
    if (self.type == CTListPrizeTypeSmartCup || self.type == CTListPrizeTypeToyCar || self.type == CTListPrizeTypeElectricFan || self.type == CTListPrizeTypeMedicalMask || self.type == CTListPrizeTypeDisinfectant || self.type == CTListPrizeTypeTissue || self.type == CTListPrizeTypeFan || self.type == CTListPrizeTypeWashbasin || self.type == CTListPrizeTypeTeaSet || self.type == CTListPrizeTypeTeaMassageStick || self.type == CTListPrizeTypeMiniHumidifier || self.type == CTListPrizeTypeRazor || self.type == CTListPrizeTypeCookerTool || self.type == CTListPrizeTypeWashingLiquid || self.type == CTListPrizeTypeStorageBox || self.type == CTListPrizeTypeUSBElectronicScale || self.type == CTListPrizeTypeAutoFoldUmbrella || self.type == CTListPrizeTypeMosquitoKillingLamp || self.type == CTListPrizeTypeHUAWeiMate40 || self.type == CTListPrizeTypeHoldFan  || self.type == CTListPrizeTypequalityDrawing || self.type == CTListPrizeTypeTeapot || self.type == CTListPrizeTypeiPhone12Pro || self.type == CTListPrizeTypeUglyOrange || self.type == CTListPrizeTypeRedmi9A || self.type == CTListPrizeTypeSummerSleepingMat || self.type == CTListPrizeTypeChineseWolfberry || self.type == CTListPrizeTypeSummerQuilt || self.type == CTListPrizeTypeWashingMachine || self.type == CTListPrizeTypeDisposableMop || self.type == CTListPrizeTypeHairDrier || self.type == CTListPrizeTypeKitchenRack ||  self.type == CTListPrizeTypeMultifunctionalPluginBoard  || self.type == CTListPrizeTypeBathroomMat || self.type == CTListPrizeTypeIpadMini || self.type == CTListPrizeTypeCeramicCasserole  || self.type == CTListPrizeTypeCervicalSpineMassager || self.type == CTListPrizeTypeWirelessBluetoothHeadset || self.type == CTListPrizeTypeWinterCup || self.type == CTListPrizeTypeBin || self.type == CTListPrizeTypeAirHumidifier  || self.type == CTListPrizeTypeCreativeLaundryBasket || self.type == CTListPrizeTypeBedDesk || self.type == CTListPrizeTypeHairBallTrimmer  || self.type == CTListPrizeTypePlushCushions  || self.type == CTListPrizeTypeSolidWoodHangers || self.type == CTListPrizeTypeTopCup || self.type == CTListPrizeTypeVirginPulpPaper  || self.type == CTListPrizeTypeAbsorbent || self.type == CTListPrizeTypeElectronicScale || self.type == CTListPrizeTypeWirelessMouse || self.type == CTListPrizeTypeDishwashingGloves || self.type == CTListPrizeTypeNewYearHanged || self.type == CTListPrizeTypeNewYearCandy || self.type == CTListPrizeTypeLogNapkins || self.type == CTListPrizeTypeHighTempCup || self.type == CTListPrizeTypeHeavyAbsorbentTowel || self.type == CTListPrizeTypeHackTechBroom || self.type == CTListPrizeTypeHeadScratcherMassager || self.type == CTListPrizeTypeChineseRedMaskr||self.type == CTListPrizeTypeBOLIBEI || self.type == CTListPrizeTypeKONGQI|| self.type == CTListPrizeTypeLIANGTUOXIE || self.type == CTListPrizeTypeXISHUIMAOPJIN) {
        if (ScreenWidth == 320) {
            self.contentView.frame = CGRectMake((ScreenWidth - 280) / 2, (ScreenHeight - 375) / 2 - 20, 280, 375);
        }else{
            self.contentView.frame = CGRectMake((ScreenWidth - 325) / 2, (ScreenHeight - 375) / 2 - 20, 325, 375);
        }
    }else if(self.type == CTListPrizeTypeShoe || self.type == CTListPrizeTypeSandals){
        if (ScreenWidth == 320) {
            self.contentView.frame = CGRectMake((ScreenWidth - 280) / 2, (ScreenHeight - 375 - 54) / 2 - 20, 280  , 375 + 54);
        }else{
            self.contentView.frame = CGRectMake((ScreenWidth - 325) / 2, (ScreenHeight - 375 - 54) / 2 - 20, 325, 375 + 54);
        }
    }
    
    
    
    
    //self.contentView.center = self.center;
    [self addSubview:self.contentView];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 16;
    
    
    UIButton *btn_close = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn_close.frame = CGRectMake((ScreenWidth -  50)/2, self.contentView.maxY + 20 , 50, 50);
    
    [btn_close setImage:[UIImage imageNamed:@"btn_lottery_close"] forState:UIControlStateNormal];
    
    [btn_close addTarget:self action:@selector(closeViewClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:btn_close];
    
    closeBtn = btn_close;
    
    
    
      UIImageView *topBackImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.width, 70)];
    
      topBackImg.image = [UIImage imageNamed:@"orderAddress-bg"];
      [self.contentView addSubview:topBackImg];
    
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake((self.contentView.width - 100)/2, 25 , 100, 20 )];
    titleLab.textColor = [UIColor whiteColor];
    titleLab.text = @"收货地址";
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.font = [UIFont systemFontOfSize:23];
    
    [self.contentView addSubview:titleLab];
    
    
    
    basicViewHeigth = 70 ;
    
    
    basicViewHeigth = [self creatNameViewWithHeight:20];
    
    
    if (self.type == CTListPrizeTypeShoe || self.type == CTListPrizeTypeSandals) {
        basicViewHeigth = [self creatSelectView:44];
    }
    
    
    NSArray *array = @[@"姓        名:",@"电        话:",@"所在地区:",@"详细地址:"];
    for (int i = 0; i < array.count; i++) {
        
        if (i == (array.count - 1)) {
            basicViewHeigth = [self LineTextViewBulid:array[i] lineHeight:30 index:i];
        }else{
            basicViewHeigth = [self LineViewBulid:array[i] lineHeight:30 index:i];
        }
      
    }
    
    UILabel *lb_message = [[UILabel alloc]init];
    
    
    
    lb_message.numberOfLines = 0;
    lb_message.textColor = [UIColor colorWithHex:0xfe5733];
    [self.contentView addSubview:lb_message];
    

    NSString *message = nil;
    
    
    
    if (![NSString validateWithStartTime:@"2020-01-24 00:00" withExpireTime:@"2020-01-30 24:00"]) {
        message = @"奖品会在您提交信息后，一个月内发货，到时您可查看物流信息。（由于快递停运，春节期间不发货，有疑问请联系客服微信:kankanrenzheng）";
        lb_message.frame = CGRectMake(20 , basicViewHeigth + 10 , self.contentView.width - 40, 95 );
        CGRect frame = self.contentView.frame;
        frame.size.height =  frame.size.height + 30;
        self.contentView.frame = frame;
        
        CGRect btnFrame =  btn_close.frame;
        btnFrame.size.height = btnFrame.size.height + 30;
        
        btn_close.frame = btnFrame;
    }else{
        message = @"奖品会在您提交信息后，一个月内发货，到时您可查看物流信息。（有疑问请联系客服微信:kankanrenzheng）";
        lb_message.frame = CGRectMake(20 , basicViewHeigth + 10 , self.contentView.width - 40, 65 );
    }
    
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:message];
          NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
      paragraphStyle.lineSpacing = 5.0; // 设置行间距
      //paragraphStyle.alignment = NSTextAlignmentCenter; //设置两端对齐显示
      [attributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedStr.length)];
      [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, attributedStr.length)];
   
    lb_message.numberOfLines = 0;
    lb_message.attributedText = attributedStr;
    
    
    basicViewHeigth = lb_message.maxY;
    
    
    UIButton* btn_commit = [UIButton buttonWithType:UIButtonTypeCustom];
    btn_commit.frame = CGRectMake(10, basicViewHeigth + 10, self.contentView.width - 20, 40);
    
    btn_commit.layer.cornerRadius = 8;
    
    [btn_commit setTitle:@"确认提交" forState:UIControlStateNormal];
    
    [btn_commit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    btn_commit.backgroundColor = [UIColor colorWithHex:0xfe5733];
    
    btn_commit.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [btn_commit addTarget:self action:@selector(commitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:btn_commit];
    
    //[[CitiesDataTool sharedManager] requestGetData];
    [[CitiesDataTool sharedManager]requestAllProvince];
    [self addSubview:self.cover];
    //self.chooseLocationView.address = @"广东省 广州市 越秀区";
    //self.chooseLocationView.areaCode = @"440104";
    //创建观察者，监听键盘的弹出
   [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    //创建观察者，监听键盘的隐藏
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

}


- (void)dealloc
{
    NSLog(@"addressalertView销毁了");
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


#pragma mark : UIKeyboardWillShowNotification/UIKeyboardWillHideNotification
- (void)keyboardWillShow:(NSNotification *)notification
{
    NSLog(@"%@",notification.userInfo);
    CGRect rect = [self.firstResponderTextF.superview convertRect:self.firstResponderTextF.frame toView:self];//获取相对于self的位置
    CGRect frame = self.contentView.frame;
    
     NSLog(@"输入框相对于屏幕的位置%@",NSStringFromCGRect(rect));
    
    NSLog(@"contentview键盘弹出前的frame:%@",NSStringFromCGRect(self.contentView.frame));
    NSDictionary *userInfo = [notification userInfo];
       NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];//获取弹出键盘的fame的value值
       CGRect keyboardRect = [aValue CGRectValue];
       keyboardRect = [self convertRect:keyboardRect fromView:self.window];//获取键盘相对于self.view的frame ，传window和传nil是一样的
    NSLog(@"键盘相对于屏幕的位置%@",NSStringFromCGRect(keyboardRect));
    CGFloat keyboardTop = keyboardRect.origin.y;
    NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘弹出动画时间值
    NSTimeInterval animationDuration = [animationDurationValue doubleValue];
    if (keyboardTop < CGRectGetMaxY(rect)) {//如果键盘盖住了输入框
        CGFloat gap = keyboardTop - CGRectGetMaxY(rect) - 10;//计算需要网上移动的偏移量（输入框底部离键盘顶部为10的间距）
        __weak typeof(self)weakSelf = self;
        [UIView animateWithDuration:animationDuration animations:^{
            weakSelf.contentView.frame = CGRectMake(weakSelf.contentView.frame.origin.x, frame.origin.y + gap, weakSelf.contentView.frame.size.width, weakSelf.contentView.frame.size.height);
            self->closeBtn.frame = CGRectMake((ScreenWidth -  50)/2, self.contentView.maxY + 20 , 50, 50);
            NSLog(@"contentview键盘弹出后的frame:%@",NSStringFromCGRect(weakSelf.contentView.frame));
        }];
    }
}

- (void)keyboardWillHide:(NSNotification *)notification{
    NSLog(@"contentview键盘消失前的frame:%@",NSStringFromCGRect(self.contentView.frame));
    NSDictionary *userInfo = [notification userInfo];
    NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘隐藏动画时间值
    NSTimeInterval animationDuration = [animationDurationValue doubleValue];
   // if (self.contentView.frame.origin.y < 0) {//如果有偏移，当影藏键盘的时候就复原
        __weak typeof(self)weakSelf = self;
        [UIView animateWithDuration:animationDuration animations:^{
            
            if (weakSelf.type == CTListPrizeTypeShoe || weakSelf.type == CTListPrizeTypeSandals) {
                 weakSelf.contentView.frame = CGRectMake(weakSelf.contentView.frame.origin.x, (ScreenHeight - 375 - 54) / 2 - 20, weakSelf.contentView.frame.size.width, weakSelf.contentView.frame.size.height);
            }else if (weakSelf.type == CTListPrizeTypeSmartCup || self.type == CTListPrizeTypeToyCar || self.type == CTListPrizeTypeElectricFan || self.type == CTListPrizeTypeMedicalMask || self.type == CTListPrizeTypeDisinfectant || self.type == CTListPrizeTypeTissue || self.type == CTListPrizeTypeFan || weakSelf.type == CTListPrizeTypeWashbasin || self.type == CTListPrizeTypeTeaSet || self.type == CTListPrizeTypeTeaMassageStick || self.type == CTListPrizeTypeMiniHumidifier || self.type == CTListPrizeTypeRazor || self.type == CTListPrizeTypeCookerTool || self.type == CTListPrizeTypeWashingLiquid || self.type == CTListPrizeTypeStorageBox || self.type == CTListPrizeTypeUSBElectronicScale || self.type == CTListPrizeTypeAutoFoldUmbrella || self.type == CTListPrizeTypeMosquitoKillingLamp || self.type == CTListPrizeTypeHUAWeiMate40 || self.type == CTListPrizeTypeHoldFan  || self.type == CTListPrizeTypequalityDrawing || self.type == CTListPrizeTypeTeapot || self.type == CTListPrizeTypeiPhone12Pro || self.type == CTListPrizeTypeUglyOrange || self.type == CTListPrizeTypeRedmi9A || self.type == CTListPrizeTypeSummerSleepingMat || self.type == CTListPrizeTypeChineseWolfberry || self.type == CTListPrizeTypeSummerQuilt || self.type == CTListPrizeTypeWashingMachine || self.type == CTListPrizeTypeDisposableMop || self.type == CTListPrizeTypeHairDrier || self.type == CTListPrizeTypeKitchenRack ||  self.type == CTListPrizeTypeMultifunctionalPluginBoard || self.type == CTListPrizeTypeBathroomMat || self.type == CTListPrizeTypeIpadMini || self.type == CTListPrizeTypeCeramicCasserole  || self.type == CTListPrizeTypeCervicalSpineMassager || self.type == CTListPrizeTypeWirelessBluetoothHeadset || self.type == CTListPrizeTypeWinterCup || self.type == CTListPrizeTypeBin || self.type == CTListPrizeTypeAirHumidifier  || self.type == CTListPrizeTypeCreativeLaundryBasket || self.type == CTListPrizeTypeBedDesk || self.type == CTListPrizeTypeHairBallTrimmer  || self.type == CTListPrizeTypePlushCushions  || self.type == CTListPrizeTypeSolidWoodHangers || self.type == CTListPrizeTypeTopCup || self.type == CTListPrizeTypeVirginPulpPaper  || self.type == CTListPrizeTypeAbsorbent || self.type == CTListPrizeTypeElectronicScale || self.type == CTListPrizeTypeWirelessMouse || self.type == CTListPrizeTypeDishwashingGloves || self.type == CTListPrizeTypeNewYearHanged || self.type == CTListPrizeTypeNewYearCandy || self.type == CTListPrizeTypeLogNapkins || self.type == CTListPrizeTypeHighTempCup || self.type == CTListPrizeTypeHeavyAbsorbentTowel || self.type == CTListPrizeTypeHackTechBroom || self.type == CTListPrizeTypeHeadScratcherMassager || self.type == CTListPrizeTypeChineseRedMaskr|| self.type == CTListPrizeTypeBOLIBEI || self.type == CTListPrizeTypeKONGQI|| self.type == CTListPrizeTypeLIANGTUOXIE || self.type == CTListPrizeTypeXISHUIMAOPJIN){
                 weakSelf.contentView.frame = CGRectMake(weakSelf.contentView.frame.origin.x, (ScreenHeight - 375) / 2 - 20, weakSelf.contentView.frame.size.width, weakSelf.contentView.frame.size.height);
            }
           
            self->closeBtn.frame = CGRectMake((ScreenWidth -  50)/2, self.contentView.maxY + 20 , 50, 50);
             NSLog(@"contentview键盘消失后的frame:%@",NSStringFromCGRect(weakSelf.contentView.frame));
        }];
   // }
}


#pragma mark - UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码
        [textView resignFirstResponder];
        return YES; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    return YES;
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    self.firstResponderTextF = textField;//当将要开始编辑的时候，获取当前的textField
    
    if (textField == tf_address) {
        [self endEditing:YES];
        [self addressShow];
        
        return NO;
    }
    
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - event reponse
- (void)commitBtnClick:(UIButton *)sender
{
    if (tf_name.text.length == 0) {
        [SVProgressHUD showErrorWithStatus:@"请填写收件人姓名"];
        return;
    }else if (![Tools isMobileNumber:tf_phone.text]){
        [SVProgressHUD showErrorWithStatus:@"请填写规范的手机号码"];
        return;
    }else if (tf_address.text.length == 0){
        [SVProgressHUD showErrorWithStatus:@"请选择所在地区"];
        return;
    }else if (tv_detailAddress.text.length == 0){
        [SVProgressHUD showErrorWithStatus:@"请填写详细地址"];
        return;
    }
    
    NSString *remark = nil;
    
    if (self.type == CTListPrizeTypeShoe || self.type == CTListPrizeTypeSandals) {
        if (_selectView.isWoman) {
            if (_selectView.tf_woman.text.length == 0) {
                [SVProgressHUD showErrorWithStatus:@"请填写尺码"];
                return;
            }
            remark = [NSString stringWithFormat:@"女,%@",_selectView.tf_woman.text];
        }else{
            if (_selectView.tf_man.text.length == 0) {
                [SVProgressHUD showErrorWithStatus:@"请填写尺码"];
                return;
            }else{
                remark = [NSString stringWithFormat:@"男,%@",_selectView.tf_man.text];
            }
        }
    }
    
    [self dismiss];
    
    NSDictionary*userInfo  = nil;
    
    if (self.type == CTListPrizeTypeShoe || self.type == CTListPrizeTypeSandals) {
       userInfo =  @{
            @"name":tf_name.text,
            @"mobile":tf_phone.text,
            @"address":tf_address.text,
            @"detailAddress":tv_detailAddress.text,
            @"remark":remark
        };
    }else if (self.type == CTListPrizeTypeSmartCup || self.type == CTListPrizeTypeToyCar || self.type == CTListPrizeTypeElectricFan  || self.type == CTListPrizeTypeMedicalMask || self.type == CTListPrizeTypeDisinfectant || self.type == CTListPrizeTypeTissue || self.type == CTListPrizeTypeFan || self.type == CTListPrizeTypeWashbasin || self.type == CTListPrizeTypeTeaSet || self.type == CTListPrizeTypeTeaMassageStick || self.type == CTListPrizeTypeMiniHumidifier || self.type == CTListPrizeTypeRazor || self.type == CTListPrizeTypeCookerTool || self.type == CTListPrizeTypeWashingLiquid || self.type == CTListPrizeTypeStorageBox || self.type == CTListPrizeTypeUSBElectronicScale || self.type == CTListPrizeTypeAutoFoldUmbrella || self.type == CTListPrizeTypeMosquitoKillingLamp || self.type == CTListPrizeTypeHUAWeiMate40 || self.type == CTListPrizeTypeHoldFan  || self.type == CTListPrizeTypequalityDrawing || self.type == CTListPrizeTypeTeapot || self.type == CTListPrizeTypeiPhone12Pro || self.type == CTListPrizeTypeUglyOrange || self.type == CTListPrizeTypeRedmi9A || self.type == CTListPrizeTypeSummerSleepingMat || self.type == CTListPrizeTypeChineseWolfberry || self.type == CTListPrizeTypeSummerQuilt || self.type == CTListPrizeTypeWashingMachine || self.type == CTListPrizeTypeDisposableMop || self.type == CTListPrizeTypeHairDrier || self.type == CTListPrizeTypeKitchenRack ||  self.type == CTListPrizeTypeMultifunctionalPluginBoard || self.type == CTListPrizeTypeBathroomMat || self.type == CTListPrizeTypeIpadMini || self.type == CTListPrizeTypeCeramicCasserole  || self.type == CTListPrizeTypeCervicalSpineMassager || self.type == CTListPrizeTypeWirelessBluetoothHeadset || self.type == CTListPrizeTypeWinterCup || self.type == CTListPrizeTypeBin || self.type == CTListPrizeTypeAirHumidifier  || self.type == CTListPrizeTypeCreativeLaundryBasket || self.type == CTListPrizeTypeBedDesk || self.type == CTListPrizeTypeHairBallTrimmer  || self.type == CTListPrizeTypePlushCushions  || self.type == CTListPrizeTypeSolidWoodHangers || self.type == CTListPrizeTypeTopCup || self.type == CTListPrizeTypeVirginPulpPaper  || self.type == CTListPrizeTypeAbsorbent || self.type == CTListPrizeTypeElectronicScale || self.type == CTListPrizeTypeWirelessMouse || self.type == CTListPrizeTypeDishwashingGloves || self.type == CTListPrizeTypeNewYearHanged || self.type == CTListPrizeTypeNewYearCandy || self.type == CTListPrizeTypeLogNapkins || self.type == CTListPrizeTypeHighTempCup || self.type == CTListPrizeTypeHeavyAbsorbentTowel || self.type == CTListPrizeTypeHackTechBroom || self.type == CTListPrizeTypeHeadScratcherMassager || self.type == CTListPrizeTypeChineseRedMaskr|| self.type == CTListPrizeTypeBOLIBEI || self.type == CTListPrizeTypeKONGQI|| self.type == CTListPrizeTypeLIANGTUOXIE || self.type == CTListPrizeTypeXISHUIMAOPJIN){
        userInfo =  @{
            @"name":tf_name.text,
            @"mobile":tf_phone.text,
            @"address":tf_address.text,
            @"detailAddress":tv_detailAddress.text
        };
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(commitUserInfo:)]) {
        [self.delegate commitUserInfo:userInfo];
    }
}

- (CGFloat)creatNameViewWithHeight:(CGFloat)height
{
    AddressPrizeNameBasicView *view = [[AddressPrizeNameBasicView alloc]initWithFrame:CGRectMake(0, basicViewHeigth + 15, self.contentView.width, height) type:self.type];
    [self.contentView addSubview:view];
    
    return view.maxY;
}
- (CGFloat)LineViewBulid:(NSString *)leftName lineHeight:(CGFloat)height index:(int)index
{
    AddressBasicView *view = [[AddressBasicView alloc]initWithFrame:CGRectMake(0, basicViewHeigth + 5, self.contentView.width, height) leftName:leftName];
    [self.contentView addSubview:view];
    
    if (index == 1) {
        view.tf_content.keyboardType = UIKeyboardTypeNumberPad;
    }
    
    view.tf_content.delegate =self;
    
    if (index == 0) {
        tf_name = view.tf_content;
    }else if (index == 1){
        tf_phone = view.tf_content;
    }else if (index == 2){
        tf_address = view.tf_content;
        tf_address.rightView = [self getArrowView];
        tf_address.rightViewMode = UITextFieldViewModeAlways;
        
    }
    
    
    return view.maxY;
}

- (CGFloat)LineTextViewBulid:(NSString *)leftName lineHeight:(CGFloat)height index:(int)index
{
    AddressBasic2View *view = [[AddressBasic2View alloc]initWithFrame:CGRectMake(0, basicViewHeigth + 5, self.contentView.width, height) leftName:leftName];
    [self.contentView addSubview:view];
    
    if (index == 1) {
        view.tv_content.keyboardType = UIKeyboardTypeNumberPad;
    }
    
    view.tv_content.delegate =self;
    
    
    tv_detailAddress = view.tv_content;
    
    
    return view.maxY;
}

- (CGFloat)creatSelectView:(CGFloat)height
{
    ShoeStyleSelectView *selectView = [[ShoeStyleSelectView alloc]initWithFrame:CGRectMake(0, basicViewHeigth + 5, self.contentView.width, height)];
    
    _selectView = selectView;
    
    [self.contentView addSubview:selectView];
    return selectView.maxY;
}


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    CGPoint point = [gestureRecognizer locationInView:gestureRecognizer.view];
    
    
    if ([gestureRecognizer.view isKindOfClass:[AddressAlertView class]]){
        if (CGRectContainsPoint(_contentView.frame, point) || CGRectContainsPoint(_chooseLocationView.frame, point)){
            return NO;
        }
    }
    
    if (gestureRecognizer.view == self.cover){
        if (CGRectContainsPoint(_chooseLocationView.frame, point)){
             
                return NO;
            
        }
    }
    
    
    
    return YES;
}

- (void)tapBackClcik:(UITapGestureRecognizer *)tap
{
   // [self dismiss];
    [self endEditing:YES];
}

- (void)closeViewClick:(UIButton *)sender
{
    [self dismiss];
}


#pragma mark - 弹窗展示/隐藏

/** 弹出此弹窗 */
- (void)addressShow {
    [UIView animateWithDuration:0.25 animations:^{
        //self.transform =CGAffineTransformMakeScale(0.95, 0.95);
    }];
    self.cover.hidden = NO;
    self.chooseLocationView.hidden = NO;
    self.chooseLocationView.frame =CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, 350);
    
    [UIView animateWithDuration:0.25 animations:^{
        self.chooseLocationView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 350, [UIScreen mainScreen].bounds.size.width, 350);
    }];
}

/** 移除此弹窗 */
- (void)addressDismiss {
    [UIView animateWithDuration:0.25 animations:^{
        self.chooseLocationView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, 350);
        
    } completion:^(BOOL finished) {
        self.chooseLocationView.hidden = YES;
        self.cover.hidden = YES;
    }];
}

#pragma mark - 弹窗展示/隐藏

/** 弹出此弹窗 */
- (void)show {
    // 出场动画
    self.chooseLocationView.hidden = YES;
    self.cover.hidden = YES;
    self.alpha = 0;
    self.contentView.transform = CGAffineTransformScale(self.contentView.transform, 1.3, 1.3);
    [UIView animateWithDuration:0.2 animations:^{
        self.alpha = 1;
        self.contentView.transform = CGAffineTransformIdentity;
    }];
    
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    [window addSubview:self];
}

/** 移除此弹窗 */
- (void)dismiss {
    [self removeFromSuperview];
}


#pragma mark - getters and setters
- (void)tapCover:(UITapGestureRecognizer *)tap{
    
    if (_chooseLocationView.chooseFinish) {
         _chooseLocationView.chooseFinish();
    }
}

- (ChooseLocationView *)chooseLocationView{
    
    if (!_chooseLocationView) {
       _chooseLocationView = [[ChooseLocationView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 350, [UIScreen mainScreen].bounds.size.width, 350)];
      
    }
    return _chooseLocationView;
}

- (UIView *)cover{

    if (!_cover) {
        _cover = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        _cover.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
        [_cover addSubview:self.chooseLocationView];
        __weak typeof (self) weakSelf = self;
        _chooseLocationView.chooseFinish = ^{

            [UIView animateWithDuration:0.25 animations:^{
                __strong __typeof(self) strongSelf = weakSelf;
                strongSelf->tf_address.text = weakSelf.chooseLocationView.address;
                //strongSelf.transform = CGAffineTransformIdentity;
                [strongSelf addressDismiss];
            }];
        };
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCover:)];
        [_cover addGestureRecognizer:tap];
        tap.delegate = self;
        [self addressDismiss];
    }
    return _cover;
}

- (UIImageView *)getArrowView
{
    
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    imageView.image = [UIImage imageNamed:@"pullDownImage"];
    
    imageView.contentMode = UIViewContentModeCenter;
    
    
    return imageView;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
