<template>
	<view class="container-wrap">
		<uni-nav-bar :title="config.baseUrl === 'http://120.79.80.64:8002' ? '首页' : '测试'" :status-bar="true" background-color="#3F92F9" color="#FFF">
			<view slot="left">
				<u-icon name="account-fill" color="#FFF" size="35"></u-icon>
				<span style="padding: 0 5rpx;color: #FFFFFF;">{{ userInfo.name }}</span>
			</view>
			<view slot="right" @tap="show = true">
				<span style="color: #FFFFFF;">退出</span>
			</view>
		</uni-nav-bar>
		
		<view class="container">
			<view v-for="(menu, menuIndex) in menus" :key="menuIndex">
				<view class="title">
					<span>{{ menu.name }}</span>
				</view>
				<view class="list">
					<view class="item flex-column-center" @tap="go(item.key)" v-for="(item, index) in menu.children" :key="index">
						<u-image width="60%" mode="widthFix" :src="item.icon"></u-image>
						<span class="title">{{ item.name }}</span>
					</view>
				</view>
			</view>
		</view>
		<u-modal v-model="show" content="是否退出账号" :show-cancel-button="true" @confirm="logOut"></u-modal>
	</view>
</template>

<script>
	import config from '@/libs/config/config.js'
	export default {
		data() {
			return {
				config,
				menus: this.$storage.getStorageSync('userInfo').menus,
				show: false,
				timer: null,
				
			};
		},
		methods: {
			logOut() {
				this.$http.LoginQuit().then(res => {
					if(res.code === 0) {
						this.$storage.removeStorageSync('token')
						this.$utils.openNew('/pages/login/login')
					}
				})
			},
			/* 首页页面跳转 */
			go (type) {
				console.log(type)
				switch(type) {
					
					/* 扫描贴标 */
					case 'scanPaste':
						this.scanPaste()
						break
					/* 手动贴标 */
					case '1' :
						this.$utils.open('/pages/store-in-manage/artificial-paste/artificial-paste')
						break
					/* 到货质检 */
					case '2' :
						this.$utils.open('/pages/store-in-manage/quality/quality')
						break
					/* 每日盘点 */
					case '3' :
						this.$utils.open('/pages/store-manage/day-check/day-check')
						break
					/* 库存盘点 */
					case '4' :
						this.$utils.open('/pages/store-manage/store-check/store-check')
						break
					/* 归还入库 */
					case '5' :
						this.$utils.open('/pages/apply-manage/back-in-store/back-in-store')
						break
					/* 退货申请 */
					case '6' :
						this.$utils.open('/pages/store-out-manage/return-apply/return-apply')
						break
					/* 报损申请 */
					case '7' :
						this.$utils.open('/pages/store-out-manage/breakage-apply/breakage-apply')
						break
					/* 新建标签 */
					case '8' :
						this.$utils.open('/pages/tag/tag')
						break
					/* 更换标签 */
					case '9' :
						this.$utils.open('/pages/tag/tag-change')
						break
					/* 初始化标签 */
					case '10' :
						this.$utils.open('/pages/tag/tag-init')
						break
					/* 手动出库 */
					case '11' :
						this.$utils.open('/pages/store-out-manage/store-out/store-out')
						break
					/* 手动入库 */
					case '12' :
						this.$utils.open('/pages/store-in-manage/store-in/store-in')
						break
					/* 物料库存 */
					case '13' :
						this.$utils.open('/pages/store-manage/store-material/store-material')
						break
					/* 绑定标签 */
					case '14' :
						this.$utils.open('/pages/tag/tag-new/tag-new-list')
						break
					/* 批量绑定 */
					case '15' :
						this.$utils.open('/pages/tag/tag-dispatch/tag-dispatch')
						break
					/* 批量盘点 */
					case '16' :
						this.$utils.open('/pages/store-manage/dispatch-check/dispatch-check')
						break
					/* 手动盘点 */
					case '17' :
						this.$utils.open('/pages/store-manage/user-check/user-check')
						break
					/* 库位编辑 */
					case '21' :
						this.$utils.open('/pages/store-manage/user-check/location-edit')
						break
					/* 标签纠正 */
					case '18' :
						this.$utils.open('/pages/tag/tag-right/tag-right')
						break
					/* 退仓申请 */
					case '19' :
						this.$utils.open('/pages/store-out-manage/return-stock-apply/return-stock-apply')
						break
					/* 退料清单 */
					case '20' :
						this.$utils.open('/pages/store-out-manage/return-material/return-material')
						break
					/* 物料接收 */
					case '22' :
						this.$utils.open('/pages/warehouse/warehouse-list')
						break
					/* 面料退仓 */
					case '23' :
						this.$utils.open('/pages/warehouse/return-warehouse')
						break
					case '24' :
						this.$utils.open('/pages/warehouse/review')
						break
					/* 面料修正 */
					case '25' :
						this.$utils.open('/pages/warehouse/fabric-correction')
						break
				}
			},
			/* 扫码贴标 */
			scanPaste() {
				this.$utils.open('/pages/store-in-manage/scan-paste/index')
				// this.$utils.uniScanCode().then(res => {
				// 	this.$utils.open(`/pages/store-in-manage/scan-paste/index?data=${res.result}`)
				// })
			}
		},
		onLoad() {
			uni.$on('scan', res => {
				this.scanPaste()
			})
			if(!!this.$storage.getStorageSync('token')) {
				
			} else {
				this.$utils.openReLaunch('/pages/login/login')
			}
		},
		onUnload() {
			this.$msg.hideLoading()
			clearTimeout(this.timer)
			uni.$off('scan')
		}
	}
</script>

<style lang="scss" scoped>
.container-wrap {
	background-color: #FFFFFF;
	overflow: hidden;
	.container {
		padding: 0 10rpx;
		height: calc(100vh - var(--status-bar-height) - 44px);
		overflow: auto;
		.title {
			padding: 10rpx 0;
		}
		.list {
			padding-bottom: 0;
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;
			width: 100%;
			.item {
				width: 238rpx;
				height: 238rpx;
				background-color: #F2F2F2;
				margin-bottom: 10rpx;
				border-radius: 8rpx;
				margin-right: 10rpx;
				&:nth-child(3n + 0) {
					margin-right: 0;
				}
				.title {
					font-size: 28rpx;
				}
			}
		}
	}
}
</style>
