// pages/components/voucher-select/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    columns:{
      type:Array
    },
    placeholder:{
      type:String
    },
    selectValue:{
      type:String
    },
    selectIndex:{
      type:String
    },
    background:{
      type:String
    },
    height:{
      type:String
    }
  },
  /**数据监听 */
  observers: {
    columns: function (val) {
      this.setData({
        item:val[0],
      })
    },
    selectValue:function(val){
      this.setData({
        value:val
      })
    },
    selectIndex:function(val){
      this.setData({
        index:val
      })
    }
  },
  lifetimes: {
    created: function(){
      //在组件实例刚刚被创建时执行,注意此时不能调用 setData
    },
    attached: function () {
        //在组件实例进入页面节点树时执行
    },
    ready: function () {
        // 在组件在视图层布局完成后执行
    },
    detached: function () {
        // 在组件实例被从页面节点树移除时执行
    },
    
  },

  /**
   * 组件的初始数据
   */
  data: {

    show: false,
    value:'',
    item:'',
    index:''
    
  },

  /**
   * 组件的方法列表
   */
  methods: {
    showPopup() {
      this.setData({ show: true });
    },
    onClose() {
      this.setData({ show: false });
    },
    onSelectChange(e){
      this.setData({
        item:e.detail.value
      })
    },
    onConfirm(){
      this.setData({
        value:this.data.item.text
      })
      this.triggerEvent('change',this.data.item)
      this.setData({ show: false });
    }
  }
})