Commit af845539 authored by 王玉鑫's avatar 王玉鑫

fix: 搜索条件,招商方向修正

parent d6333b27
import { useQueryList } from '@/composable/useQueryList.ts';
import { ref, type Ref, watchEffect, nextTick, type ShallowRef } from 'vue';
import { ref, type Ref, watchEffect, nextTick, type ShallowRef, computed } from 'vue';
import { RequestUrl } from '@/types/api.ts';
import type { CommonListResp, CommonListParams } from '@/types/common';
import type { RouteName } from '@/router/router.ts';
import { useRoute, onBeforeRouteLeave } from 'vue-router';
import { useSearchParamsStore } from '@/stores/searchParams.ts';
import { cloneDeep } from 'lodash-es';
import { cloneDeep, isEmpty } from 'lodash-es';
import { useRequest } from './useRequest.ts';
import { useJump } from './useJump.ts';
......@@ -13,7 +13,7 @@ type CurrentUrl = RequestUrl | ShallowRef<{ target: RequestUrl }>;
export function useListView<
T extends { id: number; [index: string]: any },
C extends Record<any, any> & { name?: string },
>(url: CurrentUrl) {
>(url: CurrentUrl, specialParams: Ref<Record<string, any>> = {} as any) {
const { open, router } = useJump();
const getCurrentUrl = () => {
if (typeof url === 'string') {
......@@ -41,6 +41,26 @@ export function useListView<
const searchParams = ref<C>(cloneDeep(searchParamsStore.urlSearchParams) || {});
const isRequesting = ref(false);
const otherParams = computed(() => {
const { searchName } = searchParamsStore;
return {
...specialParams.value,
...(searchName ? { name: searchName } : {}),
};
});
const currentParams = computed(() => {
return {
...searchParams.value,
...otherParams.value,
};
});
/** 是否存在搜索参数 */
const haveSearchParams = computed(() => {
return !isEmpty(currentParams.value);
});
/**
* 清除url传递的参数
*/
......@@ -57,7 +77,13 @@ export function useListView<
watchEffect(async () => {
try {
changeIsRequesting(true);
const { data } = await queryList(searchParams.value || {}, getCurrentUrl());
const { data } = await queryList(
{
...searchParams.value,
...otherParams.value,
} || {},
getCurrentUrl(),
);
handleUrlClear();
datas.value = data.records;
} catch (error) {
......@@ -87,14 +113,8 @@ export function useListView<
for (const item of selectList.value) {
temp[item.key] = item.value;
}
const { searchName } = searchParamsStore;
if (searchName) {
temp.name = searchName;
}
initPagination();
const { investmentDirection } = searchParams.value;
temp.investmentDirection = investmentDirection;
searchParams.value = temp;
};
......@@ -103,8 +123,7 @@ export function useListView<
*/
const handleNameSearch = (params: { name: string }) => {
nextTick(() => {
if (searchParams.value.name !== params.name) {
searchParams.value.name = params.name;
if (searchParamsStore.searchName !== params.name) {
initPagination();
}
});
......@@ -121,6 +140,7 @@ export function useListView<
totalCount,
datas,
isRequesting,
haveSearchParams,
queryList,
handleDetail,
initPagination,
......
......@@ -47,7 +47,7 @@ export function useQueryList<T, C>(queryFn: QueryFn<T, CommonListParams<C>>) {
};
const initPagination = () => {
changePagination({ page: 1, size: 10, total: 0 });
changePagination({ page: 1, size: 10 });
};
const assignPageParams = (params: C): CommonListParams<C> => {
......
......@@ -12,7 +12,7 @@
</div>
<div>
<!-- 载体列表 -->
<p v-if="!isEmpty(searchParams)" class="mb-7 text-sm font-medium text-[#4d4d4d]">
<p v-if="haveSearchParams" class="mb-7 text-sm font-medium text-[#4d4d4d]">
搜索到
<span class="text-[#C0322B]">{{ totalCount }}</span>
个相关载体
......@@ -48,7 +48,6 @@ import CommonTitle from '@/components/common/CommonTitle.vue';
import FilterView from '@/components/filter/filter-view.vue';
import type { CarrierListCondition, CarrierListItem } from '@/types/api/carrierList';
import { ref } from 'vue';
import { isEmpty } from 'lodash-es';
const {
pageNum,
......@@ -58,7 +57,7 @@ const {
handleDetail,
handleFilterChange,
handleNameSearch,
searchParams,
haveSearchParams,
} = useListView<CarrierListItem, CarrierListCondition>(RequestUrl.carrierList);
// 筛选项
const filterKeyList = ref([
......
......@@ -11,7 +11,7 @@
<FormModal></FormModal>
</div>
<div>
<p v-if="!isEmpty(searchParams)" class="mb-7 text-sm font-medium text-[#4d4d4d]">
<p v-if="haveSearchParams" class="mb-7 text-sm font-medium text-[#4d4d4d]">
搜索到
<span class="text-[#C0322B]">{{ totalCount }}</span>
个相关开发区
......@@ -48,7 +48,6 @@ import type { DevelopZoneItem, DevelopZoneListCondition } from '@/types/api/deve
import { ParkItemType } from '@/types/enum.ts';
import FilterView from '@/components/filter/filter-view.vue';
import CommonTitle from '@/components/common/CommonTitle.vue';
import { isEmpty } from 'lodash-es';
// 筛选项列表
const filterKeyList = [
......@@ -67,6 +66,6 @@ const {
handleDetail,
handleFilterChange,
handleNameSearch,
searchParams,
haveSearchParams,
} = useListView<DevelopZoneItem, DevelopZoneListCondition>(RequestUrl.developZoneList);
</script>
......@@ -11,7 +11,7 @@
<FormModal></FormModal>
</div>
<div>
<p v-if="!isEmpty(searchParams)" class="mb-7 text-sm font-medium text-[#4d4d4d]">
<p v-if="haveSearchParams" class="mb-7 text-sm font-medium text-[#4d4d4d]">
搜索到
<span class="text-[#C0322B]">{{ totalCount }}</span>
个相关产业园
......@@ -50,7 +50,6 @@ import ListPagination from '@/components/list/ListPagination.vue';
import FilterView from '@/components/filter/filter-view.vue';
import CommonTitle from '@/components/common/CommonTitle.vue';
import ParkItem from '@/components/list/ParkItem.vue';
import { isEmpty } from 'lodash-es';
// import FormModal from '@/components/form-modal/FormModal.vue';
import type {
IndustrialParkItem,
......@@ -66,7 +65,7 @@ const {
handleDetail,
handleFilterChange,
handleNameSearch,
searchParams,
haveSearchParams,
} = useListView<IndustrialParkItem, IndustrialParkListCondition>(RequestUrl.industrialParkList);
// 筛选项
const filterKeyList = [
......
......@@ -51,7 +51,7 @@
@change="handleFilterChange"
></FilterView>
<template v-if="datas.length">
<p v-if="!isEmpty(searchParams)" class="mb-7 text-sm font-medium text-[#4d4d4d]">
<p v-if="haveSearchParams" class="mb-7 text-sm font-medium text-[#4d4d4d]">
搜索到
<span class="text-[#C0322B]">{{ totalCount }}</span>
个相关{{ tabList[activeTab].name }}
......@@ -101,7 +101,7 @@
</template>
<script lang="ts" setup>
import { ref, shallowRef, watch, onMounted, nextTick } from 'vue';
import { ref, shallowRef, watch, onMounted, nextTick, computed } from 'vue';
import { useRequest } from '@/composable/useRequest.ts';
import { RequestUrl } from '@/types/api.ts';
import { useListView } from '@/composable/useListView.ts';
......@@ -114,7 +114,6 @@ import CarrierListItemView from '@/components/list/list-carrier-item.vue';
import LandListItemView from '@/components/list/list-land-item.vue';
import ParkItem from '@/components/list/ParkItem.vue';
import FilterView from '@/components/filter/filter-view.vue';
import { isEmpty } from 'lodash-es';
type tabItem = {
name: string;
......@@ -181,6 +180,12 @@ onMounted(async () => {
}
});
const otherParams = computed(() => {
return {
investmentDirection: currentDirection.value,
};
});
const {
pageNum,
pageSize,
......@@ -188,13 +193,12 @@ const {
datas,
handleDetail,
handleFilterChange,
searchParams,
haveSearchParams,
isRequesting,
} = useListView(currentUrl);
} = useListView(currentUrl, otherParams);
const handleDirectionClick = (item: string) => {
currentDirection.value = item;
searchParams.value.investmentDirection = item;
};
watch(
......
......@@ -12,7 +12,7 @@
<FormModal></FormModal>
</div>
<div>
<p v-if="!isEmpty(searchParams)" class="mb-7 text-sm font-medium text-[#4d4d4d]">
<p v-if="haveSearchParams" class="mb-7 text-sm font-medium text-[#4d4d4d]">
搜索到
<span class="text-[#C0322B]">{{ totalCount }}</span>
个相关土地
......@@ -49,8 +49,7 @@ import LandListItemView from '@/components/list/list-land-item.vue';
import CommonTitle from '@/components/common/CommonTitle.vue';
import FilterView from '@/components/filter/filter-view.vue';
import type { LandListCondition, LandListItem } from '@/types/api/landList';
import { ref, watch } from 'vue';
import { isEmpty } from 'lodash-es';
import { ref } from 'vue';
const Response = useListView<LandListItem, LandListCondition>(RequestUrl.landList);
const {
......@@ -61,13 +60,8 @@ const {
handleDetail,
handleFilterChange,
handleNameSearch,
searchParams,
haveSearchParams,
} = Response;
console.log(searchParams);
watch(searchParams, () => {
console.log(isEmpty(searchParams.value));
});
const filterKeyList = ref(['land_price', 'land_type', 'land_area']);
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment