<template>
	<view class="container share" v-if="isRequest">
		<view class="share-empty">
			<view class="icon"><image :src="imagePath" mode="widthFix"></image></view>
			<view class="text">暂无权限查看</view>
		</view>
	</view>
</template>
<script>
	import authorize from '@/common/config/authorize.js' 
	export default{
		data() {
			return{
				isRequest:false,
				invitationCode:'',
				imagePath:'https://admin-b.caimei365.com/userfiles/1/images/photo/2020/06/%E6%97%A0%E6%9D%83%E9%99%90%402x.png',
				serviceProviderId:'',
				shopOrderId:null,
				source:1,
				shareCode:'',
				authority:'',//用户权限
			}
		},
		onLoad(option) {
			// scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
			console.log(option);
			if(option.scene){
				this.shopOrderId = Number(decodeURIComponent(option.scene))
			}else{
				this.shopOrderId = option.shopOrderId
				this.authority = option.authority
				if(this.authority == '2'){
					this.source = 2
				}else if(this.authority == '3'){
					this.source = 3
				}
			}
			authorize.getSetting().then(wxResponse =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
				if(wxResponse != 1){
					this.$api.navigateTo('/pages/authorization/authorization?type=4')
					setTimeout(()=>{
						this.isRequest = true
					},2000)
				}else{
					this.infoMiniShipments();
				}
			})	
		},
		methods:{
			infoMiniShipments(){
				authorize.getCode('weixin').then(wechatcode =>{
					authorize.getUserInfo('weixin').then(wxResponse =>{
						let params = {
								code:wechatcode,
								encryptedData:wxResponse.encryptedData,
								iv:wxResponse.iv,
								shopOrderId:this.shopOrderId,
								source:this.source,
								shareCode:this.shareCode
						}
						this.ShopService.MiniShipments(params).then(res =>{
							switch(res.data.resultCode){
								case 1:
									this.shopOrderId = res.data.shopOrderId;
									this.$api.navigateTo(`/supplier/pages/order/order-service-details?shopOrderId=${this.shopOrderId}`)
									break;
								case 2:
									console.log('供应商联系人');
									this.$api.navigateTo(`/supplier/pages/order/order-details?shopOrderId=${this.shopOrderId}`)
									break;
								case 3:
									console.log('供应商发货人员');
									this.$api.navigateTo(`/supplier/pages/order/order-details?shopOrderId=${this.shopOrderId}`)
									break;
							}
						}).catch(err =>{
							if(this.source == 2){
								this.$api.setStorage('bind_supplierInfo', err.data)
								this.$api.navigateTo(`/supplier/pages/login/bind-operator?shopOrderId=${this.shopOrderId}`)
							}else if(this.source == 3){
								this.$api.navigateTo(`/supplier/pages/login/share-login?shopOrderId=${this.shopOrderId}`)
							}else{
								this.isRequest = true;
							}
						})	
					})
				})		
			}
		},
		onShow() {
			authorize.getSetting().then(wxResponse =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
				if(wxResponse == 1){
					this.isRequest = false;
					this.infoMiniShipments();
				}
			})	
		}
	}
</script>

<style lang="scss">
	.share{
		width: 100%;
		height:100%;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content:center;
		.share-empty{
			width: 376rpx;
			height: 460rpx;
			.icon{
				width: 376rpx;
				height: 400rpx;
				image{
					width: 100%;
					height: 100%;
					display: block;
				}
			}
			.text{
				font-size: $font-size-28;
				line-height: 60rpx;
				color: $text-color;
				text-align: center;
			}
		}
	}
</style>