CNLiveBindingTelView.m 25.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
//
//  CNLiveBindingTelView.m
//  CNLiveBLoginModule
//
//  Created by CNLive-zxw on 2019/9/6.
//  Copyright © 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveBindingTelView.h"
#import "YYKit.h"
#import "QMUIKit.h"
#import <CNLiveRequestBastKit/CNLiveNetworking.h>

#import "CNLiveCategory.h"
#import "CNLiveEnvironment.h"
#import <CNLiveUserSystemSDK/CNLiveUserSystemCenter.h>
#import <CNLiveUserSystemSDK/CNLiveUserSystemTypeDef.h>
#import "CNUserInfoManager.h"
#import "CNLiveManager.h"
#import "CNLiveChooseCountryController.h"

#import "CNLiveLoginCountryView.h"
#import "CNLiveLoginTextField.h"
#import "CNLiveCountDownButton.h"
#import "CNLiveThreeLoginModel.h"
#import "CNLiveLoginRequest.h"

@interface CNLiveBindingTelView()<UITextFieldDelegate,CNLiveCountDownButtonDataSource, CNLiveCountDownButtonDelegate,ChooseCountriesDelegate>
{
    NSString *_countryCode;      // 国家Code
    NSString *_countryName;      // 国家Code
    NSString *_verificationCode; // 验证码
}

@property (nonatomic, weak) QMUIButton *three;
@property (nonatomic, weak) UIImageView *bindingImage;
@property (nonatomic, weak) QMUIButton *netadd;
@property (nonatomic, weak) UILabel *desc;
@property (nonatomic, weak) UIView *line;
@property (nonatomic, weak) UIView *countryBox;
@property (nonatomic, weak) UIView *telBox;
@property (nonatomic, weak) UIView *codeBox;

@property (nonatomic, strong) CNLiveLoginTextField *telTF;
@property (nonatomic, strong) CNLiveLoginTextField *codeTF;

@property (nonatomic, strong) UILabel *country;
@property (nonatomic, strong) UIButton *code;
@property (nonatomic, strong) CNLiveCountDownButton *codeBtn;

@property (nonatomic, weak) UIButton *binding;

@property (nonatomic, strong) CNLiveThreeLoginModel *model;
@property (nonatomic, assign) CNLiveSendAuthResp type;

@end

@implementation CNLiveBindingTelView
#define XWKeyWindow [UIApplication sharedApplication].keyWindow
static NSInteger const space = 10;
static NSInteger const rowHeight = 40;
static const NSInteger timeValue = 1.5;

- (instancetype)initWithFrame:(CGRect)frame model:(CNLiveThreeLoginModel *)model {
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        [self createSubviews:frame];
        _countryName = model.countryName;
        _countryCode = model.countryCode;
        self.model = model;
        self.type = model.type;
        [self addSubview:self.country];
        [self addSubview:self.code];

        [self addSubview:self.telTF];
        [self addSubview:self.codeTF];
        [self addSubview:self.codeBtn];
    }
    return self;
    
}

