Files
laws-sinotruk-client/src/components/customField/Search.vue
T
2023-09-11 11:52:23 +08:00

286 lines
12 KiB
Vue

<template>
<a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col :md="(24 / (minLength + 1))" :sm="(24 / minLength)" v-for="(item,index) in searchList.slice(0, minLength)" :key="index" style="line-height: 48px">
<!-- 树形选择器 -->
<!-- <template v-if="item.fieldShowType === FieldType.TREE.value">-->
<!-- <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!-- <a-tree-select-->
<!-- tree-node-filter-prop="title"-->
<!-- v-model="queryParam[item.dbFieldName]"-->
<!-- :maxTagCount="1"-->
<!-- :getPopupContainer="triggerNode=> triggerNode.parentNode"-->
<!-- :tree-data="item.tree"-->
<!-- tree-checkable-->
<!-- :placeholder="$t('pleaseSelect')+item.dbFieldTxt"-->
<!-- />-->
<!-- </a-form-item>-->
<!-- </template>-->
<!-- 输入框 -->
<template
v-if="[FieldType.TEXT_BOX.value, FieldType.TEXTAREA.value,FieldType.USER_SINGLE.value,
FieldType.ORGAN_SINGLE.value, FieldType.STANDARD_MORE.value, FieldType.ORGAN_MORE.value]
.includes(item.fieldShowType)">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input :placeholder="$t('pleaseEnter')+item.dbFieldTxt"
v-model="queryParam[item.dbFieldName]"></a-input>
</a-form-item>
</template>
<!-- 数字输入框 -->
<!-- <template v-else-if="item.fieldShowType === FieldType.TEXT_NUMBER.value">-->
<!-- <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!-- <a-input-number :placeholder="$t('pleaseEnter')+item.dbFieldTxt"-->
<!-- v-model="queryParam[item.dbFieldName]" :min="1" :max="99999999"/>-->
<!-- </a-form-item>-->
<!-- </template>-->
<!-- 字典多选框 -->
<!-- <template v-else-if="item.fieldShowType === FieldType.OPTION_SINGLE.value">-->
<!-- <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!-- <j-multi-select-tag v-model="queryParam[item.dbFieldName]"-->
<!-- :placeholder="$t('pleaseSelect')+item.dbFieldTxt" :type="'select'"-->
<!-- :triggerChange="false" :dictCode="item.dict_field"/>-->
<!-- </a-form-item>-->
<!-- </template>-->
<!-- 日期区间 -->
<template v-else-if="[FieldType.DATE_SINGLE.value, FieldType.DATE_MORE.value].includes(item.fieldShowType)">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-range-picker v-model="queryParam[item.dbFieldName]"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
format="YYYY-MM-DD" value-format="YYYY-MM-DD"
@change="onChange(item.dbFieldName)"></a-range-picker>
</a-form-item>
</template>
<!-- 字典单选框 -->
<template v-else-if="item.fieldShowType === FieldType.OPTION_SINGLE.value || item.fieldShowType === FieldType.OPTION_MORE.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-dict-select-tag v-model="queryParam[item.dbFieldName]"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
:type="'select'"
:triggerChange="false" :dictCode="item.dict_field"/>
</a-form-item>
</template>
</a-col>
<template v-if="searchList.length > minLength && toggleSearchStatus">
<a-col :md="(24 / (minLength + 1))" :sm="(24 / minLength)" v-for="(item,index) in searchList.slice(minLength)" :key="index" style="line-height: 48px">
<!-- 树形选择器 -->
<template v-if="item.fieldShowType === FieldType.TREE.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-tree-select
tree-node-filter-prop="title"
v-model="queryParam[item.dbFieldName]"
:maxTagCount="1"
:getPopupContainer="triggerNode=> triggerNode.parentNode"
:tree-data="item.tree"
tree-checkable
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
/>
</a-form-item>
</template>
<!-- 输入框 -->
<template v-if="[FieldType.TEXT_BOX.value, FieldType.TEXTAREA.value,FieldType.USER_SINGLE.value,
FieldType.ORGAN_SINGLE.value, FieldType.STANDARD_MORE.value, FieldType.ORGAN_MORE.value]
.includes(item.fieldShowType)">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input :placeholder="$t('pleaseEnter')+item.dbFieldTxt"
v-model="queryParam[item.dbFieldName]"></a-input>
</a-form-item>
</template>
<!-- 日期区间选择器 -->
<template v-else-if="[FieldType.DATE_SINGLE.value, FieldType.DATE_MORE.value].includes(item.fieldShowType)">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-range-picker v-model="queryParam[item.dbFieldName]"
format="YYYY-MM-DD" value-format="YYYY-MM-DD"
@change="onChange(item.dbFieldName)"></a-range-picker>
</a-form-item>
</template>
<!-- 字典选择器 -->
<template v-else-if="item.fieldShowType === FieldType.OPTION_SINGLE.value || item.fieldShowType === FieldType.OPTION_MORE.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-dict-select-tag v-model="queryParam[item.dbFieldName]"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
:type="'select'"
:triggerChange="false" :dictCode="item.dict_field" />
</a-form-item>
</template>
</a-col>
</template>
<div style="float: right;overflow: hidden;margin-right: 11px" class="table-page-search-submitButtons">
<a @click="handleToggleSearch" v-if="searchList.length > minLength">
{{ !toggleSearchStatus ? $t('open') : $t('putAway') }}
<a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
</a>
<a-button type="primary" @click="searchQuery" style="margin-left: 8px">{{$t('query')}}</a-button>
<a-button style="margin-left: 8px" @click="searchReset">{{$t('reset')}}</a-button>
</div>
</a-row>
</a-form>
</template>
<script>
import JDictSelectTag from '../dict/JDictSelectTag'
import { FieldType } from '../../enums/commonEnums'
import eventBus from '@/common/event'
export default {
name: 'Search',
components: { JDictSelectTag },
props: {
// 获取查询条件的方法
getQueryConditionFunc: {
type: Function,
required: false,
default: () => {
return function () {
}
}
},
flag: { // 暂时不清楚flag的用处,是要查searchList的时候传给后端的
type: String,
default: ''
},
minLength: {
type: Number,
default: 3
}
// searchQueryList: {
// type: Array,
// default: () => {
// return []
// }
// }
},
data () {
return {
FieldType,
queryParam: {},
toggleSearchStatus: false,
searchList: [],
labelCol: {
span: 6
},
wrapperCol: {
span: 14
}
}
},
mounted () {
this.getSearch()
// this.searchList = [
// {
// dbFieldName: 'serial_number',
// dbFieldTxt: '编号',
// dict_field: '',
// fieldShowType: '1',
// tree: []
// },
// {
// dbFieldName: 'title',
// dbFieldTxt: '标题',
// dict_field: '',
// fieldShowType: '1',
// tree: []
// },
// {
// dbFieldName: 'state',
// dbFieldTxt: '状态',
// dict_field: 'state',
// fieldShowType: '3',
// tree: []
// },
// {
// dbFieldName: 'region',
// dbFieldTxt: '适用地区',
// dict_field: 'region',
// fieldShowType: '4',
// tree: []
// },
// {
// dbFieldName: 'technology_territory',
// dbFieldTxt: '技术领域',
// dict_field: 'technology_territory',
// fieldShowType: '0',
// tree: []
// },
// {
// dbFieldName: 'issue_time',
// dbFieldTxt: '发布日期',
// dict_field: '',
// fieldShowType: '5',
// tree: []
// },
// {
// dbFieldName: 'xin1_che1_xing2_shi2_shi1_ri4_qi1',
// dbFieldTxt: '新车型实施日期',
// dict_field: '',
// fieldShowType: '5',
// tree: []
// },
// {
// dbFieldName: 'implement_time',
// dbFieldTxt: '在产车实施日期',
// dict_field: '',
// fieldShowType: '5',
// tree: []
// }
// ]
},
methods: {
searchQuery () {
this.$emit('search', JSON.parse(JSON.stringify(this.queryParam)))
eventBus.$emit('searchQuery', JSON.parse(JSON.stringify(this.queryParam)))
},
searchReset () {
this.queryParam = {}
this.$emit('reset', JSON.parse(JSON.stringify(this.queryParam)))
eventBus.$emit('searchQuery', JSON.parse(JSON.stringify(this.queryParam)))
},
// 获取查询条件列表
getSearch () {
console.log(this.getQueryConditionFunc)
if (!this.getQueryConditionFunc || typeof this.getQueryConditionFunc !== 'function') {
return
}
const params = {
module: this.flag
}
this.getQueryConditionFunc(params).then((res) => {
if (res.success) {
this.searchList = res.result
// if (this.searchQueryList && this.searchQueryList.length > 0) {
// for (let i = 0; i < this.searchList.length; i++) {
// // 是要去掉这个字段的搜索??
// if (this.searchList[i].db_field_name === 'issue_time') {
// this.searchList.splice(i, 1)
// i--
// }
// // db_field_name 说明可以被代替位置??
// if (this.searchList[i].db_field_name === 'title') {
// const data = this.searchList[i + 1]
// this.searchList[i + 1] = this.searchQueryList[0]
// this.searchList.push(data)
// }
// }
// }
}
})
},
onChange (item) {
if (this.queryParam[item] && this.queryParam[item].length > 0) {
const startDate = item + '_start'
const endDate = item + '_end'
this.queryParam[startDate] = this.queryParam[item][0]
this.queryParam[endDate] = this.queryParam[item][1]
} else {
this.queryParam[item] = []
}
},
handleToggleSearch () {
this.toggleSearchStatus = !this.toggleSearchStatus
}
}
}
</script>
<style scoped lang="less">
</style>