<template>
	<page-meta root-font-size="system" />
	<view class="work-container">
		<!-- 宫格组件 -->
		<view v-if="processList.fList.length != 0">
			<uni-section :title="processList.ftypeList[0].typeName" titleFontSize="1.3rem" type="line"></uni-section>
			<view class="grid-body">
				<uni-grid :column="4" :showBorder="false" @change="changeProcessGrid">
					<uni-grid-item v-for="(item, index) in processList.fList" :index="index" :key="index">
						<view class="grid-item-box">
							<text class="ygoa-icon"
								:class="item.modelPicture == 'default.png' ? 'icon-outsourcing' : item.modelPicture"></text>
							<text class="text">{{ item.modelName }}</text>
						</view>
					</uni-grid-item>
				</uni-grid>
			</view>
		</view>
		<uni-section title="考勤管理" titleFontSize="1.3rem" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeAttendanceGrid">
				<uni-grid-item :index="1">
					<view class="grid-item-box">
						<text class="ygoa-icon icon-checkIn"></text>
						<text class="text">考勤</text>
					</view>
				</uni-grid-item>
				<uni-grid-item :index="2">
					<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="日报周报" titleFontSize="1.3rem" 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="系统工具" titleFontSize="1.3rem" 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 { onMounted, ref } from "vue"
import $tab from "@/plugins/tab.js"
import { useUserStore } from '@/store/user.js'
import { getProcessList } from '@/api/work.js'
import { clearCache } from '@/utils/ygoa.js'
import { onShow } from '@dcloudio/uni-app'
const userStore = useUserStore()

onMounted(() => {
	initProcessList()
})


onShow(()=>{
		uni.$emit('showTabBarBadge')
})
// 流程列表
const processList = ref({
	fList: [],
	ftypeList: [
		{
			typeName: ''
		}
	],
})
// 获取流程宫格数据
function initProcessList() {
	const staffId = userStore.user.useId
	const unitId = userStore.user.unitId
	getProcessList(staffId, unitId).then(res => {
		processList.value = res.returnParams // 设置processList
	})
}
// 点击流程宫格
function changeProcessGrid(e) { 
	// console.log('changeProcessGrid', e);
	const { modelName, modelId, control } = processList.value.fList[e.detail.index]
	// 跳转流程申请页面
	$tab.navigateTo('/pages/work/edit/index?modelName=' + modelName + '&modelId=' + modelId + '&control=' + control)
}
// 点击考勤宫格
function changeAttendanceGrid(e) {
	if (1 == e.detail.index) { // 考勤
		$tab.navigateTo('/pages/mine/checkIn/checkIn')
	}
	if (2 == e.detail.index) { // 打卡
		$tab.navigateTo('/pages/mine/clockIn/clockIn')
	}
}
// 点击日报宫格
function changeDiaryGrid(e) { 
	if (1 == e.detail.index) {
		wx.navigateToMiniProgram({
			appId: 'wxd45c635d754dbf59',
			path: `pages/detail/detail?url=https://docs.qq.com/sheet/DZndGYU5aWVBpR1Nm`
		})
		// wx.navigateToMiniProgram({
		// 	appId: 'wxde4bf149a4c88707',
		// 	path: `pages/login`
		// })
		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:
			clearCache()
			// openClearCachePopup() // 打开清除缓存弹出层
			break
		default:
	}
}
// 计算器
const calculatorPopup = ref(null)
function openCalculatorPopup() { // 打开计算器弹出层
	calculatorPopup.value.open()
}
// 清除缓存
// const clearCacheDialog = ref(null)
// function openClearCachePopup() { // 打开清除缓存弹出层
// 	clearCacheDialog.value.open()
// }
// const userStore = useUserStore()

</script>

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

.ygoa-icon {
	font-size: calc(80rpx + .5*(1rem - 16px));
}

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

view {
	font-size: calc(14px + .5*(1rem - 16px));
	line-height: inherit;
}

/* #endif */

.text {
	text-align: center;
	font-size: calc(26rpx + .5* (1rem - 16px));// 16px
	margin-top: 10rpx;
}
.work-container {
	.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>