diff --git a/src/api/search.ts b/src/api/search.ts index b5dd532..8549067 100644 --- a/src/api/search.ts +++ b/src/api/search.ts @@ -69,3 +69,13 @@ export const EnumLabelPageJumpApi = () => { method: 'get', }) } + +/** + * [枚举]首页跳转分类的枚举 + */ +export const EnumAllLabelApi = () => { + return useRequest({ + url: '/v1/mall/product/label/enum', + method: 'get', + }) +} diff --git a/src/common/constant.ts b/src/common/constant.ts index 5d8465b..c285d95 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -5,7 +5,7 @@ // export const BASE_URL = `http://192.168.0.89:40001/lymarket` // export const BASE_URL = `http://192.168.1.165:40001/lymarket` // 王霞 // export const BASE_URL = 'https://test.zzfzyc.com/lymarket' // 测试环境 -export const BASE_URL = 'https://pre.zzfzyc.com/lymarket' // 预发布 +// export const BASE_URL = 'https://pre.zzfzyc.com/lymarket' // 预发布 // export const BASE_URL = `http://192.168.1.9:40001/lymarket` // 发 // export const BASE_URL = `http://192.168.1.9:50005/lymarket` // 发 // export const BASE_URL = `http://192.168.1.30:50001/lymarket` // 发 @@ -13,7 +13,7 @@ export const BASE_URL = 'https://pre.zzfzyc.com/lymarket' // 预发布 // export const BASE_URL = 'https://www.zzfzyc.com/lymarket' // 正式环境 // export const BASE_URL = `http://192.168.1.5:40001/lymarket` // 王霞 // export const BASE_URL = 'http://192.168.1.7:50002/lymarket' // 添 -// export const BASE_URL = 'http://192.168.1.28:50002/lymarket' // 婷 +export const BASE_URL = 'http://192.168.1.28:50002/lymarket' // 婷 // export const BASE_URL = 'http://192.168.1.42:50002/lymarket' // 杰 // CDN diff --git a/src/components/filter/index.tsx b/src/components/filter/index.tsx index 4403252..41f2f01 100644 --- a/src/components/filter/index.tsx +++ b/src/components/filter/index.tsx @@ -92,7 +92,6 @@ const Filter = (props: params) => { setFilterObj(res) onFilter?.(res) onReset?.(res) - dropDownRef.current?.closePopup() } // 提交搜索 @@ -118,8 +117,12 @@ const Filter = (props: params) => { }) }, [filterObj]) + const onCloseOverlay = () => { + onVerify() + } + return ( - 筛选 diff --git a/src/pages/searchList/searchList.config.ts b/src/pages/searchList/searchList.config.ts index 22d7a05..3533712 100644 --- a/src/pages/searchList/searchList.config.ts +++ b/src/pages/searchList/searchList.config.ts @@ -1,5 +1,4 @@ export default { - navigationBarTitleText: '搜索', - enablePullDownRefresh: true, + navigationBarTitleText: '面料商城', backgroundTextStyle: 'dark', } diff --git a/src/pages/searchList/searchList.tsx b/src/pages/searchList/searchList.tsx index c5a846c..5418317 100644 --- a/src/pages/searchList/searchList.tsx +++ b/src/pages/searchList/searchList.tsx @@ -1,5 +1,5 @@ import { Text, View } from '@tarojs/components' -import Taro, { usePullDownRefresh, useRouter } from '@tarojs/taro' +import Taro, { usePullDownRefresh, useReady, useRouter } from '@tarojs/taro' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import SelectData from './components/selectData' import styles from './searchList.module.scss' @@ -15,7 +15,7 @@ import useLogin from '@/use/useLogin' import LabAndImg from '@/components/LabAndImg' import IconFont from '@/components/iconfont/iconfont' import Tag from '@/components/tag' -import { GetLabelProductsApi, HomePageJumpApi } from '@/api/search' +import { EnumAllLabelApi, GetLabelProductsApi, HomePageJumpApi } from '@/api/search' enum FilterOptions { RECOMMEND = 1, @@ -24,16 +24,34 @@ enum FilterOptions { } export default () => { + const isFirst = useRef(true) + useLogin() const router = useRouter() const { fetchData } = HomePageJumpApi() - // 获取标签列表 - const getLabels = async() => { - const res = await fetchData({ page_jump: router.params.pageJump || 1 }) - - setLabelList(res.data.list.map(item => ({ id: item.product_label_id, name: item.product_label_name }))) + // 获取指定的标签组的标签列表 + const getLabelsWithHomeJump = async() => { + await getAllLabel() + if (router.params.pageJump) { + const res = await fetchData({ page_jump: router.params.pageJump || 1 }) + const labelIds = res.data.list.map(item => item.product_label_id) + setLabelIds(labelIds) + setSearchField(prev => ({ ...prev, label_ids: labelIds.join(',') })) + } + else { + setLabelIds([]) + setSearchField(prev => ({ ...prev, label_ids: '' })) + } + isFirst.current = false + } + // 获取所有标签列表 + const { fetchData: getAllLabelApi } = EnumAllLabelApi() + const getAllLabel = async() => { + const res = await getAllLabelApi() + const labelList = res.data.list.map(item => ({ id: item.id, name: item.name })) + setLabelList(labelList) } // 搜索参数 @@ -55,17 +73,20 @@ export default () => { const getProductList = async() => { const { data } = await materialFetchData(getFilterData(searchField)) setMaterialList({ list: data.list, total: data.total }) - Taro.stopPullDownRefresh() + setRefresherTriggeredStatus(false) } useEffect(() => { - getLabels() + getLabelsWithHomeJump() }, []) // 监听筛选条件变化 useEffect(() => { - getProductList() - }, [searchField]) + // 首次进入页面不执行 + if (!isFirst.current) { + getProductList() + } + }, [searchField, isFirst.current]) // 上拉加载数据 const pageNum = useRef({ size: searchField.size, page: searchField.page }) @@ -90,15 +111,16 @@ export default () => { pageNum.current = { size: 10, page: 1 } }, []) + const handleInput = (e) => { + if (e === '') { + getSearchData(e) + } + } + const goLinkPage = (item) => { goLink('/pages/details/index', { id: item.id }) } - // 页面下拉刷新 - usePullDownRefresh(() => { - setSearchField({ ...searchField, size: 10 }) - }) - const [labelIds, setLabelIds] = useState([]) // 获取筛选条件 @@ -146,13 +168,6 @@ export default () => { [materialList], ) - // 返回 - const handCancel = () => { - Taro.navigateBack({ - delta: 1, - }) - } - const [currentOption, setCurrentOption] = useState(FilterOptions.RECOMMEND) const handleSelectFilterOptions = (key: FilterOptions) => { @@ -187,7 +202,7 @@ export default () => { return ( - +