<picker mode="multiSelector" value="{{datetimeArr.selectIndex}}" range="{{datetimeArr.pickerArr}}" bindchange="bindDatetimeChange"> </picker>
/** * 获取年月日时分秒 返回数组 */ getDatetimePicker(){ var pickerArr = [] var yearArr = [] var monthArr = [] var dayArr = [] var hourArr = [] var minutesArr = [] var secondArr = ["00"] var selectIndex = [] var date = new Date() for (let index = 20; index > 0; index--) { yearArr.push((date.getFullYear()-index).toString()) } for (let index = 0; index <20; index++) { yearArr.push((date.getFullYear()+index).toString()) } for (let index = 1; index < 13; index++) { var month = "" index<10?month=("0"+index):month=index.toString() monthArr.push(month) } var d = new Date(date.getFullYear(),date.getMonth()+1,0); for (let index = 1; index < d.getDate()+1; index++) { var day = "" index<10?day=("0"+index):day=index.toString() dayArr.push(day) } for (let index = 0; index < 24; index++) { var hour = "" index<10?hour=("0"+index):hour=index.toString() hourArr.push(hour) } for (let index = 0; index < 60; index++) { var minutes = "" index<10?minutes=("0"+index):minutes=index.toString() minutesArr.push(minutes) } pickerArr.push(yearArr) pickerArr.push(monthArr) pickerArr.push(dayArr) pickerArr.push(hourArr) pickerArr.push(minutesArr) pickerArr.push(secondArr) selectIndex= [20,date.getMonth(),date.getDate()-1,date.getHours(),date.getMinutes(),0] var res = { "selectIndex":selectIndex, "pickerArr":pickerArr } return res }
bindDatetimeChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) var datetimeArr = this.data.datetimeArr var select = e.detail.value this.setData({ datetime: datetimeArr.pickerArr[0][select[0]]+"-"+datetimeArr.pickerArr[1][select[1]]+"-"+datetimeArr.pickerArr[2][select[2]]+" "+datetimeArr.pickerArr[3][select[3]]+":"+datetimeArr.pickerArr[4][select[4]]+":"+datetimeArr.pickerArr[5][select[5]] }) },
- THE END -
最后修改:2021年4月26日