<template>
	<button type="default" @click="buclick">点击微信扫一扫</button>
</template>

<script>
	import { _API_GzhWebInits } from '@/apis/verify.js'
	import { mapState } from 'vuex'
	export default {
		name: 'ShareIndex',
		data() {
			return {
				src: ''
			}
		},
		computed: {
			...mapState([
				'userinfo'
			])
		},
		created() {
			const script = document.createElement('script')
			script.type = 'text/javascript'
			script.src = 'http://res.wx.qq.com/open/js/jweixin-1.4.0.js'
			document.getElementsByTagName('head')[0].appendChild(script)
			
			script.onload = () => {
				_API_GzhWebInits().then(res => {
					console.log(window.location.pathname.split('/'))
						console.log(res)
						wx.config({
						
							debug: false, // 开启调试模式
		
							appId: res.appId, // 必填，公众号的唯一标识
		
							timestamp: res.timestamp, // 必填，生成签名的时间戳
		
							nonceStr: res.nonceStr, // 必填，生成签名的随机串
		
							signature: res.signature, // 必填，签名，见附录1
		
							jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
		
						});
						// wx.config(res)
						wx.ready(() => {
							wx.scanQRCode({
							  needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
							  scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
							  success: function (res) {
							    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
								alert(result);
							  }
							});
						})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	#share_container {
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: space-between;
		flex-direction: column;
	}
	#imgWrapper {
		flex: 1;
		@include flex();
		.showCan {
			width: 680rpx;
			height: 960rpx;
			border-radius: 14rpx;
			box-shadow:0px 0px 23px 2px rgba(194,133,58,0.5);
		}
	}
	.sharetext {
		font-size: 80rpx;
		text-align: center;
		margin: 8rpx 0;
		box-sizing: border-box;
		padding: 30rpx 24rpx;
	}
</style>
