<!--
 * @Author: chris
 * @Date: 2025-08-18 09:27:23
 * @LastEditors: chris
 * @LastEditTime: 2026-01-16 18:49:16
-->
<script setup>
const props = defineProps({
  params: {
    type: Object,
    default: () => ({})
  }
})

const emits = defineEmits(['update:params'])

const queryRef = ref()
const dateRange = ref([])
const pestOpts = ref([])

watch(() => dateRange.value, (newVal) => {
  if (!newVal) {
    props.params.beginTime = props.params.endTime = ''
    return
  }
  props.params.beginTime = newVal[0] || ''
  props.params.endTime = newVal[1] || ''
})

watch(() => props.params, (newVal) => {
  console.log('watch', newVal)
  dateRange.value = [newVal.beginTime, newVal.endTime]
  // nextTick(() => {
  //   dateRange.value = [newVal.beginTime, newVal.endTime]
  // })
}, { immediate: false })

function resetQuery() {
  emits('reset')
}

function handleQuery() {
  emits('query')
}

function exportAnalysis() {
  emits('exportAnalysis')
}

function exportTrend() {
  emits('exportTrend')
}
</script>

<template>
  <el-form :model="props.params" ref="queryRef" :inline="true" label-width="68px">
    <el-form-item label="创建时间">
      <el-date-picker 
        style="width: 300px"
        v-model="dateRange"
        format="YYYY-MM-DD"
        value-format="YYYY-MM-DD HH:mm:ss"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :default-time="[new Date(0,0,0,0,0,0), new Date(0,0,0,23,59,59)]"
      ></el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      <el-button type="warning" icon="Download" @click="exportAnalysis">导出分析</el-button>
      <el-button type="warning" icon="Download" @click="exportTrend">导出统计</el-button>
      <el-button icon="Refresh" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
</template>

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