Commit 2dddbbf0 authored by GuanHua's avatar GuanHua

feat:商品详情价格阶梯的从大到小排序

parent 02806211
...@@ -204,7 +204,7 @@ const CommodityDetail = (props) => { ...@@ -204,7 +204,7 @@ const CommodityDetail = (props) => {
if (judgeArrisCommon(temp, selectAttrVal)) { if (judgeArrisCommon(temp, selectAttrVal)) {
setSelectCommodityId(item.id) setSelectCommodityId(item.id)
setCurrentPriceRange(item.unitPrice) setCurrentPriceRange(sortUnitPrice(item.unitPrice))
setAttrAndValList(item) setAttrAndValList(item)
setStockCount(item.stockCount) setStockCount(item.stockCount)
} }
...@@ -441,13 +441,45 @@ const CommodityDetail = (props) => { ...@@ -441,13 +441,45 @@ const CommodityDetail = (props) => {
} }
} }
} }
setCurrentPriceRange(unitPriceAndPicList[0].unitPrice) setCurrentPriceRange(sortUnitPrice(unitPriceAndPicList[0].unitPrice))
setStockCount(unitPriceAndPicList[0].stockCount) setStockCount(unitPriceAndPicList[0].stockCount)
setCommodityImgList(tempImgList) setCommodityImgList(tempImgList)
setAttributeList(tempAttrList) setAttributeList(tempAttrList)
} }
/** /**
* 对阶梯价格进行从大到小的排序
* @param priceObj
*/
const sortUnitPrice = (priceObj) => {
if (!priceObj) {
return {}
}
if (Object.keys(priceObj).length <= 1) {
return priceObj
}
let tempList = []
Object.keys(priceObj).forEach(key => {
tempList.push({
key,
value: priceObj[key]
})
})
for (let i = 0; i < tempList.length; i++) {
if (tempList[i + 1] && tempList[i].value < tempList[i + 1].value) {
let temp = tempList[i]
tempList[i] = tempList[i + 1]
tempList[i + 1] = temp
}
}
let result = {}
for (let tempItem of tempList) {
result[tempItem.key] = tempItem.value
}
return result
}
/**
* 设置当前选择的sku的价格区间 * 设置当前选择的sku的价格区间
* @param uniPrice * @param uniPrice
*/ */
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
} from '@ant-design/pro-layout'; } from '@ant-design/pro-layout';
import { useIntl, history } from 'umi'; import { useIntl, history } from 'umi';
import TopBar from '../components/TopBar' import TopBar from '../components/TopBar'
import SelectLang from '@/layouts/components/SelectLang'
import { inject, observer } from 'mobx-react' import { inject, observer } from 'mobx-react'
import ShopHeader from '../components/ShopHeader' import ShopHeader from '../components/ShopHeader'
import MainNav from '../components/MainNav' import MainNav from '../components/MainNav'
...@@ -81,7 +82,7 @@ const LXShopLayout: React.FC<LXMallLayoutPropsType> = (props) => { ...@@ -81,7 +82,7 @@ const LXShopLayout: React.FC<LXMallLayoutPropsType> = (props) => {
return ( return (
<div className={styles.lxmall_page}> <div className={styles.lxmall_page}>
<TopBar name={mallInfo.name} /> <TopBar langComponent={<SelectLang />} name={mallInfo.name} />
<div className={styles.content}> <div className={styles.content}>
<ShopHeader logo={mallInfo.logoUrl} shopId={query.shopId} shopUrlParam={shopId} shopInfo={shopInfo} /> <ShopHeader logo={mallInfo.logoUrl} shopId={query.shopId} shopUrlParam={shopId} shopInfo={shopInfo} />
<MainNav menuData={menuData} pathname={location.pathname} type={LAYOUT_TYPE.shop} shopId={query.shopId} shopUrlParam={shopId} /> <MainNav menuData={menuData} pathname={location.pathname} type={LAYOUT_TYPE.shop} shopId={query.shopId} shopUrlParam={shopId} />
......
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