form.vue 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2021-11-01 18:03:02
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-01-07 19:16:35
  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. :placeholder="label"
  37. >
  38. </el-date-picker>
  39. </template>
  40. <template v-else>
  41. <el-input
  42. v-model="object[props]"
  43. :placeholder="label"
  44. clearable
  45. ></el-input>
  46. </template>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="6">
  50. <el-form-item>
  51. <el-button type="primary" @click="handleSearch"
  52. >搜索</el-button
  53. >
  54. </el-form-item>
  55. </el-col>
  56. <el-col class="flex-justify-align-end" :span="24">
  57. <el-button
  58. v-for="({ label, props }, index) in handle"
  59. :key="index"
  60. @click="handleSubmit(props)"
  61. >
  62. <i class="el-icon-document-add font-weight-bold" />{{
  63. label
  64. }}
  65. </el-button>
  66. </el-col>
  67. </el-row>
  68. </el-form>
  69. </template>
  70. <script>
  71. export default {
  72. props: {
  73. form: {
  74. type: Array,
  75. default: () => [],
  76. },
  77. handle: {
  78. type: Array,
  79. default: () => [],
  80. },
  81. },
  82. data: () => ({
  83. object: {},
  84. }),
  85. methods: {
  86. handleSearch() {
  87. this.$emit("search", this.object);
  88. },
  89. handleSubmit(params) {
  90. this.$emit(params, this.object);
  91. },
  92. },
  93. };
  94. </script>