|
|
|
//
|
|
|
|
// CommonPopView.m
|
|
|
|
// tongxin
|
|
|
|
//
|
|
|
|
// Created by ecell on 2023/5/26.
|
|
|
|
// Copyright © 2023 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "CommonPopView.h"
|
|
|
|
#import <SMS_SDK/SMSSDK.h>
|
|
|
|
#import "User.h"
|
|
|
|
|
|
|
|
@interface CommonPopView ()<UITextFieldDelegate>
|
|
|
|
|
|
|
|
/// 背景
|
|
|
|
@property (nonatomic ,weak) UIView *bgView;
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *phoneField;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *codeField;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UIButton *codeBtn;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CommonPopView
|
|
|
|
|
|
|
|
+ (instancetype)sharedManager{
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
static CommonPopView *instance;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
instance = [[CommonPopView alloc] init];
|
|
|
|
});
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame
|
|
|
|
{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
self.frame = [UIScreen mainScreen].bounds;
|
|
|
|
self.backgroundColor = RGBA(0, 0, 0, 0.4);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)subPopView:(popViewType)type
|
|
|
|
PopTitle:(NSString *)title
|
|
|
|
PopText:(NSString *)texts
|
|
|
|
okTouchBlock:(void (^)(void))okTouchBlock
|
|
|
|
{
|
|
|
|
CGSize bgSize;
|
|
|
|
switch (type) {
|
|
|
|
case popViewType_dzwl:
|
|
|
|
bgSize = CGSizeMake(311, 206);
|
|
|
|
break;
|
|
|
|
case popViewType_czsb:
|
|
|
|
bgSize = CGSizeMake(311, 254);
|
|
|
|
break;
|
|
|
|
case popViewType_ycgj:
|
|
|
|
case popViewType_tjlxr:
|
|
|
|
case popViewType_binding:
|
|
|
|
bgSize = CGSizeMake(311, 182);
|
|
|
|
break;
|
|
|
|
case popViewType_jbsb:
|
|
|
|
bgSize = CGSizeMake(311, 230);
|
|
|
|
break;
|
|
|
|
case popViewType_outLogin:
|
|
|
|
bgSize = CGSizeMake(311, 146);
|
|
|
|
break;
|
|
|
|
case popViewType_zx:
|
|
|
|
bgSize = CGSizeMake(311, 205);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:12 borderWidth:0 borderColor:KKWhiteColorColor];
|
|
|
|
self.bgView = bgView;
|
|
|
|
[self addSubview:bgView];
|
|
|
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.equalTo(self);
|
|
|
|
make.centerY.equalTo(self);
|
|
|
|
make.size.mas_equalTo(bgSize);
|
|
|
|
}];
|
|
|
|
|
|
|
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(18) textColor:KKBlack20 text:title Radius:0];
|
|
|
|
[bgView addSubview:titleLabel];
|
|
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.equalTo(bgView);
|
|
|
|
make.top.equalTo(bgView).offset(28);
|
|
|
|
}];
|
|
|
|
|
|
|
|
UILabel *textLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(16) textColor:KKGrey102 text:@"" Radius:0];
|
|
|
|
textLabel.attributedText = [self labelFontSize:texts];
|
|
|
|
[bgView addSubview:textLabel];
|
|
|
|
[textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.equalTo(bgView).inset(24);
|
|
|
|
make.top.equalTo(titleLabel.mas_bottom).offset(15);
|
|
|
|
}];
|
|
|
|
|
|
|
|
UIButton *escBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(16) normalColor:KKBlack20 normalText:type == popViewType_tjlxr ? @"容我想想" : @"取消" click:^(id x) {
|
|
|
|
[self dismiss];
|
|
|
|
}];
|
|
|
|
escBtn.layer.borderWidth = 1;
|
|
|
|
escBtn.layer.borderColor = RGB(240, 239, 237).CGColor;
|
|
|
|
escBtn.layer.cornerRadius = 24;
|
|
|
|
//view.layer.masksToBounds = YES;
|
|
|
|
[bgView addSubview:escBtn];
|
|
|
|
[escBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.equalTo(bgView.mas_bottom).inset(28);
|
|
|
|
make.left.equalTo(bgView).offset(24);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(125, 48));
|
|
|
|
}];
|
|
|
|
|
|
|
|
UIButton *okBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(16) normalColor:KKWhiteColorColor normalText:type == popViewType_dzwl ? @"去开启" : @"确定" click:^(id x) {
|
|
|
|
okTouchBlock();
|
|
|
|
[self dismiss];
|
|
|
|
}];
|
|
|
|
okBtn.backgroundColor = mainColor;
|
|
|
|
okBtn.layer.cornerRadius = 24;
|
|
|
|
okBtn.layer.masksToBounds = YES;
|
|
|
|
[bgView addSubview:okBtn];
|
|
|
|
[okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerY.equalTo(escBtn);
|
|
|
|
make.right.equalTo(bgView.mas_right).inset(24);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(125, 48));
|
|
|
|
}];
|
|
|
|
[self showPopView];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 绑定手机号弹窗
|
|
|
|
- (void)bangdinPhone
|
|
|
|
{
|
|
|
|
WEAKSELF
|
|
|
|
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:12 borderWidth:0 borderColor:KKWhiteColorColor];
|
|
|
|
self.bgView = bgView;
|
|
|
|
[self addSubview:bgView];
|
|
|
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.equalTo(self);
|
|
|
|
make.centerY.equalTo(self);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(331, 300));
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(18) textColor:KKBlack20 text:@"添加设备需要先绑定家长手机号码" Radius:0];
|
|
|
|
[bgView addSubview:titleLabel];
|
|
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.equalTo(bgView).inset(10);
|
|
|
|
make.top.equalTo(bgView).offset(24);
|
|
|
|
}];
|
|
|
|
|
|
|
|
for (NSInteger i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
UITextField *textField = [UICommon ui_textField:CGRectZero textColor:KKTextBlackColor backColor:KKClearColor font:Font_(15) maxTextNum:11 placeholderColor:KKGrey102 placeholder:i == 0 ? @"请输入手机号" : @"请输入验证码" toMaxNum:nil change:nil];
|
|
|
|
textField.delegate = self;
|
|
|
|
textField.clearButtonMode = UITextFieldViewModeAlways;
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
textField.keyboardType = UIKeyboardTypePhonePad;
|
|
|
|
self.phoneField = textField;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textField.keyboardType = UIKeyboardTypeNumberPad;
|
|
|
|
self.codeField = textField;
|
|
|
|
}
|
|
|
|
|
|
|
|
[bgView addSubview:textField];
|
|
|
|
[textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.equalTo(bgView).inset(20);
|
|
|
|
make.top.equalTo(titleLabel.mas_bottom).offset(28+i*55);
|
|
|
|
make.height.mas_equalTo(55);
|
|
|
|
}];
|
|
|
|
|
|
|
|
UILabel *line = [UILabel new];
|
|
|
|
line.backgroundColor = RGB(240, 240, 240);
|
|
|
|
[bgView addSubview:line];
|
|
|
|
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.equalTo(bgView).inset(20);
|
|
|
|
make.top.equalTo(textField.mas_bottom);
|
|
|
|
make.height.mas_equalTo(0.5);
|
|
|
|
}];
|
|
|
|
if (i == 1)
|
|
|
|
{
|
|
|
|
UIButton *codeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontBold_(15) normalColor:mainColor normalText:@"获取验证码" click:^(id x) {
|
|
|
|
if (self.phoneField.text.length != 11)
|
|
|
|
{
|
|
|
|
[UICommon resignKeyboard];
|
|
|
|
[UICommon MessageErrorText:@"请输入正确手机号码"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.phoneField.text zone:@"86" template:nil result:^(NSError *error) {
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
NSLog(@"err=%@",error);
|
|
|
|
[UICommon resignKeyboard];
|
|
|
|
[UICommon MessageErrorText:@"验证码发送失败"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[UICommon MessageSuccessText:@"验证码发送成功" isImg:YES];
|
|
|
|
[weakSelf startTimer];
|
|
|
|
[self.codeField becomeFirstResponder];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
self.codeBtn = codeBtn;
|
|
|
|
[bgView addSubview:codeBtn];
|
|
|
|
[codeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.right.equalTo(textField.mas_right);
|
|
|
|
make.centerY.equalTo(textField);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(100, 55));
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UIButton *escBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(16) normalColor:KKBlack20 normalText:@"取消" click:^(id x) {
|
|
|
|
[self dismiss];
|
|
|
|
}];
|
|
|
|
escBtn.layer.borderWidth = 1;
|
|
|
|
escBtn.layer.borderColor = RGB(240, 239, 237).CGColor;
|
|
|
|
escBtn.layer.cornerRadius = 24;
|
|
|
|
//view.layer.masksToBounds = YES;
|
|
|
|
[bgView addSubview:escBtn];
|
|
|
|
[escBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.equalTo(bgView.mas_bottom).inset(28);
|
|
|
|
make.left.equalTo(bgView).offset(24);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(125, 48));
|
|
|
|
}];
|
|
|
|
|
|
|
|
UIButton *okBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(16) normalColor:KKWhiteColorColor normalText: @"确定" click:^(id x) {
|
|
|
|
|
|
|
|
[UICommon resignKeyboard];
|
|
|
|
[SMSSDK commitVerificationCode:weakSelf.codeField.text phoneNumber:weakSelf.phoneField.text zone:@"86" result:^(NSError *error) {
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
[UICommon MessageUpload:@"绑定中..."];
|
|
|
|
[User wxUserApplyPhone:weakSelf.phoneField.text success:^(id responseObject) {
|
|
|
|
[UICommon HidenLoading];
|
|
|
|
[weakSelf dismiss];
|
|
|
|
[UICommon MessageSuccessText:@"绑定手机号成功,请添加设备." isImg:YES];
|
|
|
|
|
|
|
|
AfterDispatch(1, ^{
|
|
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
|
|
|
|
UINavigationController *vc = [sb instantiateViewControllerWithIdentifier:@"ScanCodeViewController"];
|
|
|
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
|
|
|
|
});
|
|
|
|
//刷新数据
|
|
|
|
} failure:^(id faiObject) {
|
|
|
|
[UICommon MessageErrorText:@"绑定失败"];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[UICommon MessageErrorText:@"验证码验证失败"];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
okBtn.backgroundColor = mainColor;
|
|
|
|
okBtn.layer.cornerRadius = 24;
|
|
|
|
okBtn.layer.masksToBounds = YES;
|
|
|
|
[bgView addSubview:okBtn];
|
|
|
|
[okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerY.equalTo(escBtn);
|
|
|
|
make.right.equalTo(bgView.mas_right).inset(24);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(125, 48));
|
|
|
|
}];
|
|
|
|
[self showPopView];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)showPopView
|
|
|
|
{
|
|
|
|
[self showWithAlert:self.bgView];
|
|
|
|
[[UIApplication sharedApplication].delegate.window addSubview:self];;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
添加Alert入场动画
|
|
|
|
@param alert 添加动画的View
|
|
|
|
*/
|
|
|
|
- (void)showWithAlert:(UIView*)alert
|
|
|
|
{
|
|
|
|
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
|
|
|
|
animation.duration = 0.6;
|
|
|
|
NSMutableArray *values = [NSMutableArray array];
|
|
|
|
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
|
|
|
|
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
|
|
|
|
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
|
|
|
|
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
|
|
|
|
animation.values = values;
|
|
|
|
[alert.layer addAnimation:animation forKey:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismiss
|
|
|
|
{
|
|
|
|
[UICommon resignKeyboard];
|
|
|
|
[UIView animateWithDuration:0.6f animations:^{
|
|
|
|
self.backgroundColor = [UIColor clearColor];
|
|
|
|
self.alpha = 0;
|
|
|
|
}completion:^(BOOL finished) {
|
|
|
|
[self removeFromSuperview];
|
|
|
|
} ];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *)labelFontSize:(NSString *)text
|
|
|
|
{
|
|
|
|
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text];
|
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
|
|
paragraphStyle.lineSpacing = 5;
|
|
|
|
paragraphStyle.alignment = NSTextAlignmentCenter;
|
|
|
|
[string addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dispatch_source_t _timer;
|
|
|
|
|
|
|
|
- (void)startTimer
|
|
|
|
{
|
|
|
|
[self resetTimer];
|
|
|
|
WEAKSELF
|
|
|
|
__block int timeout = 60; //倒计时时间
|
|
|
|
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
|
|
|
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
|
|
|
|
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
|
|
|
|
dispatch_source_set_event_handler(_timer, ^{
|
|
|
|
if(timeout <=0 ){ //倒计时结束,关闭
|
|
|
|
dispatch_source_cancel(_timer);
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
//设置界面的按钮显示 根据自己需求设置
|
|
|
|
[weakSelf.codeBtn setUserInteractionEnabled:YES];
|
|
|
|
[weakSelf.codeBtn setTitle:@"获取验证码" forState:0];
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
//int minutes = timeout / 60;
|
|
|
|
//int seconds = timeout % 60;
|
|
|
|
NSString *strTime = [NSString stringWithFormat:@"重新发送(%.2d)", timeout];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
//设置界面的按钮显示 根据自己需求设置
|
|
|
|
NSLog(@"____%@",strTime);
|
|
|
|
[weakSelf.codeBtn setUserInteractionEnabled:NO];
|
|
|
|
[weakSelf.codeBtn setTitle:strTime forState:0];
|
|
|
|
|
|
|
|
});
|
|
|
|
timeout--;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dispatch_resume(_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetTimer {
|
|
|
|
if (_timer) {
|
|
|
|
dispatch_source_cancel(_timer);
|
|
|
|
_timer = nil;
|
|
|
|
}
|
|
|
|
[self.codeBtn setUserInteractionEnabled:YES];
|
|
|
|
[self.codeBtn setTitle:@"获取验证码" forState:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[self resetTimer];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
|
// An empty implementation adversely affects performance during animation.
|
|
|
|
- (void)drawRect:(CGRect)rect {
|
|
|
|
// Drawing code
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
@end
|