<!--
 * @Author: chris
 * @Date: 2026-01-16 14:58:35
 * @LastEditors: chris
 * @LastEditTime: 2026-01-16 18:01:36
-->
<script setup>
  const emits = defineEmits(['query', 'reset']);

  const queryRef = ref(null);

  const queryParams = reactive({
    startTime: '',
    endTime: ''
  });
  const dateRange = ref([]);

  watch(() => dateRange.value, (val) => {
    if (val && val.length === 2) {
      queryParams.startTime = val[0];
      queryParams.endTime = val[1];
    } else {
      queryParams.startTime = queryParams.endTime = '';
    }
  });
  
  const handleQuery = () => {
    emits('query', queryParams);
  };
  
  const resetQuery = () => {
    dateRange.value = [];
    emits('reset', queryRef.value);
  };
</script>

<template>
  <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
    <el-form-item label="时间范围">
      <el-date-picker 
        style="width: 300px"
        v-model="dateRange"
        value-format="YYYY-MM-DD"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      <el-button icon="Refresh" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<style lang="scss" scoped>
</style>
