<%
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
var lcc = toCamelCase(ulc);
var ucc = upperFirst(lcc);
var dc = toDashCase(lcc);

var pageVueName = ucc + ".vue";
var formVueName = ucc + "Form.vue";
var detailVueName = ucc + "Detail.vue";
var pageTsName = "page.ts";
var apiTsName = dc + "-api.ts";
var dTsName = dc + ".d.ts";
%>
<template>
  <ATablePage
    ref="tablePage"
    v-bind="tablePageProps">
    <template #highFormItem="formData">
       <%
       for(column in table.columns) {
           var map = tsType(column.dataType);
       %>
       <ElFormItem label="${column.comment}">
        <ElInput placeholder="${column.comment}" v-model="formData.${toCamelCase(column.name)}"/>
      </ElFormItem>
     <%}%>
    </template>
    <template #simpleFormItem="formData">
       <%
       for(column in table.columns) {
           var map = tsType(column.dataType);
       %>
       <ElFormItem>
        <ElInput placeholder="${column.comment}" v-model="formData.${toCamelCase(column.name)}"/>
      </ElFormItem>
     <%}%>
    </template>

    <template #columns>
        <%
        for(column in table.columns) {
            var map = tsType(column.dataType);
        %>
        <ElTableColumn label="${column.comment}" prop="${toCamelCase(column.name)}"/>
       <%}%>
    </template>
    <${ucc}Form ref="${lcc}Form" :research="research"/>
    <${ucc}Detail ref="${lcc}Detail"/>
  </ATablePage>
</template>

<script lang="ts" setup>
import ${ucc}Api from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${apiTsName}'
import ${ucc}Form from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${formVueName}'
import ${ucc}Detail from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${detailVueName}'
import ATablePage, {
  type ATablePageInstance,
  buildTablePageProps,
} from '@/components/a-page/a-table-page/ATablePage.tsx'

const tablePageIns = useTemplateRef<ATablePageInstance>('tablePage')
const ${lcc}FormIns = useTemplateRef<InstanceType<typeof ${ucc}Form>>('${lcc}Form')
const ${lcc}DetailIns = useTemplateRef<InstanceType<typeof ${ucc}Detail>>('${lcc}Detail')

function research() {
  tablePageIns.value?.doSearch()
}

const tablePageProps = buildTablePageProps<${ucc}Types.Search${ucc}Param, ${ucc}Types.Search${ucc}Result>({
  searchForm: {
    paging: ${ucc}Api.paging,
  },
  toolBar: {
    leftTools: [
      {
        icon: 'Plus',
        label: '新建',
        action() {
          ${lcc}FormIns.value?.open()
        },
      },
    ],
  },
  table: {
    actionColumn: {
      tableActions: [
        {
          tooltip: '详情',
          icon: 'Postcard',
          type: 'info',
          action({row}) {
            ${lcc}DetailIns.value?.open(row)
          },
        },
        {
          tooltip: '编辑',
          icon: 'Edit',
          type: 'primary',
          action({row}) {
            ${lcc}FormIns.value?.open(row)
          },
        },
        {
          icon: 'Delete',
          loading: false,
          type: 'danger',
          tooltip: '删除',
          confirm: {
            title: '是否删除当前数据',
          },
          action({row}) {
            return ${ucc}Api.del([ row.id! ])
              .then(() => {
                ElMessage.success('删除成功')
                return true
              })
          },
        },
      ],
    },
  },
})

</script>
