// compontents/curriculum/curriculum.js
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   * studyLog传过来的数据
   * height判断显不显示展开按钮
   */
  properties: {
    studyLog: {
      type: Array,
      value: []
    },
    height: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   * flag展开收起的判断
   * animationData动画封装对象
   * downUp和src传过去得值
   */
  data: {
    flag: false,
    animationData: {},
    downUp: '展开',
    src: '../../pages/image/toDown.png',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onTap (e) {
      let flage = e.target.dataset.flag;
      const height = this.properties.studyLog.length * 54;
      if(flage){
        this.util(flage, '680rpx');
        this.setData({
          'flag': false,
          'downUp': '展开',
          'src':'../../pages/image/toDown.png'
      })
      } else {
        this.util(flage, height + 'rpx');
        this.setData({
          'flag': true,
          'downUp': '收起',
          'src': '../../pages/image/toUp.png'
        })
      }
    },
    /* 创建动画并执行 */
    util (flag, height) {
      // 创建动画实例   
      var animation = wx.createAnimation({  
        duration: 200,  //动画时长  
        timingFunction: "linear", //线性  
        delay: 0  //0则不延迟  
      });
      
      this.animation = animation;

      animation.height(height).step();

      this.setData({  
        animationData: animation.export()  
      })  
    }
  },
  ready: function () {
    //console.log(this.properties.studyLog)
  }
})