<template>
	<u-navbar title="工作台" placeholder border=true leftIcon=''></u-navbar>
	<view class="mabox" v-for="item in tablist">
		<view class="boxtitl">
			{{item.name}}
		</view>
		<view class="minboxlist">
			<view @click="gopathpage(ite.router)" v-for="ite in item.minilist">
				<image mode="widthFix" :src="ite.icon"></image>
				<view>{{ite.name}}</view>
			</view>
		</view>
	</view>
	<!-- #ifdef APP -->
	<saomiao2></saomiao2>
	<!-- <saomiao></saomiao>
	<saomiao1></saomiao1>
	<saomiao2></saomiao2>
	<saomiao3></saomiao3>
	<saomiao4></saomiao4> -->
	<!-- #endif -->
	<!-- <tiplist></tiplist> -->
	<!-- <Tabber checkstate='home'></Tabber> -->
</template>

<script lang="ts" setup>
	import {
		onLoad,
		onShow,
		onHide,
		onUnload
	} from '@dcloudio/uni-app'
	import {
		appMenuroutes,
		appbuttons
	} from "@/api/user.js"
	import { getImageCache } from '@/utils/cacheimg.js'
	import { listtype } from '@/interfaces/home/index'
	// import Tabber from '@/compoment/Tabber/Tabber.vue'
	import { inject, reactive, toRefs, watchEffect } from "vue";
	let details = reactive<listtype>({
		tablist: [
			{
				type: 1,
				name: '库内',
				minilist: [
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '订单分拣',
						router: '/pagesHome/pages/ordersorting/ordersorting',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '库存品分拣',
						router: '/pagesHome/pages/lnventorysorting/lnventorysorting',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '扫码上架',
						router: '/pagesHome/pages/ScanUpType/ScanUpType',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '手动上架',
						router: '/pagesHome/pages/PeopleScanUpType/PeopleScanUpType',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '移库',
						router: '/pagesHome/pages/RelocationType/RelocationType',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '滞留',
						router: '/pagesHome/pages/Retention/Retention',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '合托',
						router: '/pagesHome/pages/MergeTray/MergeTray',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '下架',
						router: '/pagesHome/pages/DownGoodsType/DownGoodsType',
					},
				]
			},
			{
				type: 1,
				name: '出库',
				minilist: [
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '拣货扫描',
						router: '/pagesHome/pages/pickingScan/pickingScan',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '自提扫描',
						router: '/pagesHome/pages/SelfPickupScan/SelfPickupScan',
					},
				]
			},
			{
				type: 1,
				name: '配送',
				minilist: [
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '装车扫描',
						router: '/pagesHome/pages/LoadingScan/LoadingScan',
					},
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '签收扫描',
						router: '/pagesHome/pages/signinScan/signinScan',
					},
				]
			},
			{
				type: 1,
				name: '离线上传',
				minilist: [
					{
						icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
						name: '离线上传',
						router: '/pagesHome/pages/OfflineUpload/OfflineUpload',
					},
				]
			},
		]
	})
	function gopathpage(path : string) {
		uni.navigateTo({
			url: path
		})
	}
	async function init() {
		let tabber = uni.getStorageSync('homerouter')
		if (tabber) {
			details.tablist = tabber
			return
		}
		let res = await appMenuroutes({})
		console.log(res, '-------------');
		if (res.code == 200) {
			getimgcache(res.data[0])
			// details.tablist = [
			// 	{
			// 		type: 1,
			// 		name: '库内',
			// 		minilist: [
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '订单分拣',
			// 				router: '/pagesHome/pages/ordersorting/ordersorting',
			// 			},
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '库存品分拣',
			// 				router: '/pagesHome/pages/lnventorysorting/lnventorysorting',
			// 			},
			// 		]
			// 	},
			// 	{
			// 		type: 1,
			// 		name: '出库',
			// 		minilist: [
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '拣货扫描',
			// 				router: '/pagesHome/pages/pickingScan/pickingScan',
			// 			},
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '自提扫描',
			// 				router: '/pagesHome/pages/SelfPickupScan/SelfPickupScan',
			// 			},
			// 		]
			// 	},
			// 	{
			// 		type: 1,
			// 		name: '配送',
			// 		minilist: [
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '装车扫描',
			// 				router: '/pagesHome/pages/LoadingScan/LoadingScan',
			// 			},
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '签收扫描',
			// 				router: '/pagesHome/pages/signinScan/signinScan',
			// 			},
			// 		]
			// 	},
			// 	{
			// 		type: 1,
			// 		name: '离线上传',
			// 		minilist: [
			// 			{
			// 				icon: 'http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png',
			// 				name: '离线上传',
			// 				router: '/pagesHome/pages/OfflineUpload/OfflineUpload',
			// 			},
			// 		]
			// 	},
			// ]
		} else {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
		}
	}
	async function initbuts() {
		let authbut = uni.getStorageSync('authbuts')
		if (authbut) {
			return
		}
		let butres = await appbuttons({})
		console.log(butres.data);
		let qxan = []
		butres.data.map(item => {
			item.children.map(ite => {
				qxan.push(ite.name)
			})
		})
		uni.setStorageSync('authbuts', qxan)
	}
	onShow(() => {
		init()
		initbuts()
		// print()
	})
	function print() {
		// #ifdef APP
		const util = (inject('utils') as any)
		let text = '! 0 200 200 500 1\r\n'
		text += 'SETBOLD 2\r\n'
		text += `T 56 0 0 0 OPLYA成都市230700015YA7\r\n`
		text += 'LINE 0 50 420 50 3\r\n'
		text += `T 55 0 0 60 客户\r\n`
		text += 'LINE 40 50 40 110 3\r\n'
		text += `T 55 0 50 60 客户名称\r\n`
		text += 'LINE 40 80 420 80 3\r\n'
		text += `T 55 0 50 90 四川成都龙泉驿西河镇\r\n`
		text += 'LINE 0 110 420 110 3\r\n'
		text += `T 55 0 0 120 物料\r\n`
		text += 'LINE 40 110 40 140 3\r\n'
		text += `T 55 0 60 120 物料名称31\r\n`
		text += 'LINE 0 140 420 140 3\r\n'
		text += 'B QR 150 150 M 2 U 4\r\n'
		text += 'MA,123141515215212\r\n'
		text += 'ENDQR\r\n'
		text += `T 55 0 140 260 123141515215212\r\n`
		text += 'PRINT\r\n'


		// let text='! 0 200 200 500 1\r\n'
		// text+='SETBOLD 2\r\n'
		// text+='B QR 80 40 M 2 U 8\r\n'
		// text+='MA,TESTCodeBJ2308020043\r\n'
		// text+='ENDQR\r\n'
		// text+=`T 56 0 15 280 TESTCodeBJ2308020043\r\n`
		// text+='PRINT\r\n'
		let sylist = util.initbl()
		console.log(sylist);
		sylist.map(item => {
			console.log(item);
			if (item.uuids) {
				util.getbl(item, text)
			}
		})
		// #endif
	}
	watchEffect(() => {
		if (details.tablist.length > 0) {
			uni.setStorageSync('homerouter', details.tablist)
		}
	})
	function getimgcache(list) {
		let maxarr = []
		list.children.map(async item => {
			let arr = {
				type: 1,
				name: item.name,
				minilist: []
			}
			await item.children.map(async ite => {
				let result = await getImageCache('http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png')
				console.log("image cache", result);
				let obj = {
					icon: result,
					name: ite.name,
					router: ite.path
				}
				arr.minilist.push(obj)
			})
			maxarr.push(arr)
		})
		details.tablist = maxarr
		// details.tablist.map((item,index)=>{
		// 	item.minilist.map(async (ite,inde)=>{
		// 		let result = await getImageCache('http://htys.oss-cn-chengdu.aliyuncs.com/htys/afb031efec7d2f8620ee68c71f87a80e.png')
		// 		console.log("image cache", result);
		// 		if (result) {
		// 			details.tablist[index].minilist[inde].icon=result

		// 		} else {
		// 			details.tablist[index].minilist[inde].icon=ite.icon
		// 		}
		// 	})
		// })
		// setTimeout(()=>{
		// 	console.log(details.tablist);
		// },3500)
	}


	const { tablist } = toRefs(details)
</script>

<style lang="scss">
	.mabox {
		display: flex;
		flex-direction: column;
		padding: 20upx 0;
		box-sizing: border-box;
		width: 686upx;
		margin: auto;
		background-color: #ffffff;
		margin-bottom: 20upx;
		margin-top: 10upx;
		border-radius: 10upx;
		box-shadow: 0rpx 2rpx 10rpx 0rpx #e2e2e380;

		.boxtitl {
			font-size: 34upx;
			font-weight: 500;
			margin-bottom: 10upx;
			// margin-left: 10upx;
			border-bottom: 1upx solid #EEEEEE;
			padding: 0upx 20upx;
			padding-bottom: 20upx;
			color: #092C4D;
		}

		.minboxlist {
			display: grid;
			grid-template-columns: 25% 25% 25% 25%;
			padding-top: 10upx;

			>view {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-bottom: 10upx;

				>image {
					width: 60upx;
				}

				>view {
					font-size: 26upx;
				}
			}
		}
	}
</style>