日历
<template>
<div>
<div class="content-header">
<h1>预约管理<small>预约设置</small></h1>
<el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item>预约管理</el-breadcrumb-item>
<el-breadcrumb-item>预约设置</el-breadcrumb-item>
</el-breadcrumb>
</div>
<div class="app-container">
<div class="box">
<div class="box ordersetting">
<el-card class="box-card">
<div class="boxMain">
<el-button
style="margin-bottom: 20px; margin-right: 20px"
type="primary"
@click="downloadTemplate()"
>模板下载</el-button
>
<el-upload
:action="uploadAction"
name="excelFile"
:show-file-list="false"
:on-success="handleSuccess"
:before-upload="beforeUpload"
>
<el-button type="primary">上传文件</el-button>
</el-upload>
</div>
<div>
操作说明:请点击"模板下载"按钮获取模板文件,在模板文件中录入预约设置数据后点击"上传文件"按钮上传模板文件。
</div>
</el-card>
<div class="calendar">
<div class="month">
<div class="currentdate">
<span class="choose-year">{{ currentYear }}年</span>
<span class="choose-month">{{ currentMonth }}月</span>
</div>
<div class="choose">
<span
@click="goCurrentMonth(currentYear, currentMonth)"
class="gotoday"
>今天</span
>
<span @click="pickPre(currentYear, currentMonth)">❮</span>
<span @click="pickNext(currentYear, currentMonth)">❯</span>
</div>
<div class="clearfix"></div>
</div>
<div class="caldate">
<ul class="weekdays">
<li>周一</li>
<li>周二</li>
<li>周三</li>
<li>周四</li>
<li>周五</li>
<li>周六</li>
<li>周日</li>
</ul>
<ul class="days">
<li v-for="(dayobject, index) in days" :key="index">
<template>
<div
class="other-month"
v-if="dayobject.day.getMonth() + 1 != currentMonth"
>
{{ dayobject.day.getDate() }}
</div>
<div
class="everyday"
v-if="dayobject.day.getMonth() + 1 == currentMonth"
>
<span class="datenumber">{{
dayobject.day.getDate()
}}</span>
<template>
<template v-for="obj in leftobj">
<template v-if="obj.date == dayobject.day.getDate()">
<template v-if="obj.number > obj.reservations">
<div class="usual">
<p>可预约{{ obj.number }}人</p>
<p>已预约{{ obj.reservations }}人</p>
</div>
</template>
<template v-else>
<div class="fulled">
<p>可预约{{ obj.number }}人</p>
<p>已预约{{ obj.reservations }}人</p>
<p>已满</p>
</div>
</template>
</template>
</template>
<button
v-if="dayobject.day > today"
@click="handleOrderSet(dayobject.day)"
class="orderbtn"
>
设置
</button>
</template>
</div>
</template>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import { getOrderSettingByMonth,editNumberByDate } from "@/api/orderManage/orderSetting";
export default {
name: "OrderSetting",
data() {
return {
today: new Date(),
currentDay: 1,
currentMonth: 1,
LocalMonth: 1,
currentYear: 1970,
currentWeek: 1,
days: [],
leftobj: [],
uploadAction: process.env.VUE_APP_API + "/orderSetting/upload.do",
};
},
created() {
this.initData(null);
},
methods: {
handleOrderSet(day) {
this.$prompt("请输入可预约人数", "预约设置", {
confirmButtonText: "确定",
cancelButtonText: "取消",
inputPattern: /^[0-9]*[1-9][0-9]*$/,
inputErrorMessage: "只能输入正整数",
})
.then(({ value }) => {
editNumberByDate({
orderDate: this.formatDate(
day.getFullYear(),
day.getMonth() + 1,
day.getDate()
),
number: value,
}).then((response) => {
if (response.data.flag) {
this.initData(
this.formatDate(day.getFullYear(), day.getMonth() + 1, 1)
);
this.$message({
type: "success",
message: response.data.message,
});
} else {
this.$message.error(response.data.message);
}
});
})
},
beforeUpload(file) {
const isXLS = file.type === "application/vnd.ms-excel";
if (isXLS) {
return true;
}
const isXLSX =
file.type ===
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
if (isXLSX) {
return true;
}
this.$message.error("上传文件只能是xls或者xlsx格式!");
return false;
},
downloadTemplate() {
window.location.href = "/template/ordersetting_template.xlsx";
},
handleSuccess(response, file) {
if (response.flag) {
this.$message({
message: response.message,
type: "success",
});
} else {
this.$message.error(response.message);
}
},
initData(cur) {
var date;
var index = 0;
if (cur) {
date = new Date(cur);
} else {
var now = new Date();
var d = new Date(this.formatDate(now.getFullYear(), now.getMonth(), 1));
d.setDate(35);
date = new Date(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
}
this.currentDay = date.getDate();
this.currentYear = date.getFullYear();
this.currentMonth = date.getMonth() + 1;
this.currentWeek = date.getDay();
var today = new Date();
this.LocalMonth = today.getMonth() + 1;
if (this.currentWeek == 0) {
this.currentWeek = 7;
}
var str = this.formatDate(
this.currentYear,
this.currentMonth,
this.currentDay
);
this.days.length = 0;
for (var i = this.currentWeek - 1; i >= 0; i--) {
var d = new Date(str);
d.setDate(d.getDate() - i);
var dayobject = {};
dayobject.day = d;
var now = new Date();
if (
d.getDate() === now.getDate() &&
d.getMonth() === now.getMonth() &&
d.getFullYear() === now.getFullYear()
) {
dayobject.index = index++;
} else if (index != 0 && index < 3) dayobject.index = index++;
this.days.push(dayobject);
}
for (var i = 1; i <= 35 - this.currentWeek; i++) {
var d = new Date(str);
d.setDate(d.getDate() + i);
var dayobject = {};
dayobject.day = d;
var now = new Date();
if (
d.getDate() === now.getDate() &&
d.getMonth() === now.getMonth() &&
d.getFullYear() === now.getFullYear()
) {
dayobject.index = index++;
} else if (index != 0 && index < 3) dayobject.index = index++;
this.days.push(dayobject);
}
getOrderSettingByMonth(this.currentYear, this.currentMonth).then(
(response) => {
if (response.data.flag) {
this.leftobj = response.data.data;
} else {
this.$message.error(response.data.message);
}
}
);
},
goCurrentMonth(year, month) {
var d = new Date();
this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
},
pickPre(year, month) {
var d = new Date(this.formatDate(year, month, 1));
d.setDate(0);
this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
},
pickNext(year, month) {
var d = new Date(this.formatDate(year, month, 1));
d.setDate(35);
this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
},
formatDate(year, month, day) {
var y = year;
var m = month;
if (m < 10) m = "0" + m;
var d = day;
if (d < 10) d = "0" + d;
return y + "-" + m + "-" + d;
},
},
};
</script>
<style scoped></style>

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了