<template>
  <section class="AppWorkOrder">
    <component ref="component" :is="currentPage" @change="onChange" v-bind="$props" :listIndex="listIndex" />
  </section>
</template>

<script>
import List from './components/List'
import Detail from './components/Detail'
import Setting from './components/Setting'
import settingDetail from "./components/settingDetail";
import SetKeywordManagement from './components/SetKeywordManagement'
import SetReportType from './components/SetReportType'

export default {
  name: 'AppWorkOrder',
  label: '工单管理',

  props: {
    instance: Function,
    dict: Object,
    menuName: {default: '工单管理'}
  },

  data() {
    return {
      component: 'List',
      params: {},
      listIndex: '0'
    }
  },
  computed: {
    currentPage() {
      console.log(this.$route)
      if(this.$route.query.id || this.$route.hash == "#Setting" || this.$route.hash == "#SetKeywordManagement" || this.$route.hash == "#SetReportType") { //列表
        this.listIndex = this.$route.query.listIndex
      }
      let {hash, query: {id}} = this.$route
      // return hash == "#Setting" ? Setting :
      //     hash == "#sd" ? settingDetail :
      //         !!id ? Detail : List

      if(hash == "#sd") {
        return settingDetail
      }else if(hash == "#Detail") {
        return Detail
      }else if(hash == "#Setting") {
        return Setting
      }else if(hash == "#SetKeywordManagement") {
        return SetKeywordManagement
      }else if(hash == "#SetReportType") {
        return SetReportType
      }else {
        return List
      }
    }
  },
  components: {
    List,
    Detail,
    Setting,
    SetKeywordManagement,
    SetReportType
  },

  methods: {
    onChange(data) {
      // this.$router.push({query: data.params, hash: data.type == "Setting" ? "#Setting" : ""})
      this.$router.push({query: data.params, hash: data.type == data.type ? data.type : ""})
    }
  }
}
</script>

<style lang="scss">
.AppWorkOrder {
  height: 100%;
  background: #F3F6F9;
  overflow: auto;
}
</style>
