<template>
	<view>
	  <image src="https://api.ccttiot.com/smartmeter/img/static/uZUV03nVfyr3MvcLKUfs" class="bj" mode=""></image>
	   <view class="anniu">
	   <!-- 	<view class="zhuce" @click="btnzc">
	   		注册
	   	</view> -->
		<!-- <view class="denglu" @click="denglu">
			登录
		</view> -->
		<button class="denglu" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
			<!-- <image src="https://api.ccttiot.com/smartmeter/img/static/uxWMldLMb888YHm0qOgN" mode=""></image> -->
			快捷登录
		</button>
		<view class="zhuce" style="margin-top: 30rpx;" @click="denglus">
			暂不登录
		</view>
	   </view>
	</view>
</template>

<script>
	var xBlufi = require("@/components/blufi/xBlufi.js")
	export default {
			data() {
				return {
					
				}
			},
			// 分享到好友（会话）
			onShareAppMessage: function() {
				return {
					title: '绿小能',
					path: '/pages/index/index'
				}
			},
			
			// 分享到朋友圈  
			onShareTimeline: function() {
				return {
					title: '绿小能',
					query: '',
					path: '/pages/index/index'
				}
			},
			onLoad() {
				wx.openBluetoothAdapter({
				  success: function (res) {
				    console.log('蓝牙适配器初始化成功'); 
				  },
				  fail: function (err) {
				    console.error('蓝牙适配器初始化失败，可能是因为没有权限', err);
					// uni.showToast({
					//    	title: '蓝牙适配器初始化失败，可能是因为没有权限',
					//    	icon: 'none',
					//    	duration:2000
					// })
				  }
				}) 	
				xBlufi.initXBlufi(1)
			},
			methods:{
				// 点击微信一键登录
				getPhoneNumber(e) {
					this.jsCode = e.detail.code
					let that = this;
					const wxLoginAsync = () => {
						return new Promise((resolve, reject) => {
							wx.login({
								success(res) {
									if (res.code) {
										that.mobileCode = res.code
										let data = {
											jsCode:  e.detail.code,
											mobileCode: res.code,
										}
										resolve(data);
									} else {
										reject(res.errMsg)
									}
								},
								fail(err) {
									reject(err)
								}
							})
						})
					}
					wxLoginAsync().then(async (data) => {
						this.$u.post(`/wxlogin?mobileCode=${this.jsCode}&jsCode=${this.mobileCode}`, data).then((res) => {
							if (res.code == 200) {
								wx.setStorageSync('token', res.token)
								uni.switchTab({
									url:'/pages/index/index'
								})
							}
						})
					}).catch((err) => {
						console.error(err)
					})
				},
				// 跳转到注册页
				btnzc(){
					uni.navigateTo({
						url:'/pages/login/zhuce'
					})
				},
				// 跳转到登录页
				denglu(){
					uni.navigateTo({
						url:'/pages/login/denglu'
					})
				},
				denglus(){
					uni.switchTab({
						url:'/pages/index/index'
					})
				}
			}
		}
</script>

<style lang="less">
	.bj{
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
	}
    .anniu{
		position: fixed;
		left: 50%;
		bottom: 140rpx;
		transform: translateX(-50%);
		.zhuce{
			width: 614rpx;
			height: 102rpx;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			border: 4rpx solid #FFFFFF;
			font-size: 48rpx;
			color: #FFFFFF;
			font-weight: 600;
			text-align: center;
			line-height: 102rpx;
		}
		.denglu{
			width: 614rpx;
			height: 102rpx;
			background: #FFFFFF;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			font-size: 48rpx;
			color: #48893B;
			font-weight: 600;
			text-align: center;
			line-height: 102rpx;
			margin-top: 22rpx;
		}
	}

</style>