// pages/components/project-select/index.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    init:{
      type:Object
    },
    width:{
      type:String
    },
    left:{
      type:String
    }
  },
  /**数据监听 */
  observers: {
    init: function (val) {
      if(val){
        this.setData({
          item:val,
        })
      }
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    index:0,
    item:'',
    columns:[],
    projectList:[],
  },

  created(){
    //this.getProjectNameList();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    showPopup() {
      // var data = this.data.projectList;
      // var initData = this.data.init
      // for(var i=0;i<data.length;i++ ){
      //     if(data[i].id == initData.id){
      //         this.setData({
      //           index:i
      //         })
      //         break
      //     }
      // }

      // console.log(this.data.index)
      // this.setData({
      //     columns:data,
      //     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 });
    },
    getProjectNameList:function(){
      wx.request({
        url: app.globalData.reqUrl+'/weixin/security/getProjectNameList',
        method:"GET",
        data:{
            deptId:app.globalData.deptId,
            projectId:app.globalData.userProjectId
        },
        success: (res) =>{
          var that = this;
          that.setData({
            projectList:res.data
          })
        }
      });
    },
  }
})