riku
2025-03-12 42f42dc88214f283b43c422f37e10ab45c5c5578
src/components/search/SearchBar.vue
@@ -1,15 +1,28 @@
<template>
  <BaseCard class="">
  <BaseCard size="middle-s" direction="down">
    <template #content>
      <el-form :inline="true">
        <OptionMission v-model="formSearch.missionCode"></OptionMission>
        <OptionType v-model="formSearch.type"></OptionType>
        <OptionMission v-model="mission" @init-over="initOver"></OptionMission>
        <OptionType
          v-model="formSearch.deviceType"
          @init-over="initOver"
        ></OptionType>
        <OptionDevice
          :type="formSearch.type"
          :type="formSearch.deviceType"
          v-model="formSearch.deviceCode"
          @init-over="initOver"
        ></OptionDevice>
        <OptionTime v-model="formSearch.timeArray"></OptionTime>
        <el-button type="primary" class="el-button-custom" @click="handleClick">
        <OptionTime
          v-model="formSearch.timeArray"
          :start-date="dateRange[0]"
          :end-date="dateRange[1]"
        ></OptionTime>
        <el-button
          :loading="loading"
          type="primary"
          class="el-button-custom"
          @click="handleClick"
        >
          分析
        </el-button>
      </el-form>
@@ -18,37 +31,87 @@
</template>
<script>
// 可能会有延时初始化的选项总数,包括走航任务、设备类型、设备编号
const MAX_INIT = 3;
// 已初始化的选项数
let initCount = 0;
let initEvents = [];
// 搜索框
export default {
  props: {
    loading: Boolean,
    searchTime: Array
  },
  data() {
    return {
      mission: undefined,
      formSearch: {
        missionCode: '',
        type: '',
        deviceType: '',
        deviceCode: '',
        timeArray: []
      }
      },
      // 可选日期范围,根据走航任务决定
      dateRange: []
    };
  },
  emits: ['search'],
  watch: {
    searchTime(nV, oV) {
      if (nV != oV) {
        this.timeArray = this.searchTime;
        this.formSearch.timeArray = this.searchTime;
      }
    },
    mission(nV, oV) {
      if (nV != oV) {
        this.onInit(() => {
          this.formSearch.timeArray = [
            new Date(nV.startTime),
            new Date(nV.endTime)
          ];
          this.dateRange = [new Date(nV.startTime), new Date(nV.endTime)];
          this.formSearch.deviceType = nV.deviceType;
          this.formSearch.deviceCode = nV.deviceCode;
          // 代表首次进入界面,此时自动执行首个任务的数据查询操作
          if (oV == undefined) {
            setTimeout(() => {
              this.handleClick();
            }, 500);
          }
        });
      }
    }
  },
  methods: {
    // 各选项初始化加载完成判定
    initOver() {
      initCount++;
      if (initCount == MAX_INIT && initEvents.length > 0) {
        initEvents.forEach((e) => {
          e();
        });
        initEvents = [];
      }
    },
    onInit(event) {
      if (initCount == MAX_INIT) {
        event();
      } else {
        initEvents.push(event);
      }
    },
    handleClick() {
      this.$emit('search', this.formSearch);
      this.$emit('search', { ...this.formSearch, mission: this.mission });
    }
  },
  created() {
    initCount = 0;
    initEvents = [];
  }
};
</script>
<style lang="scss">
<style scoped lang="scss">
.map-date-selector {
  display: inline-block;
  position: relative;
@@ -62,4 +125,9 @@
.p-events-auto {
}
.el-form-item {
  margin-bottom: 0px;
  margin-right: 8px !important;
}
</style>