<template>
|
<div class="app-table-search">
|
<div class="header">
|
<div class="collapse" @click="isWrapperCollapse = !isWrapperCollapse">
|
<div class="title">{{ $t('components.table.TableSearch.title') }}</div>
|
<el-icon class="icon">
|
<Plus v-if="!isWrapperCollapse"/>
|
<Minus v-if="isWrapperCollapse"/>
|
</el-icon>
|
</div>
|
<col-setting v-bind="colSettingProps"/>
|
</div>
|
<div
|
class="content"
|
:style="`height:${isWrapperCollapse ? `${85 + (isCollapse ? (styleHeight-45) : 0)}px` : '0px'}`"
|
>
|
<div class="form"
|
>
|
<div class="input" :style="`height:${isCollapse ? `${styleHeight}px` : '45px'}`">
|
<app-form-fields
|
v-bind="formFieldsProps"
|
>
|
<template v-for="slot in Object.keys($slots)" #[slot]="scope">
|
<slot :name="slot" v-bind="scope"/>
|
</template>
|
</app-form-fields>
|
</div>
|
<div class="footer">
|
<el-button @click="onReset()" icon="RefreshRight">{{ $t('components.table.TableSearch.reset') }}</el-button>
|
<el-button type="primary" @click="onSubmit()" icon="Search">
|
{{ $t('components.table.TableSearch.search') }}
|
</el-button>
|
<div class="collapse" v-show="styleHeight > 45">
|
<el-button type="primary" link @click="isCollapse = !isCollapse">
|
{{ isCollapse ? $t('components.table.TableSearch.retract') : $t('components.table.TableSearch.expand') }}
|
<el-icon class="el-icon--right" :style="`transform:rotate(${isCollapse ? '180deg' : 0})`">
|
<ArrowDownBold/>
|
</el-icon>
|
</el-button>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
|
import ColSetting from "./ColSetting";
|
import * as tools from '@/utils/tools.js';
|
|
import {context} from '@/hooks';
|
|
const {useForceUpdate} = context;
|
|
const formFieldsRef = ref();
|
const colSettingRef = ref();
|
const isCollapse = ref(false);
|
const isWrapperCollapse = ref(true);
|
|
const props = defineProps({
|
formFields: {
|
type: Array,
|
default: []
|
},
|
subSubmit: {
|
type: Function,
|
default: () => {
|
}
|
},
|
});
|
|
const useFields = ref([]);
|
|
const [$props, forceUpdate] = useForceUpdate(props);
|
|
const $forceUpdate = async (force) => {
|
forceUpdate(force);
|
await onInit();
|
}
|
|
const onInit = async () => {
|
|
if (JSON.stringify(useFields.value) !== JSON.stringify($props.formFields)) {
|
useFields.value = $props.formFields.map(e => {
|
e.group = '';
|
e.isShow = true;
|
e.id = tools.uuid();
|
e.item.rules = [];
|
e.col.span = 8;
|
return e;
|
});
|
}
|
formFieldsProps.fields = useFields.value;
|
formFieldsRef.value.$forceUpdate(formFieldsProps);
|
|
colSettingProps.fields = [...useFields.value];
|
colSettingRef.value.$forceUpdate(colSettingProps);
|
|
styleHeight.value = getStyleHeight(formFieldsProps.fields);
|
}
|
|
const formFieldsProps = {
|
ref: formFieldsRef,
|
fields: []
|
}
|
|
const getStyleHeight = (list) => Math.ceil(list.filter(e => e.isShow).reduce((a, b) => a + b.col.span, 0) / 24) * 45
|
|
const colSettingProps = {
|
ref: colSettingRef,
|
fields: [],
|
async subFields(list) {
|
useFields.value = list;
|
formFieldsProps.fields = useFields.value.filter(e => e.isShow);
|
formFieldsRef.value.$forceUpdate(formFieldsProps);
|
styleHeight.value = getStyleHeight(formFieldsProps.fields);
|
}
|
};
|
|
const styleHeight = ref(0);
|
|
const onReset = () => {
|
formFieldsRef.value.onReset();
|
}
|
|
const onSubmit = async () => {
|
const data = await formFieldsRef.value.onValidate();
|
props.subSubmit(data);
|
}
|
|
onMounted(() => {
|
onInit();
|
})
|
|
|
defineExpose({
|
formFields: formFieldsRef,
|
$forceUpdate
|
});
|
|
</script>
|
|
<style lang="scss">
|
.app-table-search {
|
|
.el-form-item {
|
margin-bottom: 0;
|
margin-top: 5px;
|
}
|
}
|
</style>
|
|
<style scoped lang="scss">
|
.app-table-search {
|
padding: 10px;
|
background: #fff;
|
border-radius: 5px;
|
border: 1px solid var(--el-border-color-light);
|
|
.el-form-item {
|
margin-bottom: 0;
|
}
|
|
.header {
|
display: flex;
|
align-items: center;
|
|
.collapse {
|
margin-right: 10px;
|
cursor: pointer;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
flex: 1;
|
overflow: hidden;
|
|
.title {
|
font-size: 14px;
|
color: var(--el-text-color-primary);
|
font-weight: 600;
|
}
|
|
.icon {
|
padding: 0.5px;
|
box-sizing: border-box;
|
border: 1px solid var(--el-color-info-light-3);
|
}
|
}
|
}
|
|
.content {
|
overflow: hidden;
|
transition: height 0.28s;
|
|
.form {
|
.footer {
|
display: flex;
|
justify-content: flex-end;
|
margin-top: 10px;
|
}
|
|
.input {
|
overflow: hidden;
|
transition: height 0.28s;
|
}
|
|
.collapse {
|
display: flex;
|
align-items: center;
|
margin-left: 10px;
|
}
|
}
|
}
|
}
|
</style>
|