<template>
  <div class="seach">
    <el-form class="generat-seach" :inline="true" :model="queryForm">
      <!-- <el-form-item label="场站" class="!mb-0">
        <el-select
          style="width: 140px"
          v-model="queryForm.station"
          @change="getWtList"
        >
          <el-option
            v-for="item in stationList"
            :key="item.nemCode"
            :label="item.aname"
            :value="item.nemCode"
          >
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="风机" class="!mb-0">
        <el-select
          style="width: 150px"
          v-model="queryForm.wt"
          multiple
          collapse-tags
        >
          <el-option
            v-for="item in wtList"
            :key="item.id"
            :label="item.nemCode"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间" class="!mb-0">
        <el-date-picker
          v-model="queryForm.dateTime"
          size="mini"
          type="daterange"
          range-separator="-"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="开始"
          end-placeholder="结束"
          popper-class="date-select"
        >
        </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-group>
      </el-form-item>
      <el-form-item class="!mb-0">
        <el-button type="primary" @click="funSubmit">执行</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup name="search">
import { onMounted, reactive, ref } from "vue";
import httpRequest from "@/utils/request.js";
import dayjs from "dayjs";
import SubmitBtn from "@/components/generatingCapacityComponent/SubmitBtn.vue";
// import configStationJson from './configStation.json'

const queryForm = reactive({
  station: "NX_FGS_HA_FDC_STA",
  wt: [],
  dateTime: [
    dayjs().subtract(1, "day").format("YYYY-MM-DD"),
    dayjs().format("YYYY-MM-DD"),
  ],
  interval: 1,
});
/**场站 */
const stationList = ref([]);
const wtList = ref([]);
const funGetStation = async () => {
  const res = await httpRequest.get("/electricity/czlist");
  // stationList.value = Object.values(configStationJson) // configStationJson
  stationList.value = Object.values(res?.data || []);
  if (stationList.value.length) {
    queryForm.station = stationList.value[0].nemCode;
  }

  getWtList();
};
const getWtList = async () => {
  const res = await httpRequest.get(
    `/pro-basic-equipment/equipmentsByWpid2?wpid=${queryForm.station}`
  );
  wtList.value = Object.values(res?.data?.data || []);
  if (wtList.value.length) {
    let wt = [wtList.value[0].id];
    // wtList.value.forEach((item) => {
    //   wt.push(item.id);
    // });
    queryForm.wt = wt;
  }

  funSubmit();
};
/**导出 */
const emits = defineEmits(["submit"]);
const funSubmit = async () => {
  const startTs = dayjs(queryForm.dateTime[0]).unix();
  const endTs = dayjs(queryForm.dateTime[1]).unix();
  const query = {
    windturbineId: queryForm.wt.toString() || "",
    startTs,
    endTs,
    interval: queryForm.interval,
  };
  switch (queryForm.interval) {
    case 1:
      query.interval = 60;
      break;
    case 2:
      query.interval = 300;
      break;
    case 3:
      query.interval = 600;
      break;
  }
  emits("submit", query);
};
/**created */
onMounted(() => {
  funGetStation();
});
</script>