<template>
  <el-row>
    <!-- 搜索用表单 -->
    <search-fold-form ref="searchForm" :model="searchParams" class="search" @search="searchClick">
      <el-form-item prop="name" label="组织名称">
        <el-input
          v-model.trim="searchParams.name"
          placeholder="请输入组织名称"
          clearable
        />
      </el-form-item>
      <el-form-item label="上级组织" prop="parentId">
        <DeptSelect ref="deptSelect" v-model.trim="searchParams.parentName" search-mode @change="(e) => Object.assign(searchParams, { parentId: e.deptId, parentName: e.deptName })" />
      </el-form-item>
      <el-form-item slot="buts">
        <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 = { // 搜索栏初始值
  name: '',
  parentId: '',
  parentName: ''
}
export default {
  inject: ['global'],
  components: { SearchFoldForm },
  props: {
    searchParams: {
      require: true,
      type: Object,
      default: () => deepClone(defaultSearchParams)
    }
  },
  data() {
    return {
    }
  },
  mounted() {
    this.$emit('search', deepClone(defaultSearchParams))
  },
  methods: {
    search() {
      this.$emit('search', this.searchParams)
    },
    reset() {
      this.$refs.searchForm.resetFields()
      this.$emit('search', deepClone(defaultSearchParams))
    }
  }
}
</script>

<style scoped>
</style>
