<template>
	<view class="container">
		<tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading	="true" :loadingType="7"></tui-skeleton>
		<template v-else>
			<view class="share-empty">
				<view class="icon"><image :src="imagePath" mode="widthFix"></image></view>
				<view class="text">暂无权限查看</view>
			</view>
		</template>
	</view>
</template>

<script>
import { mapMutations } from 'vuex'
import authorize from '@/common/config/authorize.js' 
export default {
	computed: {
		
	},
	data() {
		return {
			CustomBar:this.CustomBar,// 顶部导航栏高度
			imagePath:'https://static.caimei365.com/app/img/icon/icon-noremb.png',
			skeletonShow:true,
			receiptId:0,
			receiptType:1// 收款款项类型：1订单款，2非订单款，3返佣款 4订单款或者非订单款（因财务阶段无法区分订单非订单）, 5供应商退款
		} 
	},
	onLoad(options) {
		this.receiptId = option.id
		this.receiptType = option.receiptType
	},
	methods: {
		...mapMutations(['login', 'logout']),
		async getWxAuthorize(){// 初始化授权登录
			const WxCode = await authorize.getCode('weixin')
			const Wx = await authorize.getUserInfo('weixin')
			this.UserService.UserLoginAuthApplets({ 
				code:WxCode,
				encryptedData:Wx.encryptedData,
				iv:Wx.iv ,
			})
			.then(response =>{
				let data  = response.data
				this.login(response.data)
				this.$store.commit('updateStatus',response.data)
				setTimeout(()=>{
					this.navigateLink(response.data)
				},500)
			}).catch(error =>{
				this.logout()
				this.skeletonShow = false
				this.$store.commit('updateStatus',error.data)
			})
		},
		navigateLink(data){// 根据用户权限跳转对应页面
			/**
			 * 用户类型(userType) 1协销人员,2客服,3财务,4超级管理员
			 * 1. 协销人员跳转到收款列表页面
			 * 2. 客服跳转到收款列表页面
			 * 3. 财务人员跳转到款项识别页面
			 * 4. 超级管理员跳转到款项识别页面
			 * */
			 switch(data.userType){
				 case 1:// 协销
					this.receiptTypeJump()
					break
				 case 2:// 客服
					this.receiptTypeJump()
					break
				 case 3:// 财务
					this.receiptTypeJump()
					break
				 case 4:// 超级管理员
					this.receiptTypeJump()
					break
			 }
		},
		receiptTypeJump(){//跳转URL 收款款项类型：1订单款，2非订单款，3返佣款 4订单款或者非订单款（因财务阶段无法区分订单非订单）, 5供应商退款
			switch(this.receiptType){
				case 1:// 订单款
					this.$api.navigateTo(`/pages/relation/ordinary/index?id=${this.receiptId}`)
					break
				case 2:// 非订单款
					this.$api.navigateTo(`/pages/relation/nonorder/detail?id=${this.receiptId}`)
					break
				case 3:// 返佣款
					this.$api.navigateTo(`/pages/relation/return/index?id=${this.receiptId}`)
					break
				case 4:// 订单款或者非订单款
					this.$api.navigateTo(`/pages/relation/ordinary/index?id=${this.receiptId}`)
					break
				case 5:// 供应商退款管理权限
					this.$api.navigateTo(`/pages/relation/refund/index?id=${this.receiptId}`)
					break
			}
		},
		permissionNav(data){
			/**
			 * 用户权限(permission) 1录入收款权限，2收款确认权限，3收款审核权限 4返佣管理权限 5供应商退款管理权限
			 * 1. 
			 * 2. 
			 * 3. 
			 * 4.
			 * 5.
			 * */
		}
	},
	onShow() {
		this.getWxAuthorize()
	}
}
</script>

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