<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(option) {
		this.receiptId = option.id
	},
	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.getOrderReceiptDetailType(this.receiptId,response.data)
				},1000)
			}).catch(error =>{
				this.logout()
				this.skeletonShow = false
				this.$store.commit('updateStatus',error.data)
				this.$api.navigateTo('/pages/login/login-account')
			})
		},
		navigateLink(data){// 根据用户权限跳转对应页面
			
			 switch(data.userType){
				 case 1:// 协销
					this.getOrderReceiptDetailType(this.receiptId,data)
					break
				 case 2:// 客服
					this.getOrderReceiptDetailType(this.receiptId,data)
					break
				 case 3:// 财务
					this.getOrderReceiptDetailType(this.receiptId,data)
					break
				 case 4:// 超级管理员
					this.getOrderReceiptDetailType(this.receiptId,data)
					break
			 }
		},
		getOrderReceiptDetailType(id,data) {
			// 收款详情查询跳转URL 收款款项类型：1订单款，2非订单款，3返佣款 4订单款或者非订单款（因财务阶段无法区分订单非订单）, 5供应商退款
			this.OrderService.orderReceiptDetailType({ id: id })
				.then(response => {
					/**
					 * 用户类型(userType) 1协销人员,2客服,3财务,4超级管理员
					 * 1. 协销人员跳转到收款列表页面
					 * 2. 客服跳转到收款列表页面
					 * 3. 财务人员跳转到款项识别页面
					 * 4. 超级管理员跳转到款项识别页面
					 * */
					const receipt = response.data
					switch(data.userType){
						 case 1:// 协销
							this.navigateLinkJump(receipt)
							break
						 case 2:// 客服
							this.navigateLinkJump(receipt)
							break
						 case 3:// 财务
							this.$api.navigateTo('/pages/collection/list')
							break
						 case 4:// 超级管理员
							this.navigateLinkJump(receipt)
							break
					}
				})
				.catch(err => {
					console.log('=======>分享查询收款详情异常<=======')
				})
		},
		navigateLinkJump(receipt){
			switch(receipt.receiptType){
				case 1:// 1:订单 1待确认、2已确认(待审核)、3审核通过、4审核未通过、5收款撤销【线上支付成功为审核通过】
					if(receipt.receiptStatus == 1 || receipt.receiptStatus == 4 || receipt.receiptStatus == 5){// 订单待确认
						console.log('订单待确认')
						this.$api.navigateTo(`/pages/relation/ordinary/index?type=share&id=${receipt.id}`)
					}else if(receipt.receiptStatus == 2){// 待审核
						console.log('待审核')
						this.$api.navigateTo(`/pages/relation/ordinary/examine-detail?type=share&id=${receipt.id}`)
					}else if(receipt.receiptStatus == 3){// 审核通过
						console.log('审核通过')
						this.$api.navigateTo(`/pages/relation/ordinary/detail?type=share&id=${receipt.id}`)
					}
					break
				case 2:// 2：非订单 
					this.$api.navigateTo(`/pages/relation/nonorder/detail?type=share&id=${receipt.id}`)
					break
				case 3:// 3：返佣 
					if(receipt.receiptStatus == 1 || receipt.receiptStatus == 4 || receipt.receiptStatus == 5){// 返佣待确认
						this.$api.navigateTo(`/pages/relation/return/index?type=share&id=${receipt.id}`)
					}else if(receipt.receiptStatus == 2){
						this.$api.navigateTo(`/pages/relation/return/detail?type=share&id=${receipt.id}`)
					}
					break
				case 5:// 4：供应商退款
					if(receipt.receiptStatus == 1 || receipt.receiptStatus == 4 || receipt.receiptStatus == 5){// 返佣待确认
						this.$api.navigateTo(`/pages/relation/refund/index?type=share&id=${receipt.id}`)
					}else if(receipt.receiptStatus == 2){
						this.$api.navigateTo(`/pages/relation/refund/detail?type=share&id=${receipt.id}`)
					}
					break
			}
		}
	},
	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>
