Commit 1700b95e by 李伟康

feat(OrderPopup): 添加日期时间选择功能

- 新增 DateTime 组件用于选择日期和时间
- 更新 Popup 组件以支持 DateTime
- 修改 index.vue 以集成 DateTime 组件
- 优化其他组件的命名和配置
1 parent 85fcb5e1
<template>
<view class="date-list">
<picker-view
class="picker picker_max"
:value="dateValues"
indicator-class="indicator"
@change="changeDate"
>
<picker-view-column>
<template v-for="(item,index) in days">
<view
class="view"
:key="index"
>{{item}}</view>
</template>
</picker-view-column>
</picker-view>
<picker-view
class="picker"
:value="hourValues"
indicator-class="indicator"
@change="changeHour"
>
<picker-view-column>
<template v-for="(item,index) in hours">
<view
class="view"
:key="index"
>{{item}}</view>
</template>
</picker-view-column>
</picker-view>
<picker-view
class="picker"
:value="minuteValues"
indicator-class="indicator"
@change="changeMinutes"
>
<picker-view-column>
<template v-for="(item,index) in minutes">
<view
class="view"
:key="index"
>{{item}}</view>
</template>
</picker-view-column>
</picker-view>
</view>
</template>
<script type='text/ecmascript-6'>
import dayjs from 'dayjs'
export default {
name: 'DateTime',
inject: ['userInfo'],
data () {
return {
hours: [],
days: [],
minutes: [],
dateValues: [],
hourValues: [],
minuteValues: [],
loading: true
}
},
props: {
},
mounted () {
this.initDate()
},
methods: {
initDate () {
this.dateValues = []
this.hourValues = []
this.minuteValues = []
const today = new Date()
this.getDateList('2019/01/01', new Date(today.getFullYear(), today.getMonth(), today.getDate()))
},
getDateList (starDay, endDay) {
const arr = [];
const dates = [];
// 设置两个日期UTC时间
const db = new Date(starDay);
const de = new Date(endDay);
// 获取两个日期GTM时间
const s = db.getTime() - 24 * 60 * 60 * 1000;
const d = de.getTime() - 24 * 60 * 60 * 1000;
// 获取到两个日期之间的每一天的毫秒数
for (let i = s; i <= d;) {
i = i + 24 * 60 * 60 * 1000;
arr.push(parseInt(String(i)));
}
// 获取每一天的时间 YY-MM-DD
for (const j in arr) {
const time = new Date(arr[j]);
const year = time.getFullYear();
const mouth = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
const day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
const YYMMDD = year + '/' + mouth + '/' + day;
dates.push(YYMMDD);
}
this.getHourList(dates)
},
getHourList (days) {
const hours = [], today = new Date();
for (let hour = 0; hour < today.getHours() + 1; hour++) {
hours.push(hour.toString().padStart(2, '0'));
}
this.getMinuteList(days, hours)
},
getMinuteList (days, hours) {
const minutes = [];
const today = new Date()
for (let minute = 0; minute < today.getMinutes() + 1; minute++) {
minutes.push(minute.toString().padStart(2, '0'));
}
// 设置默认时间
let { dateValues, hourValues, minuteValues } = this
const HOUR_STR = today.getHours().toString().padStart(2, '0')
const MUNTUE_STR = today.getMinutes().toString().padStart(2, '0')
// const defalutHIndex = hours.indexOf(HOUR_STR)
// const defalutMIndex = minutes.indexOf(MUNTUE_STR)
dateValues.push(days.length + 1)
hourValues.push(hours.length + 1)
minuteValues.push(minutes.length + 1)
this.currentDate = dayjs().format('YYYY/MM/DD')
this.currentHour = HOUR_STR
this.currentMinute = MUNTUE_STR
this.hours = hours
this.days = days
this.minutes = minutes
this.dateValues = dateValues
this.hourValues = hourValues
this.minuteValues = minuteValues
this.loading = false
setTimeout(() => {
this.minuteValues = minuteValues
this.loading = false
}, 100)
},
changeDate (e) {
const { days } = this
const { value } = e.detail
const index = value[0]
this.currentDate = days[index]
// 选择过去时间需要重新初始化时分
const today = dayjs().format('YYYY/MM/DD')
const timeType = this.currentDate != today ? 1 : 0
this.getAllTimeOrPartTime(timeType)
},
changeHour (e) {
const { hours, days, dateValues } = this
const { value } = e.detail
const index = value[0]
this.currentHour = hours[index]
// 处理当前天切换别的小时,别的分不能选后面分到60的问题
// const dayIndex = dateValues[0]
// this.currentDate = days[dayIndex]
const today = dayjs().format('YYYY/MM/DD')
const timeType = this.currentDate != today ? 1 : 0
this.getAllTimeOrPartTimeMinute(timeType)
},
changeMinutes (e) {
const { minutes } = this
const { value } = e.detail
const index = value[0]
this.currentMinute = minutes[index]
},
getAllTimeOrPartTime (type) {
const today = new Date()
const hours = [], minutes = [], hour_len = type == 1 ? 24 : today.getHours() + 1, minute_len = type == 1 ? 60 : today.getMinutes() + 1;
for (let hour = 0; hour < hour_len; hour++) {
hours.push(hour.toString().padStart(2, '0'));
}
for (let minute = 0; minute < minute_len; minute++) {
minutes.push(minute.toString().padStart(2, '0'));
}
this.hours = hours
this.minutes = minutes
},
getAllTimeOrPartTimeMinute (type) {
const today = new Date()
const currentHour = today.getHours()
const timeType = this.currentHour != currentHour ? 1 : 0
const minutes = [], minute_len = type == 1 || timeType == 1 ? 60 : today.getMinutes() + 1;
for (let minute = 0; minute < minute_len; minute++) {
minutes.push(minute.toString().padStart(2, '0'));
}
this.minutes = minutes
},
getResult () {
let str = ''
str = this.currentDate + ' ' + this.currentHour + ':' + this.currentMinute + ":00"
const result = dayjs(str).format('YYYY/MM/DD HH:mm:ss')
return result
}
}
}
</script>
<style scoped lang='scss'>
.date-list {
height: 100%;
display: grid;
grid-template-columns: repeat(3, 1fr);
.picker {
height: 100%;
text-align: center;
}
}
</style>
\ No newline at end of file \ No newline at end of file
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import NP from 'number-precision' import NP from 'number-precision'
export default { export default {
name: 'GoodsList', name: 'PackageList',
inject: ['userInfo', 'baseConfigData'], inject: ['userInfo', 'baseConfigData'],
data () { data () {
return { return {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
export default { export default {
name: '', name: 'Popup',
props: { props: {
animation: { animation: {
type: Boolean, type: Boolean,
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
export default { export default {
name: 'GoodsList', name: 'SkuGoodsList',
inject: ['userInfo', 'baseConfigData'], inject: ['userInfo', 'baseConfigData'],
data () { data () {
return { return {
......
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
components: { components: {
Popup, Popup,
}, },
name: '', name: 'SkuPopup',
props: { props: {
}, },
......
...@@ -65,7 +65,7 @@ const componentConfig = { ...@@ -65,7 +65,7 @@ const componentConfig = {
title: '选择商品(可多选)', title: '选择商品(可多选)',
placeholder: '请输入名称', placeholder: '请输入名称',
idKey: 'goodsId', idKey: 'goodsId',
goodsType:[2] // 前侧窗玻璃 goodsType: [2] // 前侧窗玻璃
}, },
8: { 8: {
name: 'GoodsList', name: 'GoodsList',
...@@ -86,19 +86,24 @@ const componentConfig = { ...@@ -86,19 +86,24 @@ const componentConfig = {
title: '选择商品(可多选)', title: '选择商品(可多选)',
placeholder: '请输入名称', placeholder: '请输入名称',
idKey: 'goodsId', idKey: 'goodsId',
goodsType:[5, 6, 7] // 天窗 goodsType: [5, 6, 7] // 天窗
}, },
11:{ 11: {
name: 'PackageList', name: 'PackageList',
title: '选择套餐', title: '选择套餐',
placeholder:'查找', placeholder: '查找',
idKey: 'packageCode' idKey: 'packageCode'
}, },
12:{ 12: {
name:'SkuGoodsList', name: 'SkuGoodsList',
title: '选择商品', title: '选择商品',
placeholder:'查找', placeholder: '查找',
},
13: {
name: 'DateTime',
title: '选择时间',
hideSearch: true,
} }
} }
export default { componentConfig}
\ No newline at end of file \ No newline at end of file
export default { componentConfig }
\ No newline at end of file \ No newline at end of file
...@@ -78,6 +78,7 @@ import GoodsList from './components/GoodsList.vue' ...@@ -78,6 +78,7 @@ import GoodsList from './components/GoodsList.vue'
import PackageList from './components/PackageList.vue' import PackageList from './components/PackageList.vue'
import SkuGoodsList from './components/SkuGoodsList.vue' import SkuGoodsList from './components/SkuGoodsList.vue'
import SkuPopup from './components/SkuPopup.vue' import SkuPopup from './components/SkuPopup.vue'
import DateTime from './components/DateTime.vue'
export default { export default {
components: { components: {
Popup, Popup,
...@@ -88,7 +89,8 @@ export default { ...@@ -88,7 +89,8 @@ export default {
GoodsList, GoodsList,
PackageList, PackageList,
SkuGoodsList, SkuGoodsList,
SkuPopup SkuPopup,
DateTime
}, },
name: '', name: '',
props: { props: {
...@@ -183,6 +185,9 @@ export default { ...@@ -183,6 +185,9 @@ export default {
}, },
confirm () { confirm () {
let { chooseContent, popupType } = this let { chooseContent, popupType } = this
if (popupType === 13) {
chooseContent = this.componentRef().getResult()
}
if (chooseContent) { if (chooseContent) {
this.$emit('onConfirm', { this.$emit('onConfirm', {
chooseContent, chooseContent,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!