120 lines
2.5 KiB
Vue
120 lines
2.5 KiB
Vue
<template>
|
|
<view @click="handleSelectDate" class="pos-rlt">
|
|
<u-input :placeholder="placeholder" :fontSize="fontSize" :modelValue="inputValue"
|
|
:custom-style="`border-radius: 10rpx;padding: 11rpx 20rpx;${customStyle};`"
|
|
readonly="true"
|
|
>
|
|
<template v-slot:suffix>
|
|
<u-icon name="calendar" :size="fontSize*1.5"></u-icon>
|
|
</template>
|
|
</u-input>
|
|
<view class="pos-abt-all">
|
|
<view v-if="showTools" @click.stop="">
|
|
<tpx-select :list="toolsRangesList" :value="value[0]" :customInput="true" mode="drop" @onChange="handleToolsRangChange">
|
|
<view :style="`height: 64rpx;`" ></view>
|
|
</tpx-select>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<!-- 日历 -->
|
|
<u-calendar title="请选择日期范围" color="#B12D29" mode="range" rowHeight="90" closeOnClickOverlay :show="showCladar" :defaultDate="value" @confirm="handleClaOk" @close="handleSwitchCladar"
|
|
></u-calendar>
|
|
</template>
|
|
|
|
<script>
|
|
import { } from "@/common/untool"
|
|
import dayjs from "dayjs"
|
|
|
|
export default {
|
|
computed: {
|
|
inputValue() {
|
|
const val = this.value
|
|
return val && (val.length > 1 ? val.join("~") : val[0])
|
|
}
|
|
},
|
|
props: {
|
|
value: {
|
|
default () {
|
|
return ''
|
|
}
|
|
},
|
|
placeholder:{
|
|
default () {
|
|
return '请选择日期'
|
|
}
|
|
},
|
|
fontSize: {
|
|
default () {
|
|
return 26
|
|
}
|
|
},
|
|
customStyle:{
|
|
default () {
|
|
return ''
|
|
}
|
|
},
|
|
showTools:{
|
|
default () {
|
|
return true
|
|
}
|
|
},
|
|
toolsRangesList: {
|
|
default () {
|
|
return [
|
|
{ title: '今日', val: dayjs().format("YYYY-MM-DD") },
|
|
{ title: '昨日', val: dayjs().subtract(1, 'days').format("YYYY-MM-DD") },
|
|
{ title: '最近一周', val: dayjs().subtract(7, 'days').format("YYYY-MM-DD") },
|
|
{ title: '自定义', val: -1 },
|
|
]
|
|
}
|
|
},
|
|
placeholderStyle:{
|
|
default () {
|
|
return ''
|
|
}
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
showCladar: false
|
|
}
|
|
},
|
|
created() {
|
|
|
|
},
|
|
onHide() {
|
|
|
|
},
|
|
unmounted() {},
|
|
|
|
methods: {
|
|
handleSelectDate() {
|
|
this.handleSwitchCladar()
|
|
},
|
|
handleChange(val){
|
|
this.$emit('change', val)
|
|
this.$emit('update:value', val)
|
|
},
|
|
handleClaOk(res){
|
|
const ary = Object.values(res)
|
|
const val = [ary[0], ary[ary.length-1]]
|
|
this.handleChange(val)
|
|
this.handleSwitchCladar()
|
|
},
|
|
handleSwitchCladar() {
|
|
this.showCladar = !this.showCladar
|
|
},
|
|
handleToolsRangChange(val) {
|
|
if(val == -1) {
|
|
this.handleSwitchCladar()
|
|
} else {
|
|
this.handleChange([val, dayjs().format("YYYY-MM-DD")])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
|
|
</style> |