<template>
	<view class="pages">
		<image :src="img_url+'member/success.png'" mode=""></image>
		<text>认证成功！</text>
		<button @click="toUpgradesRenewals">开通会员</button>
		<!-- <button @click="toUpgradesRenewals" v-else>{{type == 0?'升级会员':'立即续费'}}</button> -->
	</view>
</template>

<script>
	import config_img from "@/utils/js/config.js"
	export default {
		data() {
			return {
				img_url: config_img.img_url,
				id: '',
				type: ''
			}
		},
		onLoad(options) {
			this.id = options.id
			this.type = options.type
		},
		methods: {
			// 获取用户信息
			getUserInfo () {
				uni.showLoading();
				this.$api('getUserInfo')
				.then(res => {
					let { code, result, message } = res
					uni.hideLoading();
					if (code === 200) {
						const userInfo = {...result.userInfo,...result.account}
						this.$storage.setStorage("__user_info",userInfo)
						console.log(userInfo)
					} else {
						this.$Toast(message)
						
					}
				})
				.catch(err => {
					this.$Toast(err.message)
					uni.hideLoading();
				})
			},
			toUpgradesRenewals() {
				const id = this.id
				console.log(this.type == 0,this.type )
				let url = this.type == 0 ? 'vipRolePay': 'vipPay'
				
				this.$api(url,{id}).then(res =>{
					const { code, result, message } = res
					console.log(res)
					if (code == 200) { 
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: result.timeStamp,
							nonceStr: result.nonceStr,
							package: result.packageValue,
							signType: result.signType,
							paySign: result.paySign,
							success: res => {
								this.$Toast('支付成功');
								// 刷新用户数据
								this.getUserInfo();
								setTimeout(() => {
									this.$tools.navigateTo({
										url: './../upgrades_renewals/index'
									})
								},1500)
							},
							fail:error=>{
								this.$Toast('取消支付')
							}
						})
					} else{
						setTimeout(() => {
							this.$tools.navigateTo({
								url: './../upgrades_renewals/index'
							})
						},1500)
						this.$Toast(message)
					}
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.pages{
		display: flex;
		flex-direction: column;
		align-items: center;
		image{
			width: 451rpx;
			height: 401rpx;
			margin-top: 161rpx;
			margin-bottom: 32rpx;
		}
		text{
			font-size: 45rpx;
			font-weight: bold;
			color: #01AEEA;
		}
		button{
			margin-top: 133rpx;
			width: 569rpx;
			height: 94rpx;
			border: 3rpx solid #01AEEA;
			box-sizing: border-box;
			border-radius: 46rpx;
			background-color: #fff;
			font-size: 30rpx;
			font-weight: bold;
			color: #01AEEA;
			text-align: center;
			line-height: 94rpx;
		}
	}
</style>
