<template>
	<view class="home_content">
		<view class="zd-row header">
			<view class="zd-col-8 logo"></view>
			<view class="zd-col-8 home_title">首页</view>
			<view class="zd-col-8 zd-row jcflexend home_userinfo">
				<uni-icons type="person" size="24" color="#191c17"></uni-icons>
				<view class="user_name">{{userName}}admin</view>
				<view class="exit_text" @tap="Quit">退出</view>
			</view>
		</view>
		<view class="welcome_text_wraper">
			<view class="welcome_text">{{userName}}admin, 欢迎进入诺力三期平板系统！</view>
		</view>
		<view class="zd_wrapper">
			<view class="zd-row menu-wrap">
				<view class="menu-item" v-for="(e, i) in menuList" :key="i" @tap="toPage(e)">
					<view class="menu_name_bg" :style="{backgroundImage: `url('/static/images/theme/menu/${e.djlx}.png')`}" :class="`bg_${e.ywlx}`">
						<view class="menu-name">{{e.name}}</view>
						<view v-show="Number(e.counts) > 0" class="bill_count">{{e.counts}}</view>
					</view>
				</view>
				<view class="menu-item" @tap="toPage1('/pages/management/move-inventory')">
					<view class="menu_name_bg bg_YC">
						<view class="menu-name">移库</view>
					</view>
				</view>
				<view class="menu-item" @tap="toPage1('/pages/management/check')">
					<view class="menu_name_bg bg_PD">
						<view class="menu-name">盘点</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getBillsCount} from '@/utils/getData2.js'
	export default {
		data() {
			return {
				intervalId: null,
				// interTime: this.$store.getters.setTime,
				interTime: 60000,
				userName: this.$store.getters.userInfo !== '' ? JSON.parse(this.$store.getters.userInfo).person_name : '',
				menuList: []
			};
		},
		onLoad () {
			this._getBillsCount()
			this.timerFun(this._getBillsCount, this.interTime)()
		},
		beforeDestroy () {
			if (this.intervalId !== null) {
				clearTimeout(this.intervalId)
				this.intervalId = null
			}
		},
		methods: {
			timerFun(f, time) {
				let _this = this
			    return function backFun() {
			        clearTimeout(_this.intervalId)
			        _this.intervalId = setTimeout(function () {
			            f()
			            backFun() 
			        }, time)
			    }
			},
			async _getBillsCount () {
				let res = await getBillsCount()
				if (res.code === 1) {
					this.menuList = [...res.result]
				} else {
					uni.showToast({
						title: res.desc,
						icon: 'none'
					})
				}
			},
			toPage (e) {
				let url = ''
				if (e.ywlx === 'DB') {
					url = '/pages/management/alloc-maintenance_new?type=' + e.ywlx
				} else if (e.ywlx === 'SH') {
					url = '/pages/management/receive-confirm_new?type=' + e.ywlx
				} else {
					if (e.djlx === 'LLCKD') {
						url = '/pages/management/in-storage_LLCKD?id=' + e.djlx + '&name=' + e.name + '&type=' + e.ywlx
					} else {
						url = '/pages/management/in-storage_new?id=' + e.djlx + '&name=' + e.name + '&type=' + e.ywlx
					}
				}
				uni.redirectTo({
					url: url
				})
			},
			toPage1 (e) {
				uni.redirectTo({
					url: e
				})
			},
			Quit () {
			  this.$store.dispatch('delUserInfo', '')
			  uni.redirectTo({
			  	url: '/pages/login/login'
			  })
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.home_content
	position relative
	_wh(100%, 100vh)
	background-color #f3f3f3
.header
	height 40px
	padding 0 15px
	margin-bottom 10px
	justify-content space-between
	background linear-gradient(70deg, #9eedde,#dcfade)
	// _bis(#3375f7,'../../static/images/theme/1/header_bg.jpg', 100%, 100%,center)
.logo
	height 40px
	// _bis(,'../../static/images/theme/logo.png', 68%, auto,left,center)
.home_title
	_font(24px,30px,#191c17,,center)
	// font-family: YouSheBiaoTiHei;
.home_userinfo
	height 35px
.user_icon
	_wh(25px, 25px)
	margin-right 5px
	_bis(,'../../static/images/user_icon.png', 100%, 100%,center)
.user_name
	_font(17px,17px,#191c17,,center)
	padding-right 5px
	margin 9px 10px 9px 0
.exit_text
	height 22px
	_font(14px,22px,#191c17,,center)
	padding 0 20px
	margin 2.5px 0
	background-color rgba(142, 148, 143, 20%)
	border-radius 20px
.welcome_text_wraper
	height 40px
	margin 0 15px
.welcome_text
	_font(26px, 40px,  #373737,,)
	padding-left 20px
	font-family: YouSheBiaoTiHei
.zd_wrapper
	_wh(calc(100% - 30px),calc(100% - 100px))
	margin 0px 15px
	padding 20px 16px
	background-color #fff
	border 1px solid #ebebeb
.menu-wrap
	flex-wrap wrap
	justify-content flex-start
	align-content center
	height 100%
.menu-item
	position relative
	width calc(20% - 16px)
	margin-right 20px
	margin-top 15px
	&:nth-child(5n)
		margin-right 0
	&:nth-child(-n+5)
		margin-top 0
.menu_name_bg
	position relative
	_wh(100%, 90px)
	margin 0 auto
	border-radius 10px
	background-repeat no-repeat
	background-size: auto calc(100% - 25px);
	background-position top center
.bg_OUT
	background-color #ebfcf4
.bg_IN
	background-color #fff6ef
.bg_DB, .bg_SH
	background-color #eff3fe
.menu-name
	position absolute
	bottom 5px
	_wh(100%, 25px)
	_font(18px, 25px, #0f0f0f,400,center)
.bill_count
	position absolute
	top -10px
	right -13px
	_wh(40px, 22px)
	background-color $red
	border-radius 14px
	_font(14px, 22px, #fff,bold,center)
.left_bg
	position absolute
	left 0
	top 0
	_wh(25px, 100%)
	_bis(,'../../static/images/hud_left.png', 100%, ,center)
.right_bg
	left auto
	right 0
	background-image url('../../static/images/hud_right.png')
.bg_YC
	background-image: url('../../static/images/theme/menu/YC.png')
	background-color: #fff0ee
.bg_PD
	background-image: url('../../static/images/theme/menu/PD.png')
	background-color: #fff0ee
</style>
