<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">
      <div class="search-box">
        <div class="flex gap-2">
          <div class="item border">
            <span class="pl-[15px] text-[14px]">选择时间</span>
            <el-popover
              trigger="click"
              placement="bottom-start"
              popper-class="search-popover"
            >
              <div class="flex flex-col items-center">
                <div class="tab-box">
                  <div
                    :class="['tab-item', { active: form.type == 'year' }]"
                    @click="changeTab('year')"
                  >
                    按年
                  </div>
                  <div
                    :class="['tab-item', { active: form.type == 'month' }]"
                    @click="changeTab('month')"
                  >
                    按月
                  </div>
                  <div
                    :class="['tab-item', { active: form.type == 'date' }]"
                    @click="changeTab('date')"
                  >
                    按日
                  </div>
                </div>
                <div class="tab-content w-ull">
                  <date-picker
                    v-show="form.type == 'year'"
                    v-model="form.year"
                    type="year"
                    value-format="yyyy"
                    placeholder="选择年"
                  >
                  </date-picker>
                  <date-picker
                    v-show="form.type == 'month'"
                    v-model="form.month"
                    type="month"
                    value-format="yyyy-MM"
                    placeholder="选择月"
                  >
                  </date-picker>
                  <date-picker
                    v-show="form.type == 'date'"
                    v-model="form.day"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日"
                  >
                  </date-picker>
                </div>
              </div>
              <el-input
                size="small"
                placeholder="暂未选择"
                :value="dateInputVal"
                slot="reference"
                clearable
                @clear="handleClearDate"
              ></el-input>
            </el-popover>
          </div>
          <div class="item border">
            <span class="pl-[15px] text-[14px]">选择业务</span>
            <el-popover
              trigger="click"
              placement="bottom-start"
              popper-class="search-popover"
            >
              <el-input
                size="small"
                placeholder="暂未选择"
                slot="reference"
              ></el-input>
            </el-popover>
          </div>
          <div class="item border">
            <span class="pl-[15px] text-[14px]">选择部门</span>
            <el-popover
              trigger="click"
              placement="bottom-start"
              popper-class="search-popover"
            >
              <el-input
                size="small"
                placeholder="暂未选择"
                slot="reference"
              ></el-input>
            </el-popover>
          </div>
          <div class="item">
            <span class="pl-[15px] text-[14px]">选择窗口</span>
            <el-popover
              trigger="click"
              placement="bottom-start"
              popper-class="search-popover"
            >
              <el-input
                size="small"
                placeholder="暂未选择"
                slot="reference"
              ></el-input>
            </el-popover>
          </div>
        </div>
        <div class="btn">检索</div>
      </div>
      <div class="back-btn" @click="$router.push('/engine')">返回</div>
    </div>
  </div>
</template>

<script>
import { findBottomSubarrays } from "@/utils";
export default {
  components: {},
  data() {
    return {
      subMenus: [],
      form: {
        type: "year",
        businessName: "",
        deptName: "",
        windowName: "",
        year: "",
        month: "",
        day: "",
        pjOption: "",
      },
    };
  },
  computed: {
    activeKey() {
      return this.$route.path;
    },
    dateInputVal() {
      if (this.form.type == "year") {
        return this.form.year;
      } else if (this.form.type == "month") {
        return this.form.month;
      } else {
        return this.form.day;
      }
    },
  },
  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
      );
    },
    changeTab(key) {
      this.form.type = key;
    },
    handlePick(val) {
      console.log(val);
    },
    handleClearDate() {
      this.form.year = "";
      this.form.month = "";
      this.form.day = "";
    },
  },
};
</script>

<style lang="less" scoped>
.search {
  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;
  }
}
.border {
  border-right: 1px solid #ccc;
}
.search-box {
  height: 68px;
  width: 60%;
  padding: 0px 15px;
  background: #fff;
  border-radius: 34px;
  display: flex;
  align-items: center;
}

.btn,
.back-btn {
  width: 96px;
  height: 60px;
  flex-shrink: 0;
  font-weight: 700;
  color: #fff;
  line-height: 60px;
  text-align: center;
  background: linear-gradient(90deg, #5ab6ff, #2e9aff);
  border-radius: 30px;
  cursor: pointer;
}
.back-btn {
  color: var(--primary);
  background: #fff;
}
:deep(.el-input) {
  .el-input__inner {
    border: none;
  }
}
.tab-box {
  width: 300px;
  height: 40px;
  background-color: #ebebeb;
  border-radius: 20px;
  display: flex;
  position: relative;
  .tab-item {
    width: 100px;
    height: 100%;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .active {
    background-color: #fff;
    border: 2px solid var(--primary);
  }
}

:deep(.el-picker-panel) {
  border: none;
  box-shadow: none;
  border-radius: 0px;
}
:global(.search-popover) {
  width: 348px;
  min-height: 330px;
}
</style>
