Commit 1851a8ab authored by GuanHua's avatar GuanHua

feat:商品购买数量,单价计算

parent f94b9266
......@@ -60,8 +60,6 @@ const InputNumber: React.FC<InputNumberPropsType> = (props) => {
Number(value) < minCount && onChange(minCount)
Number(value) > maxCount && onChange(maxCount)
}
}
return (
......
......@@ -18,6 +18,7 @@ import { GetSearchShopStoreGetCommodityDetailResponse } from '@/services/SearchA
import { numFormat, priceFormat } from '@/utils/numberFomat'
import jinhuodanIcon from '@/assets/imgs/jinhuodan.png'
import styles from './index.less'
import { isEmpty } from 'lodash'
enum COMMODITY_TYPE {
/**
......@@ -196,7 +197,6 @@ const CommodityDetail = (props) => {
}
const handleAddToPurchase = () => {
if (!selectCommodityId) {
message.destroy()
message.info("请选择商品属性")
......@@ -407,6 +407,9 @@ const CommodityDetail = (props) => {
}
}
/**
* 根据购买的数量获取单前商品单价
*/
const getUnitPrice = () => {
let unitPrice = 0
if (!commodityPriceInfo) {
......@@ -419,30 +422,31 @@ const CommodityDetail = (props) => {
let temp = commodityPriceInfo.filter(item => {
return Number(buyCount) >= Number(item.min) && Number(buyCount) <= Number(item.max)
})
unitPrice = temp[0]?.price
if (isEmpty(temp)) {
let maxItem = getMaxCountRange()
unitPrice = maxItem.price
} else {
unitPrice = temp[0]?.price
}
}
}
return unitPrice
}
const getAmount = () => {
let unitPrice = getUnitPrice()
let amount = unitPrice * (Number(buyCount) || 0)
return priceFormat(amount)
}
let unitPrice = 0
if (!commodityPriceInfo) {
return 0
}
if (commodityDetail?.priceType === COMMODITY_TYPE.prompt) {
if (commodityPriceInfo.length <= 1) {
unitPrice = commodityPriceInfo[0]?.price
} else {
let temp = commodityPriceInfo.filter(item => {
return Number(buyCount) >= Number(item.min) && Number(buyCount) <= Number(item.max)
})
unitPrice = temp[0]?.price
const getMaxCountRange = () => {
let maxItem: any = {}
for (let item of commodityPriceInfo) {
if (Number(item.max) > Number(maxItem.max || 0)) {
maxItem = item
}
}
let amount = unitPrice * (Number(buyCount) || 0)
return priceFormat(amount)
return maxItem
}
/**
......
import React, { useState, useEffect } from 'react'
import { history } from 'umi'
import { Input } from 'antd'
import { GetTemplateChannelFindChannelResponse } from '@/services/TemplateApi'
import logo from '@/theme/imgs/logo_w.png'
import isEmpty from 'lodash/isEmpty'
import './index.less'
interface HeaderPropsType {
shopInfo: GetTemplateChannelFindChannelResponse
shopInfo: GetTemplateChannelFindChannelResponse,
id: number,
shopUrlParam: string,
}
const Header: React.FC<HeaderPropsType> = (props) => {
const { shopInfo } = props
const { id, shopUrlParam, shopInfo } = props
const [searchValue, setSearchValue] = useState<string>("")
const { search } = history.location.query
useEffect(() => {
// console.log(shopInfo, "shopInfo")
}, [shopInfo])
if (!!search) {
setSearchValue(search)
} else {
setSearchValue("")
}
}, [search])
const handleSearchCommodity = () => {
if (!isEmpty(searchValue)) {
history.push(`/channelmall/commodity/search?id=${shopUrlParam}&search=${encodeURIComponent(searchValue)}`)
} else {
history.push(`/channelmall/commodity/search?id=${shopUrlParam}`)
}
}
return (
<div className="header">
......@@ -22,8 +40,8 @@ const Header: React.FC<HeaderPropsType> = (props) => {
</div>
<div className="mall_search">
<div className="mall_search_box">
<input className="mall_search_input" placeholder="请输入关键词" />
<div className="search_btn">搜索</div>
<Input className="mall_search_input" value={searchValue} placeholder="请输入关键词" onChange={e => setSearchValue(e.target.value)} onPressEnter={() => handleSearchCommodity()} />
<div className="search_btn" onClick={() => handleSearchCommodity()}>搜索</div>
</div>
</div>
</div>
......
......@@ -6,7 +6,6 @@ import isEmpty from 'lodash/isEmpty'
import logo from '@/theme/imgs/logo_w.png'
import shop_icon from '@/assets/imgs/shop_icon.png'
import credit_icon from '@/assets/imgs/credit_icon.png'
import shopLogo from '@/assets/imgs/shop_logo.png'
import { GetTemplateShopFindShopResponse } from '@/services/TemplateApi'
import styles from './index.less'
......
......@@ -81,7 +81,7 @@ const LXChannelLayout: React.FC<LXMallLayoutPropsType> = (props) => {
{
!menuRouter?.hideHeader && (
<>
<ChannelHeader shopInfo={shopInfo} />
<ChannelHeader id={query.shopId} shopUrlParam={id} shopInfo={shopInfo} />
<MainNav menuData={menuData} pathname={location.pathname} type={LAYOUT_TYPE.channel} shopId={query.shopId} shopUrlParam={id} />
</>
)
......
......@@ -14,6 +14,7 @@ import { LAYOUT_TYPE } from '@/constants'
import { GetProductPurchaseGetPurchaseListResponse } from '@/services/ProductApi'
import { GetTemplateChannelFindChannelResponse } from '@/services/TemplateApi'
import { GlobalConfig } from '@/global/config'
import { isEmpty } from 'lodash'
interface PurchaseOrderPropsType {
layoutType: LAYOUT_TYPE,
......@@ -227,6 +228,9 @@ const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => {
priceItem = item
}
}
if (isEmpty(priceItem)) {
priceItem = getMaxCountRange(priceRange)
}
return parseFloat(priceItem.price) * count
}
}
......@@ -479,12 +483,27 @@ const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => {
let temp = detail.priceRange.filter(item => {
return Number(count) >= Number(item.min) && Number(count) <= Number(item.max)
})
unitPrice = temp[0]?.price
if (isEmpty(temp)) {
let maxItem = getMaxCountRange(detail.priceRange)
unitPrice = maxItem.price
} else {
unitPrice = temp[0]?.price
}
}
return unitPrice
}
const getMaxCountRange = (priceRange) => {
let maxItem: any = {}
for (let item of priceRange) {
if (Number(item.max) > Number(maxItem.max || 0)) {
maxItem = item
}
}
return maxItem
}
return (
<div className={styles.purchase_order}>
<div className={styles.purchase_order_container}>
......
......@@ -85,7 +85,7 @@ baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit):
options.paramsSerializer = params => {
return qs.stringify(params, { arrayFormat: 'brackets' })
}
return {
// 前缀如果已经带上api, 跳过自动补前缀
url: url.startsWith('/api') ? url : basePrefix + url,
......@@ -116,11 +116,12 @@ class ApiRequest {
baseRequest<IRequestSuccess<T>>(url, options).then(res => {
// 登录验证
if (res.code === 1101) {
removeAuth()
// removeAuth()
// history.replace(`/user/login?redirect=${btoa(encodeURIComponent(String(window.location)))}`)
window.location.replace(`/user/login?redirect=${btoa(encodeURIComponent(String(window.location)))}`)
// window.location.replace(`/user/login?redirect=${btoa(encodeURIComponent(String(window.location)))}`)
message.destroy()
message.error(res.message)
reject(res)
return false
}
......
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