<template>
	<view>
		<image src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/wkthuiyuanbg.png" class="imgstyle" mode=""></image>
		<button class="btnclass" open-type="getPhoneNumber" @getphonenumber="sumbit">立即开通 </button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shopId: "",
				switchdata: true, // 绑定后
			}
		},
		onLoad(e) {
			this.shopId = e.shopId
		},
		onUnload() {
			if (this.switchdata) {
				uni.navigateBack()
			}
		},
		methods: {
			sumbit(d) {
				if (d.detail.iv) {
					uni.login({
						provider: 'weixin',
						success: async (data) => {
							let res = await this.api.userwxlogins({
								code: data.code,
								encryptedData: d.detail.encryptedData,
								iv: d.detail.iv,
								shopId: this.shopId
							})
							if (res.code == 0) {
								let resdata = await this.api.loginwxuserInfo({
									userId: uni.cache.get('userInfo').id
								})
								if (resdata.code == 0) {
									this.switchdata = false
									uni.cache.set('userInfo', resdata.data);
									uni.pro.redirectTo('/pages/member/index', {
										shopId: this.shopId,
										type: 'index'
									})
								}


							}
						}
					})
				}
			}
		}
	}
</script>

<style scoped lang="less">
	.imgstyle {
		width: 694rpx;
		height: 414rpx;
		margin: 70rpx auto;
	}

	.btnclass {
		width: 694rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: #6D89A4;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		text-align: center;
		margin: auto;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 36rpx;
		color: #FFFFFF;

	}
</style>