Commit a5cf0678 authored by XieZhiXiong's avatar XieZhiXiong

物流方式从商品中获取

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