// packageF/storeManagement/components/collapse/collapse.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    active:{
      type:[Array,Number,String],
      value:{}
    }
  },
  relations: {
    './collapse-item': {
      type: 'child', // 关联的目标节点应为子节点
      linked: function(target) {
        this.data.children.push(target);
        // 每次有custom-li被插入时执行，target是该节点实例对象，触发在该节点attached生命周期之后
      },
      linkChanged: function(target) {
        this.data.children.splice(active.indexOf(target),1);
        // 每次有custom-li被移动后执行，target是该节点实例对象，触发在该节点moved生命周期之后
      },
      unlinked: function(target) {
        // 每次有custom-li被移除时执行，target是该节点实例对象，触发在该节点detached生命周期之后
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    children:[],
  },
  
  observers:{
    active(){
      this.data.children.forEach((child) => {
        child.updateExpanded();
      });
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    switch(name){
      let active = JSON.parse(JSON.stringify(this.data.active));
      if(active.indexOf(name)!=-1){
        active.splice(active.indexOf(name),1);
      }else {
        active.push(name);
      }
      this.triggerEvent("change",active);
    }
  }
});
