Commit 75e3fdd1 by 杨北旺

修复时间组件问题

1 parent 31fa7c56
...@@ -2,7 +2,12 @@ Component({ ...@@ -2,7 +2,12 @@ Component({
properties: { properties: {
show: { show: {
type: Boolean type: Boolean,
observer: function (n) {
if (n) {
this.initDate()
}
}
}, },
}, },
...@@ -13,7 +18,8 @@ Component({ ...@@ -13,7 +18,8 @@ Component({
minutes: [], minutes: [],
dateValues: [], dateValues: [],
hourValues: [], hourValues: [],
minuteValues: [] minuteValues: [],
loading: true
}, },
...@@ -65,7 +71,6 @@ Component({ ...@@ -65,7 +71,6 @@ Component({
const YYMMDD = year + '/' + mouth + '/' + day; const YYMMDD = year + '/' + mouth + '/' + day;
dates.push(YYMMDD); dates.push(YYMMDD);
} }
console.log(dates)
this.getHourList(dates) this.getHourList(dates)
}, },
getHourList(days) { getHourList(days) {
...@@ -85,11 +90,11 @@ Component({ ...@@ -85,11 +90,11 @@ Component({
let { dateValues, hourValues, minuteValues } = this.data let { dateValues, hourValues, minuteValues } = this.data
const HOUR_STR = today.getHours().toString().padStart(2, '0') const HOUR_STR = today.getHours().toString().padStart(2, '0')
const MUNTUE_STR = today.getMinutes().toString().padStart(2, '0') const MUNTUE_STR = today.getMinutes().toString().padStart(2, '0')
const defalutHIndex = hours.indexOf(HOUR_STR) // const defalutHIndex = hours.indexOf(HOUR_STR)
const defalutMIndex = minutes.indexOf(MUNTUE_STR) // const defalutMIndex = minutes.indexOf(MUNTUE_STR)
dateValues.push(days.length) dateValues.push(days.length + 1)
hourValues.push(defalutHIndex) hourValues.push(hours.length + 1)
minuteValues.push(defalutMIndex) minuteValues.push(minutes.length + 1)
this.currentDate = new Date().format('yyyy/MM/dd') this.currentDate = new Date().format('yyyy/MM/dd')
this.currentHour = HOUR_STR this.currentHour = HOUR_STR
this.currentMinute = MUNTUE_STR this.currentMinute = MUNTUE_STR
...@@ -99,7 +104,14 @@ Component({ ...@@ -99,7 +104,14 @@ Component({
minutes, minutes,
dateValues, dateValues,
hourValues, hourValues,
minuteValues }, () => {
wx.nextTick(() => { });
setTimeout(() => {
this.setData({
minuteValues,
loading:false
})
}, 100);
}) })
}, },
changeDate(e) { changeDate(e) {
...@@ -125,13 +137,21 @@ Component({ ...@@ -125,13 +137,21 @@ Component({
str = this.currentDate + ' ' + this.currentHour + ':' + this.currentMinute + ":00" str = this.currentDate + ' ' + this.currentHour + ':' + this.currentMinute + ":00"
const result = new Date(str).format('yyyy/MM/dd hh:mm:ss') const result = new Date(str).format('yyyy/MM/dd hh:mm:ss')
this.triggerEvent('confirm', result) this.triggerEvent('confirm', result)
},
initDate() {
this.setData({
dateValues: [],
hourValues: [],
minuteValues: [],
})
const today = new Date()
this.getDateList('2019/01/01', new Date(today.getFullYear(), today.getMonth(), today.getDate()))
} }
}, },
//组件的生命周期 //组件的生命周期
lifetimes: { lifetimes: {
attached: function () { attached: function () {
const today = new Date() this.initDate()
this.getDateList('2019/01/01', new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1))
}, },
}, },
}) })
\ No newline at end of file \ No newline at end of file
<!-- components/DatePicker/DatePicker.wxml --> <!-- components/DatePicker/DatePicker.wxml -->
<block wx:if="{{show}}"> <block wx:if="{{show}}">
<view class="fixed-box fixed-date-box" catchtouchmove="noScroll"> <view class="fixed-box fixed-date-box" catchtouchmove="noScroll">
<view class="fixed-bg" bindtap="hide" data-name="showDateSelect"></view> <view class="fixed-bg" data-name="showDateSelect"></view>
<view class="fixed-content"> <view class="fixed-content">
<view class="fixed-title text-center">门店收款时间</view> <view class="fixed-title text-center">门店收款时间</view>
<view class="fixed-body"> <view class="fixed-body">
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</block> </block>
</picker-view-column> </picker-view-column>
</picker-view> </picker-view>
<picker-view class="picker" value="{{minuteValues}}" indicator-class="indicator" bindchange="changeMinutes"> <picker-view wx:if="{{!loading}}" class="picker" value="{{minuteValues}}" indicator-class="indicator" bindchange="changeMinutes">
<picker-view-column> <picker-view-column>
<block wx:for="{{minutes}}" wx:key="index"> <block wx:for="{{minutes}}" wx:key="index">
<view class="view">{{item}}</view> <view class="view">{{item}}</view>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!