Commit 75e3fdd1 by 杨北旺

修复时间组件问题

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