<template>
	<view class="container login" v-if="isShareStatus">
		<view class="login-main">
			<image class="logo" :src="imagePath" mode=""></image>
		</view>
		<view class="login-input">
			<input type="number" 
				   v-model="shareCode"  
				   maxlength="4" 
				   class="input" 
				   placeholder="请输入分享码"
			/>
		</view>
		<view class="login-btn"  @click="goLogin">查看订单</view>
	</view>
</template>
<script>
	import authorize from '@/common/config/authorize.js' 
	import { orderShareCode } from "@/api/order.js" 
	export default{
		data() {
			return{
				imagePath:'https://img.caimei365.com/group1/M00/03/83/Cmis214FbbCAQhKoAAKWfqqSIds292.png',
				shareCode:'',  		//获取用户登录的邀请码
				isUserInfo:false,	//控制显示授权弹窗
				nickName:'',		//存储用户名
				userInfo:'',		//存储微信用户授权信息
				orderID:0,			//订单ID
				userID:0			,//分享人的用户ID
				isShareStatus:false,
				serviceProviderId:''
			}
		},
		onLoad(e) {
			console.log(e)
			this.orderID = e.orderID
			this.userID = e.userID
			this.serviceProviderId = e.serviceProviderId
		},
		methods:{
			initQueryUser(){
				authorize.getCode('weixin').then(wechatcode =>{
					let params ={
							code:wechatcode,
							orderID:this.orderID,
							userID:this.userID,
							shareCode:this.shareCode,
							serviceProviderId:this.serviceProviderId
						}
					orderShareCode(params).then(response =>{
						if(response.code === 2){
							this.$api.navigateTo(`/market/pages/order/order-details?type=share&orderID=${this.orderID}`)
						}else if(response.code === 0) {
							if(response.data == true){//同为会所运营人员查看订单详情
								this.$api.navigateTo(`/pages/user/order/order-details?type=share&orderID=${this.orderID}`)
							}else{//游客第二次查看订单详情
								this.$api.redirectTo(`/pages/user/order/order-sharedetails?orderID=${this.orderID}`)
							}
						}else if(response.code === -2){
							this.$util.modal('提示',response.msg,'确定','',false,() =>{})
						}else{
							this.isShareStatus = true
						}
					})
				})
			},
			goLogin() {
				if(this.shareCode == ''){
					this.$util.msg('请联系分享人获取分享码',2000);
					return
				}
				if(!this.$api.isNumber(this.shareCode)){
					this.$util.msg('分享码格式不正确',2000);
					return
				}
				authorize.getCode('weixin').then(wechatcode =>{
					let params ={
							code:wechatcode,
							orderID:this.orderID,
							userID:this.userID,
							shareCode:this.shareCode
						}
					orderShareCode(params).then(response =>{
						if (response.code === 0) {//游客第一次查看订单详情
							this.$api.redirectTo('/pages/user/order/order-sharedetails?orderID='+this.orderID)
						}else{
							this.$util.msg(response.msg,2000);
						}
					})
				})
			},
		},
		onShow() {
			this.initQueryUser()
		}
	}
</script>

<style lang="scss">
	.login{
		width: 100%;
		height:100%;
		background: #FFFFFF;
		.model-warp.none{
			display: none;			
		}
		.model-warp.show{
			display: block;
		}
		.login-main{
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 128rpx 0;
			.logo{
				width: 658rpx;
				height: 354rpx;
				display: block;
			}
		}
		.login-input{
			width: 654rpx;
			height: 40rpx;
			padding: 24rpx;
			margin: 0 auto;
			margin-bottom: 60rpx;
			background: #F7F7F7;
			.input{
				width: 100%;
				height: 100%;
				background: #F7F7F7;
				font-size: $font-size-28;
				border-radius: 14rpx;  
				line-height: 40rpx;
				color: #333333;
			}
		}
		.login-btn{
			width: 702rpx;
			height: 88rpx;
			font-size: $font-size-28;
			line-height: 88rpx;
			color: #FFFFFF;
			margin: 0 auto;
			margin-top: 100rpx;
			text-align: center;
			background: $btn-confirm;
			border-radius: 14rpx;
		}
		.model-authorization{
			width: 100%;
			height: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 999;
			.authorization{
				width: 518rpx;
				height: 320rpx;
				position: absolute;
				background: rgba(255,255,255,.7);
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				margin: auto;
				.to-btn{
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					margin: auto;
					width: 70%;
					height: 88rpx;
					font-size: $font-size-28;
					line-height: 88rpx;
					color: #FFFFFF;
					text-align: center;
					border-radius: 44rpx;
				}
			}
		}
	}
</style>