import { mapState } from 'vuex'

export default {
  data() {
    return {
      collapseOpenArr: [] // 当前打开的折叠面板
    }
  },
  computed: {
    ...mapState('scrollStore', {
      scrollRef: state => state.scrollRefs,
      stepHeight: state => state.stepHeight
    })
  },
  created() {
    this.collapseOpenArr = []
  },
  methods: {
    handleChange(val) {
      this.collapseOpenArr = val
    },
    // 触发折叠面板打开
    triggerCollapseOpen(index) {
      if (!this.collapseOpenArr.includes(index)) {
        this.collapseOpenArr.push(index)
        this.activeNames = this.collapseOpenArr
      } else {
        const scrollDom = document.getElementById(index)
        if (this.scrollRef && scrollDom) {
          this.scrollRef.wrap.scrollTop = scrollDom.offsetTop - (this.stepHeight + 55)
        }
      }
    }
  }
}
