CNLiveUpdateTelController.m 9.47 KB
//
//  CNLiveUpdateTelController.m
//  CNLiveSettingModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveUpdateTelController.h"
#import "CNLiveChooseCountryController.h"
#import "YYKit.h"
#import <Masonry/Masonry.h>
#import "QMUIKit.h"

#import <CNLiveUserSystemSDK/CNLiveUserSystemCenter.h>
#import "CNUserInfoManager.h"
#import "NSString+CNLiveExtension.h"

#import "CNLiveSettingNavigationBar.h"
#import "CNLiveUpdateTelView.h"

@interface CNLiveUpdateTelController()<UITextFieldDelegate, CNLiveSettingNavigationBarDelegate, CNLiveUpdateTelViewDelegate, ChooseCountriesDelegate>

@property (nonatomic, strong) CNLiveSettingNavigationBar *navigationBar;
@property (nonatomic, strong) CNLiveUpdateTelView *updateTel;//背景
@property (nonatomic, strong) YYLabel *connection;

@end

@implementation CNLiveUpdateTelController
static const NSInteger timeValue = 1.5;

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
    
    [self createSubViews];
    [self xw_layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {

    }];
    QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
          __strong typeof(weakSelf) strongSelf = weakSelf;
          if(!strongSelf) return ;
          [strongSelf.navigationController popViewControllerAnimated:YES];

      }];
           
    QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"更换手机号将只能使用新绑定的手机号登录app,是否继续修改?" message:@"" preferredStyle:QMUIAlertControllerStyleAlert];
    [alertController addAction:sure];
    [alertController addAction:cancel];
    
    NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
           
    titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
    
    NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
    cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];

    sure.buttonAttributes = titleAttributs;
    cancel.buttonAttributes = cancelAttributs;

    [alertController showWithAnimated:YES];
    
}

#pragma mark - UI
- (void)createSubViews{
    [self.view addSubview:self.navigationBar];
    [self.view addSubview:self.updateTel];
    [self.view addSubview:self.connection];
}

- (void)xw_layoutSubviews{
    [self.updateTel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(NavigationContentTop+1);
        make.height.mas_equalTo(220);
    }];
    [self.connection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).offset(-30);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - ChooseCountriesDelegate
- (void)chooseViewController:(CNLiveChooseCountryController *)controller countryName:(NSString *)name countryCode:(NSString *)code{
    _updateTel.countryName.text = name;
    _updateTel.countryCode.text = [NSString stringWithFormat:@"+%@",code];
    _updateTel.codeNum = code;

}

#pragma mark - CNLiveUpdateTelViewDelegate
- (void)selectCountry:(CNLiveUpdateTelView *)view{
    CNLiveChooseCountryController *vc = [[CNLiveChooseCountryController alloc]init];
    vc.delegate = self;
    vc.hidesBottomBarWhenPushed = YES;
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)bindingSuccess:(CNLiveUpdateTelView *)view{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.updateTel.telTF resignFirstResponder];
}

#pragma mark - Lazy Loading
- (CNLiveSettingNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [[CNLiveSettingNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
        _navigationBar.backgroundColor = [UIColor whiteColor];
        _navigationBar.delegate = self;
        _navigationBar.title.text = @"更换手机号";
        _navigationBar.right = nil;
    }
    return _navigationBar;
}

- (CNLiveUpdateTelView *)updateTel{
    if (!_updateTel) {
        _updateTel = [[CNLiveUpdateTelView alloc] init];
        _updateTel.delegate = self;
        _updateTel.codeNum = @"86";
    }
    return _updateTel;
}

- (YYLabel *)connection {
    if (!_connection) {
        _connection = [[YYLabel alloc] init];
        [_connection setFont:UIFontMake(12)];
        _connection.numberOfLines = 0;
        NSString *str = @"若当前号码已不用或丢失,请点击联系客服";
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
        text.color = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1.0];
        [text setTextHighlightRange:NSMakeRange(text.length-4, 4) color:[UIColor colorWithRed:44/255.0 green:209/255.0 blue:201/255.0 alpha:1.0] backgroundColor:[UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            
            NSString *phoneStr = @"010-65832485";
            
            QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"好" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
                if (@available(iOS 10.0, *)) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneStr]] options:@{} completionHandler:nil];
                } else {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneStr]]];
                }

            }];
            QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
            }];
                   
            QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"联系客服" message:[NSString stringWithFormat:@"将给%@拨打电话",phoneStr] preferredStyle:QMUIAlertControllerStyleAlert];
            [alertController addAction:sure];
            [alertController addAction:cancel];
            
            NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
                   
            titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
            
            NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
            cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];

            sure.buttonAttributes = titleAttributs;
            cancel.buttonAttributes = cancelAttributs;

            [alertController showWithAnimated:YES];
            
        } ];
        _connection.attributedText = text;
        _connection.textAlignment = NSTextAlignmentCenter;
        
    }
    return _connection;
}

/*
#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.
}
*/

/**
 *  创建图片
 *
 *  @param imageName 图片名字
 *  @param bundleName 图片所在的bundle名字
 *  @param targetClass 类和bundle的同级目录
 *  @return 返回UIImage
 */
- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
    NSBundle *bundle = [NSBundle bundleForClass:targetClass];
    NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
    NSBundle *targetBundle = [NSBundle bundleWithURL:url];
    UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
    return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
}

#pragma mark - CNLiveSettingNavigationBarDelegate
- (void)navigationBar:(CNLiveSettingNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
    if ([actionEvents isEqualToString:@"1"]) {
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([actionEvents isEqualToString:@"2"]){
        
    }
}

@end