// components/factory-picker/index.js Component({ options: { addGlobalClass: true, }, /** * 页面的初始数据 */ data: { type: 0, modalName: null, value: [0], dataList: [] }, methods: { isEmpty: function (val) { return typeof val === 'undefined' || val === '' || val === null }, showPicker: function (dataList, value, type) { if(!this.isEmpty(value)){ for (var i = 0; i < dataList.length; i++) { if (parseInt(dataList[i].value) == parseInt(value)) { this.data.value[0] = i break } } } this.data.type = type var that = this this.setData({ modalName: 'bottomModal', dataList }) if(!this.isEmpty(value)){ setTimeout(function () { that.setData({ value: that.data.value }) }, 100) } }, onChange: function (e) { this.setData({ value: e.detail.value}) }, hideModal: function(){ this.setData({ modalName: null }) this.triggerEvent('customevent', null) }, confrimModal: function () { this.setData({ modalName: null }) var val = this.data.dataList[this.data.value[0]] val.type = this.data.type this.triggerEvent('customevent', val) } } })