<template>
	<view class="content">
		<text class="title">{{ title }}</text>
		<view>
	
			     <image
			          v-bind:src="imageUlr"
			         style="width:204rpx; height: 256rpx;" 
					  >
			        </image>
			<view
			class="resultInfor"
			style="white-space: pre-wrap;"
			>{{ result }}</view>
			
			<button type="primary" @click="open">打开设备</button>
			<button type="primary" @click="readIDCard">读取身份证</button>
			<button type="primary" @click="close">关闭设备</button>
			<!-- <view class="">
				{{result1}}
			</view> -->
			
		</view>
	</view>
</template>

<script>
const  termbSDK = uni.requireNativePlugin('Card-Module');
  
export default {
	data() {
		return {
			title: '欢迎使用termb SDK',
			result: '请先打开读卡设备',
			result1:0,
			imageUlr: '',
		};
		
		
	},
	onLoad() {},
	methods: {
				
		open(){
			
			termbSDK.Open(data => {
					if(data.result == 0){
						this.result = "打开设备成功"
					}else if(data.result == -2){
						this.result = "打开设备失败：未发现读卡器";
					}else if(data.result == -4){
						this.result = "打开设备失败：未获取usb权限";
					}else {
						this.result = "打开设备失败："+data.result;
					}
		
				});

		},		
		close(){
			
		let ret =  termbSDK.Close();
		if(ret == 0){
			this.result ="关闭设备成功";
		}else{
			this.result ="关闭设备失败 "+ret;
		}
		
		},
		readIDCard(){
			
			let idInfo = termbSDK.ReadIDCard(1);
		
			if(idInfo.code == 0){
					this.result = "中文姓名："+ idInfo.name+"\n"
                    +"英文姓名："+ idInfo.enFullName+"\n"
                    +"性    别："+ idInfo.sex+"\n"
                    +"民    族："+ idInfo.nation+"\n"
                    +"出身日期："+ idInfo.birthDate+"\n"
                    +"家庭住址："+ idInfo.address+"\n"
                    +"身份证号："+ idInfo.idNO+"\n"
                    +"签发单位："+ idInfo.organs+"\n"
                    +"开始有效期限："+ idInfo.issueDate+"\n"
                    +"结束有效期限："+ idInfo.expireDate+"\n"
                    +"证件类别："+ idInfo.certType+"\n"
                    +"证件版本："+ idInfo.certVersion+"\n"
					+"英文姓名备用："+ idInfo.reserveName+"\n"
					+"既往版本号码："+ idInfo.previousVersionNO+"\n"
                    +"通行证号："+ idInfo.passNu+"\n"
                    +"签发数次："+ idInfo.signCount+"\n"
					+"指纹数据："+ idInfo.figData+"\n"
					this.imageUlr = "data:image/png;base64,"+idInfo.headStr;
			}else{
				this.result = idInfo.code;	
			}
		
		}
	}
};
</script>

<style>
.content {
	text-align: left;
	height: 400upx;
}
.resultInfor {
	text-align: left;
}

.title {
	font-size: 36upx;
	color: #8f8f94;
}

button {
	margin-top: 20upx;
	margin-bottom: 20upx;
}

.button-sp-area {
	margin: 0 auto;
	width: 60%;
}

.content {
	text-align: center;
	height: 400upx;
}

.wrapper {
	flex-direction: column;
	justify-content: center;
}

.button {
	width: 200px;
	margin-top: 20px;
	margin-left: 20px;
	padding-top: 20px;
	padding-bottom: 20px;
	border-width: 2px;
	border-style: solid;
	border-color: #458b00;
	background-color: #458b00;
}

.text {
	font-size: 30px;
	color: #666666;
	text-align: center;
}
</style>
