纸通宝小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

65 lines
1.8 KiB

// components/factory-picker/index.js
Component({
options: {
addGlobalClass: true,
},
/**
* 页面的初始数据
*/
data: {
type: 0,
modalName: null,
value: [],
dataList: []
},
methods: {
isEmpty: function (val) {
return typeof val === 'undefined' || val === '' || val === null
},
showPicker: function (dataList, value, type) {
var valueList
if(this.isEmpty(value)){
valueList = []
}
if(this.data.dataList.length > 0 && this.data.type == type){
this.setData({ modalName: 'bottomModal' })
} else {
valueList = []
if (value.indexOf(',') != -1) {
for (var i = 0; i < this.data.dataList.length; i++) {
if (value.indexOf(this.data.dataList[i].value) != -1) {
valueList.push(this.data.dataList[i])
}
}
}
this.setData({ modalName: 'bottomModal', value: valueList, type, dataList })
}
},
clickItem: function (e) {
var item = this.data.dataList[e.currentTarget.dataset.index]
var index = -1
for(var i = 0; i< this.data.value.length; i++){
if (Number(item.value) == Number(this.data.value[i].value)){
index = i
break
}
}
if(index >= 0){
this.data.value.splice(index, 1)
} else {
this.data.value.push(item)
}
this.setData({ value: this.data.value })
this.triggerEvent('customevent', { type: this.data.type, value: this.data.value })
},
hideModal: function(){
this.setData({ modalName: null })
this.triggerEvent('customevent', null)
},
confrimModal: function () {
this.setData({ modalName: null })
this.triggerEvent('customevent', null)
}
}
})