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

const queryForm = reactive({
	station: '',
	point:"",
	description:'',
	uniformcode:"",
	
})
/**场站 */
const stationList = ref([])
const funGetStation = async () => {
	const res = await request.get("/base/station")
	stationList.value = res.data
	if (stationList.value.length) {
		queryForm.station = stationList.value[0].id
		funGetWind(queryForm.station)
	}
}
const funStationChange = (stationId) => {
	if (stationId) {
		funGetWind(stationId)
	} else {
		windList.value = []
	}
}
/**风机 */
const checkAll = ref(true)
const windList = ref([])
const funGetWind = async (stationId) => {
	const res = await request.get("/base/windturbine", {params: { stationId }})
	windList.value = res.data
	queryForm.wtIds = res.data.map(o => o.id)
	checkAll.value = true
}

const funCheckAll = () => {
	checkAll.value = !checkAll.value
	if(checkAll.value){
		queryForm.wtIds = windList.value.map(o => o.id)
	}else{
		queryForm.wtIds = []
	}
}


/**导出 */
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 = {
		station: queryForm.station,
		wtIds: queryForm.wtIds.join(),
		st: new Date(startDate).getTime(),
		et: 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">
		
		<el-form class="" :inline="true" :model="queryForm">
			<el-form-item label="场站" class="!mb-0">
				<el-select v-model="queryForm.station" class="w-[150px]" @change="funStationChange">
					<el-option v-for="item in stationList" :key="item.id" :label="item.name" :value="item.id"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="测点" class="!mb-0">
					<el-input v-model="queryForm.point" />
			</el-form-item>
			<el-form-item label="描述" class="!mb-0">
					<el-input v-model="queryForm.description" />
			</el-form-item>
			<el-form-item label="统一识别码" class="!mb-0">
					<el-input v-model="queryForm.uniformcode" />
			</el-form-item>
			<el-form-item class="!mb-0">
				<submit-btn v-prevdbclick:5000="funSubmit" desc="查询"></submit-btn>
                <submit-btn v-prevdbclick:5000="funSubmit" desc="导出"></submit-btn>
			</el-form-item>
		</el-form>
	</div>
</template>