<%_
const { detailFieldLines, detailShowInOneRelationships: showInOneRelationships, detailShowInOneContainerConfig: showInOneContainerConfig, detailShowInOneImportComponents: showInOneImportComponents } = (bcEntityData || { detailFieldLines: [] });
_%>
<template>
  <div class="w-100%"<% if (cypressTests) { %> data-cy="<%= entityInstance %>DetailsHeading"<% } %>>
    <Descriptions ref="<%= entityInstance %>DetailRef" v-bind="descriptionsProps"></Descriptions>
  <%_ if (showInOneRelationships && showInOneRelationships.length) { _%>
  <<%= showInOneContainerConfig.componentName %>>
    <%_ showInOneRelationships.forEach(relationship => {
      const relationshipComponentConfig = showInOneContainerConfig.relationshipsConfig[relationship.relationshipName];
    _%>
      <<%= showInOneContainerConfig.subComponentName %> :<%= showInOneContainerConfig.subLabelName %>="relationTables.<%= relationshipComponentConfig.relationTableKey %>.title" :key="relationTables.<%= relationshipComponentConfig.relationTableKey %>.name">
        <<%= relationshipComponentConfig.componentTypeName %> ref="<%= relationshipComponentConfig.relationTableKey %>Ref" v-bind="relationTables.<%= relationshipComponentConfig.relationTableKey %>.props()" v-on="relationTables.<%= relationshipComponentConfig.relationTableKey %>.events">
          <%_ if (relationshipComponentConfig.componentTypeName === 'Grid') { _%>
          <template #recordAction></template>
          <%_ } _%>
          <%_ if (relationship.source?.annotationOnSource?.includes('editByDescList')) { _%>
          <template #default="{ item }">
            <<%= relationship.otherEntity.entityNameCapitalized %>Desc :entity-id="item.<%= relationship.otherEntity.primaryKey.name %>"<% if (!anyFieldIsBlobDerived) { %> :columns="3"<% } %><% if (extendAbstractAuditingEntity) { %> :hide-columns="['createdBy', 'createdDate', 'lastModifiedBy', 'lastModifiedDate'<% if (relationship.otherRelationship?.relationshipName) { %>, '<%= relationship.otherRelationship.relationshipName + '.' + relationship.otherRelationship.otherEntityField %>'<% } %>]"<% } %> />
          </template>
          <%_ } _%>
        </<%= relationshipComponentConfig.componentTypeName %>>
      </<%= showInOneContainerConfig.subComponentName %>>
    <%_ }); _%>
    </<%= showInOneContainerConfig.componentName %>>
  <%_ } _%>
  </div>
</template>
<script lang="ts" setup>
import ServerProvider from '@/api-service/index';
import config from '../config/detail-config';
import { I<%= entityAngularName %> } from '@/models/<%= entityModelFileName %>.model';
<%_ if (showInOneImportComponents && Object.keys(showInOneImportComponents).length) { _%>
  <%_ Object.values(showInOneImportComponents).forEach(importLine => { _%>
<%- importLine %>
  <%_ });_%>
<%_ } _%>
<%_ if (addCustomMethod.indexOf('updateTemplate') !== -1) { _%>
<%- include(`../common/entity-custom/${entityClass}.updateTemplate.ejs`, {position: 'import'}); -%>
<%_ } _%>

<%_ let apiModuleName = this._.camelCase(clientRootFolder || microserviceName); _%>
// begcode-please-regenerate-this-file 如果您不希望重新生成代码时被覆盖，将please修改为don't ！！！
defineOptions({
  name: '<%= this._.upperFirst((moduleName || clientRootFolder) ? (moduleName || clientRootFolder) + entityAngularName : entityInstance) %>Detail',
  inheritAttrs: false,
});

const props = defineProps({
entityId: {
  type: [String, Number] as PropType<string | number>,
  default: '',
  required: true,
},
columns: {
  type: Number,
  default: 1,
},
hideColumns: {
  type: Array as PropType<string[]>,
  default: () => [],
},
});

