<script setup lang="ts">
import { ref } from 'vue';
import SearchForm from '@/components/advanced/search-form.vue';

defineOptions({
  name: 'OssSearch',
  inheritAttrs: false
});

const dateRange = ref<[string, string] | null>(null);
const model = defineModel<Api.SystemManage.OssSearchParams>('model', { required: true });

function handleDate(value: [string, string]) {
  model.value.params =
    value === null
      ? []
      : {
          beginCreateTime: value[0],
          endCreateTime: value[1]
        };
}
</script>

<template>
  <SearchForm v-model:model="model" v-bind="$attrs" @reset-interlayer="dateRange = null">
    <template #formItem>
      <NFormItemGi span="24 s:12 m:6" label="文件名称" class="pr-24px">
        <NInput v-model:value="model.fileName" placeholder="请输入文件名称" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="原名" class="pr-24px">
        <NInput v-model:value="model.originalName" placeholder="请输入原名" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="文件后缀" class="pr-24px">
        <NInput v-model:value="model.fileSuffix" placeholder="请输入文件后缀" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="上传用户" class="pr-24px">
        <NInput v-model:value="model.createBy" placeholder="请输入上传用户" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="服务商" class="pr-24px">
        <NInput v-model:value="model.service" placeholder="请输入服务商" />
      </NFormItemGi>
      <NFormItemGi span="24 s:12 m:6" label="上传时间" class="pr-24px">
        <NDatePicker
          v-model:formatted-value="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          clearable
          @update:formatted-value="handleDate"
        />
      </NFormItemGi>
    </template>
  </SearchForm>
</template>

<style scoped></style>
