<template>
  <FormPage
    ref="formPage"
    :action-column="actionColumn"
    :left-tools="leftTools"
    :paging="paging">
    <template #searchFormItem="{ searchForm }">
      <ElFormItem label="Id">
        <ElInput v-model="searchForm.id" placeholder="Id"/>
      </ElFormItem>
      <ElFormItem label="编号">
        <ElInput v-model="searchForm.sn" placeholder="编号"/>
      </ElFormItem>
      <ElFormItem label="责任人">
        <ElInput v-model="searchForm.responsibleId" placeholder="责任人"/>
      </ElFormItem>
      <ElFormItem label="仓库">
        <ElInput v-model="searchForm.warehouseId" placeholder="仓库"/>
      </ElFormItem>
      <ElFormItem label="存放位置">
        <ElInput v-model="searchForm.location" placeholder="存放位置"/>
      </ElFormItem>
      <ElFormItem label="出库时间">
        <ElInput v-model="searchForm.outTime" placeholder="出库时间"/>
      </ElFormItem>
      <ElFormItem label="销售单">
        <ElInput v-model="searchForm.orderId" placeholder="销售单"/>
      </ElFormItem>
      <ElFormItem label="销售单号；wh_sales_order.sn">
        <ElInput v-model="searchForm.orderSn" placeholder="销售单号；wh_sales_order.sn"/>
      </ElFormItem>
      <ElFormItem label="产品分类 Id">
        <ElInput v-model="searchForm.goodsCategoryId" placeholder="产品分类 Id"/>
      </ElFormItem>
      <ElFormItem label="分类名称">
        <ElInput v-model="searchForm.goodsCategoryName" placeholder="分类名称"/>
      </ElFormItem>
      <ElFormItem label="产品 Id">
        <ElInput v-model="searchForm.goodsId" placeholder="产品 Id"/>
      </ElFormItem>
      <ElFormItem label="产品名称">
        <ElInput v-model="searchForm.goodsName" placeholder="产品名称"/>
      </ElFormItem>
      <ElFormItem label="产品编码">
        <ElInput v-model="searchForm.goodSn" placeholder="产品编码"/>
      </ElFormItem>
      <ElFormItem label="数量">
        <ElInput v-model="searchForm.quantity" placeholder="数量"/>
      </ElFormItem>
      <!-- <ElFormItem label="计量单位；字典代码：unit">
        <ElInput
          v-model="searchForm.unit"
          placeholder="计量单位；字典代码：unit"/>
      </ElFormItem> -->
      <ElFormItem label="备注">
        <ElInput v-model="searchForm.memo" placeholder="备注"/>
      </ElFormItem>
      <!-- <ElFormItem label="创建人 Id； sys_user.id">
        <ElInput
          v-model="searchForm.creatorId"
          placeholder="创建人 Id； sys_user.id"/>
      </ElFormItem>
       <ElFormItem label="修改人 Id； sys_user.id">
        <ElInput
          v-model="searchForm.modifierId"
          placeholder="修改人 Id； sys_user.id"/>
      </ElFormItem> -->
      <ElFormItem label="创建时间">
        <ElInput v-model="searchForm.createTime" placeholder="创建时间"/>
      </ElFormItem>
      <ElFormItem label="修改时间">
        <ElInput v-model="searchForm.modifyTime" placeholder="修改时间"/>
      </ElFormItem>
    </template>
    <template #simpleSearchFormItem="{ searchForm }">
      <ElFormItem label="编号">
        <ElInput v-model="searchForm.sn" placeholder="编号"/>
      </ElFormItem>
    </template>
    <template #columns>
      <ElTableColumn label="编号" prop="sn"/>
      <ElTableColumn label="仓库" prop="warehouseName"/>
      <ElTableColumn label="存放位置" prop="location"/>
      <ElTableColumn label="出库时间" prop="outTime" width="170px"/>
      <ElTableColumn label="销售单号" prop="orderSn" width="140px"/>
      <ElTableColumn label="分类名称" prop="goodsCategoryName"/>
      <ElTableColumn label="产品名称" prop="goodsName"/>
      <ElTableColumn label="产品编码" prop="goodSn" width="100px"/>
      <ElTableColumn label="数量" prop="quantity"/>
      <ElTableColumn label="计量单位" prop="unit"/>
      <ElTableColumn label="备注" prop="memo"/>
      <ElTableColumn label="创建时间" prop="createTime" width="170px"/>
      <ElTableColumn label="修改时间" prop="modifyTime" width="170px"/>
    </template>
    <OutOrderForm ref="outOrderForm" :research="research"/>
  </FormPage>
</template>

<script lang="ts" setup>
import OutOrderApi from '@/pages/wh/out-order/out-order-api.ts'
import OutOrderForm from '@/pages/wh/out-order/OutOrderForm.vue'
import FormPage from '@/components/page/FormPage.vue'
import type {
  ActionColumnType,
  ToolType,
} from '@/components/page/a-page-type.ts'
import type { ComponentExposed } from 'vue-component-type-helpers'

const outOrderFormIns = useTemplateRef<InstanceType<typeof OutOrderForm>>('outOrderForm')
const formPageIns = useTemplateRef<ComponentExposed<typeof FormPage>>('formPage')

const actionColumn = reactive<ActionColumnType<OutOrderTypes.SearchOutOrderResult>>({
  tableActions: [
    {
      tooltip: '编辑',
      icon: 'Edit',
      type: 'success',
      action({row}) {
        outOrderFormIns.value?.open(row)
      },
    },
    {
      icon: 'Delete',
      loading: false,
      type: 'danger',
      tooltip: '删除',
      confirm: {
        title: '是否删除当前数据',
      },
      action({row}) {
        return OutOrderApi.del([ row.id! ])
          .then(() => {
            ElMessage.success('删除成功')
            return true
          })
      },
    },
  ],
})
const leftTools: ToolType[] = [
  {
    icon: 'Plus',
    label: '新建',
    action() {
      outOrderFormIns.value?.open()
    },
  },
]

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

function paging(param: OutOrderTypes.SearchOutOrderParam) {
  return OutOrderApi.paging(param)
}
</script>
