|
@@ -28,9 +28,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, defineProps, toRefs, watch, defineEmits } from 'vue';
|
|
|
-import { Getdictionary } from "@/mixins/index.js";
|
|
|
-
|
|
|
+import { ref, watch, defineProps, defineEmits, toRefs } from 'vue';
|
|
|
+import { Getdictionary } from '@/mixins/index.js'
|
|
|
// 接收 props
|
|
|
const props = defineProps({
|
|
|
SearchForm: {
|
|
@@ -40,21 +39,21 @@ const props = defineProps({
|
|
|
type: 'input',
|
|
|
label: '字典名称',
|
|
|
field: 'source',
|
|
|
- value: '', // 双向绑定的值
|
|
|
+ value: '',
|
|
|
},
|
|
|
{
|
|
|
type: 'input',
|
|
|
label: '资费ID',
|
|
|
field: 'trafficId',
|
|
|
- value: '', // 双向绑定的值
|
|
|
+ value: '',
|
|
|
},
|
|
|
{
|
|
|
type: 'select',
|
|
|
label: '卡类型',
|
|
|
field: 'simType',
|
|
|
- options: [], // 默认空,后面会通过字典加载
|
|
|
+ options: [],
|
|
|
dict: 'CardType',
|
|
|
- value: '', // 双向绑定的值
|
|
|
+ value: '',
|
|
|
width: '200'
|
|
|
},
|
|
|
],
|
|
@@ -63,18 +62,18 @@ const props = defineProps({
|
|
|
|
|
|
const { SearchForm } = toRefs(props);
|
|
|
|
|
|
+// 保存原始的SearchForm副本
|
|
|
+const originalSearchForm = ref([]);
|
|
|
+
|
|
|
// 分割完成的数据
|
|
|
-const InitialData = ref()
|
|
|
-const show = ref(false)
|
|
|
-const showIcon = ref(false)
|
|
|
+const InitialData = ref();
|
|
|
+const show = ref(false);
|
|
|
+const showIcon = ref(false);
|
|
|
const formState = ref({});
|
|
|
|
|
|
-const data = ref()
|
|
|
+const data = ref();
|
|
|
|
|
|
-const emit = defineEmits(['query'])
|
|
|
-SearchForm.value.forEach(item => {
|
|
|
- formState.value[item.field] = item.value;
|
|
|
-});
|
|
|
+const emit = defineEmits(['query', 'reset']);
|
|
|
|
|
|
// 字典加载
|
|
|
const loadedDicts = ref({});
|
|
@@ -88,29 +87,32 @@ const loadDictOptions = async (index, dict) => {
|
|
|
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);
|
|
|
- }
|
|
|
- }
|
|
|
- // 如果当前长度超过5条就需要折叠展开
|
|
|
- if (SearchForm.value.length >= 6) {
|
|
|
- show.value = true;
|
|
|
+// 在watch首次执行或者组件挂载完成时保存原始副本
|
|
|
+watch(() => SearchForm.value, () => {
|
|
|
+ if (originalSearchForm.value.length === 0) {
|
|
|
+ originalSearchForm.value = [...SearchForm.value];
|
|
|
+ }
|
|
|
+ for (let index = 0; index < SearchForm.value.length; index++) {
|
|
|
+ const item = SearchForm.value[index];
|
|
|
+ if (item.dict && !loadedDicts.value[item.dict]) {
|
|
|
+ loadDictOptions(index, item.dict);
|
|
|
}
|
|
|
- // 初始化切割数组
|
|
|
- InitialData.value = SearchForm.value.splice(0, 6)
|
|
|
- data.value = [...InitialData.value, ...SearchForm.value]
|
|
|
- }, { immediate: true });
|
|
|
+ }
|
|
|
+ // 如果当前长度超过5条就需要折叠展开
|
|
|
+ if (originalSearchForm.value.length >= 6) {
|
|
|
+ show.value = true;
|
|
|
+ }
|
|
|
+ // 基于原始副本进行数组分割操作
|
|
|
+ InitialData.value = originalSearchForm.value.splice(0, 6);
|
|
|
+ data.value = [...InitialData.value, ...originalSearchForm.value];
|
|
|
+}, { immediate: true, deep: true });
|
|
|
|
|
|
// 查询操作
|
|
|
const handleQuery = () => {
|
|
|
emit('query', formState.value);
|
|
|
};
|
|
|
|
|
|
+// 重置操作,正确更新formState并触发reset事件
|
|
|
const handleReset = () => {
|
|
|
const newFormState = {};
|
|
|
SearchForm.value.forEach(item => {
|
|
@@ -124,7 +126,9 @@ const handleReset = () => {
|
|
|
});
|
|
|
formState.value = newFormState;
|
|
|
emit('reset', formState.value);
|
|
|
-}
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
|
|
|
</script>
|
|
|
|