//
|
// HDLFVTempPassViewController.m
|
// Ezviz
|
//
|
// Created by 陈启扬 on 2022/4/22.
|
// Copyright © 2022 hdl. All rights reserved.
|
//
|
|
#import "HDLFVTempPassViewController.h"
|
#import "HDLFVCreateTemPassView.h"
|
#import "HDLFVCommonButton.h"
|
#import "PGDatePickManager.h"
|
#import "HDLFVImageDetail.h"
|
#import "HDLFVVisitorRecordViewController.h"
|
#import "HDLFVAlert.h"
|
#import "HDLFVAddTemPassModel.h"
|
#import "HDLFVCancleTemPModel.h"
|
#import "HDLFVHttpRequestManager.h"
|
|
typedef enum {
|
HDLFVPickTimeType_Effective=0, //生效
|
HDLFVPickTimeType_Expire=1,//失效
|
}HDLFVPickTimeType;
|
|
@interface HDLFVTempPassViewController ()<PGDatePickerDelegate>
|
@property(nonatomic,strong)HDLFVCreateTemPassView *tempView; //临时密码view
|
@property (nonatomic, strong)HDLFVCommonButton *sureBtn;//确认按钮
|
|
@property(nonatomic,strong)PGDatePicker *datePicker;//时间选择器
|
|
@property (nonatomic, copy)NSString *selectedEffectiveTime;//已选择的生效时间
|
@property (nonatomic, copy)NSString *selectedExpireTime;//已选择的失效时间
|
|
@property(nonatomic,assign)HDLFVPickTimeType pickTimeType;//选择时间类型
|
|
@property(nonatomic,strong)HDLFVImageDetail * imgD;//
|
|
@property(nonatomic,strong)HDLFVAddTemPassModel *addTemPModel;//添加临时密码model
|
@property(nonatomic,strong)HDLFVCancleTemPModel *cancleTemPModel;//取消临时密码model
|
|
|
@end
|
|
@implementation HDLFVTempPassViewController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
|
[self setTopBarViewWithTitle:HDLFVLocalizedString(@"Visitor Invitation")];
|
|
if (self.temPassType==HDLFVTemPassType_Generate) {
|
self.rightBtnTitle=HDLFVLocalizedString(@"Visitor Record");
|
}
|
|
// Do any additional setup after loading the view.
|
}
|
|
-(void)addSubViews{
|
|
//确认添加按钮
|
_sureBtn=[[HDLFVCommonButton alloc] init];
|
[self.view addSubview:_sureBtn];
|
[_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerX.equalTo(self.view.mas_centerX);
|
make.bottom.equalTo(self.view).offset(-APP_TAB_BOTTOM_HEIGHT-20);
|
make.height.mas_equalTo(44);
|
make.width.mas_equalTo(HDLFVGetRealWidth(220));
|
}];
|
if (self.temPassType==HDLFVTemPassType_Detail) {
|
_sureBtn.titleName=HDLFVLocalizedString(@"Cancle Visitor Credentials");
|
}else{
|
_sureBtn.titleName=HDLFVLocalizedString(@"Generate Visitor Credentials");
|
}
|
[_sureBtn addTarget:self action:@selector(sure) forControlEvents:UIControlEventTouchDown];
|
|
|
|
//临时密码view
|
_tempView=[[HDLFVCreateTemPassView alloc] init];
|
[self.view addSubview:_tempView];
|
[_tempView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view).offset(APP_TOP_BAR_HEIGHT);
|
make.left.right.equalTo(self.view);
|
make.bottom.equalTo(_sureBtn.mas_top).offset(-5);
|
}];
|
_tempView.temPassType=self.temPassType;
|
WeakSelf(weakSelf);
|
_tempView.validTimeV.clickBtn = ^{
|
[weakSelf selectEffectiveTime];
|
};
|
|
_tempView.expireTimeV.clickBtn = ^{
|
[weakSelf selectExpirationTime];
|
};
|
|
_tempView.temPassInputV.clickBtn = ^{
|
[weakSelf genarateTemPass];
|
};
|
|
_tempView.clickQRCodeBlock = ^(UIImage * _Nonnull image) {
|
[weakSelf tapQRCode:image];
|
};
|
|
_tempView.longTapQRCodeBlock = ^(UIImage * _Nonnull image) {
|
[weakSelf longTapQRCode:image];
|
|
};
|
|
//展示临时凭证详情
|
if (self.temPassType==HDLFVTemPassType_Detail) {
|
|
_tempView.phoneInputV.inputTextF.text=self.temPdetailModel.phone;
|
_tempView.temPassInputV.inputTextF.text=self.temPdetailModel.tempPwd;
|
// _tempView.useTimesInputV.inputTextF.text=self.temPdetailModel.useCount;
|
_tempView.validTimeV.contentL.text=[Constants turnDateString:self.temPdetailModel.validBeginTime toFormater:[NSString stringWithFormat:@"yyyy%@MM%@dd%@ HH:mm",HDLFVLocalizedString(@"Y"),HDLFVLocalizedString(@"M"),HDLFVLocalizedString(@"D")]];
|
_tempView.expireTimeV.contentL.text=[Constants turnDateString:self.temPdetailModel.validEndTime toFormater:[NSString stringWithFormat:@"yyyy%@MM%@dd%@ HH:mm",HDLFVLocalizedString(@"Y"),HDLFVLocalizedString(@"M"),HDLFVLocalizedString(@"D")]];
|
|
_tempView.QRCodeImageV.image=[Constants creatCIQRCodeImage:_tempView.temPassInputV.inputTextF.text];
|
self.selectedEffectiveTime=self.temPdetailModel.validBeginTime;
|
self.selectedExpireTime=self.temPdetailModel.validEndTime;
|
[_tempView showQRCode:YES];
|
HDLFVLog(@"tempId吧:%@",self.temPdetailModel.ID);
|
|
//判断是否过期
|
// NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
// [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
|
// NSDate *date = [dateFormatter dateFromString:self.temPdetailModel.validEndTime];
|
// if ([Constants compareOneDay:[NSDate date] withAnotherDay:date]==1) {
|
// _tempView.isInvalid=YES;
|
// }
|
|
if (!self.temPdetailModel.status) {
|
HDLFVLog(@"密码无效");
|
_tempView.isInvalid=YES;
|
[_sureBtn setHidden:YES];
|
}
|
|
}
|
|
}
|
|
//点击导航栏右边按钮
|
-(void)clickRightBtn{
|
HDLFVLog(@"点击了右边按钮");
|
HDLFVVisitorRecordViewController *vc=[[HDLFVVisitorRecordViewController alloc] init];
|
[self.navigationController setNavigationBarHidden:YES];
|
[self.navigationController pushViewController:vc animated:YES];
|
}
|
|
|
/*点击了生成临时密码
|
*/
|
-(void)genarateTemPass{
|
HDLFVLog(@"点击生成动态码");
|
_tempView.temPassInputV.inputTextF.text=[FVTool randomNumerWithCount:6];
|
|
}
|
|
/*点击了选择生效时间
|
*/
|
-(void)selectEffectiveTime{
|
self.pickTimeType=HDLFVPickTimeType_Effective;
|
[self showDatePicker];
|
}
|
|
/*点击了选择失效时间
|
*/
|
-(void)selectExpirationTime{
|
self.pickTimeType=HDLFVPickTimeType_Expire;
|
[self showDatePicker];
|
|
}
|
|
/*点击了确认按钮
|
*/
|
-(void)sure{
|
if (_tempView.phoneInputV.inputTextF.text.length==0||_tempView.phoneInputV.inputTextF.text.length!=11) {
|
[HDLToast showTostWithMessage:HDLFVLocalizedString(@"Please enter a correct phone number")];
|
return;
|
}
|
if (_tempView.temPassInputV.inputTextF.text.length!=6) {
|
[HDLToast showTostWithMessage:HDLFVLocalizedString(@"Input 6-digits temporary password")];
|
return;
|
}
|
// if (_tempView.useTimesInputV.inputTextF.text.length==0) {
|
// [HDLToast showTostWithMessage:HDLFVLocalizedString(@"Input usage times")];
|
// return;
|
// }
|
if (self.selectedEffectiveTime.length==0) {
|
[HDLToast showTostWithMessage:HDLFVLocalizedString(@"Please select a effective time")];
|
return;
|
}
|
if (self.selectedExpireTime.length==0) {
|
[HDLToast showTostWithMessage:HDLFVLocalizedString(@"Please select a expire time")];
|
return;
|
}
|
|
WeakSelf(weakSelf);
|
HDLFVAlert *alert=[[HDLFVAlert alloc] init];
|
if (self.temPassType==HDLFVTemPassType_Generate) {
|
self.addTemPModel=[[HDLFVAddTemPassModel alloc] init];
|
self.addTemPModel.homeId=[HDLFVHttpRequestManager sharedInstance].currentUserId;
|
self.addTemPModel.phone=_tempView.phoneInputV.inputTextF.text;
|
self.addTemPModel.tempPwd=_tempView.temPassInputV.inputTextF.text;
|
self.addTemPModel.useCount=@"10000";
|
// _addTemPModel.deviceId=_deviceId;
|
self.addTemPModel.validBeginTime=self.selectedEffectiveTime;
|
self.addTemPModel.validEndTime=self.selectedExpireTime;
|
|
HDLFVLog(@"生成:%@",self.addTemPModel);
|
|
[alert showAlertWithTitle:HDLFVLocalizedString(@"Tips") message:HDLFVLocalizedString(@"After confirmation, the visitor QR code will be generated, and the 6-digit dynamic digital password SMS will also be sent to the visitor's mobile phone.") height:158 cancle:^{
|
} sure:^{
|
HDLFVLog(@"点击了确认");
|
[weakSelf generateCredentials];
|
}];
|
}else{
|
[alert showAlertWithTitle:HDLFVLocalizedString(@"Tips") message:HDLFVLocalizedString(@"You are canceling visitor credentials") height:158 cancle:^{
|
} sure:^{
|
HDLFVLog(@"点击了确认");
|
[weakSelf cancleCredentials];
|
}];
|
}
|
|
}
|
|
/*点击了二维码
|
*/
|
-(void)tapQRCode:(UIImage *)QRImage{
|
HDLFVLog(@"点击了二维码");
|
_imgD=[[HDLFVImageDetail alloc] init];
|
[_imgD showImage:QRImage describe:HDLFVLocalizedString(@"Long press the QR code to save the QR code to the album")];
|
|
}
|
|
/*长按二维码
|
*/
|
-(void)longTapQRCode:(UIImage*)QRCImage{
|
|
[Constants saveImageToPhotosAlbum:QRCImage];
|
}
|
|
/*展示时间选择器
|
*/
|
-(void)showDatePicker{
|
PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
|
datePickManager.isShadeBackgroud = true;
|
self.datePicker = datePickManager.datePicker;
|
self.datePicker.delegate = self;
|
|
datePickManager.confirmButtonTextColor=HDLFV_COLOR_TEXT_LIGHT_BLUE;
|
datePickManager.confirmButtonFont=HDLFV_Get_FontRegularWithSize(HDLFV_FontSize_16);
|
datePickManager.headerViewBackgroundColor=HDLFV_COLOR_NAV_BACKGROUND;
|
datePickManager.cancelButtonTextColor=HDLFV_COLOR_TEXT_TITLE_GRAY;
|
datePickManager.cancelButtonFont=HDLFV_Get_FontRegularWithSize(HDLFV_FontSize_16);
|
|
self.datePicker.datePickerMode = PGDatePickerModeDateHourMinute;
|
[self presentViewController:datePickManager animated:false completion:nil];
|
|
}
|
|
/*生成临时凭证
|
*/
|
-(void)generateCredentials{
|
WeakSelf(weakSelf);
|
[HDLFVHUD showHudInView:self.view];
|
[[HDLFVHttpRequestManager sharedInstance] addTemPassWithAddTemPassModel:self.addTemPModel success:^(NSString *_Nullable tempId) {
|
[HDLFVHUD hideHUDForView:weakSelf.view];
|
[weakSelf generateTempSuccess:tempId];
|
} fail:^(NSError * _Nullable error) {
|
[HDLFVHUD hideHUDForView:weakSelf.view];
|
[HDLToast showTostWithMessage:error.localizedDescription];
|
}];
|
}
|
|
/*取消临时凭证
|
*/
|
-(void)cancleCredentials{
|
WeakSelf(weakSelf);
|
[HDLFVHUD showHudInView:self.view];
|
_cancleTemPModel=[[HDLFVCancleTemPModel alloc] init];
|
_cancleTemPModel.homeId=[HDLFVHttpRequestManager sharedInstance].currentUserId;
|
HDLFVLog(@"tempId:%@",self.temPdetailModel.ID);
|
_cancleTemPModel.ID=self.temPdetailModel.ID;
|
[[HDLFVHttpRequestManager sharedInstance] deleteTemPassWithAddTemPassModel:_cancleTemPModel success:^{
|
[HDLFVHUD hideHUDForView:weakSelf.view];
|
[weakSelf cancleTempSuccess];
|
} fail:^(NSError * _Nullable error) {
|
[HDLFVHUD hideHUDForView:weakSelf.view];
|
[HDLToast showTostWithMessage:error.localizedDescription];
|
}];
|
}
|
|
/*生成临时凭证成功
|
*/
|
-(void)generateTempSuccess:(NSString*)tempId{
|
[_tempView showQRCode:YES];
|
_tempView.QRCodeImageV.image=[Constants creatCIQRCodeImage:_tempView.temPassInputV.inputTextF.text];
|
_tempView.temPassType=HDLFVTemPassType_Detail;
|
HDLFVLog(@"tempId:%@",tempId);
|
self.temPdetailModel=[[HDLFVTemPDetailModel alloc] init];
|
self.temPdetailModel.ID=tempId;
|
_sureBtn.titleName=HDLFVLocalizedString(@"Cancle Visitor Credentials");
|
self.temPassType=HDLFVTemPassType_Detail;
|
}
|
|
/*取消临时凭证成功
|
*/
|
-(void)cancleTempSuccess{
|
if (_isShowDetail) {
|
[[NSNotificationCenter defaultCenter] postNotificationName:HDLFVNotificationChangeTemP object:nil];
|
[self.navigationController popViewControllerAnimated:YES];
|
}else{
|
[self.navigationController popViewControllerAnimated:YES];
|
//
|
// _tempView.temPassType=HDLFVTemPassType_Generate;
|
// _sureBtn.titleName=HDLFVLocalizedString(@"Generate Visitor Credentials");
|
// self.temPassType=HDLFVTemPassType_Generate;
|
}
|
}
|
|
|
#pragma PGDatePickerDelegate
|
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
|
|
NSString *sendTimeStr=[NSString stringWithFormat:@"%ld-%@-%@ %@:%@:00",dateComponents.year,[Constants autoFillZero:dateComponents.month],[Constants autoFillZero:dateComponents.day],[Constants autoFillZero:dateComponents.hour],[Constants autoFillZero:dateComponents.minute]];//请求接口格式的时间
|
NSString *showTimeStr=[NSString stringWithFormat:@"%ld%@%@%@%@%@ %@:%@",dateComponents.year,HDLFVLocalizedString(@"Y"),[Constants autoFillZero:dateComponents.month],HDLFVLocalizedString(@"M"),[Constants autoFillZero:dateComponents.day],HDLFVLocalizedString(@"D"),[Constants autoFillZero:dateComponents.hour],[Constants autoFillZero:dateComponents.minute]];//展示格式的时间
|
|
if (self.pickTimeType==HDLFVPickTimeType_Effective) {
|
self.selectedEffectiveTime=sendTimeStr;
|
_tempView.validTimeV.contentL.text=showTimeStr;
|
}else{
|
self.selectedExpireTime=sendTimeStr;
|
_tempView.expireTimeV.contentL.text=showTimeStr;
|
|
}
|
|
}
|
@end
|