Commit f8758331 authored by GuanHua's avatar GuanHua

feat:企业商城价格区间筛选接口对接

parent 00a66bb0
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Slider } from 'antd'
import { LAYOUT_TYPE, FILTER_TYPE } from '@/constants'
import { PublicApi } from '@/services/api'
import FilterBox from '../FilterBox'
import './index.less'
......@@ -10,8 +11,35 @@ interface PricePropsType {
}
const Points: React.FC<PricePropsType> = (props) => {
const { layoutType = LAYOUT_TYPE.mall } = props
const { onFilter } = props.FilterStore
const [pointsRange, setPointsRange] = useState<any>([0, 900])
const [maxPrice, setMaxPrice] = useState<number>(900)
const [pointsRange, setPointsRange] = useState<any>([0, maxPrice])
useEffect(() => {
fetchMaxPrice()
}, [])
const fetchMaxPrice = () => {
let getFn
switch (layoutType) {
case LAYOUT_TYPE.channel:
case LAYOUT_TYPE.ichannel:
case LAYOUT_TYPE.channelScoreMall:
getFn = PublicApi.getSearchShopChannelGetCommodityMaxPrice
break;
default:
getFn = PublicApi.getSearchShopStoreGetCommodityMaxPrice
break;
}
getFn && getFn().then(res => {
if (res.code === 1000) {
setMaxPrice(res.data)
setPointsRange([0, res.data])
}
})
}
const handlePriceChange = (value) => {
setPointsRange(value)
......@@ -36,15 +64,15 @@ const Points: React.FC<PricePropsType> = (props) => {
const handleConfirmpointsRange = () => {
let min = pointsRange[0]
let max = pointsRange[1]
if (min === 900) {
if (min === maxPrice) {
filterMinPoints(min)
} else if (min === 0 && max !== 900) {
} else if (min === 0 && max !== maxPrice) {
filterMinPoints(min, false)
filterMaxPoints(max)
} else if (min !== 0 && max === 900) {
} else if (min !== 0 && max === maxPrice) {
filterMinPoints(min)
filterMaxPoints(max, false)
} else if ((min === 0 && max === 900) || (min !== 0 && max !== 900)) {
} else if ((min === 0 && max === maxPrice) || (min !== 0 && max !== maxPrice)) {
filterMinPoints(min)
filterMaxPoints(max)
}
......@@ -55,13 +83,13 @@ const Points: React.FC<PricePropsType> = (props) => {
title="所需积分范围"
>
<div className="filter_price">
<Slider range step={1} min={0} max={900} value={pointsRange} onChange={handlePriceChange} />
<Slider range step={1} min={0} max={maxPrice} value={pointsRange} onChange={handlePriceChange} />
<div className="price_box">
<span className="price_box_brief">积分:</span>
<div className="price_range">
<span className="price">{pointsRange[0]}</span>
<span className="split">-</span>
<span className="price">{pointsRange[0] === 900 ? '' : `${pointsRange[1]}`}</span>
<span className="price">{pointsRange[0] === maxPrice ? '' : `${pointsRange[1]}`}</span>
</div>
<div className="confirm_btn" onClick={() => handleConfirmpointsRange()}>确定</div>
</div>
......
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Slider } from 'antd'
import { LAYOUT_TYPE, FILTER_TYPE } from '@/constants'
import { PublicApi } from '@/services/api'
import FilterBox from '../FilterBox'
import './index.less'
......@@ -10,9 +11,34 @@ interface PricePropsType {
}
const Price: React.FC<PricePropsType> = (props) => {
const { layoutType = LAYOUT_TYPE.mall } = props
const { onFilter, filterList } = props.FilterStore
const MAX_COUNT = 900
const [priceRange, setPriceRange] = useState<any>([0, MAX_COUNT])
const [maxPrice, setMaxPrice] = useState<number>(900)
const [priceRange, setPriceRange] = useState<any>([0, maxPrice])
useEffect(() => {
fetchMaxPrice()
}, [])
const fetchMaxPrice = () => {
let getFn
switch (layoutType) {
case LAYOUT_TYPE.channel:
case LAYOUT_TYPE.ichannel:
case LAYOUT_TYPE.shopScoreMall:
getFn = PublicApi.getSearchShopChannelGetCommodityMaxPrice
break;
default:
getFn = PublicApi.getSearchShopStoreGetCommodityMaxPrice
break;
}
getFn && getFn().then(res => {
if (res.code === 1000) {
setMaxPrice(res.data)
setPriceRange([0, res.data])
}
})
}
const handlePriceChange = (value) => {
setPriceRange(value)
......@@ -37,19 +63,19 @@ const Price: React.FC<PricePropsType> = (props) => {
const handleConfirmPriceRange = () => {
let min = priceRange[0]
let max = priceRange[1]
if (min === MAX_COUNT) {
if (min === maxPrice) {
filterMinPrice(min)
} else if (min === 0 && max !== MAX_COUNT) {
} else if (min === 0 && max !== maxPrice) {
if (checkHasType(FILTER_TYPE.minPrice)) {
filterMinPrice(min, false)
}
filterMaxPrice(max)
} else if (min !== 0 && max === MAX_COUNT) {
} else if (min !== 0 && max === maxPrice) {
filterMinPrice(min)
if (checkHasType(FILTER_TYPE.maxPrice)) {
filterMaxPrice(max, false)
}
} else if ((min === 0 && max === MAX_COUNT) || (min !== 0 && max !== MAX_COUNT)) {
} else if ((min === 0 && max === maxPrice) || (min !== 0 && max !== maxPrice)) {
filterMinPrice(min)
filterMaxPrice(max)
}
......@@ -64,13 +90,13 @@ const Price: React.FC<PricePropsType> = (props) => {
title="价格"
>
<div className="filter_price">
<Slider range step={1} min={0} max={MAX_COUNT} value={priceRange} onChange={handlePriceChange} />
<Slider range step={1} min={0} max={maxPrice} value={priceRange} onChange={handlePriceChange} />
<div className="price_box">
<span className="price_box_brief">价格:</span>
<div className="price_range">
<span className="price">¥{priceRange[0]}</span>
<span className="split">-</span>
<span className="price">{priceRange[0] === MAX_COUNT ? '' : `¥${priceRange[1]}`}</span>
<span className="price">{priceRange[0] === maxPrice ? '' : `¥${priceRange[1]}`}</span>
</div>
<div className="confirm_btn" onClick={() => handleConfirmPriceRange()}>确定</div>
</div>
......
......@@ -46,7 +46,7 @@ const InterestedCommodity: React.FC<InterestedCommodityPropsType> = (props) => {
return link
}
return (
return dataList && dataList.length > 0 && (
<div className={styles.interested_commodity}>
<div className={styles.interested_commodity_title}>
<span>您可能也感兴趣:</span>
......@@ -57,7 +57,7 @@ const InterestedCommodity: React.FC<InterestedCommodityPropsType> = (props) => {
</div>
<div className={styles.interested_commodity_list}>
{
dataList && dataList.map((item, index) => index < 5 && (
dataList.map((item, index) => index < 5 && (
<div className={styles.interested_commodity_list_item} key={`interested_commodity_list_item_${item.id}`}>
<a href={getCommodityDetailLink(item)} target="_blank">
<div className={styles.interested_commodity_list_item_imgbox}>
......
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