<template>
  <el-row>
    <!-- 搜索用表单 -->
    <search-fold-form ref="searchForm" :model="searchParams" class="search" @search="searchClick">
      <el-form-item label="编号">
        <el-input v-model.trim="searchParams.id" placeholder="请输入编号" clearable size="small" />
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model.trim="searchParams.type">
          <el-option
            v-for="(item, index) in global.type"
            :key="index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker v-model.trim="searchParams.timerange" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss" type="datetimerange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :default-time="['00:00:00', '23:59:59']" :clearable="false" />
      </el-form-item>
      <el-form-item>
        <el-button :loading="global.loading" type="primary" @click="search"> 查询 </el-button>
        <el-button :loading="global.loading" @click="reset">重置</el-button>
      </el-form-item>
    </search-fold-form>
  </el-row>
</template>

<script>
import SearchFoldForm from '@/components/SearchFoldForm/index.vue'
import { deepClone } from '@/utils'
const defaultSearchParams = { // 搜索栏初始值
  id: '',
  type: '',
  timerange: ''
}
export default {
  inject: ['global'],
  components: { SearchFoldForm },
  props: {
    searchParams: {
      require: true,
      type: Object,
      default: () => deepClone(defaultSearchParams)
    }
  },
  data() {
    return {
    }
  },
  created() {
  {{#unless (equal treeType '')}}
    this.$emit('search', deepClone(defaultSearchParams))
  {{/unless}}
  },
  mounted() {
  {{#if (equal treeType '')}}
    this.$emit('search', deepClone(defaultSearchParams))
  {{/if}}
  },
  methods: {
    search() {
      this.$emit('search', this.searchParams)
    },
    reset() {
      this.$refs.searchForm.resetFields()
      this.$emit('search', deepClone(defaultSearchParams))
    }
  }
}
</script>

<style scoped>
</style>
