<template>
  <div class="demo">
    <div v-if="btns.length" class="contens1 btns">
      <div class="btns flex-wrap">
        <div v-for="(item,index) in btns" :key="index">
          <template v-if="item.show_type == 1">
            <el-button @click="handleClick(item)">{{ item.auth_name }}</el-button>
          </template>
          <template v-else-if="item.show_type == 2">
            <el-button :icon="item.show_icon" @click="handleClick(item)"></el-button>
          </template>
          <template v-else-if="item.show_type == 3">
            <el-button :icon="item.show_icon" @click="handleClick(item)">{{ item.auth_name }}</el-button>
          </template>
        </div>
      </div>
    </div>
    <div v-if="flag" :style="{ height:btns.length ? 'calc(100% - 60px)' : '100%' }" class="contents2">
      <Table />
    </div>
  </div>
</template>

<script>
import { getAuthData } from '@/utils/validate'
import Table from '../table/index.vue'
export default {
  name: 'Demo',
  components: { Table },
  data () {
    return {
      type: null,
      title: '',
      btns: [],
      flag: false
    }
  },
  created () {
    const { title, auth_id } = this.$route.meta
    const { type, arrs } = getAuthData(auth_id)
    const table = arrs.filter(item => item.auth_type == 4)
    const btns = arrs.filter(item => item.auth_type != 4)
    this.type = type
    if (btns && btns.length) {
      this.btns = btns
    }
    if (table && table.length) {
      this.flag = true
    }
    this.title = title
  },
  methods: {
    handleClick (item) {
      switch (item.open_method) {
        case '1':
          this.$message.success('平铺')
          break;
        case '2':
          this.$router.push(item.route_info)
          break;
        case '3':
          this.$message.success('弹框')
          break;
        default:
          break;
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.demo {
  padding: 24px;
  height: calc(100vh - 100px);
  .btns {
    margin-bottom: 20px;
    > div {
      margin-right: 20px;
    }
  }
}
</style>