<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 { mapState,mapMutations } from 'vuex'
	import authorize from '@/common/config/authorize.js' 
	export default{
		data() {
			return{
				isRequest:false,
				invitationCode:'',
				imagePath:'https://static.caimei365.com/app/img/icon/icon-noremb.png',
				serviceProviderId:'',
				shopOrderId:null,
				source:1,
				shareCode:'',
				authority:'',//用户权限
				params:{
					code:'',
					encryptedData:'',
					iv:'',
					shopOrderId:0,
					source:1,
					shareCode:''
				}
			}
		},
		computed: {
			...mapState(['isWxAuthorize'])
		},
		onLoad(option) {
			// scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
			console.log(option);
			if(option.scene){
				this.params.shopOrderId = Number(decodeURIComponent(option.scene))
			}else{
				this.params.shopOrderId = option.shopOrderId
				this.authority = option.authority
				if(this.authority == '2'){
					this.params.source = 2
				}else if(this.authority == '3'){
					this.params.source = 3
				}
			}
			this.infoMiniShipments();
		},
		methods:{
			async infoMiniShipments(){
					const WeiXin =  await authorize.getUserInfo('weixin')
					this.params.iv = WeiXin.iv
					this.params.encryptedData = WeiXin.encryptedData
					this.params.code = await authorize.getCode('weixin')
					this.ShopService.MiniShipments(this.params).then(res =>{
						switch(res.data.resultCode){
							case 1:
								this.params.shopOrderId = res.data.shopOrderId;
								this.$api.navigateTo(`/pages/supplier/order/order-service-details?shopOrderId=${this.params.shopOrderId}`)
								break;
							case 2:
								console.log('供应商联系人');
								this.$api.navigateTo(`/pages/supplier/order/order-details?shopOrderId=${this.params.shopOrderId}`)
								break;
							case 3:
								console.log('供应商发货人员');
								this.$api.navigateTo(`/pages/supplier/order/order-details?shopOrderId=${this.params.shopOrderId}`)
								break;
						}
					}).catch(err =>{
						if(this.params.source == 2){
							this.$api.setStorage('bind_supplierInfo', err.data)
							this.$api.navigateTo(`/pages/supplier/login/bind-operator?shopOrderId=${this.params.shopOrderId}`)
						}else if(this.params.source == 3){
							this.$api.navigateTo(`/pages/supplier/login/share-login?shopOrderId=${this.params.shopOrderId}`)
						}else{
							this.isRequest = true;
						}
					})	
			}
		},
		onShow() {
			this.isRequest = false;
		}
	}
</script>

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