<template>
  <div class="worktableButtonBox">
    <div class="for-button-box" @click="goPage(item)"
         v-for="(item,index) in buttonList" :key="index">
      <img :src="item.url">
      <p class="for-name">{{item.name}}</p>
      <p class="position-p" v-if="index!=0"></p>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'worktableButtonBox',
    data(){
      return{
        routeList:[],
        buttonList:[
          {
            name:"开展检查",
            key:"startInspection",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_kzjc.png'),
            path:"/safetyCheck/startInspection",
            type:false,
          },
          {
            name:"巡查管理",
            key:"inspectionManagement",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_xcgl.png'),
            path:"/safetyCheck/schoolInspection/inspectionManagement",
            type:false,
          },
          {
            name:"自查管理",
            key:"selfInspectionManagement",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_zcgl.png'),
            path:"/safetyCheck/laboratorySelfTest/selfInspectionManagement",
            type:false,
          },
          {
            name:"安全隐患",
            key:"safetyHazard",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_aqyht.png'),
            path:"/safetyCheck/safetyHazard",
            type:false,
          },
          {
            name:"随手拍",
            key:"snapshotManagement",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_ssp.png'),
            path:"/safetyCheck/snapshotManagement",
            type:false,
          },
          {
            name:"整改报告",
            key:"rectificationReport",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_zgbg.png'),
            path:"/safetyCheck/rectificationReport",
            type:false,
          },
          {
            name:"数据统计",
            key:"dataStatistics",
            url:require('@/assets/ZDimages/safetyCheck/icon_gzt_sjtj.png'),
            path:"/safetyCheck/dataStatistics",
            type:false,
          },
        ],
      }
    },
    created(){
    },
    mounted(){
      this.setButtonList();
    },
    methods:{
      //权限查找
      setButtonList(){
        let self = this;
        let localRoute = JSON.parse(localStorage.getItem("routeData"))
        for(let x=0;x<self.buttonList.length;x++){
          self.forRouteData(self.buttonList[x],localRoute);
        }
      },
      forRouteData(item,list){
        let self = this;
        for(let i=0;i<list.length;i++){
         if(item.key == list[i].path){
           item.type = true;
         }else{
           if(list[i].children){
             self.forRouteData(item,list[i].children)
           }
         }
        }
      },
      goPage(item){
        if(item.type){
          this.$router.push({ path: item.path });
        }else{
          this.msgError('没有相关权限,请联系管理员')
        }
      },
    }
  }
</script>

<style scoped lang="scss">
  .worktableButtonBox{
    height:120px;
    display: flex;
    .for-button-box{
      cursor: pointer;
      width:118px;
      position: relative;
      img{
        width:44px;
        height:44px;
        margin:24px 37px 13px;
      }
      .for-name{
        font-size:16px;
        line-height:20px;
        text-align: center;
      }
      .position-p{
        width:1px;
        height: 30px;
        position: absolute;
        left:0;
        top:45px;
        background-color: #d8d8d8;
      }
    }
  }
</style>
