<template>
  <div class="NavScroll">
        <!-- 导航栏 -->
    <div class="sidebar">
      <a
        :href="'#bid' + item.id"
        v-for="(item, index) in allMenuList"
        :key="index"
        @click="jump(index)"
      >
        <div
          class="navbar"
          :class="[index === activeStep ? 'active' : '']"
        >
          <span style="margin-left:5px">{{ item.name }}</span>
          <i class="el-icon-caret-right icon-right"></i>
        </div>
      </a>
    </div>
    <div class="applications-content">
       <el-scrollbar class="scrollbar" ref="scroll" id="resultScroll">
        <!-- 施工许可 -->
      <ConstructionPermit />
        <!-- 五方责任主体 -->
        <ResponsibleSubject />
      </el-scrollbar>
    </div>
  </div>
</template>

<script>
import ConstructionPermit from './component/ConstructionPermit.vue'
import ResponsibleSubject from './component/ResponsibleSubject.vue'
export default {
  name: 'ConstructionProcedures',
  components: {
    ConstructionPermit,
    ResponsibleSubject
  },
  data() {
    return {
      allMenuList: [
        {id: 1, name: '施工许可'},
        {id: 2, name: '五方责任主体'},
      ],
      activeStep: 0,
    }
  },
  mounted() {
    document
      .getElementById('resultScroll')
      .addEventListener('scroll', this.handleScroll, true)
  },
  beforeDestroy() {
    document
      .getElementById('resultScroll')
      .removeEventListener('scroll', this.handleScroll, false)
  },
  methods: {
    handleScroll(event) {
       let scrollTop=event.target.scrollTop
        let divContent=document.querySelectorAll('.items')
        let offsetTopArr=[]
        divContent.forEach(item=>{
        offsetTopArr.push(item.offsetTop)
        })
        for(let n=0;n<offsetTopArr.length;n++){
          if(scrollTop>=offsetTopArr[n]-100){
            this.activeStep=n;
        }
      }
    },
    // 点击切换锚点
    jump(index) {
      this.activeStep = index
    },
  },
}
</script>

<style scoped lang="scss">
@import './css/navbarCommon.scss';
.navbar {
  width: 100px;
}
</style>