Commit 65fdba3d authored by GuanHua's avatar GuanHua

feat:对接订单收货地址接口

parent c870f334
......@@ -99,7 +99,7 @@ const CommodityDetail = (props) => {
case COMMODITY_TYPE.prompt:
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={() => history.push(`/order`)}>立即订购</div>
<div className={cx(styles.product_info_btn_item, styles.add)} onClick={() => setAddSuccessVisible(true)} >
<img className={styles.btn_icon} src={jinhuodanIcon} />
<span>加入进货单</span>
......
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Radio } from 'antd'
import { DownOutlined } from '@ant-design/icons'
import AddAddress from '../components/addAddress'
import { PublicApi } from '@/services/api'
import { GetLogisticsReceiverAddressPageResponseDetail } from '@/services/LogisticsApi'
import styles from './index.less'
const Address: React.FC = () => {
const [selectKey, setSelectKey] = useState<number>()
const [expand, setExpand] = useState<boolean>(false)
const [addressFormVisible, setAddressFormVisible] = useState<boolean>(false)
const [addressList, setAddressList] = useState<GetLogisticsReceiverAddressPageResponseDetail[]>([])
const mock_data = [
{
......@@ -54,6 +57,23 @@ const Address: React.FC = () => {
}
]
useEffect(() => {
fetchAddressList()
}, [])
const fetchAddressList = () => {
let param = {
current: 1,
pageSize: 50
}
//@ts-ignore
PublicApi.getLogisticsReceiverAddressPage(param).then(res => {
if (res.code === 1000) {
setAddressList(res.data?.data)
}
})
}
const handleSelect = (e: any) => {
setSelectKey(e.target.value)
}
......@@ -67,12 +87,12 @@ const Address: React.FC = () => {
<Radio.Group className={styles.address_raido_group} value={selectKey} onChange={handleSelect}>
<div className={styles.address_list}>
{
mock_data.map((item, index) => (!expand ? index < 3 : true) && (
addressList.map((item, index) => (!expand ? index < 3 : true) && (
<Radio className={styles.address_list_radio} value={item.id} key={`address_list_radio_${item.id}`}>
<div className={styles.adderss_list_radio_line}>
<span>{item.name}</span>
<span>{item.address}</span>
<span>{item.mobile}</span>
<span>{item.receiverName}</span>
<span>{item.fullAddress}</span>
<span>{item.phone}</span>
{
item.isDefault === 1 ? <div className={styles.default_address}>默认地址</div> :
<div className={styles.set_default_address}>设为默认地址</div>
......@@ -91,18 +111,25 @@ const Address: React.FC = () => {
}
</div>
</Radio.Group>
<div className={styles.more_btn} onClick={() => setExpand(!expand)}>
<span>{expand ? '收起' : '更多地址'}</span>
<div className={styles.more_btn_icon}>
<DownOutlined rotate={expand ? 180 : 0} />
</div>
</div>
{
addressList.length > 3 && (
<div className={styles.more_btn} onClick={() => setExpand(!expand)}>
<span>{expand ? '收起' : '更多地址'}</span>
<div className={styles.more_btn_icon}>
<DownOutlined rotate={expand ? 180 : 0} />
</div>
</div>
)
}
<AddAddress
title="新增收货地址"
visible={addressFormVisible}
onCancel={() => setAddressFormVisible(false)}
onOk={() => {
setAddressFormVisible(false)
fetchAddressList()
}}
/>
</div>
)
}
......
......@@ -45,6 +45,7 @@ const { onFieldValueChange$ } = FormEffectHooks
const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const { visible = false, title, onOk, onCancel } = props
const [confirmLoading, setConfirmLoading] = useState<boolean>(false)
const [Options, setOptions] = useState([])
const [state, setState] = useState({ editable: true })
const [provinceName, setProvinceName] = useState('')
......@@ -96,7 +97,6 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
* @return:
*/
const formSubmit = (values) => {
console.log(values)
let id = 0 //0新建
let type = 2 //'1' 发货 '2'收货
let value = { ...values }
......@@ -107,10 +107,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
value.provinceName = provinceName
value.cityName = cityName
value.districtName = districtName
setConfirmLoading(true)
PublicApi.postLogisticsReceiverAddressAdd(value).then(res => {
setConfirmLoading(false)
if (res.code == 1000) {
onOk()
}
}).catch(() => {
setConfirmLoading(false)
})
}
......@@ -122,7 +126,6 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const useAreaEffects = () => {
const { setFieldState } = createFormActions()
onFieldValueChange$('provinceCode').subscribe(({ value }) => {
console.log(value)
setFieldState('districtCode', state => {
state.value = ''
})
......@@ -143,7 +146,6 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
})
onFieldValueChange$('cityCode').subscribe(({ value }) => {
console.log(value)
let name = value && value.split('-').length > 1 ? value.split('-')[1] : ''
setCityName(name)
setFieldState('*(districtCode)', state => {
......@@ -176,6 +178,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
onOk={handleOk}
width={600}
centered
confirmLoading={confirmLoading}
className={styles.common_add_modal}
onCancel={onCancel}
maskClosable={false}
......
......@@ -60,7 +60,9 @@
background-color: var(--mall_main_color);
border-color: var(--mall_main_color);
&:hover {
&:hover,
&:focus,
&:active {
color: #ffffff;
opacity: .9;
}
......
......@@ -55,6 +55,7 @@ const errorHandler = (error: ResponseError): IRequestError => {
const defaultHeaders = {
'Content-Type': 'Application/json',
'source': '1',
'environment': '1',
'site': GlobalConfig.global.siteId.toString()
}
......@@ -76,7 +77,8 @@ baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit):
...options.headers,
userId,
memberId,
token
token,
}
options.paramsSerializer = params => {
return qs.stringify(params, { arrayFormat: 'brackets' })
......
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