FormSearchGroup.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!-- 需要配合 page_search search_content content_left 一起使用 -->
  2. <template>
  3. <div class="simple_filter">
  4. <template v-for="item in props.searchList" :key="item.key">
  5. <el-select
  6. v-if="item.type == 'select' && !item.hidden"
  7. v-model="searchData[item.key]"
  8. @change="(val)=>HandleSearchItemChange(item.key)"
  9. :placeholder="item.placeholder"
  10. :disabled="formDisabled || item.disabled"
  11. >
  12. <el-option
  13. v-for="optItm in item.options"
  14. :key="optItm.value" :value="optItm.value"
  15. :label="optItm.label"
  16. :disabled="optItm.disabled ? true : false">
  17. </el-option>
  18. </el-select>
  19. <!-- :size="size" -->
  20. <el-date-picker
  21. @change="(val)=>HandleSearchItemChange(item.key)"
  22. v-else-if="item.type == 'datePicker'"
  23. v-model="searchData[item.key]"
  24. :disabeld="formDisabled || item.disabled"
  25. type="daterange"
  26. range-separator="-"
  27. start-placeholder="开始时间"
  28. end-placeholder="结束时间"
  29. />
  30. <!-- 这个输入框的搜索要动态查询 ———— -->
  31. <el-input
  32. v-else-if="item.type == 'input'"
  33. v-model="searchData[item.key]"
  34. @input="(val,e)=>HandleInputChange(val,e,item.key)"
  35. @keyup.enter="(event)=>HandleSearchItemChange(item.key)"
  36. :placeholder="item.placeholder"
  37. :disabled="formDisabled || item.disabled"
  38. >
  39. <template #append>
  40. <el-button @click="HandleSearchItemChange(item.key)" :icon="Search" />
  41. </template>
  42. </el-input>
  43. <el-radio-group
  44. v-else-if="item.type == 'radio'"
  45. v-model="searchData[item.key]"
  46. @change="()=>HandleSearchItemChange(item.key)"
  47. :disabled="formDisabled || item.disabled"
  48. >
  49. <el-radio v-for="radioItem in item.options" :key="radioItem.value" :value="radioItem.value">{{ radioItem.label }}</el-radio>
  50. </el-radio-group>
  51. </template>
  52. </div>
  53. </template>
  54. <script setup lang="ts">
  55. import { Search } from '@element-plus/icons-vue'
  56. import { ref, watch } from 'vue'
  57. interface SearchItem {
  58. key:String,
  59. type:'input'|'select'|'datePicker'|'radio',
  60. placeholder?:String,
  61. hidden:boolean,
  62. defaultValue?:any,
  63. disabled?:Boolean
  64. options?:{
  65. label:String,
  66. value:String,
  67. disabled?:Boolean
  68. }[]
  69. }
  70. const props = defineProps({
  71. searchList:{
  72. type:Array<SearchItem>,
  73. required:true
  74. },
  75. formDisabled:{
  76. type:Boolean,
  77. required:false
  78. }
  79. })
  80. const emit = defineEmits(['searchChange'])
  81. const searchData = ref({})
  82. // 筛选条件变更触发新的查询
  83. const HandleSearchItemChange = async (key)=>{
  84. // 触发父级页面的查询
  85. emit('searchChange',searchData.value,key)
  86. }
  87. const inputFlag = ref()
  88. const HandleInputChange = (val,e,key)=>{
  89. if(inputFlag.value){
  90. // 还在定时器内,延迟触发
  91. clearTimeout(inputFlag.value)
  92. inputFlag.value = ''
  93. }
  94. // 要防抖
  95. inputFlag.value = setTimeout(()=>{
  96. console.log('input__输入的值',val)
  97. // 触发父级页面的查询
  98. emit('searchChange',searchData.value,key)
  99. },400)
  100. }
  101. //
  102. watch(()=>props.searchList, (newVal)=>{
  103. searchData.value = {}
  104. // console.log('查询项变更了===表单',newVal)
  105. newVal.forEach(item=>{
  106. if(item.defaultValue){
  107. searchData.value[item.key] = item.defaultValue
  108. }
  109. })
  110. // emit('searchChange',searchData.value)
  111. },{immediate:true,deep:true})
  112. </script>
  113. <style lang="scss" scoped>
  114. .simple_filter {
  115. display: flex;
  116. flex-wrap: wrap;
  117. gap: 10px;
  118. :deep(.el-date-editor){
  119. max-width: 240px;
  120. }
  121. :deep(.el-input){
  122. width: 260px;
  123. }
  124. :deep(.el-radio-group){
  125. .el-radio{
  126. margin-right: 20px;
  127. }
  128. }
  129. }
  130. .page_search .search_content .content_right{
  131. .el-button {
  132. margin-left: -20px !important;
  133. min-width: auto !important;
  134. }
  135. }
  136. </style>