Commit 30100405 authored by XieZhiXiong's avatar XieZhiXiong
parents da292250 935fef95
......@@ -79,7 +79,7 @@ const Address: React.FC<AddressPropsType> = (props) => {
return new Promise((resolve, reject) => {
PublicApi.postLogisticsReceiverAddressDelete({ id }).then(res => {
if (res.code === 1000) {
resolve()
resolve(true)
fetchAddressList()
}
}).catch(() => {
......
......@@ -11,19 +11,9 @@ import { Input, Switch, Select, FormMegaLayout } from '@formily/antd-components'
import { PublicApi } from '@/services/api'
import { PATTERN_MAPS } from '@/constants/regExp'
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 { isEmpty } from 'lodash'
const _width: number = 24
const _height: number = 17
interface countryItem {
name: string,
key: string,
icon: string
}
//列表带来的参数
export interface ListProps {
title?: React.ReactNode
......@@ -50,24 +40,19 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
const { visible = false, title, onOk, onCancel, editItem, type } = props
const [confirmLoading, setConfirmLoading] = useState<boolean>(false)
const [Options, setOptions] = useState([])
const [state, setState] = useState({ editable: true })
const [telCodeList, setTelCodeList] = useState([])
const [state] = useState({ editable: true })
const [provinceName, setProvinceName] = useState('')
const [cityName, setCityName] = useState('')
const [districtName, setDistrictName] = useState('')
const [headerTitle, setHeaderTitle] = useState('')
const [provinceList, setProvinceList] = useState([])
const [cityList, setCityList] = useState([])
const [telCode, setTelCode] = useState<any>([])
// useEffect(() => {
// if (type === 'edit' && !!editItem) {
// initAddressItemInfo()
// }
// }, [editItem, type])
const [cityList] = useState([])
const initAddressItemInfo = async () => {
//@ts-ignore
const addressDetailRes = await PublicApi.getLogisticsReceiverAddressGet({ id: editItem.id })
const param: any = {
id: editItem.id
}
const addressDetailRes = await PublicApi.getLogisticsReceiverAddressGet(param)
const addressDetail = addressDetailRes.data
Object.keys(addressDetail).forEach(key => {
......@@ -87,41 +72,46 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
})
}
// const selectList: any = [
// { label: <><img src={ChinaImg} key='1' style={{ width: _width, height: _height }} /> +86</>, value: '1' },
// { label: <><img src={japenImg} key='3' style={{ width: _width, height: _height }} /> +86</>, value: '3' },
// { label: <><img src={korenImg} key='4' style={{ width: _width, height: _height }} /> +86</>, value: '4' },
// { label: <><img src={us} key='5' style={{ width: _width, height: _height }} /> +86</>, value: '5' }
// ]
// let _Options: any = []
let TelCodeList: any = []
useEffect(() => {
const fetchCountryAreaTelCode = () => {
if(isEmpty(telCodeList)) {
PublicApi.getManageCountryAreaGetTelCode().then(res => {
const result: any = []
res.data.forEach((item, index) => {
TelCodeList.push({ label: item, value: (index).toString() })
result.push({ label: item, value: (index).toString() })
})
setOptions(TelCodeList)
setTelCodeList(result)
})
const getAllCode = setTimeout(() => {
}
}
useEffect(() => {
if(visible) {
fetchCountryAreaTelCode()
let getAllCode = null
if(isEmpty(provinceList)) {
getAllCode = setTimeout(() => {
PublicApi.getManageAreaByPcodeAll({ pcode: '100000' }).then(res => {
let list = []
const 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)
})
}, 1000)
}
if (type === 'edit' && !!editItem) {
if (type === 'edit' && editItem) {
initAddressItemInfo()
}
return () => {
clearTimeout(getAllCode)
}
}, [editItem, type])
}
}, [editItem, type, visible])
/**
* @description: Form保存
......@@ -129,7 +119,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
* @return:
*/
const formSubmit = (values) => {
let value = { ...values }
const value = { ...values }
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
......@@ -167,12 +157,12 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
setFieldState('districtCode', state => {
state.value = ''
})
let name = value && value.split('-').length > 1 ? value.split('-')[1] : ''
const name = value && value.split('-').length > 1 ? value.split('-')[1] : ''
setProvinceName(name)
setFieldState('*(cityCode)', state => {
state.value = ''
let list = []
let pcode = value && value.split('-').length > 1 ? value.split('-')[0] : value
const list = []
const pcode = value && value.split('-').length > 1 ? value.split('-')[0] : value
PublicApi.getManageAreaByPcodeAll({ pcode: pcode }).then(res => {
res.data.forEach((item: any, index: number) => {
// list.push({ label: item.name, value: item.code })
......@@ -184,12 +174,12 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
})
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)
setFieldState('*(districtCode)', state => {
state.value = ''
let list = []
let pcode = value && value.split('-').length > 1 ? value.split('-')[0] : value
const list = []
const pcode = value && value.split('-').length > 1 ? value.split('-')[0] : value
PublicApi.getManageAreaByPcodeAll({ pcode: pcode }).then(res => {
res.data.forEach((item: any, index: number) => {
// list.push({ label: item.name, value: item.code })
......@@ -200,7 +190,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
})
})
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)
})
}
......@@ -316,7 +306,7 @@ const AddAddress: React.FC<AddAddressPropsType> = (props) => {
message: '请选择区号',
}}
x-component="Select"
enum={Options}
enum={telCodeList}
x-component-props={{
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