CustomSearch.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="search-container">
  3. <el-row :gutter="10" type="flex" class="search-items" justify="end">
  4. <el-col v-for="(item, index) in propCfg" :key="index" :span="6">
  5. <el-select
  6. v-if="item.type === $GCFG.typeSel"
  7. :key="index"
  8. v-model="searchForm[item.prop]"
  9. style="width: 100%"
  10. :placeholder="getPropPH(item, businessKey, 'search')"
  11. :size="$GCFG.size"
  12. clearable
  13. @change="selectChg($event, item)"
  14. >
  15. <el-option
  16. v-for="selItem in dictMap[item.prop]"
  17. :key="selItem[item.dict.props.value]"
  18. :label="selItem[item.dict.props.label]"
  19. :value="selItem[item.dict.props.value]"
  20. />
  21. </el-select>
  22. <el-date-picker
  23. v-if="item.type === $GCFG.typeDateTime"
  24. :key="index"
  25. v-model="searchForm[item.prop]"
  26. :placeholder="getPropPH(item, businessKey, 'search')"
  27. :size="$GCFG.size"
  28. type="datetime"
  29. format="yyyy-MM-dd HH:mm:ss"
  30. value-format="yyyy-MM-dd HH:mm:ss"
  31. />
  32. <el-input
  33. v-if="item.type === $GCFG.typeOrg"
  34. ref="deptName"
  35. :key="index"
  36. v-model="searchForm[$GCFG.getOrgObjKeyFlag(item.prop)].name"
  37. :placeholder="getPropPH(item, businessKey, 'search')"
  38. :size="$GCFG.size"
  39. suffix-icon="el-icon-search"
  40. @click.native="showOfficeDialog(searchForm, item)"
  41. />
  42. <el-input
  43. v-if="item.type === $GCFG.typeInput"
  44. :key="index"
  45. v-model="searchForm[item.prop]"
  46. :placeholder="getPropPH(item, businessKey, 'search')"
  47. :size="$GCFG.size"
  48. />
  49. </el-col>
  50. </el-row>
  51. <div class="btn-container">
  52. <el-button
  53. :size="$GCFG.size"
  54. type="primary"
  55. icon="el-icon-search"
  56. @click="search()"
  57. >{{ $GPROP.searchBtn }}</el-button>
  58. <el-button
  59. :size="$GCFG.size"
  60. icon="el-icon-refresh"
  61. @click="search('reset')"
  62. >{{ $GPROP.resetBtn }}</el-button>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import common from './mixins/common'
  68. import props from './mixins/props'
  69. import org from './mixins/org'
  70. import { initDicts } from './core/dictService'
  71. export default {
  72. name: 'CustomSearch',
  73. mixins: [common, props, org],
  74. data() {
  75. return {
  76. searchForm: {}
  77. }
  78. },
  79. created() {
  80. this.initSearchForm()
  81. },
  82. methods: {
  83. search(isReset) {
  84. this.$emit('search-change', isReset)
  85. },
  86. initSearchForm() {
  87. for (const item of this.propCfg) {
  88. if (item.type === this.$GCFG.typeOrg) {
  89. const keyFlag = this.$GCFG.getOrgObjKeyFlag(item.prop)
  90. this.$set(this.searchForm, item.prop, '')
  91. this.$set(this.searchForm, keyFlag, {})
  92. this.$set(this.searchForm[keyFlag], 'id', '')
  93. this.$set(this.searchForm[keyFlag], 'name', '')
  94. continue
  95. }
  96. this.$set(this.searchForm, item.prop, '')
  97. }
  98. },
  99. selectChg(id, item) {
  100. const that = this
  101. if (item.cascader && item.cascader.length > 0) {
  102. item.cascader.forEach((cascaderItem) => {
  103. that.searchForm[cascaderItem] = ''
  104. that.dictMap[cascaderItem] = []
  105. initDicts(item.cascaderObj[cascaderItem], id, false, (data) => {
  106. that.dictMap[cascaderItem] = data
  107. })
  108. })
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .search-container {
  116. display: flex;
  117. width: 100%; // 占满整个可用空间
  118. justify-content: space-between; // 从右边到左边布局
  119. .btn-container {
  120. padding-left: 10px;
  121. flex: 0 0 auto; // 仅占用本身所需要的最小空间
  122. }
  123. .search-items {
  124. flex: 1; // 占用剩余的所有空间
  125. }
  126. }
  127. </style>