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
26738ceb
Commit
26738ceb
authored
Aug 10, 2021
by
XieZhiXiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复现有地址无法点击确认的问题
parent
aeb13370
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
98 deletions
+95
-98
index.tsx
src/components/AddressSelect/index.tsx
+94
-91
schema.ts
src/components/AddressSelect/schema.ts
+1
-7
No files found.
src/components/AddressSelect/index.tsx
View file @
26738ceb
...
...
@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-08-05 10:28:06
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-
09 16:52:37
* @LastEditTime: 2021-08-
10 10:20:55
* @Description: 地址选择 FormItem
*/
import
React
,
{
useState
,
useEffect
,
useMemo
,
useRef
}
from
'react'
;
...
...
@@ -204,99 +204,102 @@ const AddressSelect: React.FC<IProps> = (props) => {
const
handleSubmit
=
async
(
values
:
SubmitValuesType
)
=>
{
let
next
=
values
.
address
;
const
originData
=
formActions
.
getFieldState
(
'provinceCode'
,
(
fieldState
)
=>
{
return
fieldState
.
originData
;
});
if
(
!
originData
)
{
message
.
warn
(
'未找到地区信息'
);
return
;
}
const
currentProvince
=
originData
.
find
((
item
)
=>
item
.
code
===
values
.
provinceCode
);
const
currentCity
=
currentProvince
?.
areaResponses
?.
find
((
item
)
=>
item
.
code
===
values
.
cityCode
);
const
currentDistrict
=
currentCity
?.
areaResponses
?.
find
((
item
)
=>
item
.
code
===
values
.
districtCode
);
const
provinceName
=
currentProvince
?.
name
;
const
cityName
=
currentCity
?.
name
;
const
districtName
=
currentDistrict
?.
name
;
const
{
name
,
detailed
,
isDefault
,
...
rest
}
=
values
;
const
commonPayload
=
{
...
rest
,
id
:
0
,
provinceName
,
cityName
,
districtName
,
address
:
detailed
,
isDefault
:
isDefault
?
1
:
0
,
};
// 新增地址
if
(
values
.
name
&&
!
editAddressId
.
current
)
{
try
{
setSubmitLoading
(
true
);
const
addRes
=
addressType
===
2
?
await
PublicApi
.
postLogisticsShipperAddressAdd
({
...
commonPayload
,
shipperName
:
name
,
})
:
await
PublicApi
.
postLogisticsReceiverAddressAdd
({
...
commonPayload
,
receiverName
:
name
,
});
if
(
addRes
.
code
===
1000
)
{
next
=
{
fullAddress
:
`
${
provinceName
}${
cityName
}${
districtName
}
`
,
id
:
addRes
.
data
?.
id
,
isDefault
:
values
.
isDefault
?
1
:
0
,
name
:
values
.
name
,
phone
:
values
.
tel
,
};
// 重新获取列表,打新添加的内容加载出来
getAddressList
();
formActions
.
reset
({
selector
:
'ADDRESS_NEW.*'
,
validate
:
false
});
formActions
.
setFieldState
(
'ADDRESS_NEW'
,
state
=>
{
state
.
visible
=
false
;
});
// 有值表示是新增 或 修改操作
if
(
values
.
name
)
{
const
originData
=
formActions
.
getFieldState
(
'provinceCode'
,
(
fieldState
)
=>
{
return
fieldState
.
originData
;
});
if
(
!
originData
)
{
message
.
warn
(
'未找到地区信息'
);
return
;
}
const
currentProvince
=
originData
.
find
((
item
)
=>
item
.
code
===
values
.
provinceCode
);
const
currentCity
=
currentProvince
?.
areaResponses
?.
find
((
item
)
=>
item
.
code
===
values
.
cityCode
);
const
currentDistrict
=
currentCity
?.
areaResponses
?.
find
((
item
)
=>
item
.
code
===
values
.
districtCode
);
const
provinceName
=
currentProvince
?.
name
;
const
cityName
=
currentCity
?.
name
;
const
districtName
=
currentDistrict
?.
name
;
const
{
name
,
detailed
,
isDefault
,
...
rest
}
=
values
;
const
commonPayload
=
{
...
rest
,
id
:
0
,
provinceName
,
cityName
,
districtName
,
address
:
detailed
,
isDefault
:
isDefault
?
1
:
0
,
};
// 新增地址
if
(
!
editAddressId
.
current
)
{
try
{
setSubmitLoading
(
true
);
const
addRes
=
addressType
===
2
?
await
PublicApi
.
postLogisticsShipperAddressAdd
({
...
commonPayload
,
shipperName
:
name
,
})
:
await
PublicApi
.
postLogisticsReceiverAddressAdd
({
...
commonPayload
,
receiverName
:
name
,
});
if
(
addRes
.
code
===
1000
)
{
next
=
{
fullAddress
:
`
${
provinceName
}${
cityName
}${
districtName
}
`
,
id
:
addRes
.
data
?.
id
,
isDefault
:
values
.
isDefault
?
1
:
0
,
name
:
values
.
name
,
phone
:
values
.
tel
,
};
// 重新获取列表,打新添加的内容加载出来
getAddressList
();
formActions
.
reset
({
selector
:
'ADDRESS_NEW.*'
,
validate
:
false
});
formActions
.
setFieldState
(
'ADDRESS_NEW'
,
state
=>
{
state
.
visible
=
false
;
});
}
setSubmitLoading
(
false
);
}
catch
(
error
)
{
console
.
warn
(
error
)
}
setSubmitLoading
(
false
);
}
catch
(
error
)
{
console
.
warn
(
error
)
}
}
// 编辑地址
if
(
values
.
name
&&
editAddressId
.
current
)
{
try
{
setSubmitLoading
(
true
);
const
addRes
=
addressType
===
2
?
await
PublicApi
.
postLogisticsShipperAddressUpdate
({
...
commonPayload
,
id
:
editAddressId
.
current
,
shipperName
:
name
,
})
:
await
PublicApi
.
postLogisticsReceiverAddressUpdate
({
...
commonPayload
,
id
:
editAddressId
.
current
,
receiverName
:
name
,
});
if
(
addRes
.
code
===
1000
)
{
next
=
{
fullAddress
:
`
${
provinceName
}${
cityName
}${
districtName
}
`
,
id
:
editAddressId
.
current
,
isDefault
:
values
.
isDefault
?
1
:
0
,
name
:
values
.
name
,
phone
:
values
.
tel
,
};
// 重新获取列表,打新添加的内容加载出来
getAddressList
();
editAddressId
.
current
=
null
;
formActions
.
reset
({
selector
:
'ADDRESS_NEW.*'
});
// 编辑地址
if
(
editAddressId
.
current
)
{
try
{
setSubmitLoading
(
true
);
const
addRes
=
addressType
===
2
?
await
PublicApi
.
postLogisticsShipperAddressUpdate
({
...
commonPayload
,
id
:
editAddressId
.
current
,
shipperName
:
name
,
})
:
await
PublicApi
.
postLogisticsReceiverAddressUpdate
({
...
commonPayload
,
id
:
editAddressId
.
current
,
receiverName
:
name
,
});
if
(
addRes
.
code
===
1000
)
{
next
=
{
fullAddress
:
`
${
provinceName
}${
cityName
}${
districtName
}
`
,
id
:
editAddressId
.
current
,
isDefault
:
values
.
isDefault
?
1
:
0
,
name
:
values
.
name
,
phone
:
values
.
tel
,
};
// 重新获取列表,打新添加的内容加载出来
getAddressList
();
editAddressId
.
current
=
null
;
formActions
.
reset
({
selector
:
'ADDRESS_NEW.*'
});
}
setSubmitLoading
(
false
);
}
catch
(
error
)
{
console
.
warn
(
error
)
}
setSubmitLoading
(
false
);
}
catch
(
error
)
{
console
.
warn
(
error
)
}
}
if
(
!
(
'value'
in
props
))
{
...
...
src/components/AddressSelect/schema.ts
View file @
26738ceb
...
...
@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-08-05 14:02:46
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-
06 14:46:35
* @LastEditTime: 2021-08-
10 14:05:13
* @Description:
*/
import
{
ISchema
}
from
'@formily/antd'
;
...
...
@@ -35,12 +35,6 @@ export const createSchema = (addressType = 2): ISchema => {
'x-component-props'
:
{
onClickEdit
:
'{{ handleEditAddress }}'
,
},
'x-rules'
:
[
{
required
:
true
,
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