Commit a5cf0678 authored by XieZhiXiong's avatar XieZhiXiong

物流方式从商品中获取

parent 3061edce
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: XieZhiXiong * @Author: XieZhiXiong
* @Date: 2020-09-16 15:16:47 * @Date: 2020-09-16 15:16:47
* @LastEditors: XieZhiXiong * @LastEditors: XieZhiXiong
* @LastEditTime: 2020-11-20 16:25:08 * @LastEditTime: 2020-11-20 19:01:57
* @Description: 联动逻辑相关 * @Description: 联动逻辑相关
*/ */
import { Modal } from 'antd'; import { Modal } from 'antd';
...@@ -321,14 +321,12 @@ export const useBusinessEffects = (context, actions) => { ...@@ -321,14 +321,12 @@ export const useBusinessEffects = (context, actions) => {
setFieldValue('supplyMembersName', first ? first.supplyMembersName : ''); setFieldValue('supplyMembersName', first ? first.supplyMembersName : '');
setFieldValue('relevanceInvoicesId', first ? first.id : null); setFieldValue('relevanceInvoicesId', first ? first.id : null);
setFieldValue('address', first ? `${first.fullAddress} ${first.receiverName}/${first.phone}` : ''); setFieldValue('address', first ? `${first.fullAddress} ${first.receiverName}/${first.phone}` : '');
setFieldValue('transport', first && first.deliveryType ? DELIVERY_TYPE[first.deliveryType] : '');
// 以下数据只用于收集,不用于展示 // 以下数据只用于收集,不用于展示
setFieldValue('deliveryAddresId', first ? first.deliveryAddresId : null); setFieldValue('deliveryAddresId', first ? first.deliveryAddresId : null);
setFieldValue('receiverName', first ? first.receiverName : ''); setFieldValue('receiverName', first ? first.receiverName : '');
setFieldValue('fullAddress', first ? first.fullAddress : ''); setFieldValue('fullAddress', first ? first.fullAddress : '');
setFieldValue('phone', first ? first.phone : ''); setFieldValue('phone', first ? first.phone : '');
setFieldValue('deliveryType', first ? first.deliveryType : null);
setFieldValue('isDefault', first ? first.isDefault : false); setFieldValue('isDefault', first ? first.isDefault : false);
if (!first) { if (!first) {
...@@ -389,6 +387,17 @@ export const useBusinessEffects = (context, actions) => { ...@@ -389,6 +387,17 @@ export const useBusinessEffects = (context, actions) => {
setFieldValue('invoicesDetailsRequests', []); setFieldValue('invoicesDetailsRequests', []);
}); });
// 关联明细
onFieldInputChange$('invoicesDetailsRequests').subscribe(fieldState => {
const { value } = fieldState;
if (!value.length) {
// 明细数据为空,或者明细每项数据的 商品 未选,物流方式都设置成 ''
setFieldValue('transport', '');
setFieldValue('deliveryType', null);
}
});
// 关联明细 商品下拉框 联动商品ID、单价 // 关联明细 商品下拉框 联动商品ID、单价
onFieldInputChange$('invoicesDetailsRequests.*.product').subscribe(fieldState => { onFieldInputChange$('invoicesDetailsRequests.*.product').subscribe(fieldState => {
const { name, originAsyncData, value } = fieldState; const { name, originAsyncData, value } = fieldState;
...@@ -436,6 +445,25 @@ export const useBusinessEffects = (context, actions) => { ...@@ -436,6 +445,25 @@ export const useBusinessEffects = (context, actions) => {
state.value = `¥0.00`; state.value = `¥0.00`;
} }
); );
// 配送方式,一个单据只能有一个配送方式
setFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.deliveryType`
}),
state => {
state.value = undefined;
}
);
const invoicesDetailsRequestsValue = getFieldValue('invoicesDetailsRequests');
// 明细每项数据的 商品 未选中,物流方式设置成 ''
if (
invoicesDetailsRequestsValue.every(item => !item.product)
) {
setFieldValue('transport', '');
setFieldValue('deliveryType', null);
}
} }
if (!current) { if (!current) {
...@@ -482,6 +510,46 @@ export const useBusinessEffects = (context, actions) => { ...@@ -482,6 +510,46 @@ export const useBusinessEffects = (context, actions) => {
state.value = `¥${(current.purchaseCount * current.price).toFixed(2)}`; state.value = `¥${(current.purchaseCount * current.price).toFixed(2)}`;
} }
); );
// 配送方式,一个单据只能有一个配送方式
setFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.deliveryType`
}),
state => {
state.value = current.logistics && current.logistics.deliveryType ? current.logistics.deliveryType : undefined;
}
);
setTimeout(() => {
const invoicesDetailsRequestsValue = getFieldValue('invoicesDetailsRequests');
// 配送方式,一个单据只能有一个配送方式
setFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.product`
}),
state => {
if (
current.logistics &&
invoicesDetailsRequestsValue.some(item => item.deliveryType && item.deliveryType !== current.logistics.deliveryType)
) {
state.errors = '商品配送方式不一致,请保持一次性';
} else {
state.errors = '';
}
}
);
// 明细每项数据的 商品 选中,物流方式设置成 为对应商品的物流方式
if (
current.logistics &&
current.logistics.deliveryType &&
invoicesDetailsRequestsValue.every(item => item.deliveryType === current.logistics.deliveryType)
) {
setFieldValue('transport', DELIVERY_TYPE[current.logistics.deliveryType]);
setFieldValue('deliveryType', current.logistics.deliveryType);
}
}, 0);
}); });
// 关联明细 商品数量 联动计算商品金额 // 关联明细 商品数量 联动计算商品金额
......
...@@ -33,6 +33,8 @@ import { ...@@ -33,6 +33,8 @@ import {
DOC_TYPE_RETURN_RECEIPT, DOC_TYPE_RETURN_RECEIPT,
DOC_TYPE_EXCHANGE_INVOICE, DOC_TYPE_EXCHANGE_INVOICE,
DOC_TYPE_EXCHANGE_RECEIPT, DOC_TYPE_EXCHANGE_RECEIPT,
DELIVERY_TYPE,
} from '@/constants'; } from '@/constants';
import { addBillSchema, goodsSearchSchema } from './schema'; import { addBillSchema, goodsSearchSchema } from './schema';
import { createEffects } from './effects'; import { createEffects } from './effects';
...@@ -141,6 +143,7 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -141,6 +143,7 @@ const BillsForm: React.FC<BillsFormProps> = ({
deliveryType, deliveryType,
isDefault, isDefault,
invoicesDetailsList, invoicesDetailsList,
transport,
...rest ...rest
} = res.data; } = res.data;
...@@ -148,6 +151,7 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -148,6 +151,7 @@ const BillsForm: React.FC<BillsFormProps> = ({
...item, ...item,
product: item.productId, product: item.productId,
amount: `¥${(+item.productCount * item.price).toFixed(2)}`, amount: `¥${(+item.productCount * item.price).toFixed(2)}`,
deliveryType,
})) : []; })) : [];
addSchemaAction.setFieldState( addSchemaAction.setFieldState(
...@@ -170,7 +174,7 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -170,7 +174,7 @@ const BillsForm: React.FC<BillsFormProps> = ({
fullAddress: fullAddress || '', fullAddress: fullAddress || '',
receiverName: receiverName || '', receiverName: receiverName || '',
phone: phone || '', phone: phone || '',
deliveryType, // deliveryType,
isDefault, isDefault,
} }
] : ] :
...@@ -178,6 +182,8 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -178,6 +182,8 @@ const BillsForm: React.FC<BillsFormProps> = ({
, ,
invoicesDetailsRequests: details, invoicesDetailsRequests: details,
...rest, ...rest,
deliveryType,
transport: DELIVERY_TYPE[deliveryType],
}); });
}).finally(() => { }).finally(() => {
setInfoLoading(false); setInfoLoading(false);
...@@ -375,6 +381,7 @@ const BillsForm: React.FC<BillsFormProps> = ({ ...@@ -375,6 +381,7 @@ const BillsForm: React.FC<BillsFormProps> = ({
const newInvoicesDetailsRequests = invoicesDetailsRequests.map(({ const newInvoicesDetailsRequests = invoicesDetailsRequests.map(({
product, product,
productCount, productCount,
deliveryType,
...rest ...rest
}) => ({ }) => ({
productCount: +productCount, productCount: +productCount,
......
...@@ -340,7 +340,7 @@ export const addBillSchema: ISchema = { ...@@ -340,7 +340,7 @@ export const addBillSchema: ISchema = {
type: 'string', type: 'string',
'x-component': 'Text', 'x-component': 'Text',
title: '物流方式', title: '物流方式',
default: '', // default: '', // 奇了怪了,initialValues 覆盖不了 default,就这个字段会
}, },
// 不用于展示,只用于收集值 // 不用于展示,只用于收集值
deliveryAddresId: { deliveryAddresId: {
...@@ -450,7 +450,7 @@ export const addBillSchema: ISchema = { ...@@ -450,7 +450,7 @@ export const addBillSchema: ISchema = {
'x-component-props': { 'x-component-props': {
allowClear: true, allowClear: true,
style: { style: {
width: 100, width: 180,
}, },
}, },
'x-rules': [ 'x-rules': [
...@@ -460,11 +460,6 @@ export const addBillSchema: ISchema = { ...@@ -460,11 +460,6 @@ export const addBillSchema: ISchema = {
}, },
], ],
}, },
// 不用于展示,只收集值
productName: {
type: 'string',
display: false,
},
productId: { productId: {
type: 'string', type: 'string',
title: '商品ID', title: '商品ID',
...@@ -497,6 +492,16 @@ export const addBillSchema: ISchema = { ...@@ -497,6 +492,16 @@ export const addBillSchema: ISchema = {
title: '金额', title: '金额',
'x-component': 'Text', 'x-component': 'Text',
}, },
// 不用于展示,只收集值
productName: {
type: 'string',
display: false,
},
// 配送方式,不用于展示,只收集值
deliveryType: {
type: 'string',
display: false,
},
}, },
} }
}, },
......
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