- (void)setType:(CNLiveSendAuthResp)type{
    switch (type) {
        case CNLiveSendAuthRespWX:
        {
            UIImage *image = [self getImageWithImageName:@"login_binding_wechat" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
            [self.three setImage:image forState:UIControlStateNormal];
            [self.three setTitle:@"微信" forState:UIControlStateNormal];
            self.desc.text = @"确定后,此微信账号将与网家家账号绑定";
        }
            break;
        case CNLiveSendAuthRespQQ:
        {
            UIImage *image = [self getImageWithImageName:@"login_binding_qq" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
            [self.three setImage:image forState:UIControlStateNormal];
            [self.three setTitle:@"QQ" forState:UIControlStateNormal];
            self.desc.text = @"确定后,此QQ账号将与网家家账号绑定";
        }
            break;
        case CNLiveSendAuthRespWB:
        {
            UIImage *image = [self getImageWithImageName:@"login_binding_weibo" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
            [self.three setImage:image forState:UIControlStateNormal];
            [self.three setTitle:@"微博" forState:UIControlStateNormal];
            self.desc.text = @"确定后,此微博账号将与网家家账号绑定";
        }
            break;
        case CNLiveSendAuthRespApple:
        {
            UIImage *image = [self getImageWithImageName:@"login_binding_apple" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
            [self.three setImage:image forState:UIControlStateNormal];
            [self.three setTitle:@"苹果" forState:UIControlStateNormal];
            self.desc.text = @"确定后,此苹果账号将与网家家账号绑定";
        }
            break;
            
    }
    
}


- (void)createSubviews:(CGRect)frame{
    
    CGFloat width = SCREEN_WIDTH - (SCREEN_WIDTH == 320 ? 30 : 60);
       
    CGFloat btnLeft = (SCREEN_WIDTH == 320 ? 30 : 60)/2.0;
    CGFloat btnTop = 20;
    CGFloat btnWidth = width/3.0;
    CGFloat btnHeight = 80;
 
    QMUIButton *three = [QMUIButton buttonWithType:UIButtonTypeCustom];
    three.frame = CGRectMake(btnLeft, btnTop, btnWidth, btnHeight);
    [three setImage:[self getImageWithImageName:@"login_binding_logo" bundleName:@"CNLiveBLoginModule" targetClass:[self class]] forState:UIControlStateNormal];
    three.imagePosition = QMUIButtonImagePositionTop;
    three.spacingBetweenImageAndTitle = 10;
    [three setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]  forState:UIControlStateNormal];
    three.titleLabel.font = [UIFont systemFontOfSize:13];
    three.adjustsImageWhenHighlighted = NO;
    three.userInteractionEnabled = NO;
    [self addSubview:three];
    self.three = three;
    
    UIImageView *bindingImage = [[UIImageView alloc]initWithFrame:CGRectMake(three.right, three.top, three.width,  three.height)];
    UIImage *image1 = [self getImageWithImageName:@"login_binding_ways" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
    bindingImage.image = image1;
    bindingImage.contentMode = UIViewContentModeCenter;
    [self addSubview:bindingImage];
    self.bindingImage = bindingImage;
    
    QMUIButton *netadd = [QMUIButton buttonWithType:UIButtonTypeCustom];
    netadd.frame = CGRectMake(bindingImage.right, three.top, three.width, three.height);
    [netadd setImage:[self getImageWithImageName:@"login_binding_logo" bundleName:@"CNLiveBLoginModule" targetClass:[self class]] forState:UIControlStateNormal];
    [netadd setTitle:@"网家家企业版" forState:UIControlStateNormal];
    [netadd setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]  forState:UIControlStateNormal];
    netadd.titleLabel.font = [UIFont systemFontOfSize:13];
    netadd.imagePosition = QMUIButtonImagePositionTop;
    netadd.spacingBetweenImageAndTitle = 10;
    netadd.adjustsImageWhenHighlighted = NO;
    netadd.userInteractionEnabled = NO;
    [self addSubview:netadd];
    self.netadd = netadd;
    
    UILabel *desc = [[UILabel alloc] initWithFrame:CGRectMake(0, three.bottom+10, SCREEN_WIDTH, btnHeight/2.0)];
     desc.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    desc.font = [UIFont systemFontOfSize:15];
    desc.textAlignment = NSTextAlignmentCenter;
    [self addSubview:desc];
    self.desc = desc;
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, desc.bottom+10, SCREEN_WIDTH, 0.5)];
     line.backgroundColor = [UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1.0];
    [self addSubview:line];
    self.line = line;
    
    UIView *countryBox = [[UIView alloc]initWithFrame:CGRectMake(2*space, self.line.bottom + 2*space, SCREEN_WIDTH  - (4*space), 45)];
    countryBox.layer.cornerRadius = 45/2.0;
    countryBox.layer.masksToBounds = YES;
    countryBox.layer.borderWidth = 0.5;
    countryBox.layer.borderColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0  alpha:1.0].CGColor;
    [self addSubview:countryBox];
    self.countryBox = countryBox;
    
    UIView *telBox = [[UIView alloc]initWithFrame:CGRectMake(_countryBox.left, _countryBox.bottom + space,  _countryBox.width,  _countryBox.height)];
    telBox.layer.cornerRadius = 45/2.0;
    telBox.layer.masksToBounds = YES;
    telBox.layer.borderWidth = 0.5;
    telBox.layer.borderColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0].CGColor;
    [self addSubview:telBox];
    self.telBox = telBox;
    
    UIView *codeBox = [[UIView alloc]initWithFrame:CGRectMake(_telBox.left, _telBox.bottom + space, _telBox.width,   _telBox.height)];
    codeBox.layer.cornerRadius = 45/2.0;
    codeBox.layer.masksToBounds = YES;
    codeBox.layer.borderWidth = 0.5;
    codeBox.layer.borderColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0].CGColor;
    [self addSubview:codeBox];
    self.codeBox = codeBox;
    
