<template>
	<view class="container">
		<view class="topclass">
			<view class="flex">
				<view class="">
					<view class="cu-item">
						<view class="cu-avatar round txImg">
						</view>
					</view>
				</view>
				<view class="itemtwo">
					<view v-if="userInfo !=null" class="classname">
						{{userInfo.username}}
					</view>
					<view style="margin-top: 5px;">
						<span class="classxx">股东</span>
					</view>
				</view>

				<view class="itemend">
					<view class="classgzpz" @click="onClickWorkSet('工作配置')">
						退出登录
					</view>
				</view>
			</view>
		</view>
		<!-- 运维板块 -->
		<view class="section" v-for="(item,index) in dataList" :key="index">
			<text class="section-title">{{item.name}}</text>
			<view class="icon-row">
				<view class="icon-item" v-for="(icon, i) in item.chilren" :key="index" @click="onClikcList(icon)">
					<view class="classimg" :class="icon.id==isSeleid?`classimgsm`:``">
						<!-- <image :src="icon.src" class="icon-image" />	 -->
						<uni-icons v-if="icon.customsrc" custom-prefix="iconfont" color="#1488f5" :type="icon.customsrc"
							size="25"></uni-icons>
						<uni-icons v-else color="#1488f5" :type="icon.src ? icon.src:'image'" size="25"></uni-icons>
					</view>
					<view class="classimgwz">
						{{ icon.label }}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		showModelMessage,
		getUrlParams
	} from '@/utils/tools.js';
	const isSeleid = ref(-1);
	const userInfo = ref(null)
	onMounted(() => {
		//获取用户信息 
		userInfo.value = uni.getStorageSync('userInfo');
	});
	// 仓库板块图标
	const dataList = ref([{
			"category": "operation",
			"name": "运维",
			"chilren": [{
					"customsrc": "icon-ebikeBluetooth1",
					"label": "蓝牙扫码",
					"id": 2,
					"bh": "yw_lysm",
					"path": "/pages/warehouse/bluetooth/bluetoothscan"
				},
				{
					"src": "link",
					"label": "换二维码",
					"id": 3,
					"bh": "yw_ghewm",
					"path": "/pages/warehouse/qrcodereplace/qrcodereplace"
				},
				{
					"customsrc": "icon-ebikedianchigenghuan",
					"label": "换电",
					"id": 4,
					"bh": "yw_hd",
					"path": "/pages/devops/changebatteries/changebatteries"
				},
				{
					"customsrc": "icon-ebikedianchi1",
					"label": "领料",
					"id": 5,
					"bh": "yw_ll",
					"path": "/pages/warehouse/component/picking"
				}
			]
		},
		{
			"category": "warehouse",
			"name": "仓库",
			"chilren": [{
					"src": "settings",
					"label": "测试中控",
					"id": 36,
					"bh": "ck_cszk",
					"path": "/pages/warehouse/detectionecu/detectionecu"
				},
				{
					"customsrc": "icon-ebikewode-wodecheku",
					"label": "整车仓库",
					"id": 37,
					"bh": "ck_zcck",
					"path": "/pages/warehouse/ebikehouse/ebikehouse"
				}, {
					"src": "tune",
					"label": "解绑中控",
					"id": 38,
					"bh": "yw_jbzk",
					"path": "/pages/warehouse/ecuunbind/ecuunbindlist"
				},
				{
					"customsrc": "icon-ebiketoukui",
					"label": "绑定头盔",
					"id": 39,
					"bh": "yw_bdtk",
					"path": "/pages/warehouse/bindhelmet/bindhelmet"
				},
				{
					"customsrc": "icon-ebikebangdingcheliang-01",
					"label": "整车绑定",
					"id": 40,
					"bh": "yw_zcbd",
					"path": "/pages/warehouse/wholebind/wholebind"
				},
				{
					"customsrc": "icon-ebikeguzhangshangbao",
					"label": "故障上报",
					"id": 41,
					"bh": "yw_gzsb",
					"path": "/pages/devops/faultreport/faultreport"
				},
				{
					"customsrc": "icon-ebikebtn_tongyong_shebeijiancha",
					"label": "设备检查",
					"id": 42,
					"bh": "yw_sbjc",
					"path": "/pages/devops/checkDevice/checkDevice"
				},
				{
					"customsrc": "icon-ebikeweixiu",
					"label": "维修",
					"id": 43,
					"bh": "yw_sbwx",
					"path": "/pages/devops/maintenancepage/maintenancepage"
				},
				{
					"customsrc": "icon-ebikeqitachuku",
					"label": "部件出库",
					"id": 44,
					"bh": "yw_bjck",
					"path": "/pages/warehouse/component/outlist"
				},
				{
					"customsrc": "icon-ebikeqitaruku",
					"label": "部件入库",
					"id": 45,
					"bh": "yw_bjrk",
					"path": "/pages/warehouse/component/enterlist"
				}
			]
		},
		{
			"category": "warehouse",
			"name": "运营",
			"chilren": [{
				"src": "navigate",
				"label": "运营车辆",
				"id": 80,
				"bh": "",
				"path": "/pages/warehouse/ebikehouse/vehicleoperation"
			}]
		}
	]);

	const onClikcList = (icon) => {
		const {
			id,
			bh,
			label,
			path
		} = icon;

		isSeleid.value = id;
		// if (bh == "yw_hd") { //跳转到运维换电
		// 	setTimeout(() => {
		// 		uni.navigateTo({
		// 			url: '/pages/warehouse/ebikehouse/ebikelist', // 测试可删除
		// 		});
		// 	}, 100); // 延迟100毫秒后执行 
		// } 
		// else if (bh == 'yw_sbwx') {
		// 	uni.scanCode({
		// 		onlyFromCamera: true, //只能扫码
		// 		scanType: ["qrCode"],
		// 		success: function(res) {
		// 			const {
		// 				result
		// 			} = res;
		// 			if (!result || result.indexOf("number") == -1) {
		// 				showModelMessage("无效的车辆二维码");
		// 			} else {
		// 				const params = getUrlParams(result);
		// 				setTimeout(() => {
		// 					uni.navigateTo({
		// 						url: path + "?bikeCode=" + params["number"], //
		// 					});
		// 				}, 100);
		// 			}
		// 		}
		// 	})
		// }
		if (path) {
			setTimeout(() => {
				uni.navigateTo({
					url: path, //
				});
			}, 100); // 延迟100毫秒后执行 
		}
		setTimeout(() => {
			isSeleid.value = -1
		}, 200); // 延迟100毫秒后执行 
	}

	const onClickWorkSet = (res) => {
		uni.showModal({
			title: '确认退出',
			content: '是否确认退出并清除缓存？',
			success: function(res) {
				if (res.confirm) {
					uni.clearStorage();
					uni.reLaunch({
						url: "/pages/login/login"
					});
				} else if (res.cancel) {}
			}
		});
	}
