smart-switch-ui/src/components/DateRangePicker/index.vue
2024-11-06 08:41:31 +08:00

70 lines
1.5 KiB
Vue

<template>
<el-date-picker
v-model="dateRange"
type="daterange"
value-format="yyyy-MM-dd"
range-separator=""
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
:clearable="false"
v-on="$listeners"
/>
</template>
<script >
import { getLastDate, getLastMonth } from '@/utils'
export default {
name: "DateRangePicker",
props: {
startDate: {
type: String,
default: false,
},
endDate: {
type: String,
default: false,
}
},
data() {
return {
pickerOptions: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = getLastDate(0);
const start = getLastDate(6);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = getLastDate(0);
const start = getLastMonth(1);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = getLastDate(0);
const start = getLastMonth(3);
picker.$emit('pick', [start, end]);
}
}]
},
}
},
computed: {
dateRange: {
get() {
return [this.startDate, this.endDate];
},
set(val) {
this.$emit('update:startDate', val[0]);
this.$emit('update:endDate', val[1])
}
}
},
}
</script>