<template>
	<view style="background-color: #fff;">
		<view style="padding: 20rpx;ba">
			<view style="font-size: 38rpx;font-weight: 600;">公文办理</view>
			<view style="margin-top: 40rpx;">
				<u-grid :border="false" col="4">
					<u-grid-item @click="shouwen('收文','003',1)">
						 <u-badge style="z-index: 999;" :type="type" max="99" :value="numList['003']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/swgl.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">收文</text>
					</u-grid-item>
					<u-grid-item @click="shouwen('发文','002',2)">
						<u-badge style="z-index: 999;" :type="type" max="99" :value="numList['002']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/fwgl.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">发文</text>
					</u-grid-item>
					<u-grid-item @click="shouwen('其他处室收文','012',1)">
						<u-badge style="z-index: 999;" :type="type" max="99" :value="numList['012']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/swgl.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">其他处室收文</text>
					</u-grid-item>
					<u-grid-item @click="shouwen('其他处室发文','005',2)">
						<u-badge style="z-index: 999;" :type="type" max="99" :value="numList['005']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/fwgl.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">其他处室发文</text>
					</u-grid-item>
					<u-grid-item  @click="shouwen('信息发布审核','010',3)">
						<u-badge style="z-index: 999;" :type="type" max="99" :value="numList['010']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/xxfbsh.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">信息发布审核</text>
					</u-grid-item>
				</u-grid>
			</view>
		</view> 
		<u-divider></u-divider>
		<view style="padding: 20rpx;">
			<view style="font-size: 38rpx;font-weight: bold;">日常办公</view>
			<view style="margin-top: 40rpx;">
				<u-grid :border="false" col="4">
					<u-grid-item @click="dailyWork('中层出差备案','006',1)">
						<u-badge style="z-index: 999;" :type="type" max="99" :value="numList['006']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/ccba.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">出差备案</text>
					</u-grid-item>
					<u-grid-item @click="dailyWork('外出授课备案','007',2)">
						<u-badge style="z-index: 999;" :type="type" max="99" :value="numList['007']" :offset="[-10,10]" :showZero="false" absolute ></u-badge>
						<image src="/static/skba.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">授课备案</text>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
		<u-divider></u-divider>
		<view style="padding: 20rpx;">
			<view style="font-size:38rpx;font-weight: bold;">考勤管理</view>
			<view style="margin-top: 40rpx;">
				<u-grid :border="false" col="4">
					<u-grid-item @click="kaoqin">
						<image src="/static/kqgl.png" mode="widthFix" style="width: 100rpx;"></image>
						<text class="grid-text">考勤管理</text>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				numList:{},
				type:"error",
				value:100,
				num:0
			}
		},
		onShow(){
			this.getdbNum()
			this.getUnreadEmail()
		},
		watch:{
			'num':{
				handler:function(v,o){
					if(this.num>0){
						this.$forceUpdate()
					}
				},
				deep:true
			},
		},
		methods: {
			//收发文
			shouwen(v,i,t){
				uni.navigateTo({
					url:`/pages/shouwen/shouwen?title=${v}&fkFlow=${i}&type=${t}`
				})
			},
			//考勤
			kaoqin(){
				uni.navigateTo({
					url:"/pages/kaoqin/kaoqin"
				})
			},
			//日常办公
			dailyWork(v,i,t){
				uni.navigateTo({
					url:`/pages/dailyWork/dailyWork?title=${v}&fkFlow=${i}&type=${t}`
				})
			},
			//查询待办数量
			getdbNum(){
				uni.$u.http.get('/jflow/restful/DB_Todolist_Num?token='+uni.getStorageSync('jtoken')).then(res=>{
					if(res.code==200){
						this.num = 0
						this.numList = {}
						if (res.list.length > 0) {
							let qwe = 0
							for(let i in res.list){
								if(res.list[i].FK_Flow != '008' && res.list[i].FK_Flow != '009'){
									qwe = res.list[i].Total + qwe
									
									this.numList[res.list[i].FK_Flow]=res.list[i].Total
									this.num++
								}
								if(i == res.list.length-1){
									this.$forceUpdate()
									uni.setTabBarBadge({ //显示数字
										index: 1, //tabbar下标
										text: '' + qwe + '' //数字
									})
								}
							}
						} else {
							this.$forceUpdate()
							uni.removeTabBarBadge({ //显示数字
								index: 1, //tabbar下标
							})
						}
					}
					
				})
			},
			//获取未读邮件
			getUnreadEmail() {
				uni.$u.http.get('/oa/mail/count/unread').then(res => {
					if (res == 0) {
						uni.removeTabBarBadge({ //显示数字
							index: 2, //tabbar下标
						})
					} else {
						uni.setTabBarBadge({ //显示数字
							index: 2, //tabbar下标
							text: '' + res + '' //数字
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.grid-text {
		font-size: 28rpx;
		color: #606266;
		padding: 10rpx 0 20rpx 0rpx;
		/* #ifndef APP-PLUS */
		box-sizing: border-box;
		/* #endif */
	}
	::v-deep .u-badge{
		width: 36rpx;
		height: 36rpx;
		display: flex;
		font-size: 28rpx;
		align-items: center;
		justify-content: center;
		// font-weight: bold;
	}
</style>