flower-mp/components/count-picker/index.js
sdaduanbilei 81d68c96ab change ui
2025-11-13 16:55:23 +08:00

80 lines
1.4 KiB
JavaScript

// components/picker/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
item: {
type: Object,
require: true
},
prop: {
type: String,
require: true
},
value: {
type: String,
require: false
},
},
observers: {
// 监听 visible 的变化
'value': function (newVal, oldVal) {
if (newVal) {
this.setData({
result:newVal
})
}
}
},
/**
* 组件的初始数据
*/
data: {
visible: false,
result: '',
defaultValue:[],
counts: []
},
/**
* 组件的方法列表
*/
methods: {
init() {
var list = []
for (let index = 1; index <= 365; index++) {
const item = {
label: index,
value: index
}
list.push(item)
}
this.setData({
counts: list
})
},
confirm(e) {
const value = e.detail.value[0]
const item = this.data.item
item.period = value
this.setData({item:item})
this.triggerEvent('ok', {
value: item
});
},
onVisibleChange(e) {
const value = e.currentTarget.dataset.value
const show = !this.data.visible
if (show) {
this.init()
}
this.setData({
defaultValue:[value],
visible: show
})
},
}
})