emis-sapp/components/buns-revtime-sheet/buns-revtime-sheet.vue

225 lines
5.6 KiB
Vue
Raw Normal View History

2023-12-09 11:13:21 +00:00
<template>
<tpx-dialog :show="show" title="上门取件时间" @onClose="handleCloseModal()">
2023-12-10 05:53:38 +00:00
<view style="position: relative;height: calc(60vh);">
2023-12-09 11:13:21 +00:00
<tpx-layout>
<template v-slot:body>
<view class="shet-cont">
<view>
<u-text :text="tips" size="28" color="#999" margin="0 0 20rpx 0"></u-text>
</view>
<view style="flex: 1;">
<view style="display: flex;flex-direction: row;height: 100%;">
<view style="width: 300rpx;height: 100%;background-color:#F6F6F6;">
<tpx-checkitems :list="dayList"
v-model:value="model.date" v-slot="dCurrent" min-checked="1" type="single"
>
<view slot :class="`day-item ${dCurrent.checked?'active':''}`">
{{ dCurrent.item.title }}
</view>
</tpx-checkitems>
</view>
<view style="flex: 1;position: relative;">
<view class="pos-abt-all" style="overflow-y: auto;">
<tpx-checkitems :list="timeFilterList"
v-model:value="model.time" v-slot="tCurrent" min-checked="1" type="single"
>
<view slot :class="`time-item ${tCurrent.checked?'active':''}`">
<u-row justify="between">
<view>
{{ tCurrent.item.title }}
</view>
<view v-if="tCurrent.checked">
<u-icon name="checkbox-mark" size="32" :bold="true"
:custom-style="`${tCurrent.checked?'color:#B12D29;':''}`"
></u-icon>
</view>
</u-row>
</view>
</tpx-checkitems>
</view>
</view>
</view>
</view>
</view>
</template>
<template v-slot:footer>
<view class="blcok-white-noradius" style="margin-top: 0;margin-bottom: 0;">
<u-button @click="handleEditItem()" type="primary" size="large" shape="circle"
custom-style="height:80rpx;font-size: 30rpx;"
>确认</u-button>
</view>
</template>
</tpx-layout>
</view>
</tpx-dialog>
</template>
<script>
import { setClipboardData } from "@/common/untool"
2023-12-10 05:53:38 +00:00
import { numberToChinese } from "@/common/util"
2024-01-29 02:28:56 +00:00
import dayjs from 'dayjs'
2024-07-15 15:18:27 +00:00
let dayFormat = 'YYYY-MM-DD'
let dateTimeFormat = 'YYYY-MM-DD HH:mm:ss'
2023-12-09 11:13:21 +00:00
export default {
2024-07-15 15:18:27 +00:00
watch:{
show: {
handler: function(cval, oval) {
cval && this.initData()
},
deep: true
}
},
2023-12-09 11:13:21 +00:00
computed: {
2024-07-15 15:18:27 +00:00
modelInfo: {
get(){
return this.value
}
},
2023-12-09 11:13:21 +00:00
timeFilterList() {
const _this = this
let list = []
const tItem = this.dayList.filter(t=> _this.model.date == t.val)[0] || {}
list = tItem.timeList || []
return list
},
},
props: {
show: {
default () {
return false
}
},
value: {
default () {
2024-07-15 15:18:27 +00:00
return { }
2023-12-09 11:13:21 +00:00
}
2024-07-15 15:18:27 +00:00
},
2023-12-09 11:13:21 +00:00
},
data() {
return {
tips: '推荐上午 9:00 - 15:00 之间',
range: [8, 19],
model: {
date: '',
time: ''
},
dayList: [
]
}
},
created() {
this.initData()
},
onHide() {
},
2024-01-30 03:09:49 +00:00
unmounted() {},
2023-12-09 11:13:21 +00:00
methods: {
initData() {
this.makeList()
2024-07-15 15:18:27 +00:00
let { pickStartDate, pickFinishDate } = this.modelInfo || {}
2023-12-09 11:13:21 +00:00
// 默认值
this.model.date = this.dayList[0].val
2024-07-15 15:18:27 +00:00
if(pickStartDate && pickFinishDate) {
this.model.date = dayjs(pickStartDate).format(dayFormat)
this.model.time = `${pickStartDate}~${pickFinishDate}`
}
2023-12-09 11:13:21 +00:00
},
makeList() {
const _this = this
const now = dayjs(new Date())
2024-07-15 15:18:27 +00:00
const nowDate = dayjs(now).format(dayFormat)
const plus1Date = dayjs(nowDate).add(1, 'day').format(dayFormat)
const plus2Date = dayjs(nowDate).add(2, 'day').format(dayFormat)
2023-12-09 11:13:21 +00:00
const nowHour = now.get("hours")
let dayList = [
{ title: '今天', val: nowDate },
{ title: '明天', val: plus1Date },
{ title: '后天', val: plus2Date }
]
dayList.map((dItem, dIndex)=> {
const timeList = []
let start = _this.range[0]
let end = _this.range[1]
2023-12-10 05:53:38 +00:00
if(dIndex == 0 && nowHour > start) {
2023-12-09 11:13:21 +00:00
start = nowHour + 1
}
for(var tIndex = start; tIndex <= end; tIndex ++) {
2024-07-15 15:18:27 +00:00
let tItem = {}
tItem.startTime = dayjs(`${dItem.val} ${tIndex}`).format(dateTimeFormat)
tItem.endTime = dayjs(`${dItem.val} ${tIndex + 1}`).format(dateTimeFormat)
tItem.val = `${tItem.startTime}~${tItem.endTime}`
tItem.title = `${dayjs(tItem.startTime).format("HH:mm")}-${dayjs(tItem.endTime).format("HH:mm")}`
2023-12-09 11:13:21 +00:00
if(dIndex == 0 && tIndex == start) {
2024-07-15 15:18:27 +00:00
tItem.title = `${numberToChinese(start - nowHour)}小时内`
2023-12-09 11:13:21 +00:00
}
2024-07-15 15:18:27 +00:00
timeList.push(tItem)
2023-12-09 11:13:21 +00:00
}
dItem.timeList = timeList
})
dayList = dayList.filter(d=> d.timeList.length > 0)
this.dayList = dayList
},
handleCloseModal() {
this.$emit('update:show', false)
},
handleEditItem() {
const { date, time } = this.model
const value = `${date} ${time}`
2024-07-15 15:18:27 +00:00
let curItem
this.dayList.map(d=> {
if(d.val == date) {
d.timeList.map(t=> {
if(t.val == time) {
curItem = t
}
})
}
})
this.$emit('onChange', curItem)
if(curItem){
this.modelInfo.pickStartDate = curItem.startTime
this.modelInfo.pickFinishDate = curItem.endTime
}
2023-12-09 11:13:21 +00:00
this.handleCloseModal()
}
}
}
</script>
<style scoped lang="scss">
.shet-cont{
height: 100%;
padding: 10rpx 0 30rpx 0;
display: flex;
flex-direction: column;
}
.day-item{
height: 100rpx;
line-height: 100rpx;
font-size: 30rpx;
font-weight: 600;
text-align: center;
&.active{
background-color: #fff;
}
}
.time-item{
height: 80rpx;
line-height: 80rpx;
font-size: 28rpx;
padding-left: 100rpx;
&.active{
font-weight: 600;
color: $uni-color-primary;
}
}
</style>