|
|
|
@ -8,7 +8,7 @@ |
|
|
|
|
<view style="flex: 1;display: flex;flex-wrap: wrap;align-content: flex-start; gap:25rpx"> |
|
|
|
|
<view @click="seleFn(index)" v-for="(item,index) in dateOptions" |
|
|
|
|
:class=" seleIndex==index?'seledatebody_item': 'datebody_item'">{{item.label}}</view> |
|
|
|
|
<uni-datetime-picker @change='pickerClick' type="datetimerange" :start="starDate" :end="endDate" |
|
|
|
|
<uni-datetime-picker @change='pickerClick' type="datetimerange" :start="starDate" :end="endDate" |
|
|
|
|
rangeSeparator="至" v-model="single"> |
|
|
|
|
<view @click="seleIndex=4" :class=" seleIndex==4?'seledatebody_item':'datebody_item'">自定义</view> |
|
|
|
|
</uni-datetime-picker> |
|
|
|
@ -19,7 +19,6 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
props: { |
|
|
|
|
value: { |
|
|
|
@ -54,8 +53,8 @@ |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
single: '', |
|
|
|
|
endDate:'', |
|
|
|
|
starDate:'', |
|
|
|
|
endDate: '', |
|
|
|
|
starDate: '', |
|
|
|
|
seleIndex: 1, |
|
|
|
|
seachValue: '', |
|
|
|
|
dateOptions: [{ |
|
|
|
@ -78,49 +77,81 @@ |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
created() { |
|
|
|
|
let date = new Date |
|
|
|
|
this.starDate = new Date |
|
|
|
|
this.starDate.setMonth((date.getMonth()-1 ==0?12:date.getMonth()-1)) |
|
|
|
|
this.starDate.setDate(1) |
|
|
|
|
this.starDate = `${this.starDate.getFullYear()}-${this.starDate.getMonth()+1}-${this.starDate.getDate()} ${this.starDate.getHours()}:${this.starDate.getMinutes()}` |
|
|
|
|
this.endDate = `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}` |
|
|
|
|
// let date = new Date |
|
|
|
|
// this.starDate = new Date |
|
|
|
|
// this.starDate.setMonth((date.getMonth() - 1 == 0 ? 12 : date.getMonth() - 1)) |
|
|
|
|
// this.starDate.setDate(1) |
|
|
|
|
// this.starDate = |
|
|
|
|
// `${this.starDate.getFullYear()}-${this.starDate.getMonth()+1}-${this.starDate.getDate()} ${this.starDate.getHours()}:${this.starDate.getMinutes()}` |
|
|
|
|
// this.endDate = |
|
|
|
|
// `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}` |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
pickerClick(e){ |
|
|
|
|
pickerClick(e) { |
|
|
|
|
this.$emit('input', false) |
|
|
|
|
this.$emit('datePopupChange',e) |
|
|
|
|
this.$emit('datePopupChange', e) |
|
|
|
|
}, |
|
|
|
|
handlerDate(date) { |
|
|
|
|
if(date instanceof String || date instanceof Number) { |
|
|
|
|
date = new Date(parseInt(date)) |
|
|
|
|
} |
|
|
|
|
if (!(date instanceof Date)) return {} |
|
|
|
|
return { |
|
|
|
|
y: date.getFullYear(), |
|
|
|
|
M: (date.getMonth() + 1 + '').padStart(2, '0'), |
|
|
|
|
d: (date.getDate() + '').padStart(2, '0'), |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
seleFn(index) { |
|
|
|
|
this.seleIndex = index |
|
|
|
|
let date = new Date |
|
|
|
|
let date = new Date() |
|
|
|
|
switch (this.seleIndex) { |
|
|
|
|
case 0: |
|
|
|
|
this.$emit('datePopupChange',[`${date.getFullYear()}-${date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1}-${date.getDate()<10?'0'+date.getDate():date.getDate()} 00:00:00`,`${date.getFullYear()}-${date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1}-${date.getDate()<10?'0'+date.getDate():date.getDate() } 23:59:59`]) |
|
|
|
|
let dayInfo = this.handlerDate(date) |
|
|
|
|
this.$emit('datePopupChange', [ |
|
|
|
|
`${dayInfo.y}-${dayInfo.M}-${dayInfo.d} 00:00:00`, |
|
|
|
|
`${dayInfo.y}-${dayInfo.M}-${dayInfo.d} 23:59:59` |
|
|
|
|
]) |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
let yesterday = new Date((date.getTime() - (86400000))) |
|
|
|
|
this.$emit('datePopupChange',[`${yesterday.getFullYear()}-${yesterday.getMonth()+1<10?'0'+(yesterday.getMonth()+1):yesterday.getMonth()+1}-${yesterday.getDate()<10?'0'+yesterday.getDate():yesterday.getDate()} 00:00:00`,`${yesterday.getFullYear()}-${yesterday.getMonth()+1<10?'0'+(yesterday.getMonth()+1):yesterday.getMonth()+1}-${yesterday.getDate()<10?'0'+yesterday.getDate():yesterday.getDate()} 23:59:59`]) |
|
|
|
|
let yesterday = new Date((date.getTime() - (86400000))); |
|
|
|
|
let yesterdayInfo = this.handlerDate(yesterday) |
|
|
|
|
this.$emit('datePopupChange', [ |
|
|
|
|
`${yesterdayInfo.y}-${yesterdayInfo.M}-${yesterdayInfo.d} 00:00:00`, |
|
|
|
|
`${yesterdayInfo.y}-${yesterdayInfo.M}-${yesterdayInfo.d} 23:59:59` |
|
|
|
|
]) |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
let endLastWeek = new Date(date.getTime() - ((date.getDay() == 0 ? 7 : date.getDay()) * 86400000 )) |
|
|
|
|
let starLastWeek = new Date(endLastWeek.getTime() - (6*86400000)) |
|
|
|
|
this.$emit('datePopupChange',[`${starLastWeek.getFullYear()}-${starLastWeek.getMonth()+1<10?'0'+(starLastWeek.getMonth()+1):starLastWeek.getMonth()+1}-${starLastWeek.getDate()<10?'0'+starLastWeek.getDate():starLastWeek.getDate()} 00:00:00`,`${endLastWeek.getFullYear()}-${endLastWeek.getMonth()+1<10?'0'+(endLastWeek.getMonth()+1):endLastWeek.getMonth()+1}-${endLastWeek.getDate()<10?'0'+endLastWeek.getDate():endLastWeek.getDate()} 23:59:59`]) |
|
|
|
|
let endLastWeek = new Date(date.getTime() - ((date.getDay() == 0 ? 7 : date.getDay()) * 86400000)) |
|
|
|
|
let starLastWeek = new Date(endLastWeek.getTime() - (6 * 86400000)) |
|
|
|
|
|
|
|
|
|
let starLastWeekInfo = this.handlerDate(starLastWeek) |
|
|
|
|
let endLastWeekInfo = this.handlerDate(endLastWeek) |
|
|
|
|
|
|
|
|
|
this.$emit('datePopupChange', [ |
|
|
|
|
`${starLastWeekInfo.y}-${starLastWeekInfo.M}-${starLastWeekInfo.d} 00:00:00`, |
|
|
|
|
`${endLastWeekInfo.y}-${endLastWeekInfo.M}-${endLastWeekInfo.d} 23:59:59` |
|
|
|
|
]) |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
let LastMonth = new Date(date.getTime() - ((86400000 * date.getDate()))) |
|
|
|
|
this.$emit('datePopupChange',[`${LastMonth.getFullYear()}-${LastMonth.getMonth()+1<10?'0'+(LastMonth.getMonth()+1):LastMonth.getMonth()+1}-01 00:00:00`,`${LastMonth.getFullYear()}-${LastMonth.getMonth()+1<10?'0'+(LastMonth.getMonth()+1):LastMonth.getMonth()+1}-${LastMonth.getDate()<10?'0'+LastMonth.getDate():LastMonth.getDate()} 23:59:59`]) |
|
|
|
|
let LastMonthInfo = this.handlerDate(LastMonth) |
|
|
|
|
this.$emit('datePopupChange', [ |
|
|
|
|
`${LastMonthInfo.y}-${LastMonthInfo.M}-01 00:00:00`, |
|
|
|
|
`${LastMonthInfo.y}-${LastMonthInfo.M}-${LastMonthInfo.d} 23:59:59` |
|
|
|
|
]) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
this.$emit('input',false) |
|
|
|
|
this.$emit('input', false) |
|
|
|
|
}, |
|
|
|
|
pickerChange(e) { |
|
|
|
|
this.$emit('pickerChange', this.list[e.detail.value[0]]) |
|
|
|
|
}, |
|
|
|
|
change(e) { |
|
|
|
|
this.$emit('input',e.show) |
|
|
|
|
this.$emit('input', e.show) |
|
|
|
|
}, |
|
|
|
|
confirmFn() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|