是通过v-model绑定的值来判断,用watch监听,获取到用户填写的数据经过处理,点击发布提示
在data中将makeDate定义成数组
<div style="margin-top: 30px">
<span style="display:inline-block;width: 120px;">选择预约日期:</span>
<el-date-picker
v-model="makeDate"
type="daterange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
@change="dateChange()"
></el-date-picker>
</div>
watch监听,取到用户填写开始时间和结束时间相减,处理数据
watch: {
makeDate(newVal) {
// 7天时间
this.seven = 6 * 86400000
// 用户填写的开始时间和结束时间
let dStart = new Date(newVal[0])
let tStart = dStart.getTime(dStart)
let dEnd = new Date(newVal[1])
let tEnd = dEnd.getTime(dEnd)
// 结束时间减去开始时间
this.time = tEnd - tStart
// 判断用户的时间是否大于7天
if (this.time > this.seven) {
console.log('超过7天!')
this.date = [newVal[0], newVal[0]]
}
}
},
点击立即添加
addMake() {
if (this.makeLoading) return
if (this.timeIsNull() || !this.makeDate) {
this.$notify({
message: '请填写完整预约信息',
type: 'warning'
})
return
}
// 当用户选择的时间大于7天,提示再return出去,后面的不执行
if (this.time > this.seven) {
this.$message({
showClose: true,
message: '预约日期最多可以选择7天!',
type: 'error'
})
return
}
this.makeLoading = true
this.handleTimeList()
this.$axios
.post(BASE.BASE_URL2 + `/venueDestine/addVenueDestine`, {
beginDate: this.makeStartDate,
endDate: this.makeEndDate,
fieldId: this.fieldId,
openTimeSection: this.timeStr,
venueId: this.$route.query.venueId
})
.then(res => {
this.makeLoading = false
if (res.data.status === 'success') {
this.$notify({
message: '发布成功',
type: 'success'
})
this.closeRoomPopover()
} else {
}
})
},