//    CNLiveLoginTextField *account = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(0, self.codeBox.height+10, frame.size.width, rowHeight)];
//    account.keyboardType = UIKeyboardTypeNumberPad;
//    account.placeholder = @"请输入手机号";
//    account.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
//    account.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
//    account.font = [UIFont systemFontOfSize:16];
//    account.textAlignment = NSTextAlignmentLeft;
//    [account addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
//    account.clearButtonMode = UITextFieldViewModeWhileEditing;
//    account.delegate = self;
//    [self addSubview:account];
//    self.account = account;
//
//    CNLiveLoginTextField *code = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(account.left, account.bottom+space, frame.size.width/2.0, rowHeight)];
//    code.keyboardType = UIKeyboardTypeNumberPad;
//    code.placeholder = @"请输入验证码";
//    code.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
//    code.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
//    code.font = [UIFont systemFontOfSize:16];
//    code.textAlignment = NSTextAlignmentLeft;
//    [code addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
//    code.clearButtonMode = UITextFieldViewModeWhileEditing;
//    code.delegate = self;
//    [self addSubview:code];
//    self.code = code;
//
//    CNLiveCountDownButton *countDown = [CNLiveCountDownButton buttonWithType:UIButtonTypeCustom];
//    countDown.dataSource = self;
//    countDown.delegate = self;
//    countDown.frame = CGRectMake(frame.size.width-80, account.bottom+space+10, 80, rowHeight-10);
//    UIImage *image2 = [self getImageWithImageName:BusinessLive?@"login_get_code_b":@"login_get_code" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
//    [countDown setImage:image2 forState:UIControlStateNormal];
//    countDown.adjustsImageWhenHighlighted = NO;
//    [countDown setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    countDown.titleLabel.font = [UIFont systemFontOfSize:12.0];
//    countDown.layer.cornerRadius = 15;
//    countDown.layer.masksToBounds = YES;
//    [self addSubview:countDown];
//    self.countDown = countDown;
//
    UIButton *binding = [UIButton buttonWithType:UIButtonTypeCustom];
    binding.frame = CGRectMake(2*space, self.codeBox.bottom+2*space, frame.size.width-4*space, rowHeight);
    [binding setTitle:@"确认手机绑定并同意协议" forState:UIControlStateNormal];
    [binding setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    binding.titleLabel.font = [UIFont systemFontOfSize:15.0];
    UIColor *color = BusinessLive?[UIColor colorWithRed:72/255.0 green:168/255.0 blue:249/255.0 alpha:1.0]:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
    binding.backgroundColor = color;
    binding.layer.cornerRadius = 20;
    binding.layer.masksToBounds = YES;
    binding.adjustsImageWhenHighlighted = NO;
    [binding addTarget:self action:@selector(bindingDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:binding];
    self.binding = binding;
    
}

#pragma mark - CNLiveLoginCountryViewDelegate
- (void)chooseViewController:(CNLiveChooseCountryController *)controller countryName:(NSString *)countryName countryCode:(NSString *)countryCode {
    _countryName = countryName;
    _country.text = countryName;
    _countryCode = countryCode;
    [_code setTitle:[NSString stringWithFormat:@"+%@",countryCode] forState:UIControlStateNormal];
}
#pragma mark - Action
- (void)countryCodeDidClicked:(UIButton *)btn{
    CNLiveChooseCountryController *vc = [[CNLiveChooseCountryController alloc]init];
    vc.delegate = self;
    vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
    vc.hidesBottomBarWhenPushed = YES;
    [CNLivePageJumpManager presentViewController:vc];
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if ([textField isEqual:_telTF] || [textField isEqual:_codeTF]) {
        return YES;
    }
    else {
        return YES;
        
    }
}

- (void)textFieldDidChange:(UITextField *)textField {
    if (![_telTF.text isEqualToString:@""] && ![_codeTF.text isEqualToString:@""]) {
        _binding.enabled = YES;
        
    }
    else {
        _binding.enabled = NO;
        
    }
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if ([textField isEqual:_telTF]) {
        NSInteger maxTextLength  = 20;
        if(string.length == 0) {
            //判断是不是删除键
            return YES;
        }
        else if(textField.text.length >= maxTextLength) {
            NSLog(@"输入的字符个数大于20,忽略输入");
            return NO;
        }
        else if (![self isNum:string]) {
            return NO;
        }
        else if (textField.text.length + string.length > maxTextLength){
            NSInteger length = textField.text.length;
            NSInteger needLen = maxTextLength - length;
            textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]];
            return NO;
        }
        else{
            return YES;
        }
    }
    else if ([textField isEqual:self.code]){
        NSInteger maxTextLength  = 6;
        if(string.length == 0) {
            //判断是不是删除键
            return YES;
        }
        else if(textField.text.length >= maxTextLength) {
            NSLog(@"输入的字符个数大于6,忽略输入");
            return NO;
        }
        else if (![self isNum:string]) {
            return NO;
        }
        else if (textField.text.length + string.length > maxTextLength){
            NSInteger length = textField.text.length;
            NSInteger needLen = maxTextLength - length;
            textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]];
            return NO;
        }
        else{
            return YES;
        }
    }
    else{
        return YES;
    }
}

