<template>
  <div class="lakala-container">
    <el-header height="60px">
      <el-menu
        :default-active="activeMenu"
        mode="horizontal"
        @select="handleMenuSelect"
        class="el-menu-horizontal"
      >
        <el-menu-item index="profitShareReceiver">
          <span>分账接收方申请</span>
        </el-menu-item>
        <el-menu-item index="profitShareOrder">
          <span>分帐申请</span>
        </el-menu-item>
        <el-menu-item index="tradeOrder">
          <span>拉卡拉交易记录</span>
        </el-menu-item>
      </el-menu>
    </el-header>

    <el-main>
      <component :is="currentComponent" />
    </el-main>
  </div>
</template>

<script>
import ProfitShareReceiver from './views/ProfitShareReceiver.vue'
import ProfitShareOrder from './views/ProfitShareOrder.vue'
import TradeOrder from './views/TradeOrder.vue'

const componentMap = {
  profitShareReceiver: ProfitShareReceiver,
  profitShareOrder: ProfitShareOrder,
  tradeOrder: TradeOrder
}

export default {
  name: 'LakalaIndex',
  components: {
    ProfitShareReceiver,
    ProfitShareOrder,
    TradeOrder
  },
  data() {
    return {
      activeMenu: this.$route.query.tab || 'profitShareReceiver'
    }
  },
  computed: {
    currentComponent() {
      return componentMap[this.activeMenu] || ProfitShareReceiver
    }
  },
  watch: {
    '$route.query.tab'(val) {
      if (val && componentMap[val]) {
        this.activeMenu = val
      }
    }
  },
  methods: {
    handleMenuSelect(index) {
      this.activeMenu = index
      this.$router.replace({ query: { tab: index } })
    }
  }
}
</script>

<style scoped>
.lakala-container {
  padding: 0;
  height: calc(100vh - 120px);
}

.el-header {
  padding: 0;
  background-color: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.el-menu-horizontal {
  height: 60px;
  font-size: 16px;
}

.el-main {
  padding: 30px;
  background: #fff;
  margin: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  flex: 1;
}
</style>
