<!--
 * @Description: 
 * @Author: 陈长吉
 * @Date: 2018-10-29 16:30:28
 * @LastEditTime: 2020-09-02 15:16:23
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div class="search-box">
    <el-form :inline="true" ref="search" :model="search">
      <slot></slot>
      <search-more>
        <slot name="more"> </slot>
      </search-more>
      <el-button size="small" type="primary" plain @click="handleSearch">查询</el-button>
      <el-button size="small" type="text" @click="resetForm">重置</el-button>
    </el-form>
  </div>
</template>
<script>
// @yunjidoc 功能组件 - 搜索框
import { searchUpdateRoute } from '@/utils'
export default {
  componentName: 'Search',
  components: {
    'search-more': (resolve) => require(['@p/SearchMore'], resolve)
  },
  props: {
    /**
     * @prop {Object} query 搜索参数  默认: {}
     */
    query: {
      type: Object
    }
  },
  data() {
    return {
      search: {}
    }
  },
  mounted() {
    this.search = this.getSearch()
  },
  methods: {
    handleSearch() {
      searchUpdateRoute(Object.assign({}, this.query, this.search), this)
    },
    resetForm() {
      this.$refs.search.resetFields()
    },
    getSearch(query) {
      let search = Object.assign({}, query, this.$route.query)
      delete search.pageTotal
      delete search.total
      delete search.pageIndex
      delete search.pageSize
      return search
    }
  }
}
</script>
