<template>
  <div
    class="search mb-[15px] flex h-[170px] w-full flex-col items-center justify-around"
  >
    <div class="flex gap-10">
      <router-link v-for="(v, i) in subMenus" :key="i" :to="v.path">
        {{ v.meta.title }}
      </router-link>
    </div>
    <div class="flex items-center justify-center gap-2">
      <el-form ref="form" size="small" inline :model="form">
        <el-form-item prop="type">
          <el-select
            style="width: 100px"
            v-model="form.type"
            placeholder="请选择"
          >
            <el-option label="按年" value="year"></el-option>
            <el-option label="按月" value="month"></el-option>
            <el-option label="按日" value="day"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="year" v-if="form.type == 'year'">
          <el-date-picker
            style="width: 150px"
            v-model="form.year"
            type="year"
            value-format="yyyy"
            placeholder="选择年"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item prop="month" v-if="form.type == 'month'">
          <el-date-picker
            style="width: 150px"
            v-model="form.month"
            type="month"
            value-format="yyyy-MM"
            placeholder="选择月"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item prop="day" v-if="form.type == 'day'">
          <el-date-picker
            style="width: 150px"
            v-model="form.day"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          prop="businessName"
          v-if="$route.path == '/enginesearch/queueupdata'"
        >
          <el-select
            style="width: 150px"
            v-model="form.businessName"
            placeholder="请选择业务"
            clearable
            filterable
          >
            <el-option
              v-for="v in businessList"
              :key="v.id"
              :label="v.businessName"
              :value="v.businessName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="pjOption" v-else>
          <el-select
            style="width: 150px"
            v-model="form.pjOption"
            placeholder="请选择评价选项"
            clearable
            filterable
          >
            <el-option
              v-for="(v, i) in pjOption"
              :key="i"
              :label="v"
              :value="v"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="deptName">
          <el-select
            style="width: 150px"
            v-model="form.deptName"
            placeholder="请选择部门"
            clearable
            filterable
          >
            <el-option
              v-for="v in deptList"
              :key="v.id"
              :label="v.name"
              :value="v.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="windowNum">
          <el-select
            style="width: 150px"
            v-model="form.windowNum"
            placeholder="请选择窗口"
            clearable
            filterable
          >
            <el-option
              v-for="v in windowList"
              :key="v.id"
              :label="`${v.name}-${v.fromnum}`"
              :value="v.fromnum"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleSearch">检索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="$router.push('/engine')">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { findBottomSubarrays } from "@/utils";
let pjOption = ["非常满意", "满意", "基本满意", "不满意", "非常不满意"];
export default {
  components: {},
  data() {
    return {
      pjOption,
      subMenus: [],
      form: {
        type: "year",
        businessName: "",
        deptName: "",
        windowNum: "",
        year: "",
        month: "",
        day: "",
        pjOption: "",
      },
    };
  },
  computed: {
    ...mapState("user", ["businessList", "deptList", "windowList"]),
    activeKey() {
      return this.$route.path;
    },
  },
  created() {
    this.getSubMenus();
  },
  mounted() {},
  methods: {
    changeRouter(e) {
      this.$router.push(e.name);
    },
    // 获取当前顶层路由下的所有子路由
    getSubMenus() {
      let path = this.$route?.meta.parentPath
        ? this.$route.meta.parentPath
        : this.$route.path;
      let options = this.$router.options.routes[0].children;
      let curRouters = options.filter((v) => v.path == path);
      this.subMenus = findBottomSubarrays(curRouters).filter(
        (v) => !v.meta.hidden
      );
    },
    handleSearch() {
      this.$emit("search", this.form);
    },
  },
};
</script>

<style lang="less" scoped>
.search {
  flex-shrink: 0;
  background: url("@/assets/img/engineSearch_bg.svg") no-repeat center / 100%
    100%;
  a {
    color: rgba(254, 254, 254, 0.65);
  }
  .router-link-active {
    color: #fff;
    font-weight: 600;
  }
}
</style>
