<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" @submit.prevent="">
      <el-row :gutter="8">
        <el-col :lg="8" :md="18" :sm="17" :xs="24">
          <el-form-item label="上下文ID">
            <el-input v-model="form.contextId" maxlength="32" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="客户端ID">
            <el-input v-model="form.clientId" maxlength="32" placeholder=""></el-input>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="18" :sm="17" :xs="24">
          <el-form-item label="请求时间">
            <el-date-picker
              unlink-panels
              type="datetimerange"
              v-model="dateRange"
              range-separator="-"
              value-format="YYYY-MM-DD HH:mm:ss"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              class="ele-fluid"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="4" :md="6" :sm="7" :xs="24">
          <el-form-item label-width="6px">
            <div style="white-space: nowrap">
              <el-button type="primary" @click="search">查询</el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </ele-card>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { useFormData } from '@/utils/use-form-data';
  import type { RequestRecordParam } from '@/api/system/request-record/model';

  const emit = defineEmits<{
    (e: 'search', where?: RequestRecordParam): void;
  }>();

  /** 表单数据 */
  const [form, resetFields] = useFormData<RequestRecordParam>({
    contextId: "",
    clientId: ""
  });

  /** 日期范围 */
  const dateRange = ref<[string, string]>(['', '']);

  /** 搜索 */
  const search = () => {
    const [createTimeStart, createTimeEnd] = dateRange.value || [];
    emit('search', { ...form, createTimeStart, createTimeEnd });
  };

  /**  重置 */
  const reset = () => {
    resetFields();
    dateRange.value = ['', ''];
    search();
  };
</script>
