<template>
  <ATablePage
    ref="tablePage"
    v-bind="tablePageProps">
    <template #highFormItem="formData">
      <ElFormItem label="项目名称">
        <ElInput
          v-model="formData.projectName"
          placeholder="项目名称"/>
      </ElFormItem>
      <ElFormItem label="客户名称">
        <ElInput
          v-model="formData.fringeName"
          placeholder="客户名称"/>
      </ElFormItem>
      <ElFormItem label="运输方名称">
        <ElInput
          v-model="formData.transName"
          placeholder="运输方名称"/>
      </ElFormItem>
      <ElFormItem label="合同有效期">
        <ADtPicker v-model="formData.contractTimes" :change-handler="research"/>
      </ElFormItem>
      <ElFormItem label="创建时间">
        <ADtPicker v-model="formData.createTimes" :change-handler="research"/>
      </ElFormItem>
    </template>
    <template #simpleFormItem="formData">
      <ElFormItem>
        <ElInput
          v-model="formData.projectName"
          placeholder="项目名称"/>
      </ElFormItem>
      <!-- <ElFormItem>
        <ElInput
          v-model="formData.fringeName"
          placeholder="客户姓名"/>
      </ElFormItem>
      <ElFormItem>
        <ElInput
          v-model="formData.transName"
          placeholder="运输方名称"/>
      </ElFormItem> -->
    </template>
    <template #columns>
      <ElTableColumn label="项目名称" prop="projectName"/>
      <ElTableColumn label="运输方联系人" prop="transCustomerInfo.customerName" width="140px"/>
      <ElTableColumn label="运输方联系电话" prop="transCustomerInfo.phone" width="140px"/>
      <ElTableColumn label="运输企业名称" prop="transOrgInfo.orgName" width="140px"/>
      <ElTableColumn label="客户姓名" prop="fringeCustomerInfo.customerName" width="140px"/>
      <ElTableColumn label="客户联系电话" prop="fringeCustomerInfo.phone" width="140px"/>
      <ElTableColumn label="客户企业名称" prop="fringeOrgInfo.orgName" width="140px"/>
      <!-- <ElTableColumn label="详细地址" prop="address" width="240" show-overflow-tooltip/> -->
      <ElTableColumn label="合同有效期" prop="contractStartDate" width="220">
        <template #default="{ row }">
          {{ row.contractStartDate + ' 至 ' + (row.contractEndDate ?? '--') }}
        </template>
      </ElTableColumn>
      <ElTableColumn label="创建时间" prop="createTime" width="190"/>
    </template>
    <ProjectForm ref="projectForm" :research="research"/>
    <!-- <ProjectDetail ref="projectDetail" @edit-succ="research"/> -->
  </ATablePage>
</template>

<script lang="ts" setup>
import ProjectApi from '@/pages/cst/project/project-api.ts'
import ProjectForm from '@/pages/cst/project/ProjectForm.vue'
import ADtPicker from '@/components/a-dt-picker/ADtPicker.vue'
import ATablePage, {
  type ATablePageInstance,
  buildTablePageProps,
} from '@/components/a-page/a-table-page/ATablePage.tsx'

const tablePageIns = useTemplateRef<ATablePageInstance>('tablePage')
// const projectDetailIns = useTemplateRef<InstanceType<typeof ProjectDetail>>('projectDetail')
const projectFormIns = useTemplateRef<InstanceType<typeof ProjectForm>>('projectForm')

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

const tablePageProps = buildTablePageProps<ProjectTypes.SearchProjectParam, ProjectTypes.SearchProjectResult>({
  pageLayout: {
    dataListHeight: 3,
    enableHighForm: false,
  },
  toolBar: {
    leftTools: [
      {
        icon: 'Plus',
        label: '新建',
        action() {
          projectFormIns.value?.open()
        },
      },
    ],
  },
  table: {
    actionColumn: {
      tableActions: [
        /* {
         tooltip: '详情',
         icon: 'Postcard',
         action({row}) {
         projectDetailIns.value?.open(row)
         },
         }, */
        {
          tooltip: '编辑',
          icon: 'Edit',
          type: 'success',
          action({row}) {
            projectFormIns.value?.open(row)
          },
        },
      ],
    },
  },
  searchForm: {
    paging: ProjectApi.paging,
  },
})

</script>
