<template>
	<view class="lf-p-40">
		<view class="lf-row-center lf-font-28">确认核销权限...</view>
		<button class="cu-btn lf-bg-white lf-m-t-30" style="border: 1px solid #1998FE;" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
			<text class="lf-font-32 lf-color-blue">确认核销</text>
		</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: '',
				loadOptions: ''
			}
		},
		onLoad(options) {
			this.userInfo = uni.getStorageSync('userinfo')
			this.loadOptions = options.scene
			// if (options.scene) {
			//     // 单个参数
			//     let str = decodeURIComponent(options.scene);
			// 	this.$http(this.API.API_CONFIRM_CODE, {verify_code: str}).then(res => {
			// 		this.$msg('核销成功!');
			// 	});
			// }
		},
		methods: {
			// 微信快捷登录获取手机号
			getPhoneNumber(event){
				if(this.userInfo.mobile == '') {
					console.log('需绑定手机号')
					if(event.detail.errMsg == 'getPhoneNumber:ok'){
						let encryptedData = event.detail.encryptedData;
						let iv = event.detail.iv;
						// let userInfo = uni.getStorageSync('userinfo') || {};
						this.$http(this.API.API_WECHAT_SETPHONE, {
							encryptedData,
							iv,
							// token: userInfo.token // 已在公共参数传
						}).then(res => {
							this.$msg('更新成功', {icon: 'success'});
							uni.setStorageSync('userinfo', res.data);
							let str = decodeURIComponent(this.loadOptions);
							this.$http(this.API.API_CONFIRM_CODE, {verify_code: str}).then(res => {
								this.$msg('核销成功!');
							});
						})
					}
				}else {
					let str = decodeURIComponent(this.loadOptions);
					this.$http(this.API.API_CONFIRM_CODE, {verify_code: str}).then(res => {
						this.$msg('核销成功!');
					});
					console.log('无需绑定手机号')
				}
			},
		}
	}
</script>

<style>
</style>
