jiangchengfeiyi-Web/src/layout/components/appointTime.vue

224 lines
7.0 KiB
Vue
Raw Normal View History

2024-12-02 05:04:45 +00:00
<template>
<div class="date-picker">
<div class="father">
<div v-for="(item, index) in dayList" :key="index">
<div class="inner" style="font-size: medium;">
{{ index + 1 }}
2024-12-03 11:51:45 +00:00
<el-checkbox v-model="isAvailableArray[index]" label="这天可预约" style="margin-left: 10px;"/>
2024-12-02 05:04:45 +00:00
</div>
<!-- 时间段部分 -->
<div class="time-picker">
<div v-for="(item, row) in timeList[index]" :key="row" class="box">
<span> {{ row + 1 }} 个时间段</span>
<el-time-select v-model="timeList[index][row].startTime"
style="width: 150px"
:max-time="timeList[index][row].endTime"
placeholder="Start time" size="default"
start="08:30" step="00:15" end="18:30" />
<el-time-select v-model="timeList[index][row].endTime" style="width: 150px"
:min-time="timeList[index][row].startTime" placeholder="End time" size="default"
start="08:30" step="00:15" end="18:30" />
<div class="numRange">
<span>人数范围</span>
<el-select v-model="timeList[index][row].minNumValue"
placeholder="最小人数"
style="width: 100px"
2024-12-03 11:51:45 +00:00
@change="minNumFun(index,row)">
2024-12-02 05:04:45 +00:00
<el-option v-for="item in minOptions[index][row]"
:key="item"
:value="item" />
</el-select>
2024-12-03 11:51:45 +00:00
<el-select v-model="timeList[index][row].maxNumValue"
2024-12-02 05:04:45 +00:00
placeholder="最大人数"
2024-12-03 11:51:45 +00:00
style="width: 100px"
@change="maxNumFun(index,row)"
>
2024-12-02 05:04:45 +00:00
<el-option v-for="item in maxOptions[index][row]"
:key="item"
:value="item" />
</el-select>
<el-button circle @click="addList(index, row)"><el-icon>
<Plus />
</el-icon></el-button>
<el-button circle @click="subList(index, row)" v-if="row + 1 > 1"><el-icon>
<Minus />
</el-icon></el-button>
</div>
</div>
</div>
</div>
</div>
2024-12-02 08:30:55 +00:00
<div class="totalButton">
<el-form-item>
<el-button type="primary" @click="onSubmit">保存</el-button>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetForm">重置</el-button>
</el-form-item>
</div>
2024-12-02 05:04:45 +00:00
</div>
</template>
<script setup lang="ts">
2024-12-02 08:30:55 +00:00
import { onMounted, ref , defineEmits } from 'vue'
2024-12-02 05:04:45 +00:00
import { Plus } from '@element-plus/icons-vue';
2024-12-03 11:51:45 +00:00
import { transfer } from '../../utils/dealStringArray'; //导入js函数
import { ElMessage } from 'element-plus';
2024-12-02 05:04:45 +00:00
const dayList = ref([0, 1, 2, 3]) //今天和未来三天
const timeList = ref([ //时间段数组可以直接通过timeList[index][row]访问对应的时间段
[
{
startTime: '',
endTime: '',
minNumValue: '',
2024-12-03 11:51:45 +00:00
maxNumValue: ''
2024-12-02 05:04:45 +00:00
}
],
[
{
startTime: '',
endTime: '',
minNumValue: '',
2024-12-03 11:51:45 +00:00
maxNumValue: ''
2024-12-02 05:04:45 +00:00
}
],
[
{
startTime: '',
endTime: '',
minNumValue: '',
2024-12-03 11:51:45 +00:00
maxNumValue: ''
2024-12-02 05:04:45 +00:00
}
],
[
{
startTime: '',
endTime: '',
minNumValue: '',
2024-12-03 11:51:45 +00:00
maxNumValue: ''
2024-12-02 05:04:45 +00:00
}
]
])
2024-12-03 11:51:45 +00:00
const isAvailableArray = ref(
Array.from({length:4},()=>(false))
)
2024-12-02 05:04:45 +00:00
//人数数组,初始化好四天六个时间段的人数
const minOptions = ref(
Array.from({length:4},()=>(
Array.from({length:6},()=>(
Array.from({length:50},()=>( 0 ))
))
))
)
const maxOptions = ref(
Array.from({length:4},()=>(
Array.from({length:6},()=>(
Array.from({length:50},()=>( 0 ))
))
))
)
const flag = ref(0) //第一个人数下标
2024-12-03 04:29:33 +00:00
var arr = new Array(4)
2024-12-02 08:30:55 +00:00
const emit = defineEmits(['time-Info']) //组件绑定
2024-12-02 05:04:45 +00:00
onMounted(()=>{
2024-12-03 04:29:33 +00:00
init()
2024-12-02 05:04:45 +00:00
for(let i=0; i<4; i++) { //开始时初始化人数的数组
for(let j=0; j<6; j++) {
for(let k=0;k<50;k++) {
2024-12-02 08:30:55 +00:00
minOptions.value[i][j][k] = k+5;
maxOptions.value[i][j][k] = k+6;
2024-12-02 05:04:45 +00:00
}
}
}
})
const addList = (index: any, row: any) => {
if (timeList.value[index].length < 6) {
timeList.value[index].push({
startTime: '',
endTime: '',
minNumValue: '',
2024-12-03 11:51:45 +00:00
maxNumValue: ''
2024-12-02 05:04:45 +00:00
})
flag.value += 1
}
}
const subList = (index: number, row: number) => {
timeList.value[index].splice(row, 1)
}
2024-12-03 11:51:45 +00:00
const minNumFun = (index : number,row : number)=> {
if(timeList.value[index][row].maxNumValue < timeList.value[index][row].minNumValue && timeList.value[index][row].maxNumValue != '') {
ElMessage({
type: 'error',
message: '最小人数不大于最大人数'
})
timeList.value[index][row].minNumValue = ''
return;
}
2024-12-02 08:30:55 +00:00
}
//组件传值
2024-12-03 04:29:33 +00:00
const onSubmit =()=> {
2024-12-03 11:51:45 +00:00
let tempArr = transfer(timeList.value, arr,isAvailableArray.value)
// console.log(tempArr)
2024-12-02 08:30:55 +00:00
//将数组处理成后端格式
2024-12-03 04:29:33 +00:00
emit('time-Info',tempArr)
2024-12-02 08:30:55 +00:00
}
const resetForm=()=>{
for(let i=0;i<4;i++) {
timeList.value[i] = [{
startTime: '',
endTime: '',
minNumValue: '',
2024-12-03 11:51:45 +00:00
maxNumValue: '',
2024-12-02 08:30:55 +00:00
}]
2024-12-03 11:51:45 +00:00
isAvailableArray.value[i] = false
}
}
const init = () => {
for (var i = 0; i < 4; i ++ ) {
arr[i] = new Array(6)
}
for (var i = 0; i < 4; i ++ ) {
for (var j = 0; j < 6; j ++ ) {
arr[i][j] = {
timeSlot: '',
numberRange: '',
isAvailable: ''
}
}
}
}
const maxNumFun =(index: number ,row: number)=>{
if(timeList.value[index][row].maxNumValue < timeList.value[index][row].minNumValue) {
ElMessage({
type: 'error',
message: '最大人数应该大于最小人数'
})
return;
2024-12-02 05:04:45 +00:00
}
}
</script>
<style lang="scss" scoped>
2024-12-02 08:30:55 +00:00
.date-picker {
height: 750px;
}
2024-12-02 05:04:45 +00:00
div {
font-size: 12px;
color: rgb(96, 98, 102);
}
.time-picker {
display: flex;
flex-wrap: wrap;
}
.box {
width: 380px;
height: 50pxpx;
}
.numRange {
margin-left: 26px;
}
2024-12-02 08:30:55 +00:00
.totalButton {
display: flex;
justify-content: space-evenly;
}
2024-12-02 05:04:45 +00:00
</style>