const app = getApp()
import {
	Base
} from '../../../utils/base.js';
const base = new Base()
Page({
	data: {
		die: false,
		// isBindTel: false,
		canIUseGetUserProfile: false,
	},
	onLoad: function (options) {
		if (wx.getUserProfile && wx.canIUse('getUserProfile')) {
            this.setData({
                canIUseGetUserProfile: true
            })
        } else {
            this.setData({
                canIUseGetUserProfile: false
            })
        }
	},
	onShow() {
		this.setData({
			// isBindTel: app.globalData.hasTel
		})
	},
	userInfoHandler: function (e) {
		if (e.detail.errMsg == 'getUserInfo:ok') {
			app.saveUserInfo(e.detail, this.tc)
		} else {
			base.toast('请先授权，才能验证身份')
		}
	},
	getUserProfile(e) {
		wx.getUserProfile({
			desc: '获取中',
			success: (res) => {
				console.log(res)
				if (res.errMsg == 'getUserProfile:ok') {
					app.saveUserInfo(res, this.tc)
				} else {
					base.toast('请先授权，才能验证身份')
				}
			},
			fail: function (res) {
				console.log(res)
				base.toast('授权失败，无法登陆')
			}
		})
	},
	tc() {
		setTimeout(() => {
			wx.redirectTo({
			  url: '../confirmPay/confirmPay',
			})
		}, 800)
	},
	checkVisions: function () {
		if (wx.canIUse !== undefined && wx.canIUse('button.open-type.getUserInfo')) {
			this.setData({
				die: false
			})
		} else {
			this.setData({
				die: true
			})
			wx.showModal({
				title: '提示',
				content: '当前微信版本过低,无法更好体验该功能，请先升级微信到最新版',
				showCancel: true
			})
		}
	},
})