Files
dvcp_v2_wxcp_app/src/components/AiDate.vue

61 lines
1.3 KiB
Vue
Raw Normal View History

2021-11-15 10:29:05 +08:00
<template>
<section class="AiDate">
2021-12-01 16:06:47 +08:00
<u-calendar v-model="show" :maxDate="maxDate"
2021-11-18 17:53:42 +08:00
@confirm="handleSelect" :mode="mode" @close="show=false"/>
2021-11-15 10:29:05 +08:00
<div flex @click="show=true">
<div v-if="label" v-html="label"/>
<div v-else v-html="placeholder"/>
<i class="iconfont iconfont-iconArrow_Down"/>
</div>
</section>
</template>
<script>
import dayjs from 'dayjs'
export default {
name: "AiDate",
computed: {
label() {
let arr = (this.selected || this.value)?.toString()?.split(",") || []
arr = arr.map(e => dayjs(e).format("MM-DD").replace("Invalid Date", ''))
return arr.join('至')
}
},
data() {
return {
show: false,
selected: ""
}
},
props: {
value: {default: ""},
placeholder: {default: "请选择"},
mode: {default: "single"},//date 单个日期|range 日期范围
2021-12-01 16:06:47 +08:00
maxDate: String
2021-11-15 10:29:05 +08:00
},
methods: {
handleSelect(v) {
2021-11-18 17:53:42 +08:00
this.show = false
2021-11-15 10:29:05 +08:00
if (this.mode == 'date') {
2021-11-18 17:53:42 +08:00
this.selected = v?.[0]
2021-11-15 10:29:05 +08:00
} else if (this.mode == 'range') {
2021-11-18 17:53:42 +08:00
this.selected = [v?.[0], v?.slice(-1)?.[0]]
2021-11-15 10:29:05 +08:00
}
2021-11-18 17:53:42 +08:00
this.$emit('change', this.selected)
2021-11-15 10:29:05 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.AiDate {
color: #333333;
.iconfont-iconArrow_Down {
margin-left: 4px;
font-size: 32px;
}
}
</style>