<route lang="yaml">
meta:
  enabled: false
</route>

<script lang="ts" setup name="bizObjectDetails">
import BizObjectAttrListComponent from '../object_attr/index.vue'
import BizObjectComponent from '@/views/biz/object/components/Object.vue'
import { getObjectById } from '@/api/biz/bizObjectApi'
import useSettingsStore from '@/store/modules/settings'

const settingsStore = useSettingsStore()

const router = useRouter()
const tabbar = useTabbar()
const route = useRoute()

const bizId = parseInt(route.params.bizId.toString())
const objectId = parseInt(route.params.objectId.toString())

const state = reactive({
  loading: false,
  objectInfo: {
    objectTitle: '',
    objectCode: '',
    objectType: 0,
    comment: '',
  },
  dialogState: 1,
  search: {
    bizId,
    objectId,
    keywords: '',
  },
  params: '',
  result: '',
})

const objectRef = ref()

// 查询数据
const getObjectData = async () => {
  state.loading = true
  const { data } = await getObjectById(bizId, objectId)
  state.loading = false
  state.objectInfo.objectTitle = data.objectTitle
  state.objectInfo.objectType = data.objectType
  state.objectInfo.objectCode = data.objectCode
  state.objectInfo.comment = data.comment
}

onMounted(() => {
  getObjectData()
  nextTick(() => {

  })
})

const activeTab = ref('first')
const onObjectEdit = () => {
  objectRef.value.showEditModel(bizId, objectId)
}

const bizObjectAttrList = ref()
// 返回列表页
function goBack() {
  if (settingsStore.settings.tabbar.enable && settingsStore.settings.tabbar.mergeTabsBy !== 'activeMenu') {
    tabbar.close({ name: 'biz_object_list' })
  }
  else {
    router.push({ name: 'biz_object_list' })
  }
}
</script>

<template>
  <div class="absolute-container">
    <page-header :title="state.objectInfo.objectTitle">
      <el-button size="default" round @click="goBack">
        <template #icon>
          <el-icon>
            <svg-icon name="i-ep:arrow-left" />
          </el-icon>
        </template>
        返回
      </el-button>
    </page-header>

    <page-main>
      <div class="container">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="基本信息" name="first">
            <el-descriptions
              :title="state.objectInfo.objectTitle"
              :column="1"
              size="small"
              border>
              <template #extra>
                <el-button type="primary" @click="onObjectEdit">编辑</el-button>
              </template>

              <el-descriptions-item
                label-align="right"
                label-class-name="el-description_label"
                label="对象类型"
                width="150px">
                {{ state.objectInfo.objectType }}
              </el-descriptions-item>

              <el-descriptions-item
                label="代码"
                label-class-name="el-description_label"
                width="150px"
                label-align="right">
                {{ state.objectInfo.objectCode }}
              </el-descriptions-item>

              <el-descriptions-item
                label-align="right"
                label-class-name="el-description_label"
                width="150px"
                label="说明">
                {{ state.objectInfo.comment }}
              </el-descriptions-item>
            </el-descriptions>
          </el-tab-pane>

          <el-tab-pane label="对象属性" name="second">
            <BizObjectAttrListComponent :bizId="bizId" :objectId="objectId" ref="bizObjectAttrList" />
          </el-tab-pane>
        </el-tabs>
      </div>
    </page-main>

    <BizObjectComponent ref="objectRef" @success="getObjectData" />
  </div>
</template>

<style scoped>
.el-descriptions {
  margin: 0 10px;
}

.el-description_label

.cell-item {
  display: flex;
  align-items: center;
}
</style>
