<template>
	<view class="work-container">
		<!-- 宫格组件 -->
		<uni-section title="日常办公" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeProcessGrid">
				<uni-grid-item :index="1">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-outsourcing"></text>
						<text class="text">外协结算</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="2">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-car"></text>
						<text class="text">用车申请</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="3">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-business"></text>
						<text class="text">出差申请</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="4">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-out"></text>
						<text class="text">外出申请</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="5">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-expense"></text>
						<text class="text">费用报销</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="6">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-overtime"></text>
						<text class="text">加班申请</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="7">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-leave"></text>
						<text class="text">请假申请</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="8">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-purchase"></text>
						<text class="text">采购申请</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="9">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-apply-sign-contract"></text>
						<text class="text">合同会签</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="10">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-checkIn"></text>
						<text class="text">考勤</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="11">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-location"></text>
						<text class="text">打卡</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
		<uni-section title="日报周报" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeDiaryGrid">
				<uni-grid-item :index="1">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-diary"></text>
						<text class="text">日报</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="2">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-diary"></text>
						<text class="text">日报</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>

		<uni-section title="系统工具" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeToolsGrid">
				<uni-grid-item :index="1">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-calculator"></text>
						<text class="text">计算器</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="2">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-clear-cache"></text>
						<text class="text">清除缓存</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
		<!-- 计算器弹出层 -->
		<view class="popup_container">
			<cui-calculator ref="calculatorPopup" size="normal"></cui-calculator>
		</view>
		<!-- 清除缓存弹出层 -->
		<view class="clear_cache_popup_container">
			<uni-popup ref="clearCacheDialog" type="dialog">
				<uni-popup-dialog title="确认清除缓存" @confirm="clearCache"></uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script setup lang="ts">
	import cuiCalculator from "@/components/cui-calculator/cui-calculator.vue"
	import { ref } from "vue"
	// import $modal from "@/plugins/modal.js"
	import $tab from "@/plugins/tab.js"
	import { getUserInfo } from '@/utils/auth'
	import { useUserStore } from '@/store/user.js'
	function changeProcessGrid(e) { // 点击流程宫格
		console.log('changeProcessGrid', e);
		// 跳转流程申请页面
		$tab.navigateTo('/pages/work/edit/index?title=' + '')
	}
	function changeDiaryGrid(e) {
		if (1 == e.detail.index) {
			wx.navigateToMiniProgram({
				appId: 'wxd45c635d754dbf59',
				path: `pages/detail/detail?url=https://docs.qq.com/sheet/DZndGYU5aWVBpR1Nm`
			})
			return
		}
		if (2 == e.detail.index) {
			$tab.navigateTo('/pages/work/diary/index')
			return
		}
	}
	function changeToolsGrid(e) { // 点击工具宫格
		switch (e.detail.index) {
			case 1:
				openCalculatorPopup()
				break
			case 2:
				openClearCachePopup()
				break
			default:
		}
		console.log('changeToolsGrid', e);
		// $tab.navigateTo('/pages/work/edit/index?title=' + '')
		// $modal.showToast('模块建设中~')
	}
	// 计算器
	const calculatorPopup = ref(null)
	function openCalculatorPopup() { // 打开计算器弹出层
		calculatorPopup.value.open()
	}
	function closeCalculatorPopup() { // 关闭计算器弹出层
		calculatorPopup.value.close()
	}
	// 清除缓存
	const clearCacheDialog = ref(null)
	function openClearCachePopup() { // 打开清除缓存弹出层
		clearCacheDialog.value.open()
	}
	function closeClearCachePopup() { // 关闭清除缓存弹出层
		clearCacheDialog.value.close()
	}
	const userStore = useUserStore()
	function clearCache() {
		const userInfo = getUserInfo()
		uni.clearStorageSync();
		console.log('userStore.user', userStore.user.value);
		console.log('userInfo', userInfo);
		uni.setStorageSync('userInfo', userInfo)
		console.log('userInfo', userStore.user.value);
		// 提示用户缓存清理成功
		uni.showToast({
			title: '缓存清理成功',
			icon: 'success',
			duration: 2000
		});
	}
</script>

<style lang="scss">
	@import "@/static/font/ygoa/iconfont.css";

	.ygoa-icon {
		font-size: 80rpx;
		// color: #468bf0;
	}

	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}
</style>