This commit is contained in:
aihe 2024-07-16 20:18:23 +08:00
parent a5d7623a4a
commit 762bba38b7

View File

@ -59,8 +59,25 @@
import { setClipboardData } from "@/common/untool" import { setClipboardData } from "@/common/untool"
import { numberToChinese } from "@/common/util" import { numberToChinese } from "@/common/util"
import dayjs from 'dayjs' import dayjs from 'dayjs'
let dayFormat = 'YYYY-MM-DD'
let dateTimeFormat = 'YYYY-MM-DD HH:mm:ss'
export default { export default {
watch:{
show: {
handler: function(cval, oval) {
cval && this.initData()
},
deep: true
}
},
computed: { computed: {
modelInfo: {
get(){
return this.value
}
},
timeFilterList() { timeFilterList() {
const _this = this const _this = this
let list = [] let list = []
@ -77,9 +94,9 @@
}, },
value: { value: {
default () { default () {
return '' return { }
} }
} },
}, },
data() { data() {
return { return {
@ -106,15 +123,20 @@
methods: { methods: {
initData() { initData() {
this.makeList() this.makeList()
let { pickStartDate, pickFinishDate } = this.modelInfo || {}
// 默认值 // 默认值
this.model.date = this.dayList[0].val this.model.date = this.dayList[0].val
if(pickStartDate && pickFinishDate) {
this.model.date = dayjs(pickStartDate).format(dayFormat)
this.model.time = `${pickStartDate}~${pickFinishDate}`
}
}, },
makeList() { makeList() {
const _this = this const _this = this
const now = dayjs(new Date()) const now = dayjs(new Date())
const nowDate = dayjs(now).format('YYYY-MM-DD') const nowDate = dayjs(now).format(dayFormat)
const plus1Date = dayjs(nowDate).add(1, 'day').format('YYYY-MM-DD') const plus1Date = dayjs(nowDate).add(1, 'day').format(dayFormat)
const plus2Date = dayjs(nowDate).add(2, 'day').format('YYYY-MM-DD') const plus2Date = dayjs(nowDate).add(2, 'day').format(dayFormat)
const nowHour = now.get("hours") const nowHour = now.get("hours")
let dayList = [ let dayList = [
{ title: '今天', val: nowDate }, { title: '今天', val: nowDate },
@ -129,17 +151,16 @@
start = nowHour + 1 start = nowHour + 1
} }
for(var tIndex = start; tIndex <= end; tIndex ++) { for(var tIndex = start; tIndex <= end; tIndex ++) {
let cTlt = '', cVal let tItem = {}
let timeStr = `${tIndex < 10?'0':''}${tIndex}:00` tItem.startTime = dayjs(`${dItem.val} ${tIndex}`).format(dateTimeFormat)
let timeNextStr = `${(tIndex + 1) < 10?'0':''}${(tIndex + 1)}:00` tItem.endTime = dayjs(`${dItem.val} ${tIndex + 1}`).format(dateTimeFormat)
cVal = timeStr
cTlt = `${timeStr}-${timeNextStr}` tItem.val = `${tItem.startTime}~${tItem.endTime}`
tItem.title = `${dayjs(tItem.startTime).format("HH:mm")}-${dayjs(tItem.endTime).format("HH:mm")}`
if(dIndex == 0 && tIndex == start) { if(dIndex == 0 && tIndex == start) {
cTlt = `${numberToChinese(start - nowHour)}小时内` tItem.title = `${numberToChinese(start - nowHour)}小时内`
} }
timeList.push({ timeList.push(tItem)
title: cTlt , val: cVal
})
} }
dItem.timeList = timeList dItem.timeList = timeList
}) })
@ -152,8 +173,21 @@
handleEditItem() { handleEditItem() {
const { date, time } = this.model const { date, time } = this.model
const value = `${date} ${time}` const value = `${date} ${time}`
this.$emit('onChange', this.model) let curItem
this.$emit('update:value', value) this.dayList.map(d=> {
if(d.val == date) {
d.timeList.map(t=> {
if(t.val == time) {
curItem = t
}
})
}
})
this.$emit('onChange', curItem)
if(curItem){
this.modelInfo.pickStartDate = curItem.startTime
this.modelInfo.pickFinishDate = curItem.endTime
}
this.handleCloseModal() this.handleCloseModal()
} }
} }