<template>
  <div class="body" id="shijian">
    <div class="itembox">
      <template v-for="(option, index) in searchOptions" :key="index">
        <div class="item" v-if="option.type == 'input'">
          <span class="label">{{ option.label }}:</span>
          <el-input
            class="tep"
            v-model="searchForm[option.prop]"
            placeholder="请输入"
            clearable
          />
        </div>
        <div class="item" v-if="option.type == 'select'">
          <span class="label">{{ option.label }}:</span>

          <el-select
            class="tep"
            v-model="searchForm[option.prop]"
            clearable
            placeholder="Select"
          >
            <el-option
              v-for="item in option.options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div class="item" v-if="option.type == 'daterange'">
          <span class="label">{{ option.label }}:</span>
          <el-date-picker
            v-model="searchForm[option.prop]"
            type="daterange"
            class="tep"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="YYYY-MM-DD"
            format="YYYY-MM-DD"
          />
        </div>
      </template>
    </div>
    <div class="oprea">
      <el-button type="primary" class="btn" @click="getData">查询</el-button>
      <el-button class="btn" @click="reset">重置</el-button>
    </div>
  </div>
</template>
<script setup>
const props = defineProps({
  searchOptions: {
    default: [],
    type: Array,
  },
  keepState: {
    type: Boolean,
    default: false,
  },
});
const emit = defineEmits(["resetList", "dataList"]);
const searchForm = ref({});
const getData = () => {
  emit("dataList");
};
const reset = () => {
  const currentState = searchForm.value.state;
  searchForm.value = {};
  if (props.keepState) {
    if (currentState !== undefined) {
      searchForm.value.state = currentState;
    }
  }
  emit("dataList");
};
const setSearchFrom = () => {
  props.searchOptions.forEach((option) => {});
};
// const options = [
//   {
//     lable: "a",
//     value: "a",
//   },
// ];
defineExpose({ searchForm });
</script>
<style lang="scss" scoped>
.body {
  width: 100%;
  height: 100%;
  display: flex;
  margin-bottom: 20px;
  .itembox {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    .item {
      display: flex;
      align-items: center;
      width: 260px;
      .label {
        white-space: nowrap;
        margin-right: 5px;
        font-size: 14px;
      }
      .tep {
        width: 260px !important;
      }
    }
  }
  .oprea {
    width: 240px;
    height: 100%;
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center;
  }
}
</style>
<style lang="scss">
#shijian {
  .is-active {
    background-color: #f5f7fa;
  }
}
</style>
