记录自己的一点点代码
<!--ml -->
<view class="picker_group">
<picker mode="date" value="{{start}}" start="{{start}}" end="{{end}}" data-daystart='{{daystart}}' bindchange="bindDateChange">
<view class="picker">
{{ date1 }}
</view>
</picker>
至
<picker mode="date" value="{{end}}" start="{{start}}" end="{{end}}" data-dayend='{{dayend}}' bindchange="bindDateChange2">
<view class="picker">
{{ date2 }}
</view>
</picker>
</view>
// __js
var gba = require('../../utils/global.js')
var that
Page({
data: {
imgUrl: gba.globalData.imgUrl, //图片路径
date1: '选择开始时间', //选择开始时间
date2: '选择结束时间', //选择结束时间
},
onLoad: function(options) {
that = this
var timestamp = Date.parse(new Date());
var date = new Date(timestamp);
//获取年份
var Y = date.getFullYear();
//获取月份
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
//获取当日日期
var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
var day = (Y + '-' + M + '-' + D)
that.setData({
start: '2015-09-01', //开始时间
end: day, //结束时间
daystart: new Date(day.replace(/-/g, "/")).getTime(), //开始时间戳
dayend: new Date(day.replace(/-/g, "/")).getTime() //结束时间戳
})
},
// 时间段选择
bindDateChange(e) {
let that = this;
let daystart = new Date(e.detail.value.replace(/-/g, "/")).getTime()
if (daystart <= that.data.dayend) {
that.setData({
date1: e.detail.value,
daystart: daystart
})
} else {
wx.showToast({
title: '请选择正确的时间区间',
icon: 'none',
duration: 1000,
mask: true
})
}
},
bindDateChange2(e) {
let that = this;
let dayend = new Date(e.detail.value.replace(/-/g, "/")).getTime()
if (that.data.daystart <= dayend) {
that.setData({
date2: e.detail.value,
dayend: dayend
})
} else {
wx.showToast({
title: '请选择正确的时间区间',
icon: 'none',
duration: 1000,
mask: true
})
}
},
})