<template>
	<!-- 工资条插件 -->
	<view class="p-4 flex justify-between items-center">
	  <text>{{ prveMonth }}月份工资条</text>
	  <u-button size="mini" type="primary" class="m-0" @click="toLink">查看</u-button>
	</view>
</template>

<script setup>
	import { ref, computed } from 'vue';
	import { useStore } from 'vuex';
	import dayjs from 'dayjs';
	
	const props = defineProps({ task: { type: Object, default: () => {} } });
	
	const store = useStore();
	const projectId = computed(() => store.getters['project/projectId']);
	const userId = computed(() => store.getters['user/userId']);
	const roleId = computed(() => store.state.role.roleId);
	const token = computed(() => store.state.user.token);
	const domain = computed(() => store.state.domain);
	
	const prveMonth = computed(() => {
		const currMonth = dayjs(+props.task.planStart).format("M");
		return currMonth === 1 ? 12 : currMonth - 1;
	});
	
	function toLink() {
		const url = "http://101.201.226.163/tallsalary/";
		const params = {
			pid: projectId.value,
			uid: userId.value,
			rid: roleId.value,
			token: token.value,
			url: domain.value
		}
		window.location.href = `${url}?pid=${params.pid}&uid=${params.uid}&rid=${params.rid}&token=${params.token}&url=${params.url}`;
	}
</script>

<style>
</style>