Commit 935fef95 authored by GuanHua's avatar GuanHua

fix: 修复商城下单时编辑地址多次打开后模态框内没数据的问题

parent 5eb7d90a
...@@ -79,7 +79,7 @@ const Address: React.FC<AddressPropsType> = (props) => { ...@@ -79,7 +79,7 @@ const Address: React.FC<AddressPropsType> = (props) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
PublicApi.postLogisticsReceiverAddressDelete({ id }).then(res => { PublicApi.postLogisticsReceiverAddressDelete({ id }).then(res => {
if (res.code === 1000) { if (res.code === 1000) {
resolve() resolve(true)
fetchAddressList() fetchAddressList()
} }
}).catch(() => { }).catch(() => {
......
...@@ -11,19 +11,9 @@ import { Input, Switch, Select, FormMegaLayout } from '@formily/antd-components' ...@@ -11,19 +11,9 @@ 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 } from '@/services/LogisticsApi'
import ChinaImg from '../../../../../../mockStatic/china.png'
import japenImg from '../../../../../../mockStatic/japen.png'
import korenImg from '../../../../../../mockStatic/koren.png'
import us from '../../../../../../mockStatic/us.png'
import styles from './index.less' import styles from './index.less'
import { isEmpty } from 'lodash'
const _width: number = 24
const _height: number = 17
interface countryItem {
name: string,
key: string,
icon: string
}
//列表带来的参数 //列表带来的参数
export interface ListProps { export interface ListProps {
title?: React.ReactNode title?: React.ReactNode
...@@ -50,24 +40,19 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -50,24 +40,19 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
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 [telCodeList, setTelCodeList] = useState([])
const [state, setState] = useState({ editable: true }) const [state] = useState({ editable: true })
const [provinceName, setProvinceName] = useState('') const [provinceName, setProvinceName] = useState('')
const [cityName, setCityName] = useState('') const [cityName, setCityName] = useState('')
const [districtName, setDistrictName] = useState('') const [districtName, setDistrictName] = useState('')
const [headerTitle, setHeaderTitle] = useState('')
const [provinceList, setProvinceList] = useState([]) const [provinceList, setProvinceList] = useState([])
const [cityList, setCityList] = useState([]) const [cityList] = useState([])
const [telCode, setTelCode] = useState<any>([])
// useEffect(() => {
// if (type === 'edit' && !!editItem) {
// initAddressItemInfo()
// }
// }, [editItem, type])
const initAddressItemInfo = async () => { const initAddressItemInfo = async () => {
//@ts-ignore const param: any = {
const addressDetailRes = await PublicApi.getLogisticsReceiverAddressGet({ id: editItem.id }) id: editItem.id
}
const addressDetailRes = await PublicApi.getLogisticsReceiverAddressGet(param)
const addressDetail = addressDetailRes.data const addressDetail = addressDetailRes.data
Object.keys(addressDetail).forEach(key => { Object.keys(addressDetail).forEach(key => {
...@@ -87,49 +72,54 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -87,49 +72,54 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
}) })
} }
// const selectList: any = [ const fetchCountryAreaTelCode = () => {
// { label: <><img src={ChinaImg} key='1' style={{ width: _width, height: _height }} /> +86</>, value: '1' }, if(isEmpty(telCodeList)) {
// { label: <><img src={japenImg} key='3' style={{ width: _width, height: _height }} /> +86</>, value: '3' }, PublicApi.getManageCountryAreaGetTelCode().then(res => {
// { label: <><img src={korenImg} key='4' style={{ width: _width, height: _height }} /> +86</>, value: '4' }, const result: any = []
// { label: <><img src={us} key='5' style={{ width: _width, height: _height }} /> +86</>, value: '5' } res.data.forEach((item, index) => {
// ] result.push({ label: item, value: (index).toString() })
// let _Options: any = []
let TelCodeList: any = []
useEffect(() => {
PublicApi.getManageCountryAreaGetTelCode().then(res => {
res.data.forEach((item, index) => {
TelCodeList.push({ label: item, value: (index).toString() })
})
setOptions(TelCodeList)
})
const getAllCode = setTimeout(() => {
PublicApi.getManageAreaByPcodeAll({ pcode: '100000' }).then(res => {
let list = []
res.data.forEach((item: any, index: number) => {
list.push({ label: item.name, value: `${item.code}-${item.name}` })
// list.push({ label: item.name, value: item.code })
}) })
setProvinceList(list) setTelCodeList(result)
}) })
}, 1000)
if (type === 'edit' && !!editItem) {
initAddressItemInfo()
} }
}
return () => {
clearTimeout(getAllCode) useEffect(() => {
if(visible) {
fetchCountryAreaTelCode()
let getAllCode = null
if(isEmpty(provinceList)) {
getAllCode = setTimeout(() => {
PublicApi.getManageAreaByPcodeAll({ pcode: '100000' }).then(res => {
const list = []
res.data.forEach((item: any, index: number) => {
list.push({ label: item.name, value: `${item.code}-${item.name}` })
})
setProvinceList(list)
})
}, 1000)
}
if (type === 'edit' && editItem) {
initAddressItemInfo()
}
return () => {
clearTimeout(getAllCode)
}
} }
}, [editItem, type]) }, [editItem, type, visible])
/** /**
* @description: Form保存 * @description: Form保存
* @param {type} * @param {type}
* @return: * @return:
*/ */
const formSubmit = (values) => { const formSubmit = (values) => {
let 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.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.cityCode = value.cityCode.split('-').length > 1 ? value.cityCode.split('-')[0] : value.cityCode
...@@ -158,8 +148,8 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -158,8 +148,8 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
/** /**
* @description: 自定义HOOK * @description: 自定义HOOK
* @param {type} * @param {type}
* @return: * @return:
*/ */
const useAreaEffects = () => { const useAreaEffects = () => {
const { setFieldState } = createFormActions() const { setFieldState } = createFormActions()
...@@ -167,12 +157,12 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -167,12 +157,12 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
setFieldState('districtCode', state => { setFieldState('districtCode', state => {
state.value = '' state.value = ''
}) })
let name = value && value.split('-').length > 1 ? value.split('-')[1] : '' const name = value && value.split('-').length > 1 ? value.split('-')[1] : ''
setProvinceName(name) setProvinceName(name)
setFieldState('*(cityCode)', state => { setFieldState('*(cityCode)', state => {
state.value = '' state.value = ''
let list = [] const list = []
let pcode = value && value.split('-').length > 1 ? value.split('-')[0] : value const pcode = value && value.split('-').length > 1 ? value.split('-')[0] : 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, index: number) => {
// list.push({ label: item.name, value: item.code }) // list.push({ label: item.name, value: item.code })
...@@ -184,12 +174,12 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -184,12 +174,12 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
}) })
onFieldValueChange$('cityCode').subscribe(({ value }) => { onFieldValueChange$('cityCode').subscribe(({ value }) => {
let name = value && value.split('-').length > 1 ? value.split('-')[1] : '' const name = value && value.split('-').length > 1 ? value.split('-')[1] : ''
setCityName(name) setCityName(name)
setFieldState('*(districtCode)', state => { setFieldState('*(districtCode)', state => {
state.value = '' state.value = ''
let list = [] const list = []
let pcode = value && value.split('-').length > 1 ? value.split('-')[0] : value const pcode = value && value.split('-').length > 1 ? value.split('-')[0] : 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, index: number) => {
// list.push({ label: item.name, value: item.code }) // list.push({ label: item.name, value: item.code })
...@@ -200,7 +190,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -200,7 +190,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
}) })
}) })
onFieldValueChange$('districtCode').subscribe(({ value }) => { onFieldValueChange$('districtCode').subscribe(({ value }) => {
let name = value && value.split('-').length > 1 ? value.split('-')[1] : '' const name = value && value.split('-').length > 1 ? value.split('-')[1] : ''
setDistrictName(name) setDistrictName(name)
}) })
} }
...@@ -316,7 +306,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => { ...@@ -316,7 +306,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
message: '请选择区号', message: '请选择区号',
}} }}
x-component="Select" x-component="Select"
enum={Options} enum={telCodeList}
x-component-props={{ x-component-props={{
placeholder: '请选择' placeholder: '请选择'
}} }}
......
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