81 lines
1.4 KiB
JavaScript
81 lines
1.4 KiB
JavaScript
const date = new Date()
|
|
const years = []
|
|
const months = []
|
|
|
|
for (let i = 1990; i <= date.getFullYear(); i++) {
|
|
years.push(i)
|
|
}
|
|
|
|
for (let i = 1; i <= 12; i++) {
|
|
months.push(i)
|
|
}
|
|
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
// 是否弹出显示
|
|
visible: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
//点击外部的遮罩层是否允许关闭
|
|
outClickCanClose: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
// 模式,年或者月,默认只有年
|
|
mode: {
|
|
type: String,
|
|
value: 'year'
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
years: years,
|
|
year: date.getFullYear(),
|
|
months: months,
|
|
month: 2,
|
|
value: [9999, 1, 1],
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
closePopup() {
|
|
this.triggerEvent("close", {
|
|
visible: this.data.visible
|
|
})
|
|
},
|
|
outClick(){
|
|
if (this.data.outClickCanClose){
|
|
this.triggerEvent("close", {
|
|
visible: this.data.visible
|
|
})
|
|
}
|
|
},
|
|
// 日期改变
|
|
bindChange: function (e) {
|
|
const val = e.detail.value
|
|
this.setData({
|
|
year: this.data.years[val[0]],
|
|
month: this.data.months[val[1]],
|
|
})
|
|
},
|
|
ok(e){
|
|
let value = ''
|
|
if(this.properties.mode === 'month'){
|
|
value = this.data.year + '-' + this.data.month
|
|
}else {
|
|
value = this.data.year
|
|
}
|
|
this.triggerEvent("ok", value)
|
|
}
|
|
}
|
|
})
|