TaskSystem-admin/src/views/task/taskCalendar.vue

236 lines
6.0 KiB
Vue
Raw Normal View History

2023-08-08 12:03:03 +08:00
<template>
2023-08-14 18:31:27 +08:00
<div>
<el-card class="!border-none" v-loading="loading" shadow="never">
<div style="display: flex; justify-content: space-between">
<el-button
2023-08-15 17:10:07 +08:00
v-perms="['task.taskCalendar/add']"
2023-08-14 18:31:27 +08:00
type="primary"
@click="handleAdd"
>
<template #icon>
<icon name="el-icon-Plus" />
</template>
新增
</el-button>
<!-- <div class="btn">
2023-08-14 18:10:43 +08:00
<div :class="{ active: nowType == 0 }" @click="nowType = 0">日历</div>
<div :class="{ active: nowType == 1 }" @click="nowType = 1">列表</div>
</div> -->
2023-08-14 18:31:27 +08:00
</div>
<calendar
:list="taskList"
@clickItem="clickTask"
@initShowDate="initShowDate"
></calendar>
<!-- <div class="mt-4">
2023-08-14 12:05:31 +08:00
<el-calendar v-model="dateValue">
<template #dateCell="{ data }">
<div style="width: 100%; height: 100%">
<p
:class="data.isSelected ? 'is-selected' : ''"
style="padding: 8px 8px 0 8px"
>
{{ data.day.split("-").slice(1).join("-") }}
</p>
<div
class="task"
@click="clickTask(item)"
v-for="(item, index) in taskListFilter(data.day)"
:key="index"
>
{{ item.template_name }}
</div>
2023-08-12 16:05:13 +08:00
</div>
2023-08-14 12:05:31 +08:00
</template>
</el-calendar>
2023-08-14 18:10:43 +08:00
</div>-->
2023-08-14 18:31:27 +08:00
</el-card>
2023-08-09 12:03:55 +08:00
2023-08-14 18:31:27 +08:00
<EditTowPopup
ref="editTowRef"
:task="task"
:type="popupType"
2023-08-17 10:00:38 +08:00
:company_id="company_id"
2023-08-14 18:31:27 +08:00
@success="loadTask"
@close="showEditTow = false"
/>
</div>
2023-08-08 12:03:03 +08:00
</template>
2023-08-12 16:05:13 +08:00
<script lang="ts" setup name="task">
2023-08-14 18:31:27 +08:00
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";
2023-08-08 12:03:03 +08:00
// import { getRoutePath } from "router";
2023-08-14 18:31:27 +08:00
import EditTowPopup from "./editTow.vue";
import { reactive, watch } from "vue";
import { apiTaskList, apiTaskDetails } from "@/api/task";
import calendar from "./calendar.vue";
2023-08-14 18:10:43 +08:00
2023-08-14 18:31:27 +08:00
const route = useRoute();
2023-08-11 18:23:36 +08:00
2023-08-14 18:31:27 +08:00
const dateValue = ref(new Date());
2023-08-14 12:05:31 +08:00
// 当前点击的任务
const task = ref({
2023-08-14 18:31:27 +08:00
create_user_id: 0,
end_time: "",
id: 0,
scheduling_id: 0,
start_time: "",
status: 0,
template_id: 0,
template_name: "",
});
const popupType = ref("add");
2023-08-14 12:05:31 +08:00
const clickTask = (e: any) => {
2023-08-14 18:31:27 +08:00
popupType.value = "show";
// task.value = e;
2023-08-15 12:34:16 +08:00
task.value = taskList.value.find((item: any) => item.id == e) || null;
2023-08-14 18:31:27 +08:00
handleSelect();
};
2023-08-08 20:54:28 +08:00
2023-08-08 12:03:03 +08:00
// 加载
2023-08-14 18:31:27 +08:00
const loading = ref(true);
2023-08-08 12:03:03 +08:00
2023-08-14 18:31:27 +08:00
const editRef = shallowRef<InstanceType<typeof EditPopup>>();
const editTowRef = shallowRef<InstanceType<typeof EditPopup>>();
2023-08-08 12:03:03 +08:00
// 是否显示编辑框
2023-08-14 18:31:27 +08:00
const showEdit = ref(false);
const showEditTow = ref(false);
2023-08-08 12:03:03 +08:00
// 查询条件
const queryParams = reactive({
2023-08-14 18:31:27 +08:00
scheduling_id: "",
start_time: "",
end_time: "",
page_no: 1,
pageSize: 150,
});
2023-08-14 18:18:33 +08:00
if (route.query.id) {
2023-08-14 18:31:27 +08:00
queryParams.scheduling_id = route.query.id.toString();
2023-08-14 18:18:33 +08:00
}
2023-08-17 10:00:38 +08:00
const company_id = ref("");
if (route.query.company_id) company_id.value = route.query.company_id;
2023-08-14 18:31:27 +08:00
const taskList = ref<any>([]);
2023-08-08 12:03:03 +08:00
// 查询
const loadTask = async () => {
2023-08-14 18:31:27 +08:00
apiTaskList(queryParams).then((res) => {
taskList.value = res.lists;
loading.value = false;
});
};
2023-08-08 12:03:03 +08:00
2023-08-14 18:31:27 +08:00
const start_date = ref("");
const end_date = ref("");
2023-08-08 12:03:03 +08:00
// 计算当前显示的第一天和最后一天
2023-08-14 18:31:27 +08:00
const initShowDate = (dateStr = "") => {
const currentDate = dateStr ? new Date(dateStr) : new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth();
const lastDay = new Date(currentYear, currentMonth + 1, 0).getDay(); //获取第一天星期
const startDay = new Date(currentYear, currentMonth, 1).getDay(); //获取最后一天星期
// console.log(new Date(currentYear, currentMonth, 1-startDay).getDate());
// console.log(new Date(currentYear, currentMonth + 1, 6-lastDay).getDate());
start_date.value = timeFormat(
new Date(currentYear, currentMonth, 1 - startDay).getTime()
); //获取第一天时间
end_date.value = timeFormat(
new Date(currentYear, currentMonth + 1, 6 - lastDay).getTime()
); //获取最后一天时间
if (queryParams.start_time != start_date.value) {
queryParams.start_time = start_date.value;
queryParams.end_time = end_date.value;
loading.value = true;
loadTask();
}
};
initShowDate();
2023-08-14 12:05:31 +08:00
// 过滤的任务列表
const taskListFilter = (e: any) => {
2023-08-14 18:31:27 +08:00
return taskList.value
.filter((item: any) => {
const now = new Date(e).getTime() / 1000;
const start = new Date(item.start_time).getTime() / 1000;
const end = new Date(item.end_time).getTime() / 1000;
return now - start >= 0 && now - end <= 0;
})
.slice(0, 5);
};
2023-08-08 12:03:03 +08:00
// 添加
const handleAdd = async () => {
2023-08-14 18:31:27 +08:00
popupType.value = "add";
showEditTow.value = true;
await nextTick();
editTowRef.value?.open("add");
editTowRef.value?.updatedForm();
};
2023-08-14 12:05:31 +08:00
// 查询
const handleSelect = async () => {
2023-08-14 18:31:27 +08:00
popupType.value = "show";
showEditTow.value = true;
await nextTick();
editTowRef.value?.open("show");
2023-08-15 12:34:16 +08:00
editTowRef.value?.updatedForm(task.value);
2023-08-14 18:31:27 +08:00
};
2023-08-14 18:10:43 +08:00
// 当前选择类型
2023-08-14 18:31:27 +08:00
const nowType = ref(0);
2023-08-14 18:10:43 +08:00
const handleTypeClick = (e) => {
2023-08-14 18:31:27 +08:00
console.log(e);
};
2023-08-08 12:03:03 +08:00
</script>
2023-08-12 16:05:13 +08:00
<style lang="scss">
2023-08-08 12:03:03 +08:00
.is-selected {
2023-08-14 18:31:27 +08:00
color: #1989fa;
2023-08-08 12:03:03 +08:00
}
.el-calendar-table .el-calendar-day {
2023-08-14 18:31:27 +08:00
min-height: 8.2rem;
padding: 0;
2023-08-08 12:03:03 +08:00
}
.task {
2023-08-14 18:31:27 +08:00
font-size: 0.8rem;
/* color: #f7ba2a; */
color: #1989fa;
padding: 0 8px;
white-space: nowrap; /* 设置文本不换行 */
overflow: hidden; /* 隐藏溢出的部分 */
text-overflow: ellipsis; /* 在溢出的部分显示省略号 */
&:hover {
background-color: rgba($color: #f38200, $alpha: 0.7);
border-radius: 4px;
color: #fff;
}
2023-08-08 12:03:03 +08:00
}
.the {
2023-08-14 18:31:27 +08:00
color: #ff5100;
2023-08-08 12:03:03 +08:00
}
.tow {
2023-08-14 18:31:27 +08:00
color: #f38200;
2023-08-08 12:03:03 +08:00
}
.fou {
2023-08-14 18:31:27 +08:00
color: red;
2023-08-08 12:03:03 +08:00
}
2023-08-14 18:10:43 +08:00
.btn {
2023-08-14 18:31:27 +08:00
height: 30px;
width: 150px;
border: 1px solid #4a5dff;
border-radius: 5px;
overflow: hidden;
display: flex;
cursor: pointer;
div {
flex: 1;
text-align: center;
line-height: 30px;
}
.active {
background-color: #4a5dff;
color: #fff;
}
2023-08-14 18:10:43 +08:00
}
2023-08-08 12:03:03 +08:00
</style>