</script>

<style scoped>
	.container {
		padding: 20px;
		background: linear-gradient(to bottom, rgb(132, 212, 248), rgb(247, 252, 255));
		height: 100vh;
	}

	.topclass {
		margin-top: 70px;
		margin-bottom: 30px;
	}

	.class1 {
		color: #55aaff;
		border: solid 1px #55aaff;
		padding: 3px;
		border-radius: 5px;
		margin-left: 10px;
		font-size: 12px;
	}

	.classxx {
		background-color: rgb(242, 242, 242);
		color: #000305;
		border-radius: 4px;
		padding: 2px 10px;
		font-size: 10px;
	}

	.section {
		margin-bottom: 15px;
		background: #fff;
		border-radius: 10px;
		padding: 15px 0px;
	}

	.section-title {
		font-size: 18px;
		font-weight: bold;
		margin: 0px 20px;
	}

	.icon-row {
		display: flex;
		justify-content: start;
		flex-wrap: wrap;
	}

	.icon-item {
		text-align: center;
		width: 20%;
	}

	.icon-image {
		width: 50px;
		height: 50px;
		margin-bottom: 5px;
	}

	.icon-label {
		font-size: 14px;
	}

	.txImg {
		background-image: url("../../static/image/tx.png");
		width: 50px;
		height: 50px;
		margin: 0px 10px;
		margin-top: -5px;
	}

	.itemtwo {
		width: 60%;
	}

	.classname {
		line-height: 20px;
		font-size: 20px;
		font-weight: bold;
	}

	.classimg {
		margin-top: 15px;
	}

	.classimgsm {
		transform: scale(0.9);
		/* 将元素缩小至原来的 0.9 倍 */
	}

	.classimg image {
		height: 30px;
		width: 30px;
	}

	.classimgwz {
		/* margin-top: -8px; */
		font-size: 13px;
	}

	.classgzpz {
		font-size: 12px;
		border-bottom: solid 1px #000;
	}
</style>