Commit 26738ceb authored by XieZhiXiong's avatar XieZhiXiong

fix: 修复现有地址无法点击确认的问题

parent aeb13370
......@@ -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)) {
......
......@@ -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: '请选择地址',
},
],
},
},
},
......
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