<template>
	<view>
		<view class="flex">
			<view class="left">
				<leftcontent :list="arrlist" @navurl="navurl" :userInfo="userInfo"></leftcontent>
			</view>
			<view class="boxrt">
				<index     :isShow="menuop == 0" v-if="swipdex == 0" @swip="swip"/>
				<material  :isShow="menuop == 1" v-if="swipdex == 1" ref="materials"></material>
				<picking   :isShow="menuop == 2" v-if="swipdex == 2"></picking>
				<finish    :isShow="menuop == 3" v-if="swipdex == 3"></finish>
				<outbound  :isShow="menuop == 4" v-if="swipdex == 4"></outbound>
				<retstock  :isShow="menuop == 5" v-if="swipdex == 5"></retstock>
				<inventory :isShow="menuop == 6" v-if="swipdex == 6" ref="inventorys"></inventory>
				<nurse     :isshow="menuop == 7" v-if="swipdex==7&&uni.getStorageSync('nuId')" />
				<!-- <invoicing :isshow="menuop == 8" v-if="swipdex==8&&uni.getStorageSync('nuId')" /> -->
				<logistics :isshow="menuop == 9" v-if="swipdex==9&&uni.getStorageSync('nuId')" />
				<invoicing :isshow="menuop == 10" v-if="swipdex==10&&uni.getStorageSync('nuId')" />
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue';
	import { onShow, onLoad, onHide, onPageScroll } from "@dcloudio/uni-app"
	import { queryPadPageList ,getPermissionList} from '@/pages/watch/api/lunpan.js'
	import leftcontent from "@/pages/NursingNew/component/leftcontent/leftcontent.vue"
	import material from "@/pages/procurement/material.vue";
	import index from "./component/index.vue"

	import picking from "../picking.vue";

	import finish from "@/pages/Warehouse/finish.vue"
	import outbound from "@/pages/procurement/outbound.vue";
	import inventory from "@/pages/procurement/inventory.vue";
	import retstock from "@/pages/procurement/retstock.vue";
	
	// import logistics from "@/pages/NursingNew/component/logistics/index.vue"
	import invoicing from "@/pages/NursingNew/component/invoicing/index.vue"
	import logistics from "@/pages/NursingNew/component/logistics/index.vue"
	import nurse from "@/pages/NursingNew/component/nurse/index.vue"

	const tabbrarr = ref([
		{ name: '护理', url: '/static/shouye/sy/n0.png', urls: '/static/shouye/sy/n1.png' ,type:'kzgn_hljz'},
		{ name: '医疗', url: '/static/shouye/sy/y0.png', urls: '/static/shouye/sy/y1.png' ,type:'kzgn_yljz'},
		{ name: '后勤', url: '/static/shouye/sy/l0.png', urls: '/static/shouye/sy/l1.png' ,type:'kzgn_hqjz'},
		{ name: '库房', url: '/static/shouye/sy/l0.png', urls: '/static/shouye/sy/l1.png' ,type:'kzgn_kfjz'},
	])
	const menuop = ref(0)
	const swipdex = ref(0)
	// onMounted(() => {
	// 	// 处理响应式
	// 	navurl(0)
	// })
	// onShow(()=>{
	// 	navurl(0,arrlist[0])
	// })
	const navurl = (e : number,v:any) => {
		// 最后一个直接返回
		menuop.value = -1;
		swipdex.value = -1;
		setTimeout(()=>{
			switch (v.type){
				case 'sy':
				swipdex.value = 0;
				setTimeout(()=>{
					menuop.value = 0
				},100)
					break;
				case 'kf_cg':
				swipdex.value = 1;
				setTimeout(()=>{
					menuop.value = 1
				},100)
					break;
				case 'kf_jh':
				swipdex.value = 2;
				setTimeout(()=>{
					menuop.value = 3
				},100)
					break;
				case 'kf_wj':
				swipdex.value = 3;
				setTimeout(()=>{
					menuop.value = 3
				},100)
					break;
				case 'kf_ql':
				swipdex.value = 4;
				setTimeout(()=>{
					menuop.value = 4
				},100)
					break;
				case 'kf_th':
				swipdex.value = 5;
				setTimeout(()=>{
					menuop.value = 5
				},100)
					break;
				case 'kf_pd':
				swipdex.value = 6;
				setTimeout(()=>{
					menuop.value = 6
				},100)
					break;
				case 'kzgn_hljz':
				swipdex.value = 7;
				setTimeout(()=>{
					menuop.value =7;
				},100)
				console.log('护理矩阵')
					break;
				case 'kzgn_yljz':
				swipdex.value = 7;
				setTimeout(()=>{
					menuop.value = 7;
				},100)
				console.log('医疗矩阵')
					break;
				case 'kzgn_hqjz':
				swipdex.value = 9;
				setTimeout(()=>{
					menuop.value = 9;
				},100)
				console.log('后勤矩阵')
					break;
				case 'kzgn_kfjz':
				swipdex.value = 10;
				setTimeout(()=>{
					menuop.value =10;
				},100)
				console.log('库房')
					break;
				case 'back':
				uni.navigateBack()
					break;
				
				default:
					break;
			}
		},10)
	}
	const arrlist = ref([ ])
	const listarr = ref([])
	const swip = ()=>{
		let nuId = uni.getStorageSync('nuId');
		getPermissionList({employessId:uni.getStorageSync('userInfo').employessId}).then(res=>{
			res.result.forEach(item=>{
				if(item.nuId == nuId){
					listarr.value  = item.dataList
				}
			})
		})
		let nuName = uni.getStorageSync('nuName')
		queryPadPageList({'pageNo':-1,'nuName':nuName}).then((res => {
			let arr = res.result.records[0].permissionList;
			arrlist.value = [
				{ name: '首页', url: '/static/shouye/ck/h0.png', urls: '/static/shouye/ck/h1.png' ,type:'sy'},
				{ name: '采购', url: '/static/shouye/ck/c0.png', urls: '/static/shouye/ck/c1.png'  ,type:'kf_cg'},
				{ name: '拣货', url: '/static/shouye/ck/j0.png', urls: '/static/shouye/ck/j1.png'  ,type:'kf_jh'},
				{ name: '完结', url: '/static/shouye/ck/w0.png', urls: '/static/shouye/ck/w1.png'  ,type:'kf_wj'},
				{ name: '请领出库', url: '/static/shouye/ck/q0.png', urls: '/static/shouye/ck/q1.png'  ,type:'kf_ql'},
				{ name: '退货入库', url: '/static/shouye/ck/t0.png', urls: '/static/shouye/ck/t1.png'  ,type:'kf_th'},
				{ name: '库存盘点', url: '/static/shouye/ck/p0.png', urls: '/static/shouye/ck/p1.png'  ,type:'kf_pd'},
			];
			let tbr = [];
			if(arr){
				arr.forEach((v,i)=>{
					let obj = listarr.value.find(item=>
						item.menuCode == v.menuCode
					);
					if(obj){
						tbr.push(v)
					}
				})
				tbr.forEach(item=>{
					let obj = tabbrarr.value.find(r=>
						r.type == item.menuCode
					);
					if(obj){
						arrlist.value.push(obj);
					}
				}) 
			}
			
			let back =[
				{ name: '返回', url: '/static/shouye/sy/f0.png', urls: '/static/shouye/sy/f1.png'  ,type:'back'},
			]
			arrlist.value.push(...back);
		}))
	}
	const materials = ref<InstanceType<typeof ChildComponent>>();
	const inventorys = ref<InstanceType<typeof ChildComponent>>()
	const userInfo = ref({})
	onShow(()=>{
		userInfo.value = uni.getStorageSync('userInfo');
		if(menuop.value == 1){
			materials.value.gwcsx(); 
		}
		if(menuop.value == 6){
			inventorys.value.firstgetqueryCgdList()
		}
	})
</script>

<style scoped lang="less">
	.flex {

		display: flex;
		position: relative;
		width: 100%;
		height: 100vh;
		background-color: #eff0f4;
		overflow: hidden;
		z-index: 12;
	}

	.left {
		width: 8.2vw;
		height: 100vh;
		
	}

	.boxrt {
		width: calc(100vw - 8.2vw);
		background: RGBA(239, 240, 244, 1);
		display: flex;
		padding-left: 1vw;
		padding-top: 1.5vw;
	}
</style>