Commit e45ca723 authored by 康振飞's avatar 康振飞

时间段控件

parent 5cc2638e
<template> <template>
<div>
<DatePicker <DatePicker
type="datetimerange" :type="type === 'date' ?'daterange':'datetimerange'"
:format="type === 'date' ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss'" :options="options01"
v-model="name" placement="bottom-end"
:format="type === 'date' ? 'yyyy/MM/dd' : 'yyyy/MM/dd HH:mm:ss'"
placeholder="选择时间段" placeholder="选择时间段"
v-model="dataValue"
:clearable="true"
@on-clear="onClear"
@on-change="changeFormat" @on-change="changeFormat"
style="float:left" class="wp"
></DatePicker> ></DatePicker>
<div v-if="showFast">
<RadioGroup
type="button"
size="small"
style="margin-left:5px;line-height:35px;"
@on-change="getTime"
>
<Radio label="当天"></Radio>
<Radio label="近一周"></Radio>
<Radio label="近一月"></Radio>
</RadioGroup>
<!-- <Button size="small" type="text" @click="getTime('1')">当天</Button>
<Button size="small" type="text" @click="getTime('2')">近一周</Button>
<Button size="small" type="text" @click="getTime('3')">近一月</Button> -->
</div>
</div>
</template> </template>
<script> <script>
export default { export default {
...@@ -34,14 +21,50 @@ export default { ...@@ -34,14 +21,50 @@ export default {
}, },
data() { data() {
return { return {
name: this.value dataValue: this.value,
options01: {
shortcuts: [
{
text: '当天',
value() {
const start = new Date(
new Date(new Date().toLocaleDateString()).getTime()
)
const end = new Date()
return [start, end]
}
},
{
text: '近一周',
value() {
const start = new Date(
new Date(new Date().toLocaleDateString()).getTime()
)
const end = new Date()
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
return [start, end]
}
},
{
text: '近一月',
value() {
const start = new Date(
new Date(new Date().toLocaleDateString()).getTime()
)
const end = new Date()
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
return [start, end]
}
}
]
}
} }
}, },
props: { props: {
value: [String, Number, Array], value: [String, Number, Array],
type: { type: {
type: String, type: String,
default: 'dateTime' default: 'date'
}, },
showFast: { showFast: {
type: Boolean, type: Boolean,
...@@ -51,47 +74,37 @@ export default { ...@@ -51,47 +74,37 @@ export default {
created() {}, created() {},
methods: { methods: {
changeFormat(val) { changeFormat(val) {
let newVal = [] console.log(val)
if (val != ',') { if (val) {
if (this.type == 'date') { let newVal = []
newVal.push(val[0].substr(0, 10) + ' 00:00:00') if (val.length==2) {
newVal.push(val[1].substr(0, 10) + ' 23:59:59') if (this.type == 'date') {
} else { if(val[0]){
newVal = val newVal.push(val[0].substr(0, 10) + ' 00:00:00')
newVal.push(val[1].substr(0, 10) + ' 23:59:59')
}else{
newVal = []
}
} else {
newVal = val
}
} }
this.dataValue = newVal
val=newVal;
} }
this.$emit('on-change', val)
this.name = newVal
this.$emit('on-change', newVal)
}, },
getTime(val) {
let timeVal = [] onClear() {
let day1 = new Date() this.$nextTick(() => {
let day2 = new Date() this.dataValue = null
let day3 = new Date() })
let today = day1.setDate(day1.getDate())
today = this.$u.toTime(today)
let week = day2.setDate(day2.getDate() - 6)
week = this.$u.toTime(week)
let month = day3.setMonth(day3.getMonth() - 1)
month = this.$u.toTime(month)
switch (val) {
case '当天':
timeVal = [today, today]
break
case '近一周':
timeVal = [week, today]
break
default:
timeVal = [month, today]
}
this.changeFormat(timeVal)
} }
}, },
computed: {}, computed: {},
watch: { watch: {
name(v) { dataValue(v) {
// this.name = v // this.dataValue = v
} }
} }
} }
......
<template>
<div>
<DatePicker
type="datetimerange"
:format="type === 'date' ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss'"
v-model="name"
placeholder="选择时间段"
@on-change="changeFormat"
style="float:left"
></DatePicker>
<div v-if="showFast">
<RadioGroup
type="button"
size="small"
style="margin-left:5px;line-height:35px;"
@on-change="getTime"
>
<Radio label="当天"></Radio>
<Radio label="近一周"></Radio>
<Radio label="近一月"></Radio>
</RadioGroup>
<!-- <Button size="small" type="text" @click="getTime('1')">当天</Button>
<Button size="small" type="text" @click="getTime('2')">近一周</Button>
<Button size="small" type="text" @click="getTime('3')">近一月</Button> -->
</div>
</div>
</template>
<script>
export default {
name: 'dtSearch',
model: {
prop: 'value',
event: 'on-change'
},
data() {
return {
name: this.value
}
},
props: {
value: [String, Number, Array],
type: {
type: String,
default: 'dateTime'
},
showFast: {
type: Boolean,
default: true
}
},
created() {},
methods: {
changeFormat(val) {
let newVal = []
if (val != ',') {
if (this.type == 'date') {
newVal.push(val[0].substr(0, 10) + ' 00:00:00')
newVal.push(val[1].substr(0, 10) + ' 23:59:59')
} else {
newVal = val
}
}
this.name = newVal
this.$emit('on-change', newVal)
},
getTime(val) {
let timeVal = []
let day1 = new Date()
let day2 = new Date()
let day3 = new Date()
let today = day1.setDate(day1.getDate())
today = this.$u.toTime(today)
let week = day2.setDate(day2.getDate() - 6)
week = this.$u.toTime(week)
let month = day3.setMonth(day3.getMonth() - 1)
month = this.$u.toTime(month)
switch (val) {
case '当天':
timeVal = [today, today]
break
case '近一周':
timeVal = [week, today]
break
default:
timeVal = [month, today]
}
this.changeFormat(timeVal)
}
},
computed: {},
watch: {
name(v) {
// this.name = v
}
}
}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment