Commit a53adc74 by 岑成威

fix: 兜底用户信息覆盖手机号码

1 parent 6806f48a
<template> <template>
<view class="date-list"> <view v-if="ready && days.length" class="date-list">
<picker-view class="picker picker_max" :value="dateValues" indicator-class="indicator" @change="changeDate"> <picker-view class="picker picker_max" :value="dateValues" indicator-class="indicator" @change="changeDate">
<picker-view-column> <picker-view-column>
<template v-for="(item, index) in days"> <template v-for="(item, index) in days">
...@@ -29,158 +29,155 @@ import dayjs from 'dayjs' ...@@ -29,158 +29,155 @@ import dayjs from 'dayjs'
export default { export default {
name: 'DateTime', name: 'DateTime',
inject: ['userInfo'], inject: ['userInfo'],
props: {
defaultTime: {
type: String,
default: ''
}
},
data () { data () {
return { return {
hours: [], hours: [],
days: [], days: [],
minutes: [], minutes: [],
dateValues: [], dateValues: [0],
hourValues: [], hourValues: [0],
minuteValues: [], minuteValues: [0],
loading: true ready: false,
currentDate: '',
currentHour: '',
currentMinute: ''
} }
}, },
props: {
},
mounted () {
this.initDate()
},
methods: { methods: {
initDate () { getList () {
this.dateValues = [] this.ready = false
this.hourValues = [] this.initDate()
this.minuteValues = []
const today = new Date()
this.getDateList('2019/01/01', new Date(today.getFullYear(), today.getMonth(), today.getDate()))
}, },
getDateList (starDay, endDay) { buildDayList () {
const arr = []; const days = []
const dates = []; const start = dayjs('2019-01-01').startOf('day')
const end = dayjs().startOf('day')
// 设置两个日期UTC时间 let cur = start
const db = new Date(starDay); while (cur.isBefore(end) || cur.isSame(end, 'day')) {
const de = new Date(endDay); days.push(cur.format('YYYY/MM/DD'))
// 获取两个日期GTM时间 cur = cur.add(1, 'day')
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) return days
},
buildHourList (isToday) {
const len = isToday ? dayjs().hour() + 1 : 24
return Array.from({ length: len }, (_, i) => String(i).padStart(2, '0'))
},
buildMinuteList (isToday, hour) {
const now = dayjs()
const isCurrentHour = isToday && hour === now.format('HH')
const len = isCurrentHour ? now.minute() + 1 : 60
return Array.from({ length: len }, (_, i) => String(i).padStart(2, '0'))
}, },
getHourList (days) { pickIndex (list, value, fallbackLast) {
const hours = [], today = new Date(); const index = list.indexOf(value)
for (let hour = 0; hour < today.getHours() + 1; hour++) { if (index >= 0) return index
hours.push(hour.toString().padStart(2, '0')); return fallbackLast ? Math.max(list.length - 1, 0) : 0
},
applyPickerValues (dateValues, hourValues, minuteValues) {
this.$nextTick(() => {
this.dateValues = dateValues
this.hourValues = hourValues
this.minuteValues = minuteValues
this.ready = true
this.$emit('onComplete')
})
},
initDate () {
const days = this.buildDayList()
if (!days.length) {
this.days = []
this.hours = []
this.minutes = []
this.ready = false
this.$emit('onComplete')
return
} }
this.getMinuteList(days, hours) const today = dayjs()
}, const todayStr = today.format('YYYY/MM/DD')
getMinuteList (days, hours) { let currentDate = todayStr
const minutes = []; let currentHour = today.format('HH')
const today = new Date() let currentMinute = today.format('mm')
for (let minute = 0; minute < today.getMinutes() + 1; minute++) {
minutes.push(minute.toString().padStart(2, '0')); if (this.defaultTime) {
const parsed = dayjs(this.defaultTime.replace(/-/g, '/'))
if (parsed.isValid()) {
currentDate = parsed.format('YYYY/MM/DD')
currentHour = parsed.format('HH')
currentMinute = parsed.format('mm')
}
} }
// 设置默认时间
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 const isToday = currentDate === todayStr
const hours = this.buildHourList(isToday)
const minutes = this.buildMinuteList(isToday, currentHour)
if (!hours.includes(currentHour)) currentHour = hours[hours.length - 1]
if (!minutes.includes(currentMinute)) currentMinute = minutes[minutes.length - 1]
this.currentDate = currentDate
this.currentHour = currentHour
this.currentMinute = currentMinute
this.days = days this.days = days
this.hours = hours
this.minutes = minutes this.minutes = minutes
this.dateValues = dateValues
this.hourValues = hourValues
this.minuteValues = minuteValues
this.loading = false
setTimeout(() => {
this.minuteValues = minuteValues
this.loading = false
}, 100)
this.$emit('onComplete')
},
changeDate (e) {
const { days } = this
const { value } = e.detail
const index = value[0]
console.log( days[index],days,index)
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的问题 this.applyPickerValues(
// const dayIndex = dateValues[0] [this.pickIndex(days, currentDate, true)],
// this.currentDate = days[dayIndex] [this.pickIndex(hours, currentHour, true)],
const today = dayjs().format('YYYY/MM/DD') [this.pickIndex(minutes, currentMinute, true)]
const timeType = this.currentDate != today ? 1 : 0 )
this.getAllTimeOrPartTimeMinute(timeType)
}, },
changeMinutes (e) { changeDate (e) {
const { minutes } = this const index = e.detail.value[0]
const { value } = e.detail const date = this.days[index]
const index = value[0] if (!date) return
this.currentMinute = minutes[index] this.currentDate = date
}, const isToday = this.currentDate === dayjs().format('YYYY/MM/DD')
getAllTimeOrPartTime (type) { this.hours = this.buildHourList(isToday)
const today = new Date() if (!this.hours.includes(this.currentHour)) {
const hours = [], minutes = [], hour_len = type == 1 ? 24 : today.getHours() + 1, minute_len = type == 1 ? 60 : today.getMinutes() + 1; this.currentHour = this.hours[this.hours.length - 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 const minutes = this.buildMinuteList(isToday, this.currentHour)
this.minutes = minutes this.minutes = minutes
if (!this.minutes.includes(this.currentMinute)) {
this.currentMinute = this.minutes[this.minutes.length - 1]
}
this.$nextTick(() => {
this.hourValues = [this.pickIndex(this.hours, this.currentHour, true)]
this.minuteValues = [this.pickIndex(this.minutes, this.currentMinute, true)]
})
}, },
getAllTimeOrPartTimeMinute (type) { changeHour (e) {
const today = new Date() const index = e.detail.value[0]
const currentHour = today.getHours() const hour = this.hours[index]
const timeType = this.currentHour != currentHour ? 1 : 0 if (hour == null) return
const minutes = [], minute_len = type == 1 || timeType == 1 ? 60 : today.getMinutes() + 1; this.currentHour = hour
for (let minute = 0; minute < minute_len; minute++) { const isToday = this.currentDate === dayjs().format('YYYY/MM/DD')
minutes.push(minute.toString().padStart(2, '0')); this.minutes = this.buildMinuteList(isToday, this.currentHour)
if (!this.minutes.includes(this.currentMinute)) {
this.currentMinute = this.minutes[this.minutes.length - 1]
} }
this.minutes = minutes this.$nextTick(() => {
this.minuteValues = [this.pickIndex(this.minutes, this.currentMinute, true)]
})
},
changeMinutes (e) {
const index = e.detail.value[0]
const minute = this.minutes[index]
if (minute == null) return
this.currentMinute = minute
}, },
getResult () { getResult () {
console.log(this.currentDate,this.currentHour,this.currentMinute) const str = `${this.currentDate} ${this.currentHour}:${this.currentMinute}:00`
let str = '' return dayjs(str.replace(/-/g, '/')).format('YYYY/MM/DD HH:mm:ss')
str = this.currentDate + ' ' + this.currentHour + ':' + this.currentMinute + ":00"
const result = dayjs(str).format('YYYY/MM/DD HH:mm:ss')
return result
} }
} }
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</template> </template>
<view v-if="componentObject[popupType]" :class="['popup-body', { 'hide-footer': componentObject[popupType].hideFooter }, { 'hide-search': componentObject[popupType].hideSearch }, { 'hide-footer-search': componentObject[popupType].hideFooter && componentObject[popupType].hideSearch }]"> <view v-if="componentObject[popupType]" :class="['popup-body', { 'hide-footer': componentObject[popupType].hideFooter }, { 'hide-search': componentObject[popupType].hideSearch }, { 'hide-footer-search': componentObject[popupType].hideFooter && componentObject[popupType].hideSearch }]">
<scroll-view scroll-y :class="['popup-scroll-view', { show: componentObject[popupType].loadComplete }]"> <scroll-view scroll-y :class="['popup-scroll-view', { show: componentObject[popupType].loadComplete }]">
<component :is="componentObject[popupType].name" :params.sync="componentObject[popupType]" :data="data" :dataKey="dataKey" :isDefeatOrder="isDefeatOrder" :defaultTime="defaultTime" :positionTypeList="positionTypeList" :show-marketing-icon="showMarketingIcon" :boutique-order-types-only="boutiqueOrderTypesOnly" ref="componentRef" @choose="chooseContent = $event" @openSkuPopup="openSkuPopup" @onComplete="componentObject[popupType].loadComplete = true" @confirm="confirm"></component> <component :is="componentObject[popupType].name" :params.sync="componentObject[popupType]" :data="data" :dataKey="dataKey" :isDefeatOrder="isDefeatOrder" :defaultTime="datePickerDefaultTime" :positionTypeList="positionTypeList" :show-marketing-icon="showMarketingIcon" :boutique-order-types-only="boutiqueOrderTypesOnly" ref="componentRef" @choose="chooseContent = $event" @openSkuPopup="openSkuPopup" @onComplete="componentObject[popupType].loadComplete = true" @confirm="confirm"></component>
<template v-if="componentObject[popupType].noData"> <template v-if="componentObject[popupType].noData">
<view class="nothing flex">暂无数据</view> <view class="nothing flex">暂无数据</view>
</template> </template>
...@@ -171,6 +171,11 @@ export default { ...@@ -171,6 +171,11 @@ export default {
const { sceneType } = uni.$storage.get('userInfo') const { sceneType } = uni.$storage.get('userInfo')
return sceneType return sceneType
}, },
datePickerDefaultTime () {
if (this.defaultTime) return this.defaultTime
const data = this.data || {}
return data.pay2Time || data.successDate || ''
}
}, },
mounted () { mounted () {
}, },
...@@ -187,6 +192,9 @@ export default { ...@@ -187,6 +192,9 @@ export default {
}) })
}, },
open () { open () {
if (this.componentObject[this.popupType]) {
this.componentObject[this.popupType].loadComplete = false
}
this.$refs.popup.open() this.$refs.popup.open()
// 等待当前 tick 的响应式 watcher(如 externalData → cacheData)执行完再初始化 // 等待当前 tick 的响应式 watcher(如 externalData → cacheData)执行完再初始化
this.$nextTick(() => { this.$nextTick(() => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!