-
Notifications
You must be signed in to change notification settings - Fork 782
Open
Description
showTimePicker = () => {
const years = []
const time = timeGroup
for (let i = 1; i < 30; i++) {
years.push(i + 2010 + '年')
}
let pickerData = []
let selectedValue = []
const date = new Date()
if (this.props.showTime) {
pickerData = [years, monthGroup, dayGroup, time]
selectedValue = [
date.getFullYear(),
date.getMonth() + 1,
date.getDate(),
date.getTime()
]
} else {
pickerData = [years, monthGroup, dayGroup]
selectedValue = [
date.getFullYear(),
date.getMonth() + 1,
date.getDate()
]
}
Picker.init({
pickerData,
selectedValue,
pickerConfirmBtnText: '确定',
pickerCancelBtnText: '取消',
pickerToolBarBg: backGroundColor,
pickerBg: backGroundColor,
pickerTitleText: this.props.title,
pickerTextEllipsisLen: 20,
onPickerConfirm: pickedValue => {
console.log('xxx pickedValue',pickedValue)
this.props.onRequestClose()
this.props.onRequestSave(pickedValue)
},
onPickerCancel: pickedValue => {
this.props.onRequestClose()
},
onPickerSelect: pickedValue => {
const targetValue = [...pickedValue]
if (Number.parseInt(targetValue[1]) === 2) {
if (Number.parseInt(targetValue[0]) % 4 === 0 && Number.parseInt(targetValue[2]) > 29) {
targetValue[2] = 29 + '日'
} else if (Number.parseInt(targetValue[0]) % 4 !== 0 && Number.parseInt(targetValue[2]) > 28) {
targetValue[2] = 28 + '日'
}
} else if (Number.parseInt(targetValue[1]) in { 4: 1, 6: 1, 9: 1, 11: 1 } && Number.parseInt(targetValue[2]) > 30) {
targetValue[2] = 30 + '日'
}
// forbidden some value such as some 2.29, 4.31, 6.31...
if (JSON.stringify(targetValue) !== JSON.stringify(pickedValue)) {
// android will return String all the time,but we put Number into picker at first
// so we need to convert them to Number again
targetValue.map((v, k) => {
if (k !== 3) {
targetValue[k] = v
}
})
Picker.select(targetValue)
pickedValue = targetValue
console.log('xxx pickedValue',pickedValue)
}
}
})
Picker.show()
}
Metadata
Metadata
Assignees
Labels
No labels