<template>
    <div class="flex1 flex-col">
        <div><b class="panel-header">
            <a-icon type="deployment-unit"/>&nbsp;实体</b></div>
        <div class="flex1 flex-col">
            <entity-list-body ref="entityList" @emitEntityId="getEntityId" :entityClassId="entityClassId"
                              :activeId="$route.params.entityId"></entity-list-body>
        </div>
    </div>
</template>

<script>
  import entityListBody from '@/components/knowledge/entityListBody'

  export default {
    name: 'entityList',
    components: {
      entityListBody
    },
    events: {
      /**
       * 实体被修改，刷新左侧列表
       * @param entityId
       */
      ['entity:entityInfoEdited'](entityId) {
        const entityClassId = this.$route.params.classId
        this.$refs.entityList.refreshEntityList(entityClassId)
      }
    },
    data() {
      return {
        entityClassId: '',
        entityActiveId: ''
      }
    },
    watch: {
      ['$route.params.entityId']() {
        this.entityActiveId = this.$route.params.entityId
      }
    },
    created() {
      this.entityClassId = this.$route.params.classId // 实体类id
      this.entityActiveId = this.$route.params.entityId // 实体id
    },
    methods: {
      /**
       * 获得需要跳转的实体id
       * @param id
       */
      getEntityId(id) {
        if(id!==this.$route.params.entityId)
            this.$router.push({name: 'e_base', params: {classId: this.entityClassId, entityId: id}})     // 有基础属性跳到基础属性
      }
    }
  }
</script>

<style scoped>

</style>
