Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenshaokai
jinfa-platform
Commits
cd53255e
Commit
cd53255e
authored
Mar 18, 2021
by
GuanHua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 商城下单页面收货地址编辑问题
parent
eb48ad23
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
38 deletions
+41
-38
index.tsx
src/pages/lxMall/order/components/addAddress/index.tsx
+41
-38
No files found.
src/pages/lxMall/order/components/addAddress/index.tsx
View file @
cd53255e
...
@@ -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
,
postLogisticsReceiverAddressUpdate
}
from
'@/services/LogisticsApi'
import
{
GetLogisticsReceiverAddressPageResponseDetail
,
postLogisticsReceiverAddressUpdate
,
GetLogisticsReceiverAddressGetResponse
}
from
'@/services/LogisticsApi'
import
styles
from
'./index.less'
import
styles
from
'./index.less'
import
{
isEmpty
}
from
'lodash'
import
{
isEmpty
}
from
'lodash'
...
@@ -46,13 +46,16 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -46,13 +46,16 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const
[
cityName
,
setCityName
]
=
useState
(
''
)
const
[
cityName
,
setCityName
]
=
useState
(
''
)
const
[
districtName
,
setDistrictName
]
=
useState
(
''
)
const
[
districtName
,
setDistrictName
]
=
useState
(
''
)
const
[
provinceList
,
setProvinceList
]
=
useState
([])
const
[
provinceList
,
setProvinceList
]
=
useState
([])
const
[
cityList
]
=
useState
([])
const
[
cityList
,
setCityList
]
=
useState
([])
const
[
districtList
,
setDistrictList
]
=
useState
([])
// const [addressDetail, setAddressDetail] = useState<GetLogisticsReceiverAddressGetResponse>()
const
initAddressItemInfo
=
async
()
=>
{
const
initAddressItemInfo
=
async
()
=>
{
const
param
:
any
=
{
const
param
:
any
=
{
id
:
editItem
.
id
id
:
editItem
.
id
}
}
const
addressDetailRes
=
await
PublicApi
.
getLogisticsReceiverAddressGet
(
param
)
const
addressDetailRes
=
await
PublicApi
.
getLogisticsReceiverAddressGet
(
param
)
// setAddressDetail(addressDetailRes.data)
const
addressDetail
=
addressDetailRes
.
data
const
addressDetail
=
addressDetailRes
.
data
Object
.
keys
(
addressDetail
).
forEach
(
key
=>
{
Object
.
keys
(
addressDetail
).
forEach
(
key
=>
{
...
@@ -60,11 +63,11 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -60,11 +63,11 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
if
(
key
==
'isDefault'
)
{
if
(
key
==
'isDefault'
)
{
state
.
value
=
addressDetail
[
key
]
===
0
?
false
:
true
state
.
value
=
addressDetail
[
key
]
===
0
?
false
:
true
}
else
if
(
key
==
'provinceCode'
)
{
}
else
if
(
key
==
'provinceCode'
)
{
state
.
value
=
`
${
addressDetail
.
provinceCode
}
-
${
addressDetail
.
provinceName
}
`
state
.
value
=
`
${
addressDetail
.
provinceCode
}
`
}
else
if
(
key
==
'cityCode'
)
{
}
else
if
(
key
==
'cityCode'
)
{
state
.
value
=
`
${
addressDetail
.
cityCode
}
-
${
addressDetail
.
cityName
}
`
state
.
value
=
`
${
addressDetail
.
cityCode
}
`
}
else
if
(
key
==
'districtCode'
)
{
}
else
if
(
key
==
'districtCode'
)
{
state
.
value
=
`
${
addressDetail
.
districtCode
}
-
${
addressDetail
.
districtName
}
`
state
.
value
=
`
${
addressDetail
.
districtCode
}
`
}
else
{
}
else
{
state
.
value
=
addressDetail
[
key
]
state
.
value
=
addressDetail
[
key
]
}
}
...
@@ -76,16 +79,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -76,16 +79,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
if
(
isEmpty
(
telCodeList
))
{
if
(
isEmpty
(
telCodeList
))
{
PublicApi
.
getManageCountryAreaGetTelCode
().
then
(
res
=>
{
PublicApi
.
getManageCountryAreaGetTelCode
().
then
(
res
=>
{
const
result
:
any
=
[]
const
result
:
any
=
[]
res
.
data
.
forEach
((
item
,
index
)
=>
{
res
.
data
.
forEach
((
item
)
=>
{
result
.
push
({
label
:
item
,
value
:
(
index
).
toString
()
})
result
.
push
({
label
:
item
,
value
:
item
})
})
})
setTelCodeList
(
result
)
setTelCodeList
(
result
)
})
})
}
}
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
visible
)
{
if
(
visible
)
{
fetchCountryAreaTelCode
()
fetchCountryAreaTelCode
()
...
@@ -94,15 +95,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -94,15 +95,14 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
getAllCode
=
setTimeout
(()
=>
{
getAllCode
=
setTimeout
(()
=>
{
PublicApi
.
getManageAreaByPcodeAll
({
pcode
:
'100000'
}).
then
(
res
=>
{
PublicApi
.
getManageAreaByPcodeAll
({
pcode
:
'100000'
}).
then
(
res
=>
{
const
list
=
[]
const
list
=
[]
res
.
data
.
forEach
((
item
:
any
,
index
:
number
)
=>
{
res
.
data
.
forEach
((
item
:
any
)
=>
{
list
.
push
({
label
:
item
.
name
,
value
:
`
${
item
.
code
}
-
${
item
.
name
}
`
})
list
.
push
({
label
:
item
.
name
,
value
:
item
.
code
})
})
})
setProvinceList
(
list
)
setProvinceList
(
list
)
})
})
},
1000
)
},
1000
)
}
}
if
(
type
===
'edit'
&&
editItem
)
{
if
(
type
===
'edit'
&&
editItem
)
{
initAddressItemInfo
()
initAddressItemInfo
()
}
}
...
@@ -121,12 +121,10 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -121,12 +121,10 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const
formSubmit
=
(
values
)
=>
{
const
formSubmit
=
(
values
)
=>
{
const
value
=
{
...
values
}
const
value
=
{
...
values
}
value
.
isDefault
=
values
.
isDefault
?
1
:
0
value
.
isDefault
=
values
.
isDefault
?
1
:
0
value
.
provinceCode
=
value
.
provinceCode
.
split
(
'-'
).
length
>
1
?
value
.
provinceCode
.
split
(
'-'
)[
0
]
:
value
.
provinceCode
value
.
cityCode
=
value
.
cityCode
.
split
(
'-'
).
length
>
1
?
value
.
cityCode
.
split
(
'-'
)[
0
]
:
value
.
cityCode
value
.
provinceName
=
getNameByCode
(
value
.
provinceCode
,
provinceList
)
value
.
districtCode
=
value
.
districtCode
.
split
(
'-'
).
length
>
1
?
value
.
districtCode
.
split
(
'-'
)[
0
]
:
value
.
districtCode
value
.
cityName
=
getNameByCode
(
value
.
cityCode
,
cityList
)
value
.
provinceName
=
provinceName
value
.
districtName
=
getNameByCode
(
value
.
districtCode
,
districtList
)
value
.
cityName
=
cityName
value
.
districtName
=
districtName
setConfirmLoading
(
true
)
setConfirmLoading
(
true
)
let
postLogisticsFn
let
postLogisticsFn
if
(
type
===
'edit'
)
{
if
(
type
===
'edit'
)
{
...
@@ -146,6 +144,19 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -146,6 +144,19 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
})
})
}
}
const
getNameByCode
=
(
code
,
list
)
=>
{
if
(
list
&&
code
)
{
let
result
=
""
list
.
forEach
(
item
=>
{
if
(
item
.
value
===
code
)
{
result
=
item
.
label
}
});
return
result
}
return
""
}
/**
/**
* @description: 自定义HOOK
* @description: 自定义HOOK
* @param {type}
* @param {type}
...
@@ -154,45 +165,37 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -154,45 +165,37 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const
useAreaEffects
=
()
=>
{
const
useAreaEffects
=
()
=>
{
const
{
setFieldState
}
=
createFormActions
()
const
{
setFieldState
}
=
createFormActions
()
onFieldValueChange$
(
'provinceCode'
).
subscribe
(({
value
})
=>
{
onFieldValueChange$
(
'provinceCode'
).
subscribe
(({
value
})
=>
{
if
(
!
value
)
return
setFieldState
(
'districtCode'
,
state
=>
{
setFieldState
(
'districtCode'
,
state
=>
{
state
.
value
=
''
state
.
value
=
''
})
})
const
name
=
value
&&
value
.
split
(
'-'
).
length
>
1
?
value
.
split
(
'-'
)[
1
]
:
''
setFieldState
(
'*(cityCode)'
,
(
state
)
=>
{
setProvinceName
(
name
)
setFieldState
(
'*(cityCode)'
,
state
=>
{
state
.
value
=
''
state
.
value
=
''
const
list
=
[]
const
list
=
[]
const
pcode
=
value
&&
value
.
split
(
'-'
).
length
>
1
?
value
.
split
(
'-'
)[
0
]
:
value
const
pcode
=
value
PublicApi
.
getManageAreaByPcodeAll
({
pcode
:
pcode
}).
then
(
res
=>
{
PublicApi
.
getManageAreaByPcodeAll
({
pcode
:
pcode
}).
then
(
res
=>
{
res
.
data
.
forEach
((
item
:
any
,
index
:
number
)
=>
{
res
.
data
.
forEach
((
item
:
any
)
=>
{
// list.push({ label: item.name, value: item.code })
list
.
push
({
label
:
item
.
name
,
value
:
item
.
code
})
list
.
push
({
label
:
item
.
name
,
value
:
`
${
item
.
code
}
-
${
item
.
name
}
`
})
})
})
setCityList
(
list
)
})
})
FormPath
.
setIn
(
state
,
'props.enum'
,
list
)
})
})
})
})
onFieldValueChange$
(
'cityCode'
).
subscribe
(({
value
})
=>
{
onFieldValueChange$
(
'cityCode'
).
subscribe
(({
value
})
=>
{
const
name
=
value
&&
value
.
split
(
'-'
).
length
>
1
?
value
.
split
(
'-'
)[
1
]
:
''
if
(
!
value
)
return
setCityName
(
name
)
setFieldState
(
'*(districtCode)'
,
state
=>
{
setFieldState
(
'*(districtCode)'
,
state
=>
{
state
.
value
=
''
state
.
value
=
''
const
list
=
[]
const
list
=
[]
const
pcode
=
value
&&
value
.
split
(
'-'
).
length
>
1
?
value
.
split
(
'-'
)[
0
]
:
value
const
pcode
=
value
PublicApi
.
getManageAreaByPcodeAll
({
pcode
:
pcode
}).
then
(
res
=>
{
PublicApi
.
getManageAreaByPcodeAll
({
pcode
:
pcode
}).
then
(
res
=>
{
res
.
data
.
forEach
((
item
:
any
,
index
:
number
)
=>
{
res
.
data
.
forEach
((
item
:
any
)
=>
{
// list.push({ label: item.name, value: item.code })
list
.
push
({
label
:
item
.
name
,
value
:
item
.
code
})
list
.
push
({
label
:
item
.
name
,
value
:
`
${
item
.
code
}
-
${
item
.
name
}
`
})
})
})
setDistrictList
(
list
)
})
})
FormPath
.
setIn
(
state
,
'props.enum'
,
list
)
})
})
})
})
onFieldValueChange$
(
'districtCode'
).
subscribe
(({
value
})
=>
{
const
name
=
value
&&
value
.
split
(
'-'
).
length
>
1
?
value
.
split
(
'-'
)[
1
]
:
''
setDistrictName
(
name
)
})
}
}
const
handleOk
=
()
=>
{
const
handleOk
=
()
=>
{
...
@@ -264,7 +267,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
...
@@ -264,7 +267,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
<
Field
<
Field
x
-
mega
-
props=
{
{
span
:
1
}
}
x
-
mega
-
props=
{
{
span
:
1
}
}
x
-
component=
"Select"
x
-
component=
"Select"
enum=
{
[]
}
enum=
{
districtList
}
x
-
rules=
{
{
x
-
rules=
{
{
required
:
true
,
required
:
true
,
message
:
'请选择区'
,
message
:
'请选择区'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment