<template>
  <FormPage
    ref="formPage"
    :action-column="actionColumn"
    :paging="paging">
    <template #searchFormItem="{searchForm}">
      <ElFormItem label="客户名称">
        <ElInput v-model="searchForm.customerName" placeholder="客户名称"/>
      </ElFormItem>
      <ElFormItem label="联系电话">
        <ElInput v-model="searchForm.phone" placeholder="联系电话"/>
      </ElFormItem>
      <ElFormItem label="企业名称">
        <ElInput v-model="searchForm.orgName" placeholder="企业名称"/>
      </ElFormItem>
      <ElFormItem label="代码">
        <ElInput v-model="searchForm.uscc" placeholder="统一社会信用代码"/>
      </ElFormItem>
    </template>
    <template #simpleSearchFormItem="{searchForm}">
      <ElFormItem>
        <ElInput v-model="searchForm.customerName" placeholder="客户名称"/>
      </ElFormItem>
      <ElFormItem>
        <ElInput v-model="searchForm.orgName" placeholder="企业名称"/>
      </ElFormItem>
    </template>
    <template #columns>
      <!-- ，GeTiHu-个体户、QiYe--企业 -->
      <ElTableColumn label="客户名称" prop="customerName"/>
      <ElTableColumn label="联系电话" prop="phone"/>
      <ElTableColumn label="企业名称" prop="orgName"/>
      <ElTableColumn label="统一社会信用代码" prop="uscc"/>
      <ElTableColumn label="法人名称" prop="legalRepresentative"/>
      <ElTableColumn label="主体类型" prop="orgCategoryTxt"/>
      <ElTableColumn label="营业执照" width="80">
        <template #default="{ row }">
          <ElImage :preview-src-list="[AppApi.fileUrl(row.businessLicense)]" :src="AppApi.fileUrl(row.businessLicense)" preview-teleported show-progress style="width: 32px; height: 32px"/>
        </template>
      </ElTableColumn>
    </template>
    <OrgForm ref="orgForm" :research="research"/>
  </FormPage>
</template>

<script lang="ts" setup>
import OrgApi from '@/pages/cst/org/org-api.ts'
import OrgForm from '@/pages/cst/org/OrgForm.vue'
import AppApi from '@/common/app/app-api.ts'
import FormPage from '@/components/page/FormPage.vue'
import type { ActionColumnType } from '@/components/page/a-page-type.ts'
import type { ComponentExposed } from 'vue-component-type-helpers'

const formPageIns = useTemplateRef<ComponentExposed<typeof FormPage>>('formPage')
const actionColumn = reactive<ActionColumnType<OrgTypes.SearchOrgResult>>({
  tableActions: [
    {
      tooltip: '详情',
      icon: 'Postcard',
      action({row}) {
      },
    },
    /* {
      icon: 'Delete',
      loading: false,
      type: 'danger',
      tooltip: '删除',
      confirm: {
        title: '是否删除当前数据',
      },
      action({row}) {
        OrgApi.del([ row.id! ])
          .then(() => {
            ElMessage.success('删除成功')
            return true
          })
      },
     }, */
  ],
})

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

function paging(param: OrgTypes.SearchOrgParam) {
  return OrgApi.paging(param)
}

</script>
