<!--
 * @Author: aBin
 * @email: binbin0314@126.com
 * @Date: 2021-07-19 14:15:35
 * @LastEditors: aBin
 * @LastEditTime: 2021-07-20 14:22:11
-->
<template>
  <!-- 时间间隔栏 -->
  <!-- <Barrier /> -->
  <scroll-view
    :lower-threshold="300"
    :scrollTop="top"
    :scrollY="true"
    :upper-threshold="300"
    @scroll="scroll"
    @scrolltolower="handleScrollBottom"
    @scrolltoupper="handleScrollTop"
    id="scroll"
  >
    <!-- 时间轴 -->
    <TimeBox ref="child" />
  </scroll-view>
</template>

<script>
// import Barrier from './component/Barrier.vue';
import { mapState, mapMutations } from 'vuex';
import TimeBox from './component/TimeBox.vue';
export default {
  name: 'TimeLine',
  components: { TimeBox },
  data() {
    return {
      top: 0,
      list1: [
        {
          state: 0,
          TaskPanel: { height: '100' },
        },
        {
          state: 1,
          TaskPanel: { height: '100' },
        },
        {
          state: 2,
          TaskPanel: { height: '100' },
        },
      ],
    };
  },

  computed: mapState('home', ['scrollTop', 'showTips', 'visibleRoles']),

  mounted() {
    let tasksHeight = 0;
    const scrollHeight = document.getElementById('scroll').clientHeight;
    for (let i = 0; i < this.list1.length; i++) {
      tasksHeight += this.list1[i].TaskPanel.height - 0 + 42;
    }
    this.top = tasksHeight - scrollHeight / 2;
    console.log('this.top: ', this.top);
  },

  methods: {
    ...mapMutations('home', ['setScrollTop', 'setShrink', 'setRoleId']),

    // 滚动
    scroll(e) {
      this.top = e.detail.scrollTop;
      this.setShrink(this.top > this.scrollTop);
      this.setScrollTop(this.top);
    },

    // 滚动到顶部
    handleScrollTop() {
      console.log('滚动到顶部');
      this.$refs.child.addTopList();
    },

    // 滚动到底部
    handleScrollBottom() {
      console.log('滚动到底部');
      this.$refs.child.addBottomList();
    },
  },
};
</script>
