| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <!-- 需要配合 page_search search_content content_left 一起使用 -->
-
- <template>
- <div class="simple_filter">
- <template v-for="item in props.searchList" :key="item.key">
- <el-select
- v-if="item.type == 'select' && !item.hidden"
- v-model="searchData[item.key]"
- @change="(val)=>HandleSearchItemChange(item.key)"
- :placeholder="item.placeholder"
- :disabled="formDisabled || item.disabled"
- >
- <el-option
- v-for="optItm in item.options"
- :key="optItm.value" :value="optItm.value"
- :label="optItm.label"
- :disabled="optItm.disabled ? true : false">
- </el-option>
- </el-select>
- <!-- :size="size" -->
- <el-date-picker
- @change="(val)=>HandleSearchItemChange(item.key)"
- v-else-if="item.type == 'datePicker'"
- v-model="searchData[item.key]"
- :disabeld="formDisabled || item.disabled"
- type="daterange"
- range-separator="-"
- start-placeholder="开始时间"
- end-placeholder="结束时间"
- />
- <!-- 这个输入框的搜索要动态查询 ———— -->
- <el-input
- v-else-if="item.type == 'input'"
- v-model="searchData[item.key]"
- @input="(val,e)=>HandleInputChange(val,e,item.key)"
- @keyup.enter="(event)=>HandleSearchItemChange(item.key)"
- :placeholder="item.placeholder"
- :disabled="formDisabled || item.disabled"
- >
- <template #append>
- <el-button @click="HandleSearchItemChange(item.key)" :icon="Search" />
- </template>
- </el-input>
- <el-radio-group
- v-else-if="item.type == 'radio'"
- v-model="searchData[item.key]"
- @change="()=>HandleSearchItemChange(item.key)"
- :disabled="formDisabled || item.disabled"
- >
- <el-radio v-for="radioItem in item.options" :key="radioItem.value" :value="radioItem.value">{{ radioItem.label }}</el-radio>
- </el-radio-group>
- </template>
- </div>
- </template>
- <script setup lang="ts">
- import { Search } from '@element-plus/icons-vue'
- import { ref, watch } from 'vue'
- interface SearchItem {
- key:String,
- type:'input'|'select'|'datePicker'|'radio',
- placeholder?:String,
- hidden:boolean,
- defaultValue?:any,
- disabled?:Boolean
- options?:{
- label:String,
- value:String,
- disabled?:Boolean
- }[]
- }
- const props = defineProps({
- searchList:{
- type:Array<SearchItem>,
- required:true
- },
- formDisabled:{
- type:Boolean,
- required:false
- }
- })
- const emit = defineEmits(['searchChange'])
- const searchData = ref({})
- // 筛选条件变更触发新的查询
- const HandleSearchItemChange = async (key)=>{
- // 触发父级页面的查询
- emit('searchChange',searchData.value,key)
- }
- const inputFlag = ref()
- const HandleInputChange = (val,e,key)=>{
- if(inputFlag.value){
- // 还在定时器内,延迟触发
- clearTimeout(inputFlag.value)
- inputFlag.value = ''
- }
- // 要防抖
- inputFlag.value = setTimeout(()=>{
- console.log('input__输入的值',val)
- // 触发父级页面的查询
- emit('searchChange',searchData.value,key)
- },400)
- }
- //
- watch(()=>props.searchList, (newVal)=>{
- searchData.value = {}
- // console.log('查询项变更了===表单',newVal)
- newVal.forEach(item=>{
- if(item.defaultValue){
- searchData.value[item.key] = item.defaultValue
- }
- })
- // emit('searchChange',searchData.value)
- },{immediate:true,deep:true})
- </script>
- <style lang="scss" scoped>
- .simple_filter {
- display: flex;
- flex-wrap: wrap;
- gap: 10px;
- :deep(.el-date-editor){
- max-width: 240px;
- }
-
- :deep(.el-input){
- width: 260px;
- }
- :deep(.el-radio-group){
- .el-radio{
- margin-right: 20px;
- }
- }
- }
- .page_search .search_content .content_right{
- .el-button {
- margin-left: -20px !important;
- min-width: auto !important;
- }
- }
-
- </style>
|