YZProjectCloud/yanzhu-ui-app/miniprogram/pages/components/voucher-select/index.js

113 lines
2.0 KiB
JavaScript

// pages/components/voucher-select/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
columns: {
type: Array
},
placeholder: {
type: String
},
selectValue: {
type: String
},
selectIndex: {
type: String
},
background: {
type: String
},
value: {
type: String,
value: ""
}
},
/**数据监听 */
observers: {
selectValue: function (val) {
setTimeout(() => {
this.timeOutValue(val)
}, 500);
},
selectIndex: function (val) {
this.setData({
index: val
})
}
},
lifetimes: {
created: function () {
//在组件实例刚刚被创建时执行,注意此时不能调用 setData
},
attached: function () {
//在组件实例进入页面节点树时执行
},
ready: function () {
// 在组件在视图层布局完成后执行
},
detached: function () {
// 在组件实例被从页面节点树移除时执行
},
},
/**
* 组件的初始数据
*/
data: {
show: false,
item: '',
index: ''
},
/**
* 组件的方法列表
*/
methods: {
timeOutValue(val){
let columns = this.data.columns;
if (val && columns) {
console.log("ssssssss",columns,val)
for (let i = 0; i < columns.length; i++) {
if (val == columns[i].id) {
val = columns[i].text;
break;
}
}
}
this.setData({
value: val
})
},
showPopup() {
this.setData({
show: true
});
},
onClose() {
this.setData({
show: false
});
},
onSelectChange(e) {
this.setData({
item: e.detail.value
})
},
onConfirm() {
let _item = this.data.item;
if(_item.length==0){
_item = this.data.columns[0];
}
this.setData({
value: _item.text
})
this.triggerEvent('change', _item)
this.setData({
show: false
});
}
}
})