c-search.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div id="c-search">
  3. <el-form :inline="true" v-if="fields.length > 0">
  4. <el-row>
  5. <el-col :span="6" v-for="i in fields" :key="i.model">
  6. <el-form-item :label="i.label">
  7. <template v-if="i.type === 'select'">
  8. <slot :name="i.model"></slot>
  9. </template>
  10. <template v-else>
  11. <el-input v-model="form[i.model]" :placeholder="`输入${i.label}`"></el-input>
  12. </template>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="24" style="text-align: right">
  16. <el-button size="mini" type="primary" @click="toSearch">查询</el-button>
  17. <el-button size="mini" @click="toReset">重置</el-button>
  18. </el-col>
  19. </el-row>
  20. </el-form>
  21. </div>
  22. </template>
  23. <script>
  24. const _ = require('lodash');
  25. export default {
  26. name: 'c-search',
  27. props: {
  28. form: { type: Object, default: () => ({}) },
  29. fields: { type: Array, default: () => [] },
  30. },
  31. model: {
  32. prop: 'form',
  33. event: 'change',
  34. },
  35. data: function () {
  36. return {};
  37. },
  38. methods: {
  39. toSearch() {
  40. this.$emit('query');
  41. },
  42. toReset() {
  43. this.form = {};
  44. this.$emit(query);
  45. },
  46. },
  47. };
  48. </script>
  49. <style lang="less" scoped></style>