fix;修改日历控件逻辑

This commit is contained in:
tt 2024-10-22 15:56:21 +08:00
parent 357063025e
commit 9f0e95e475
2 changed files with 103 additions and 4 deletions

View File

@ -33,7 +33,7 @@ export function postAddProductApi(data) {
// 商品排期详情
export function getProductSchedules(data) {
return request({
url: `/admin/products/productschedules?id=${data}`,
url: `/admin/products/productschedules?id=${data.id}&date=${data.date}`,
method: "get",
});
}

View File

@ -1,6 +1,18 @@
<template>
<div class="pro_scheduling">
<el-calendar v-model="value">
<div class="pick">
<span>{{ yue ? yue : dDate }}</span>
<el-date-picker
v-model="yue"
value-format="yyyy-MM"
format="yyyy 年 MM 月"
type="month"
placeholder="选择日期"
@change="changeYue"
>
</el-date-picker>
</div>
<el-calendar v-model="yue">
<template #dateCell="{ date }">
<div>
<div>{{ date.getDate() }}</div>
@ -77,6 +89,8 @@ export default {
num: "",
id: "",
},
yue: "",
dDate: "",
rules: {
num: [
{
@ -93,9 +107,19 @@ export default {
this.getList();
},
methods: {
async getList() {
const res = await getProductSchedules(this.formData.id);
async getList(val) {
const date = this.value; // 使
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const formattedDate = `${year}-${month}`;
this.dDate = formattedDate;
const param = {
id: this.formData.id,
date: val ? val : formattedDate,
};
const res = await getProductSchedules(param);
if (res && res.error === 0) {
this.appointments = {}; //
res.data.forEach((item) => {
this.$set(this.appointments, item.date, {
books_num: item.books_num,
@ -104,11 +128,50 @@ export default {
});
}
},
changeYue() {
this.getList(this.yue);
},
isDateAvailable(date) {
const today = new Date();
today.setHours(0, 0, 0, 0);
return date >= today;
},
isDateAvailable(date) {
const today = new Date();
today.setHours(0, 0, 0, 0);
//
const selectedYear = this.yue
? new Date(this.yue).getFullYear()
: today.getFullYear();
const selectedMonth = this.yue
? new Date(this.yue).getMonth()
: today.getMonth();
//
const dateYear = date.getFullYear();
const dateMonth = date.getMonth();
//
if (
dateYear > selectedYear ||
(dateYear === selectedYear && dateMonth > selectedMonth)
) {
return true;
}
//
if (
dateYear === selectedYear &&
dateMonth === selectedMonth &&
date >= today
) {
return true;
}
//
return false;
},
bookDate(date) {
console.log(`预约日期: ${date.toLocaleDateString()}`);
this.dialogVisible = true;
@ -151,6 +214,14 @@ export default {
</script>
<style scoped lang="scss">
.pick {
position: relative;
top: 20px;
left: -327px;
span {
margin-right: 20px;
}
}
.pro_scheduling {
display: flex;
flex-direction: column;
@ -175,4 +246,32 @@ export default {
font-size: 14px;
margin-top: 10px;
}
::v-deep .el-calendar-table:not(.is-range) td.prev,
::v-deep .el-calendar-table:not(.is-range) td.next {
cursor: not-allowed;
pointer-events: none;
// display: none;
}
// ::v-deep .el-calendar-table:not(.is-range) td.prev {
// /**/
// visibility: hidden;
// }
.prev > .el-calendar-day > .dateContent {
display: none;
}
.next > .el-calendar-day > .dateContent {
display: none;
}
//
::v-deep .el-calendar-table:not(.is-range) td.next {
/*隐藏下个月的日期*/
visibility: hidden;
}
//
::v-deep .el-calendar__button-group {
display: none;
}
::v-deep .el-calendar__title {
display: none;
}
</style>