From 29055ecb704f904921d7188808f5d8ebdef30bc9 Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Thu, 12 May 2022 11:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=B0=E5=9D=80=E9=80=89?= =?UTF-8?q?=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/search.ts | 11 +++++++++++ src/components/address/index.tsx | 29 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/api/search.ts diff --git a/src/api/search.ts b/src/api/search.ts new file mode 100644 index 0000000..9f91366 --- /dev/null +++ b/src/api/search.ts @@ -0,0 +1,11 @@ +import { useRequest } from "@/use/useHttp" + +/** + * 获取热门搜索 + */ + export const getHotSearchApi = () => { + return useRequest({ + url: `/v1/mall/hotSearch`, + method: "get", + }) +} \ No newline at end of file diff --git a/src/components/address/index.tsx b/src/components/address/index.tsx index 7f96e37..6916c65 100644 --- a/src/components/address/index.tsx +++ b/src/components/address/index.tsx @@ -14,6 +14,7 @@ type Params = { addressOnClose?: () => void, show?: true|false, defaultValue?:DefaultValueParm[] + selectStatus?: false|true, //false不需要选择完整地址,true需要选择完整地址 } type AddresParam = { @@ -22,7 +23,8 @@ type AddresParam = { level?: number, level_name?: string, name?: string, - parent_id?: number + parent_id?: number, + } @@ -30,7 +32,8 @@ export default memo(({ addressOnSelect, addressOnClose, show = false, - defaultValue = [] + defaultValue = [], + selectStatus = true }: Params) => { //省 const provinceList = useRef([]) @@ -45,6 +48,7 @@ export default memo(({ const [selectArr, setSelectArr] = useState([]) //选中的省市区 const [cityStatus, setCityStatus] = useState(false) //城市是否存在 const [areaStatus, setAreaStatus] = useState(false) //区镇是否存在 + const [confirmBtnStatus, setConfirmBtnStatus] = useState(false) //确认按钮是否可用 const [bottomStyle, setBottomStyle] = useState({width:'100rpx',left:'0rpx'}) //底部滚动条样式 @@ -53,6 +57,7 @@ export default memo(({ setSelectArr(defaultValue) if(defaultValue.length > 1) setCityStatus(true) if(defaultValue.length > 2) setAreaStatus(true) + if(defaultValue.length > 0) setConfirmBtnStatus(true) } }, [defaultValue]) @@ -117,7 +122,9 @@ export default memo(({ setList(() => cityList.current) setCityStatus(true) getDomDes('#address_tab_1') + setConfirmBtnStatus(false) } else { + setConfirmBtnStatus(true) setCityStatus(false) } } @@ -131,7 +138,9 @@ export default memo(({ setList(() => areaList.current) setAreaStatus(true) getDomDes('#address_tab_2') + setConfirmBtnStatus(false) } else { + setConfirmBtnStatus(true) setAreaStatus(false) } @@ -139,8 +148,20 @@ export default memo(({ //确定按钮 const submitSelect = () => { - addressOnClose?.() - addressOnSelect?.(selectArr) + if(selectStatus) { + if(confirmBtnStatus || selectArr.length == 3) { + addressOnClose?.() + addressOnSelect?.(selectArr) + } else { + Taro.showToast({title:'请选择完整地址',icon:'none'}) + } + } else { + addressOnClose?.() + addressOnSelect?.(selectArr) + } + + + } //获取省市区宽度