<script setup name="search">
import { onMounted, reactive, ref } from 'vue'
import request from '@/api/axios.js'
import SubmitBtn from '@com/SubmitBtn.vue'
// import configStationJson from './configStation.json'

const queryForm = reactive({
	station: '',
	st: Date.now() - 30 * 24 * 60 * 60 * 1000,
	et: Date.now(),
	interval: 3
})
/**场站 */
const stationList = ref([])
const funGetStation = async () => {
	const res = await request.get("/agc/config")
	// stationList.value = Object.values(configStationJson) // configStationJson
	stationList.value = Object.values(res)
	if (stationList.value.length) {
		queryForm.station = stationList.value[0].id
	}

	funSubmit()
}
/**导出 */
const emits = defineEmits(['submit'])
const funSubmit = async () => {
	const startDate = new Date(queryForm.st).setHours(0,0,0,0)
	const endDate = new Date(queryForm.et).setHours(0,0,0,0)
	const query = {
		id: queryForm.station,
		startTs: new Date(startDate).getTime(),
		endTs: new Date(endDate).getTime(),
		interval: queryForm.interval
	}
	switch (queryForm.interval) {
		case 2:
			query.interval = 60
			break;
		case 3:
			query.interval = 600
			break;
		case 4:
			query.interval = 900
			break;
	}
	emits('submit', query)
}
/**created */
funGetStation()
</script>
<template>
	<div class="pl-[20px] flex items-center h-[80px] relative">
		<div class="absolute top-[-7px] left-[20px] text-[#838383] text-[14px]">操作面板</div>
		<el-form class="" :inline="true" :model="queryForm">
			<el-form-item label="场站" class="!mb-0">
				<el-select v-model="queryForm.station" class="w-[150px]">
					<el-option v-for="item in stationList" :key="item.id" :label="item.title" :value="item.id"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="开始时间" class="!mb-0">
				<el-date-picker type="date" class="!w-[150px]" v-model="queryForm.st"></el-date-picker>
			</el-form-item>
			<el-form-item label="结束时间" class="!mb-0">
				<el-date-picker type="date" class="!w-[150px]" v-model="queryForm.et"></el-date-picker>
			</el-form-item>
			<el-form-item label="等间隔" class="!mb-0">
				<el-radio-group v-model="queryForm.interval">
					<el-radio :label="1">一秒钟</el-radio>
					<el-radio :label="2">一分钟</el-radio>
					<el-radio :label="3">十分钟</el-radio>
					<el-radio :label="4">十五分钟</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item class="!mb-0">
				<submit-btn v-prevdbclick:5000="funSubmit" desc="执行"></submit-btn>
			</el-form-item>
		</el-form>
	</div>
</template>