<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:'',//用户权限
			}
		},
		computed: {
			...mapState(['isWxAuthorize'])
		},
		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
				}
			}
			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() {
			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: 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>