<template>
  <el-row>
    <!-- 搜索用表单 -->
    <search-fold-form ref="searchForm" :model="searchParams" class="search" @search="searchClick">
      <el-form-item prop="userName" label="账号">
        <el-input
          v-model.trim="searchParams.userName"
          placeholder="请输入账号"
          clearable
        />
      </el-form-item>
      <el-form-item prop="nickname" label="姓名">
        <el-input
          v-model.trim="searchParams.nickname"
          clearable
          placeholder="请输入姓名"
        />
      </el-form-item>
      <el-form-item label="所属组织" prop="deptId">
        <DeptSelect v-model.trim="searchParams.deptName" search-mode @change="Object.assign(searchParams, $event)" />
      </el-form-item>
      <el-form-item prop="status" label="状态">
        <el-select
          v-model.trim="searchParams.status"
          clearable
          size="small"
          placeholder="请选择状态"
        >
          <el-option value="" label="全部" />
          <el-option
            v-for="item in Object.entries(global.dict.status).map(([id, name]) => ({ id, name }))"
            :key="item"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </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 = { // 搜索栏初始值
  nickname: '',
  userName: '',
  mobile: '',
  deptId: '',
  deptName: '',
  status: ''
}
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>