const <%= entityInstance %>DetailRef = ref(null);
const ctx = getCurrentInstance()?.proxy;
const apiService = ctx?.$apiService as typeof ServerProvider;
const <%= entityInstance %> = reactive<I<%= entityAngularName %>>({});
const getEntityData = async () => {
  if (props.entityId) {
    apiService.<%= apiModuleName ? apiModuleName + '.' : '' %><%= entityInstance %>Service.find(<% if (tsKeyType === 'number') { %>Number(props.entityId)<% } else { %>props.entityId<% } %>).then(data => {
      if (data) {
        Object.assign(<%= entityInstance %>, data);
      }
    });
  }
};
watch(
  () => props.entityId,
  getEntityData,
  { immediate: true },
);
<%_
const oneToOneNotOwnerSide =[];
let hasUseJPADerivedIdentifier = false;
let hideColumnsAdd = '';
_%>
<%_ if (showInOneRelationships && showInOneRelationships.length) {
hideColumnsAdd = '[';
const addHideColumns = showInOneRelationships.map(relationship => {
  if (relationship.relationshipManyToOne || relationship.relationshipOneToOne) {
    return `'${relationship.relationshipName}.${relationship.otherEntityField}'`
  } else {
    return `'${relationship.relationshipName}'`;
  }
});
hideColumnsAdd += addHideColumns.join(', ');
hideColumnsAdd += ']';
_%>
const relationTables = reactive({
  activeKey: 'baseInfo',
  <%_
  showInOneRelationships.forEach(relationship => {
      const relationshipComponentConfig = showInOneContainerConfig.relationshipsConfig[relationship.relationshipName];
  _%>
    <%_ if (relationship.source?.annotationOnSource?.includes('editByList')) { _%>
    <%= relationshipComponentConfig.relationTableKey %>: {
          name: '<%= relationship.otherEntity.entityNameCapitalized %>List',
          title: '<%= relationship.bcTitle%>',
          props: () => { return {
              <%_ if (relationship.source?.annotationOnSource?.toString().includes('relateByIdEntity')) { _%>
            query: { ownerEntityName: '<%= entityClass %>', ownerEntityId: entityId },
              <%_ } else { _%>
            query: {<%= relationship.otherRelationship.relationshipName%>Id: entityId },
              <%_ } _%>
            editIn: 'modal',
              <%_ if (relationship.source?.annotationOnSource?.toString().includes('relateByIdEntity')) { _%>
            baseData: { ownerEntityName: '<%= entityClass %>', ownerEntityId: entityId },
              <%_ } else { _%>
            baseData: { <%= relationship.otherRelationship.relationshipName%>Id: entityId },
              <%_ } _%>
            gridOptions: {},
            searchFormOptions: {
              disabled: false,
              allowSwitch: false,
            },
            gridCustomConfig: {
              hideOperations: false,
              hideSlots: [],
              columnsName: '',
            },
            modelName: '<%= relationship.otherEntity.entityNameCapitalized %>List',
          }; },
        },
      <%_ } else　if (relationship.source?.annotationOnSource?.includes('editByFormList')) { _%>
      <%= relationshipComponentConfig.relationTableKey %>: {
          name: 'FormList',
          title: '<%= relationship.bcTitle%>',
          props: () => { return {
              <%_ if (relationship.source?.annotationOnSource?.toString().includes('relateByIdEntity')) { _%>
            query: { ownerEntityName: '<%= entityClass %>', ownerEntityId: props.ntityId },
              <%_ } else { _%>
            query: {<%= relationship.otherRelationship.relationshipName%>Id: props.entityId },
              <%_ } _%>
            editIn: 'modal',
              <%_ if (relationship.source?.annotationOnSource?.toString().includes('relateByIdEntity')) { _%>
            baseData: { ownerEntityName: '<%= entityClass %>', ownerEntityId: props.entityId },
              <%_ } else { _%>
            baseData: { <%= relationship.otherRelationship.relationshipName%>Id: props.entityId },
              <%_ } _%>
            configData: [
              {
                formConfig: config.<%= relationship.relationshipName %>Columns,
                data: {},
              }
            ],
            modelName: 'FormList',
          }; },
        },
      <%_ } else　if (relationship.source?.annotationOnSource?.includes('editByDescList')) { _%>
      <%= relationshipComponentConfig.relationTableKey %>: {
          name: 'DescList',
          title: '<%= relationship.bcTitle%>',
          props: () => { return {
              <%_ if (relationship.source?.annotationOnSource?.toString().includes('relateByIdEntity')) { _%>
            query: { ownerEntityName: '<%= entityClass %>', ownerEntityId: props.entityId },
              <%_ } else { _%>
            query: {<%= relationship.otherRelationship.relationshipName%>Id: props.entityId },
              <%_ } _%>
            editIn: 'modal',
              <%_ if (relationship.source?.annotationOnSource?.toString().includes('relateByIdEntity')) { _%>
            baseData: { ownerEntityName: '<%= entityClass %>', ownerEntityId: props.entityId },
              <%_ } else { _%>
            baseData: { <%= relationship.otherRelationship.relationshipName%>: {<%= relationship.otherEntity.primaryKey.name %>: props.entityId }, },
              <%_ } _%>
            data: <%= entityInstance %>.<%= relationship.relationshipName %>,
            savedOpen: true,
            toolButtons: [],
            editComponentPath: '@/views/<%= relationship.otherEntity.entityFolderName%>/components/form-component.vue',
            modelName: 'DescList',
          }; },
          events: {
            refresh: async () => {
              await getEntityData();
            },
            delete: async <%= relationship.otherEntity.entityInstance %> => {
              <%_ let otherApiModuleName = this._.camelCase(relationship.otherEntity.clientRootFolder || relationship.otherEntity.microserviceName); _%>
              await apiService.<%= otherApiModuleName ? otherApiModuleName + '.' : '' %><%= relationship.otherEntity.entityInstance %>Service.delete(<%= relationship.otherEntity.entityInstance %>.<%= relationship.otherEntity.primaryKey.name %>);
              await getEntityData();
            },
          },
        },
      <%_ } else { _%>
      <%= relationshipComponentConfig.relationTableKey %>: {
          name: 'vxe-grid',
          title: '<%= relationship.bcTitle%>',
          props: () => { return {
            data: <%= entityInstance %>['<%= relationship.relationshipName%>'],
            columns: <%= useCommonTable ? '' : 'config.'%><%= relationship.relationshipName%>Columns(),
            border: true,
            showOverflow: true,
            fieldMapToTime: [],
            compact: true,
            size: 'default',
            toolbarConfig: {
              buttons: [],
              tools: [],
              import: false,
              export: false,
              print: false,
              custom: false
            }
          } as VxeGridProps; },

        },
      <%_ } _%>
      <%_ }); _%>
  });
  <%_ } _%>
  const descriptionsProps = reactive({
    schema: config.fields(props.hideColumns<%- hideColumnsAdd ? `.concat(${hideColumnsAdd})` : ''%>),
    isEdit: () => false,
    // formConfig,
    labelWidth: '120px',
    data: <%= entityInstance %>,
    column: props.columns || 1,
  });
  <%_ if (addCustomMethod.indexOf('detailTemplate') !== -1) { _%>
  <%- include(`../common/entity-custom/${entityClass}.updateTemplate.ejs`, {position: 'method'}); -%>
  <%_ } _%>
</script>
