Commit 3131198a authored by GuanHua's avatar GuanHua

feat:商品搜索

parent 4e91c9ca
...@@ -17,8 +17,23 @@ export interface UserRegister { ...@@ -17,8 +17,23 @@ export interface UserRegister {
useType: UseType; useType: UseType;
} }
export interface ShopInfo {
id: number;
name: string;
type: number;
environment: number;
logoUrl: string;
describe: string;
state: number;
url: string;
}
export interface Web { export interface Web {
shopInfo: any[]; shopInfo: ShopInfo[];
}
export interface PayConfig {
paymemberConfig?: any;
} }
export interface CountryList { export interface CountryList {
...@@ -37,5 +52,6 @@ export interface Global { ...@@ -37,5 +52,6 @@ export interface Global {
export interface RootObject { export interface RootObject {
userRegister: UserRegister; userRegister: UserRegister;
web: Web; web: Web;
payConfig: PayConfig;
global: Global; global: Global;
} }
\ No newline at end of file
...@@ -61,13 +61,18 @@ const Commodity: React.FC<CommodityPropsType> = (props) => { ...@@ -61,13 +61,18 @@ const Commodity: React.FC<CommodityPropsType> = (props) => {
useEffect(() => { useEffect(() => {
fetchCommodityList() fetchCommodityList()
}, [filterParam, current])
}, [filterParam, current, search])
const fetchCommodityList = () => { const fetchCommodityList = () => {
let param = { let param: filterQuery = {
current, current,
pageSize pageSize
} }
if (!!search) {
param.name = search
}
if (!isEmpty(filterParam)) { if (!isEmpty(filterParam)) {
param = Object.assign(param, filterParam) param = Object.assign(param, filterParam)
} }
...@@ -77,13 +82,11 @@ const Commodity: React.FC<CommodityPropsType> = (props) => { ...@@ -77,13 +82,11 @@ const Commodity: React.FC<CommodityPropsType> = (props) => {
setCommodityList(res.data.data) setCommodityList(res.data.data)
setTotalCount(res.data.totalCount) setTotalCount(res.data.totalCount)
} }
}) })
} }
const handleFilter = (filterValue: filterValueType) => { const handleFilter = (filterValue: filterValueType) => {
let filteState = filterList.some(item => item.type === filterValue.type) let filteState = filterList.some(item => item.type === filterValue.type)
let tempFilterList = [...filterList] let tempFilterList = [...filterList]
if (filteState) { if (filteState) {
...@@ -96,6 +99,7 @@ const Commodity: React.FC<CommodityPropsType> = (props) => { ...@@ -96,6 +99,7 @@ const Commodity: React.FC<CommodityPropsType> = (props) => {
} else { } else {
tempFilterList = [...tempFilterList, filterValue] tempFilterList = [...tempFilterList, filterValue]
} }
console.log(tempFilterList, "tempFilterList")
setFilterList(tempFilterList) setFilterList(tempFilterList)
} }
...@@ -175,7 +179,7 @@ const Commodity: React.FC<CommodityPropsType> = (props) => { ...@@ -175,7 +179,7 @@ const Commodity: React.FC<CommodityPropsType> = (props) => {
</div> </div>
</div> </div>
{ {
!!search ? <NoResult search={search} /> : ( (commodityList.length === 0 || !commodityList) ? <NoResult search={search} /> : (
<> <>
<CommodityList showType={showType} commodityList={commodityList} /> <CommodityList showType={showType} commodityList={commodityList} />
<div className={styles.pagination_wrap}> <div className={styles.pagination_wrap}>
......
...@@ -31,6 +31,12 @@ enum COMMODITY_TYPE { ...@@ -31,6 +31,12 @@ enum COMMODITY_TYPE {
integral = 3 integral = 3
} }
const Logistics_Type = {
1: '物流',
2: '自提',
3: '无需配送'
}
const colorList = [ const colorList = [
{ {
name: '红色', name: '红色',
...@@ -312,7 +318,7 @@ const CommodityDetail = (props) => { ...@@ -312,7 +318,7 @@ const CommodityDetail = (props) => {
<div className={cx(styles.product_info_line, styles.mar_top_10)}> <div className={cx(styles.product_info_line, styles.mar_top_10)}>
<div className={styles.product_info_line_label}>配送方式</div> <div className={styles.product_info_line_label}>配送方式</div>
<div className={styles.product_info_line_brief}> <div className={styles.product_info_line_brief}>
<span className={styles.text}>物流</span> <span className={styles.text}>{Logistics_Type[commodityDetail?.logistics.carriageType]}</span>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -69,44 +69,32 @@ const Filter: React.FC<FilterPropsType> = (props) => { ...@@ -69,44 +69,32 @@ const Filter: React.FC<FilterPropsType> = (props) => {
const renderFilter = () => { const renderFilter = () => {
if (!isEmpty(filterConfig)) { if (!isEmpty(filterConfig)) {
let result = [] return filterConfig.map(type => {
for (let type of filterConfig) {
switch (type) { switch (type) {
case FilterType.commonlyUsed: case FilterType.commonlyUsed:
result.push(<CommonlyUsed />) return <CommonlyUsed key={type} />
break
case FilterType.category: case FilterType.category:
result.push(<Category onFilter={handleFilter} />) return <Category onFilter={handleFilter} key={type} />
break
case FilterType.style: case FilterType.style:
result.push(<Style onFilter={handleFilter} />) return <Style onFilter={handleFilter} key={type} />
break
case FilterType.brand: case FilterType.brand:
result.push(<Brand onFilter={handleFilter} />) return <Brand onFilter={handleFilter} key={type} />
break
case FilterType.price: case FilterType.price:
result.push(<Price />) return <Price key={type} />
break
case FilterType.useArea: case FilterType.useArea:
result.push(<UseArea onFilter={handleFilter} />) return <UseArea onFilter={handleFilter} key={type} />
break
case FilterType.commodityType: case FilterType.commodityType:
result.push(<CommodityType />) return <CommodityType key={type} />
break
case FilterType.activeStores: case FilterType.activeStores:
result.push(<ActiveStores />) return <ActiveStores key={type} />
break
case FilterType.newJoin: case FilterType.newJoin:
result.push(<NewJoin />) return <NewJoin key={type} />
break
case FilterType.points: case FilterType.points:
result.push(<Points />) return <Points key={type} />
break
default: default:
break break
} }
} })
return result
} else { } else {
return null return null
} }
......
...@@ -61,7 +61,6 @@ ...@@ -61,7 +61,6 @@
line-height: 36px; line-height: 36px;
outline: none; outline: none;
border: none; border: none;
text-indent: 12px;
} }
.search_btn { .search_btn {
......
import React, { useState } from 'react' import React, { useState, useEffect } from 'react'
import cx from 'classnames' import cx from 'classnames'
import { Input } from 'antd'
import { Link, history } from 'umi' import { Link, history } from 'umi'
import { FileTextOutlined } from '@ant-design/icons' import { FileTextOutlined } from '@ant-design/icons'
import logo from '@/theme/imgs/logo_w.png' import logo from '@/theme/imgs/logo_w.png'
import isEmpty from 'lodash/isEmpty'
import './index.less' import './index.less'
interface HeaderPropsType { interface HeaderPropsType {
...@@ -11,6 +13,14 @@ interface HeaderPropsType { ...@@ -11,6 +13,14 @@ interface HeaderPropsType {
const Header: React.FC<HeaderPropsType> = (props) => { const Header: React.FC<HeaderPropsType> = (props) => {
const [searchType, setSearchType] = useState<number>(1) // 1:商品; 2:店铺 const [searchType, setSearchType] = useState<number>(1) // 1:商品; 2:店铺
const [searchValue, setSearchValue] = useState<string>("")
useEffect(() => {
const { search } = history.location.query
if (!!search) {
setSearchValue(search)
}
}, [])
const handleChangeSearchType = (type: number) => { const handleChangeSearchType = (type: number) => {
if (searchType !== type) { if (searchType !== type) {
...@@ -18,6 +28,15 @@ const Header: React.FC<HeaderPropsType> = (props) => { ...@@ -18,6 +28,15 @@ const Header: React.FC<HeaderPropsType> = (props) => {
} }
} }
const handleSearchCommodity = () => {
if (!isEmpty(searchValue)) {
history.push(`/commodity?search=${encodeURIComponent(searchValue)}`)
} else {
history.push(`/commodity`)
}
}
return ( return (
<div className="header"> <div className="header">
<div className="header_container"> <div className="header_container">
...@@ -32,8 +51,8 @@ const Header: React.FC<HeaderPropsType> = (props) => { ...@@ -32,8 +51,8 @@ const Header: React.FC<HeaderPropsType> = (props) => {
<div className={cx("mall_search_tags_item", searchType === 2 ? 'active' : '')} onClick={() => handleChangeSearchType(2)}>店铺</div> <div className={cx("mall_search_tags_item", searchType === 2 ? 'active' : '')} onClick={() => handleChangeSearchType(2)}>店铺</div>
</div> </div>
<div className="mall_search_box"> <div className="mall_search_box">
<input className="mall_search_input" placeholder="请输入关键词" /> <Input className="mall_search_input" value={searchValue} placeholder="请输入关键词" onChange={e => setSearchValue(e.target.value)} onPressEnter={() => handleSearchCommodity()} />
<div className="search_btn">搜索</div> <div className="search_btn" onClick={() => handleSearchCommodity()}>搜索</div>
</div> </div>
</div> </div>
<div className="shopping_cart mall" onClick={() => history.push('/purchaseOrder')}> <div className="shopping_cart mall" onClick={() => history.push('/purchaseOrder')}>
......
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