Commit 08bb8fed authored by GuanHua's avatar GuanHua

feat:添加进货单接口对接

parent e9a14ea1
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { QuestionCircleOutlined } from '@ant-design/icons' import { QuestionCircleOutlined } from '@ant-design/icons'
import { Tooltip } from 'antd' import { Tooltip, message } from 'antd'
import cx from 'classnames' import cx from 'classnames'
import { history } from 'umi' import { history } from 'umi'
import DialogModal from '../components/DialogModal' import DialogModal from '../components/DialogModal'
...@@ -59,6 +59,8 @@ const CommodityDetail = (props) => { ...@@ -59,6 +59,8 @@ const CommodityDetail = (props) => {
const [parameter, setParameter] = useState<number>() // 权益参数 const [parameter, setParameter] = useState<number>() // 权益参数
const [selectCommodityId, setSelectCommodityId] = useState<number>() const [selectCommodityId, setSelectCommodityId] = useState<number>()
const [buyCount, setBuyCount] = useState<number>(1) const [buyCount, setBuyCount] = useState<number>(1)
const [purchaseCount, setPurchaseCount] = useState<number>(0)
let clickFlag = true
useEffect(() => { useEffect(() => {
fetchDetail() fetchDetail()
...@@ -110,13 +112,50 @@ const CommodityDetail = (props) => { ...@@ -110,13 +112,50 @@ const CommodityDetail = (props) => {
} }
} }
const handleAddToPurchase = () => {
if (!selectCommodityId) {
message.destroy()
message.info("请选择商品属性")
return
}
if (clickFlag) {
clickFlag = false
let param = {
commodityUnitPrice: {
id: selectCommodityId
},
count: buyCount
}
PublicApi.postProductPurchaseSaveOrUpdatePurchase(param).then(res => {
clickFlag = true
if (res.code === 1000) {
setPurchaseCount(res.data)
setAddSuccessVisible(true)
}
}).catch(() => {
clickFlag = true
})
}
}
const handleToBuy = () => {
if (!selectCommodityId) {
message.destroy()
message.info("请选择商品属性")
return
}
history.push(`/order`)
}
const renderBtn = () => { const renderBtn = () => {
switch (commodityDetail?.priceType) { switch (commodityDetail?.priceType) {
case COMMODITY_TYPE.prompt: case COMMODITY_TYPE.prompt:
return ( return (
<> <>
<div className={cx(styles.product_info_btn_item, styles.buy)} onClick={() => history.push(`/order`)}>立即订购</div> <div className={cx(styles.product_info_btn_item, styles.buy)} onClick={() => handleToBuy()}>立即订购</div>
<div className={cx(styles.product_info_btn_item, styles.add)} onClick={() => setAddSuccessVisible(true)} > <div className={cx(styles.product_info_btn_item, styles.add)} onClick={() => handleAddToPurchase()} >
<img className={styles.btn_icon} src={jinhuodanIcon} /> <img className={styles.btn_icon} src={jinhuodanIcon} />
<span>加入进货单</span> <span>加入进货单</span>
</div> </div>
...@@ -423,12 +462,12 @@ const CommodityDetail = (props) => { ...@@ -423,12 +462,12 @@ const CommodityDetail = (props) => {
</div> </div>
<div className={styles.add_success_info_text}> <div className={styles.add_success_info_text}>
<span>当前进货单共</span> <span>当前进货单共</span>
<b>3</b> <b>{purchaseCount}</b>
<span>种商品</span> <span>种商品</span>
</div> </div>
</div> </div>
<div className={cx(styles.add_success_btn, styles.primary)}>去结算</div> <div className={cx(styles.add_success_btn, styles.primary)} onClick={() => history.push('/purchaseOrder')}>去结算</div>
<div className={styles.add_success_btn}>继续购物</div> <div className={styles.add_success_btn} onClick={() => setAddSuccessVisible(false)}>继续购物</div>
</div> </div>
<InterestedCommodity /> <InterestedCommodity />
</DialogModal> </DialogModal>
......
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
font-size: 16px; font-size: 16px;
transition: all .3s; transition: all .3s;
&>a {
display: block;
color: #FFF;
}
&:hover { &:hover {
cursor: pointer; cursor: pointer;
// background-color: var(--mall_main_color); // background-color: var(--mall_main_color);
......
import React, { useState } from 'react' import React, { useState } from 'react'
import { history } from 'umi'
import { createFromIconfontCN } from '@ant-design/icons' import { createFromIconfontCN } from '@ant-design/icons'
import FootPrint from './footprint' import FootPrint from './footprint'
import './index.less' import './index.less'
...@@ -20,13 +21,12 @@ const SideNav: React.FC = () => { ...@@ -20,13 +21,12 @@ const SideNav: React.FC = () => {
<div className="side_nav_container"> <div className="side_nav_container">
<div className="side_nav_list"> <div className="side_nav_list">
<div className="side_nav_list_item"> <div className="side_nav_list_item">
<MyIcon type="icon-aixin" /> <MyIcon type="icon-aixin" />
</div> </div>
<div className="side_nav_list_item"> <div className="side_nav_list_item">
<MyIcon type="icon-shoucang" /> <MyIcon type="icon-shoucang" />
</div> </div>
<div className="side_nav_list_item"> <div className="side_nav_list_item" onClick={() => history.push('/purchaseOrder')}>
<MyIcon type="icon-cart" /> <MyIcon type="icon-cart" />
</div> </div>
<div className="side_nav_list_item"> <div className="side_nav_list_item">
......
...@@ -3,7 +3,7 @@ import { Radio, Modal } from 'antd' ...@@ -3,7 +3,7 @@ import { Radio, Modal } from 'antd'
import { DownOutlined } from '@ant-design/icons' import { DownOutlined } from '@ant-design/icons'
import AddAddress from '../components/addAddress' import AddAddress from '../components/addAddress'
import { PublicApi } from '@/services/api' import { PublicApi } from '@/services/api'
import { GetLogisticsReceiverAddressPageResponseDetail } from '@/services/LogisticsApi' import { GetLogisticsReceiverAddressPageResponseDetail, GetLogisticsReceiverAddressGetResponse } from '@/services/LogisticsApi'
import styles from './index.less' import styles from './index.less'
const Address: React.FC = () => { const Address: React.FC = () => {
...@@ -15,10 +15,10 @@ const Address: React.FC = () => { ...@@ -15,10 +15,10 @@ const Address: React.FC = () => {
const [type, setType] = useState<'add' | 'edit'>('add') const [type, setType] = useState<'add' | 'edit'>('add')
useEffect(() => { useEffect(() => {
fetchAddressList() fetchAddressList(true)
}, []) }, [])
const fetchAddressList = () => { const fetchAddressList = (init = false) => {
let param = { let param = {
current: 1, current: 1,
pageSize: 50 pageSize: 50
...@@ -27,10 +27,23 @@ const Address: React.FC = () => { ...@@ -27,10 +27,23 @@ const Address: React.FC = () => {
PublicApi.getLogisticsReceiverAddressPage(param).then(res => { PublicApi.getLogisticsReceiverAddressPage(param).then(res => {
if (res.code === 1000) { if (res.code === 1000) {
setAddressList(res.data?.data) setAddressList(res.data?.data)
if (init) {
initDefaultAddress(res.data?.data)
}
} }
}) })
} }
const initDefaultAddress = (addressList: GetLogisticsReceiverAddressPageResponseDetail[]) => {
let defaultAddrKey
for (let item of addressList) {
if (item.isDefault === 1) {
defaultAddrKey = item.id
}
}
defaultAddrKey && setSelectKey(defaultAddrKey)
}
const handleSelect = (e: any) => { const handleSelect = (e: any) => {
setSelectKey(e.target.value) setSelectKey(e.target.value)
} }
...@@ -57,12 +70,19 @@ const Address: React.FC = () => { ...@@ -57,12 +70,19 @@ const Address: React.FC = () => {
}) })
} }
useEffect(() => { const handleSetDefaultAddress = async (addressItem: GetLogisticsReceiverAddressPageResponseDetail) => {
if (!!editItem) { //@ts-ignore
let addressDetailRes = await PublicApi.getLogisticsReceiverAddressGet({ id: addressItem.id })
let param: GetLogisticsReceiverAddressGetResponse = addressDetailRes.data
param.isDefault = 1
//@ts-ignore
PublicApi.postLogisticsReceiverAddressUpdate(param).then(res => {
if (res.code === 1000) {
fetchAddressList()
} }
})
}, [editItem]) }
return ( return (
<div className={styles.address}> <div className={styles.address}>
...@@ -84,7 +104,7 @@ const Address: React.FC = () => { ...@@ -84,7 +104,7 @@ const Address: React.FC = () => {
<span>{item.phone}</span> <span>{item.phone}</span>
{ {
item.isDefault === 1 ? <div className={styles.default_address}>默认地址</div> : item.isDefault === 1 ? <div className={styles.default_address}>默认地址</div> :
<div className={styles.set_default_address}>设为默认地址</div> <div className={styles.set_default_address} onClick={() => handleSetDefaultAddress(item)}>设为默认地址</div>
} }
{ {
selectKey === item.id && ( selectKey === item.id && (
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
import { Input, Switch, Select, FormMegaLayout } from '@formily/antd-components' import { Input, Switch, Select, FormMegaLayout } from '@formily/antd-components'
import { PublicApi } from '@/services/api' import { PublicApi } from '@/services/api'
import { PATTERN_MAPS } from '@/constants/regExp' import { PATTERN_MAPS } from '@/constants/regExp'
import { GetLogisticsReceiverAddressPageResponseDetail } from '@/services/LogisticsApi' import { GetLogisticsReceiverAddressPageResponseDetail, postLogisticsReceiverAddressUpdate } from '@/services/LogisticsApi'
import ChinaImg from '../../../../../../mockStatic/china.png' import ChinaImg from '../../../../../../mockStatic/china.png'
import japenImg from '../../../../../../mockStatic/japen.png' import japenImg from '../../../../../../mockStatic/japen.png'
import korenImg from '../../../../../../mockStatic/koren.png' import korenImg from '../../../../../../mockStatic/koren.png'
...@@ -44,9 +44,10 @@ interface AddAddressPropsType { ...@@ -44,9 +44,10 @@ interface AddAddressPropsType {
const { Option } = ISelect; const { Option } = ISelect;
const { onFieldValueChange$ } = FormEffectHooks const { onFieldValueChange$ } = FormEffectHooks
const actions = createFormActions()
const AddAddress: React.FC<AddAddressPropsType> = (props) => { const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const actions = createFormActions()
const { visible = false, title, onOk, onCancel, editItem, type } = props const { visible = false, title, onOk, onCancel, editItem, type } = props
const [confirmLoading, setConfirmLoading] = useState<boolean>(false) const [confirmLoading, setConfirmLoading] = useState<boolean>(false)
const [Options, setOptions] = useState([]) const [Options, setOptions] = useState([])
...@@ -58,15 +59,33 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -58,15 +59,33 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const [provinceList, setProvinceList] = useState([]) const [provinceList, setProvinceList] = useState([])
const [cityList, setCityList] = useState([]) const [cityList, setCityList] = useState([])
useEffect(() => { // useEffect(() => {
if (type === 'edit' && !!editItem) { // if (type === 'edit' && !!editItem) {
// actions.setFieldValue('receiverName', editItem.receiverName) // initAddressItemInfo()
// actions.setFieldValue('address', editItem.fullAddress) // }
// actions.setFieldValue('postalCode', editItem.postalCode) // }, [editItem, type])
// actions.setFieldValue('receiverName', editItem.receiverName)
// actions.setFieldValue('phone' editItem.phone) const initAddressItemInfo = async () => {
//@ts-ignore
const addressDetailRes = await PublicApi.getLogisticsReceiverAddressGet({ id: editItem.id })
const addressDetail = addressDetailRes.data
Object.keys(addressDetail).forEach(key => {
actions.setFieldState(key, state => {
if (key == 'isDefault') {
state.value = addressDetail[key] === 0 ? false : true
} else if (key == 'provinceCode') {
state.value = `${addressDetail.provinceCode}-${addressDetail.provinceName}`
} else if (key == 'cityCode') {
state.value = `${addressDetail.cityCode}-${addressDetail.cityName}`
} else if (key == 'districtCode') {
state.value = `${addressDetail.districtCode}-${addressDetail.districtName}`
} else {
state.value = addressDetail[key]
}
})
})
} }
}, [editItem, type])
const selectList: any = [ const selectList: any = [
{ label: <><img src={ChinaImg} key='1' style={{ width: _width, height: _height }} /> +86</>, value: '1' }, { label: <><img src={ChinaImg} key='1' style={{ width: _width, height: _height }} /> +86</>, value: '1' },
...@@ -99,10 +118,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -99,10 +118,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
}) })
}, 1000) }, 1000)
if (type === 'edit' && !!editItem) {
initAddressItemInfo()
}
return () => { return () => {
clearTimeout(getAllCode) clearTimeout(getAllCode)
} }
}, []) }, [editItem, type])
/** /**
* @description: Form保存 * @description: Form保存
...@@ -119,7 +142,15 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -119,7 +142,15 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
value.cityName = cityName value.cityName = cityName
value.districtName = districtName value.districtName = districtName
setConfirmLoading(true) setConfirmLoading(true)
PublicApi.postLogisticsReceiverAddressAdd(value).then(res => { let postLogisticsFn
if (type === 'edit') {
value.id = editItem.id
postLogisticsFn = postLogisticsReceiverAddressUpdate
} else {
postLogisticsFn = PublicApi.postLogisticsReceiverAddressAdd
}
postLogisticsFn(value).then(res => {
setConfirmLoading(false) setConfirmLoading(false)
if (res.code == 1000) { if (res.code == 1000) {
onOk() onOk()
...@@ -195,7 +226,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -195,7 +226,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
maskClosable={false} maskClosable={false}
> >
<SchemaForm <SchemaForm
// editable={state.editable} editable={state.editable}
actions={actions} // 要传递 actions={actions} // 要传递
components={{ components={{
Input, Select, TextArea: Input.TextArea, Switch Input, Select, TextArea: Input.TextArea, Switch
......
...@@ -119,6 +119,10 @@ ...@@ -119,6 +119,10 @@
color: #999999; color: #999999;
font-size: 12px; font-size: 12px;
&:hover {
color: var(--mall_main_color);
}
&:not(:last-child) { &:not(:last-child) {
margin-bottom: 10px; margin-bottom: 10px;
} }
......
...@@ -6,6 +6,8 @@ import { history } from 'umi' ...@@ -6,6 +6,8 @@ import { history } from 'umi'
import cx from 'classnames' import cx from 'classnames'
import { Checkbox, Affix } from 'antd' import { Checkbox, Affix } from 'antd'
import styles from './index.less' import styles from './index.less'
import { PublicApi } from '@/services/api'
import { GetProductPurchaseGetPurchaseListResponse } from '@/services/ProductApi'
interface PurchaseOrderPropsType { interface PurchaseOrderPropsType {
...@@ -51,17 +53,39 @@ let defaultMockData = [ ...@@ -51,17 +53,39 @@ let defaultMockData = [
] ]
}, },
] ]
const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => { const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => {
const [buyCount, setBuyCount] = useState<number>(1) const [buyCount, setBuyCount] = useState<number>(1)
const [indeterminate, setIndeterminate] = useState<boolean>(false) const [indeterminate, setIndeterminate] = useState<boolean>(false)
const [checkAll, setCheckAll] = useState<boolean>(true) const [checkAll, setCheckAll] = useState<boolean>(true)
const [checkedList, setCheckedList] = useState([]) const [checkedList, setCheckedList] = useState([])
const [orderList, setOrderList] = useState([]) const [orderList, setOrderList] = useState([])
const [purchaseList, setPurchaseList] = useState([])
useEffect(() => { useEffect(() => {
initMockData(defaultMockData) initMockData(defaultMockData)
fetchPurchaseList()
}, []) }, [])
const fetchPurchaseList = () => {
PublicApi.getProductPurchaseGetPurchaseList().then(res => {
if (res.code === 1000) {
initPurchaseList(res.data)
}
})
}
const initPurchaseList = (list: GetProductPurchaseGetPurchaseListResponse) => {
let result = []
for (let item of list) {
let temp: any = {}
// temp.id =
}
}
const initMockData = (list: any, initChecked?: any) => { const initMockData = (list: any, initChecked?: any) => {
let result = list.map(item => { let result = list.map(item => {
return Object.assign(item, { return Object.assign(item, {
......
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