CustomSearch.vue 3.6 KB

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