/** 判断是否为纯数字 */
- (BOOL)isNum:(NSString *)checkedNumString {
    checkedNumString = [checkedNumString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
    if(checkedNumString.length > 0) {
        return NO;
    }
    return YES;
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
#pragma mark - 懒加载
- (UILabel *)country{
    if (!_country) {
        _country = [[UILabel alloc] initWithFrame:CGRectMake(3.5*space, _countryBox.top, SCREEN_WIDTH - (4*space)-70, _countryBox.height)];
        _country.font = [UIFont systemFontOfSize:16.0];
        _country.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
        _country.text = _countryName;
        _country.userInteractionEnabled = YES;
    }
    return _country;
}

- (UIButton *)code{
    if (!_code) {
        _code = [UIButton buttonWithType:UIButtonTypeCustom];
        _code.frame = CGRectMake(SCREEN_WIDTH-3.5*space-70, _countryBox.top, 70, _countryBox.height);
        [_code setTitle:[NSString stringWithFormat:@"+%@",_countryCode] forState:UIControlStateNormal];
        [_code setTitleColor:[UIColor colorWithRed:49/255.0 green:49/255.0 blue:49/255.0 alpha:1.0] forState:UIControlStateNormal];
        _code.titleLabel.font = [UIFont systemFontOfSize:16.0];
        [_code setImage:[self getImageWithImageName:@"login_down" bundleName:@"CNLiveBLoginModule" targetClass:[self class]] forState:UIControlStateNormal];
        _code.adjustsImageWhenHighlighted = NO;
        //button图片的偏移量,距上左下右分别(0, 0, 0, 0)像素点
        _code.imageEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
        //button标题的偏移量,这个偏移量是相对于图片的
        _code.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        [_code addTarget:self action:@selector(countryCodeDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _code;
    
}
- (CNLiveLoginTextField *)telTF {
    if (!_telTF) {
        _telTF = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(3.5*space, _countryBox.bottom + space, SCREEN_WIDTH - (7*space), _countryBox.height)];
        _telTF.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
        _telTF.textColor = [UIColor blackColor];
        _telTF.keyboardType = UIKeyboardTypeNumberPad;
        _telTF.placeholder = @"请输入手机号";
        _telTF.font = UIFontMake(14);
        _telTF.clearButtonMode = UITextFieldViewModeAlways;
        _telTF.textAlignment = NSTextAlignmentLeft;
        _telTF.delegate = self;
    }
    return _telTF;
}

- (CNLiveLoginTextField *)codeTF {
    if (!_codeTF) {
        _codeTF = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(_telTF.left, _telTF.bottom + space, _telTF.width,  _telTF.height)];
        _codeTF.keyboardType = UIKeyboardTypeNumberPad;
        _codeTF.placeholder = @"请输入验证码";
        _codeTF.textColor = [UIColor blackColor];
        _codeTF.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
        _codeTF.font = UIFontMake(14);
        _codeTF.textAlignment = NSTextAlignmentLeft;
        _codeTF.delegate = self;
    }
    return _codeTF;
}

- (CNLiveCountDownButton *)codeBtn {
    if (!_codeBtn) {
        _codeBtn = [CNLiveCountDownButton buttonWithType:UIButtonTypeCustom];
        _codeBtn.frame = CGRectMake(SCREEN_WIDTH-3.5*space-80, _codeTF.top+space/2.0, 80, _telTF.height-space);
        _codeBtn.adjustsImageWhenHighlighted = NO;
        [_codeBtn setTitleColor:[UIColor colorWithRed:72/255.0 green:168/255.0 blue:249/255.0 alpha:1.0] forState:UIControlStateNormal];
        _codeBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        [_codeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        [_codeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
        _codeBtn.backgroundColor = [UIColor whiteColor];
        _codeBtn.delegate = self;
        _codeBtn.dataSource = self;
    }
    return _codeBtn;
}
#pragma mark - CNLiveCountdownButton DataSource
// 设置倒计时总秒数
- (NSInteger)startCountDownNumOfCountDownButton:(CNLiveCountDownButton *)countdownButton {
    return 60;
}

#pragma mark - CNLiveCountdownButton Delegate
// 倒计时按钮点击
- (void)countDownButtonDidClick:(CNLiveCountDownButton *)button {
    //获取验证码
    if ([_telTF.text isEqualToString:@""]) {
        [QMUITips showWithText:@"请输入手机号"];
        return;
    }
    if(![CNLiveNetworking isNetworking]){
        [QMUITips showError:@"无法连接网络" inView:XWKeyWindow hideAfterDelay:timeValue];
        return ;
    }
    _codeTF.text = @"";
    [_code becomeFirstResponder];

    button.userInteractionEnabled = NO;
    [QMUITips showLoadingInView:XWKeyWindow];
    
    [CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeShortcutLogin mobile:_telTF.text countryCode:@"86" success:^(id result) {
        [QMUITips hideAllToastInView:XWKeyWindow animated:YES];
        [QMUITips showWithText:@"验证码已发送"];
        button.frame = CGRectMake(self.frame.size.width-110-2*space, self.telTF.bottom+space+10, 110, rowHeight-10);
        [button setImage:nil forState:UIControlStateNormal];
        NSString *title = [NSString stringWithFormat:@"%d秒后重新发送", 60];
        [button setTitle:title forState:UIControlStateNormal];
        [button startCountDown];


    } failure:^(NSDictionary *errorDic) {
        [QMUITips hideAllToastInView:XWKeyWindow animated:YES];
        if ([errorDic[@"errorCode"] integerValue] == 408) {
            [QMUITips showWithText:@"请输入正确的手机号"];
        }
        else{
            [QMUITips showWithText:errorDic[@"errorMessage"]];
        }
        button.userInteractionEnabled = YES;

    }];
    
}

// 倒计时进行中
- (void)countDownButtonDidCountDown:(CNLiveCountDownButton *)button countDownNum:(NSInteger)countDownNum {
    if(button.frame.size.width != 110){
        button.frame = CGRectMake(self.frame.size.width-110, self.telTF.bottom+space+10, 110, rowHeight-10);
    }
    NSString *title = [NSString stringWithFormat:@"%ld秒后重新发送", countDownNum];
    [button setTitle:title forState:UIControlStateNormal];
    
}

// 倒计时结束
- (void)countDownButtonDidEndCountDown:(CNLiveCountDownButton *)button {
    button.frame = CGRectMake(self.frame.size.width-80, self.telTF.bottom+space+10, 80, rowHeight-10);
    button.backgroundColor = [UIColor whiteColor];
    button.userInteractionEnabled = YES;
    [button setTitle:@"" forState:UIControlStateNormal];
    UIImage *image2 = [self getImageWithImageName:BusinessLive?@"login_get_code_b":@"login_get_code" bundleName:@"CNLiveBLoginModule" targetClass:[self class]];
    [button setImage:image2 forState:UIControlStateNormal];
}

#pragma mark - Action
- (void)bindingDidClicked:(UIButton *)btn{
    if ([self.telTF.text isEqualToString:@""]) {
        [QMUITips showWithText:@"请输入手机号" inView:XWKeyWindow hideAfterDelay:1.5];
        return;
    }
    if ([self.codeTF.text isEqualToString:@""]) {
        [QMUITips showWithText:@"请输入验证码" inView:XWKeyWindow hideAfterDelay:1.5];
        return;
    }
    [self endEditing:YES];
    if(![CNLiveNetworking isNetworking]){
        [QMUITips showError:@"无法连接网络" inView:XWKeyWindow hideAfterDelay:1.5];
        return ;
    }
    btn.userInteractionEnabled = NO;
    // 绑定手机号请求登录
    [self thirdPartyLoginBindingTel];
    
}

// 绑定手机号请求登录
- (void)thirdPartyLoginBindingTel{
    NSDictionary *params = @{
                             @"mobile":self.telTF.text,
                             @"countryCode":_countryCode,
                             @"verificationCode":self.codeTF.text,
                             @"thirdPartyPlat":self.model.thirdPartyPlat?self.model.thirdPartyPlat:@"",
                             @"thirdPartyId":self.model.thirdPartyId?self.model.thirdPartyId:@"",
                             @"frmId":self.model.frmId?self.model.frmId:@"apple",
                             @"clientPlat":@"i",
                             @"nickName":self.model.nickName?self.model.nickName:@"",
                             @"gender":self.model.gender?self.model.gender:@"",
                             @"location":self.model.location?self.model.location:@"",
                             @"faceUrl":self.model.faceUrl?self.model.faceUrl:@""
                             };
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    
    [QMUITips showLoadingInView:XWKeyWindow];
    __weak typeof(self) weakSelf = self;
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNLoginIn3rdAndMobileForWJJUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        if(!strongSelf) return;
        [QMUITips hideAllToastInView:XWKeyWindow animated:YES];
        strongSelf.binding.userInteractionEnabled = YES;
        if (error.code == -1001 || error.code == -1009) {
            [QMUITips showError:@"无法连接网络" inView:XWKeyWindow hideAfterDelay:1.5];
            return ;
        }
        if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
            
            // 给用户库使用
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            [userDefaults setObject:responseObject[@"data"][@"token"] forKey:@"CNLiveAuthToken"];
            [userDefaults setObject:responseObject[@"data"][@"uid"] forKey:@"CNLiveUserSid"];
            [userDefaults synchronize];
            
            //登录成功,连接IM
            [strongSelf connectionIM:responseObject[@"data"]];
        }
        else if ([responseObject isKindOfClass:[NSDictionary class]]) {
            [QMUITips showError:responseObject[@"errorMessage"] inView:XWKeyWindow hideAfterDelay:1.5];
        }
        else{
            [QMUITips showError:@"登录失败" inView:XWKeyWindow hideAfterDelay:1.5];
        }
        
    }];
    
}
- (void)connectionIM:(id)result{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:result[@"data"]];
    NSString *faceUrl = [dic objectForKey:@"faceUrl"];
    if ([faceUrl containsString:@"/mobile/images/mobilehead/default/"]) {
        //网家家默认头像地址
        [dic setValue:CNLiveNetAddDefaultHead forKey:@"faceUrl"];
    }
    [CNUserInfoManager saveUserinfoDic:dic];
    // 连接IM
    __weak typeof(self) weakSelf = self;
    [[CNLiveLoginRequest manager] loginTIM:CNUserShareModel.uid success:^{
        __strong typeof(weakSelf) strongSelf = weakSelf;
        if(!strongSelf) return;
        // 进入tabbar
        [CNLiveNotificationManager postNotificationName:CNLiveLoginSuccess object:nil];

    } failed:^(int code, NSString * _Nonnull msg) {
        // 错误逻辑
        __strong typeof(weakSelf) strongSelf = weakSelf;
        if(!strongSelf) return;

    }];
}

@end