|
@@ -1,27 +1,34 @@
|
|
|
<template>
|
|
|
- <div ref="search">
|
|
|
+ <div class="search">
|
|
|
<!-- 动态渲染表单项 -->
|
|
|
- <a-form :model="formState" layout="inline">
|
|
|
- <a-form-item v-for="(item, index) in SearchForm" :key="index" :label="item.label" :field="item.field">
|
|
|
- <component :is="'a-' + item.type" v-model="formState[item.field].value" :placeholder="item.placeholder"
|
|
|
- allow-clear :style="{ width: item.width ? item.width + 'px' : '' }">
|
|
|
- <template v-if="item.type == 'select'">
|
|
|
- <a-option v-for="option in item.options" :key="option.value" :value="option.value">
|
|
|
- {{ option.label }}
|
|
|
- </a-option>
|
|
|
- </template>
|
|
|
- </component>
|
|
|
- </a-form-item>
|
|
|
- <a-form-item>
|
|
|
- <a-button type="primary" @click="handleQuery">查询</a-button>
|
|
|
- <a-button @click="handleReset" style="margin-left: 10px;">重置</a-button>
|
|
|
- </a-form-item>
|
|
|
- </a-form>
|
|
|
+ <div class="Form">
|
|
|
+ <a-form :model="formState" layout="inline">
|
|
|
+ <a-form-item v-for="(item, index) in showIcon ? data : InitialData" :key="index" :label="item.label"
|
|
|
+ :field="item.field" :wrapper-col-style="{ marginBottom: '20px' }">
|
|
|
+ <component :is="'a-' + item.type" v-model="formState[item.field]" item.Custom
|
|
|
+ :placeholder="item.type == 'input' ? '请输入' : '请选择' + item.label" allow-clear
|
|
|
+ :style="{ width: item.width ? item.width + 'px' : '' }">
|
|
|
+ <template v-if="item.type == 'select'">
|
|
|
+ <a-option v-for="option in item.options" :key="option.value" :value="option.value">
|
|
|
+ {{ option.label }}
|
|
|
+ </a-option>
|
|
|
+ </template>
|
|
|
+ </component>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item>
|
|
|
+ <a-button type="primary" @click="handleQuery">查询</a-button>
|
|
|
+ <a-button @click="handleReset" style="margin-left: 10px;">重置</a-button>
|
|
|
+ <div v-if="show" @click="showIcon = !showIcon" class="icon">
|
|
|
+ {{ showIcon ? '折叠' : '展开' }} <icon-down :rotate="showIcon ? 180 : 0" />
|
|
|
+ </div>
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, defineProps, toRefs, onMounted, watch, watchEffect } from 'vue';
|
|
|
+import { ref, defineProps, toRefs, watch, defineEmits } from 'vue';
|
|
|
import { Getdictionary } from "@/mixins/index.js";
|
|
|
|
|
|
// 接收 props
|
|
@@ -33,24 +40,21 @@ const props = defineProps({
|
|
|
type: 'input',
|
|
|
label: '字典名称',
|
|
|
field: 'source',
|
|
|
- placeholder: '请输入字典名称',
|
|
|
- value: '', // 双向绑定的值
|
|
|
+ value: '',
|
|
|
},
|
|
|
{
|
|
|
type: 'input',
|
|
|
label: '资费ID',
|
|
|
field: 'trafficId',
|
|
|
- placeholder: '请输入资费ID',
|
|
|
- value: '', // 双向绑定的值
|
|
|
+ value: '',
|
|
|
},
|
|
|
{
|
|
|
type: 'select',
|
|
|
label: '卡类型',
|
|
|
field: 'simType',
|
|
|
- placeholder: '选择卡类型',
|
|
|
- options: [], // 默认空,后面会通过字典加载
|
|
|
- dict:'CardType',
|
|
|
- value: '', // 双向绑定的值
|
|
|
+ options: [],
|
|
|
+ dict: 'CardType',
|
|
|
+ value: '',
|
|
|
width: '200'
|
|
|
},
|
|
|
],
|
|
@@ -59,40 +63,98 @@ const props = defineProps({
|
|
|
|
|
|
const { SearchForm } = toRefs(props);
|
|
|
|
|
|
+// 用于存储原始SearchForm数据的副本
|
|
|
+const originalSearchForm = ref([]);
|
|
|
+// 分割完成的数据
|
|
|
+const InitialData = ref([]);
|
|
|
+const show = ref(false);
|
|
|
+const showIcon = ref(false);
|
|
|
const formState = ref({});
|
|
|
+const data = ref([]);
|
|
|
+
|
|
|
+const emit = defineEmits(['query']);
|
|
|
+
|
|
|
+// 在组件创建时,拷贝原始SearchForm数据
|
|
|
+watch(() => props.SearchForm, () => {
|
|
|
+ originalSearchForm.value = JSON.parse(JSON.stringify(props.SearchForm));
|
|
|
+}, { immediate: true });
|
|
|
+
|
|
|
SearchForm.value.forEach(item => {
|
|
|
- formState.value[item.field] = {
|
|
|
- value: item.value,
|
|
|
- };
|
|
|
+ formState.value[item.field] = item.value;
|
|
|
});
|
|
|
|
|
|
// 字典加载
|
|
|
-const loadedDicts = ref({});
|
|
|
+const loadedDicts = ref({});
|
|
|
const loadDictOptions = async (index, dict) => {
|
|
|
if (loadedDicts.value[dict]) {
|
|
|
SearchForm.value[index].options = loadedDicts.value[dict];
|
|
|
return;
|
|
|
}
|
|
|
const dictionary = await Getdictionary(dict);
|
|
|
- loadedDicts.value[dict] = dictionary || [];
|
|
|
- SearchForm.value[index].options = loadedDicts.value[dict];
|
|
|
+ loadedDicts.value[dict] = dictionary || [];
|
|
|
+ SearchForm.value[index].options = loadedDicts.value[dict];
|
|
|
};
|
|
|
|
|
|
watch(
|
|
|
- () => SearchForm.value,
|
|
|
- async () => {
|
|
|
- for (let index = 0; index < SearchForm.value.length; index++) {
|
|
|
- const item = SearchForm.value[index];
|
|
|
- if (item.dict && !loadedDicts.value[item.dict]) {
|
|
|
- await loadDictOptions(index, item.dict);
|
|
|
+ () => SearchForm.value,
|
|
|
+ async () => {
|
|
|
+ for (let index = 0; index < SearchForm.value.length; index++) {
|
|
|
+ const item = SearchForm.value[index];
|
|
|
+ if (item.dict && !loadedDicts.value[item.dict]) {
|
|
|
+ await loadDictOptions(index, item.dict);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-}, { immediate: true });
|
|
|
+ // 如果当前长度超过5条就需要折叠展开
|
|
|
+ if (SearchForm.value.length >= 6) {
|
|
|
+ show.value = true;
|
|
|
+ }
|
|
|
+ // 初始化切割数组,使用原始SearchForm数据的副本进行操作
|
|
|
+ InitialData.value = originalSearchForm.value.splice(0, 6);
|
|
|
+ data.value = [...InitialData.value, ...originalSearchForm.value];
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+);
|
|
|
|
|
|
// 查询操作
|
|
|
const handleQuery = () => {
|
|
|
- // 将表单数据通过事件传递给父组件
|
|
|
emit('query', formState.value);
|
|
|
};
|
|
|
|
|
|
-</script>
|
|
|
+const handleReset = () => {
|
|
|
+ const newFormState = {};
|
|
|
+ SearchForm.value.forEach(item => {
|
|
|
+ if (typeof item.value === 'string') {
|
|
|
+ newFormState[item.field] = '';
|
|
|
+ } else if (Array.isArray(item.value)) {
|
|
|
+ newFormState[item.field] = [];
|
|
|
+ } else if (typeof item.value === 'object') {
|
|
|
+ newFormState[item.field] = {};
|
|
|
+ }
|
|
|
+ });
|
|
|
+ formState.value = newFormState;
|
|
|
+ emit('reset', formState.value);
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.search {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+}
|
|
|
+
|
|
|
+.Form {
|
|
|
+ width: 95%;
|
|
|
+}
|
|
|
+
|
|
|
+.icon {
|
|
|
+ display: flex;
|
|
|
+ // align-items: center;
|
|
|
+ color: #3491fa;
|
|
|
+ font-size: 15px;
|
|
|
+ cursor: pointer;
|
|
|
+ font-weight: 600;
|
|
|
+ margin-left: 15px;
|
|
|
+}
|
|
|
+</style>
|