form.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2021-11-01 18:03:02
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-01-10 19:27:43
  6. * @FilePath : \spfm-market-front\src\pages\main\performance\components\form.vue
  7. -->
  8. <template>
  9. <el-form :inline="true" :model="object">
  10. <el-row :gutter="24">
  11. <el-col
  12. v-for="({ props, label, type, dictionary }, index) in form"
  13. :key="index"
  14. :span="6"
  15. >
  16. <el-form-item :label="label">
  17. <template v-if="type === 'select'">
  18. <el-select
  19. v-model="object[props]"
  20. :placeholder="label"
  21. filterable
  22. clearable
  23. >
  24. <el-option
  25. :label="label"
  26. :value="value"
  27. v-for="({ label, value }, index) in dictionary"
  28. :key="index"
  29. ></el-option>
  30. </el-select>
  31. </template>
  32. <template v-else-if="['datetime', 'date', 'month'].includes(type)">
  33. <el-date-picker
  34. v-model="object[props]"
  35. :type="type"
  36. format="yyyy-MM-dd"
  37. value-format="yyyy-MM-dd"
  38. :placeholder="label"
  39. >
  40. </el-date-picker>
  41. </template>
  42. <template v-else>
  43. <el-input
  44. v-model="object[props]"
  45. :placeholder="label"
  46. clearable
  47. ></el-input>
  48. </template>
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="6">
  52. <el-form-item>
  53. <el-button type="primary" @click="handleSearch">搜索</el-button>
  54. <el-button @click="handleSearch(2)" v-if="reset == true">重置</el-button>
  55. </el-form-item>
  56. </el-col>
  57. <el-col class="flex-justify-align-end" :span="24">
  58. <el-button
  59. v-for="({ label, props, unlogo }, index) in handle"
  60. :key="index"
  61. @click="handleSubmit(props)"
  62. >
  63. <i v-if="!unlogo" class="el-icon-document-add font-weight-bold" />{{
  64. label
  65. }}
  66. </el-button>
  67. </el-col>
  68. </el-row>
  69. </el-form>
  70. </template>
  71. <script>
  72. export default {
  73. props: {
  74. reset:{
  75. type:Boolean,
  76. default: () => [],
  77. },
  78. form: {
  79. type: Array,
  80. default: () => [],
  81. },
  82. handle: {
  83. type: Array,
  84. default: () => [],
  85. },
  86. },
  87. data: () => ({
  88. object: {},
  89. }),
  90. methods: {
  91. handleSearch(e) {
  92. if (e === 2) {
  93. this.object = [];
  94. } else {
  95. this.$emit("search", this.object);
  96. }
  97. },
  98. handleSubmit(params) {
  99. this.$emit(params, this.object);
  100. },
  101. },
  102. };
  103. </script>