Files
dvcp_v2_wxcp_app/components/AiDate.vue

69 lines
1.4 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-12-02 11:50:35 +08:00
@change="handleSelect" :mode="mode" @close="show=false"/>
2021-11-15 10:29:05 +08:00
<div flex @click="show=true">
2022-01-14 09:21:24 +08:00
<div class="label" v-if="label" v-html="label"/>
<div class="placeholder" v-else v-html="placeholder"/>
<u-icon name="arrow-right" color="#ddd"/>
2021-11-15 10:29:05 +08:00
</div>
</section>
</template>
<script>
import dayjs from 'dayjs'
export default {
name: "AiDate",
computed: {
label() {
let arr = (this.selected || this.value)?.toString()?.split(",") || []
2022-01-14 09:21:24 +08:00
arr = arr.map(e => dayjs(e).format("YYYY-MM-DD").replace("Invalid Date", ''))
2021-11-15 10:29:05 +08:00
return arr.join('至')
}
},
data() {
return {
show: false,
selected: ""
}
},
props: {
value: {default: ""},
placeholder: {default: "请选择"},
2021-12-02 11:50:35 +08:00
mode: {default: "date"},//date 单个日期|range 日期范围
2021-12-01 16:06:47 +08:00
maxDate: String
2021-11-15 10:29:05 +08:00
},
methods: {
handleSelect(v) {
if (this.mode == 'date') {
2021-12-02 11:50:35 +08:00
this.selected = v.result
this.$emit('change', v.result)
2021-11-15 10:29:05 +08:00
} else if (this.mode == 'range') {
2021-12-02 11:50:35 +08:00
this.selected = [v.startDate, v.endDate]
this.$emit('change', v)
2021-11-15 10:29:05 +08:00
}
}
}
}
</script>
<style lang="scss" scoped>
.AiDate {
color: #333333;
2022-01-14 09:34:34 +08:00
font-size: 30px;
2021-11-15 10:29:05 +08:00
2022-01-14 09:21:24 +08:00
.label {
font-size: 30px;
}
2022-01-14 09:34:34 +08:00
::v-deep .u-icon {
margin-left: 8px;
2022-01-14 09:21:24 +08:00
}
2022-01-14 09:34:34 +08:00
.placeholder {
color: $uni-text-color-grey;
2021-11-15 10:29:05 +08:00
}
}
</style>