<!--
 * @Author: chris
 * @Date: 2025-08-18 09:27:23
 * @LastEditors: chris
 * @LastEditTime: 2025-09-09 16:54:23
-->
<script setup>
const props = defineProps({
  params: {
    type: Object,
    default: () => ({
      nodeId: null,
      dateRange: []
    })
  },
  weatherOptions: {
    type: Object,
    default: () => ([])
  }
})

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

const queryRef = ref()
const queryParams = reactive({...props.params});

watch(() => queryParams, (newVal) => {
  emits('update:params', newVal)
})

watch(() => props.params, (newVal) => {
  Object.assign(queryParams, newVal)
})

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

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

function exportData() {
  emits('export')
}
</script>

<template>
  <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
    <el-form-item label="参数" style="width: 260px;">
      <el-select v-model="queryParams.nodeId" placeholder="请选择参数">
        <el-option v-for="value in weatherOptions" :key="value.id" :label="value.name" :value="value.id"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="记录时间">
      <el-date-picker 
        style="width: 300px"
        v-model="queryParams.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 type="warning" icon="Download" @click="exportData">导出</el-button>
      <el-button icon="Refresh" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
</template>

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