Commit 57859ea4 authored by XieZhiXiong's avatar XieZhiXiong

fix: 修复货品+商品可以重复选择的问题

parent eafd3910
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
* @Author: XieZhiXiong * @Author: XieZhiXiong
* @Date: 2020-09-16 15:16:47 * @Date: 2020-09-16 15:16:47
* @LastEditors: XieZhiXiong * @LastEditors: XieZhiXiong
* @LastEditTime: 2021-02-19 17:42:55 * @LastEditTime: 2021-02-19 20:24:47
* @Description: 联动逻辑相关 * @Description: 联动逻辑相关
*/ */
import { Modal } from 'antd'; import { Modal, message } from 'antd';
import { FormEffectHooks, FormPath } from '@formily/antd'; import { FormEffectHooks, FormPath } from '@formily/antd';
import { useLinkageUtils } from '@/utils/formEffectUtils'; import { useLinkageUtils } from '@/utils/formEffectUtils';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch'; import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
...@@ -317,7 +317,6 @@ export const useBusinessEffects = (context, actions) => { ...@@ -317,7 +317,6 @@ export const useBusinessEffects = (context, actions) => {
// 关联单据改变 // 关联单据改变
onFieldValueChange$('orderNo').subscribe(fieldState => { onFieldValueChange$('orderNo').subscribe(fieldState => {
const invoicesTypeIdVal = getFieldValue('invoicesTypeId'); const invoicesTypeIdVal = getFieldValue('invoicesTypeId');
const invoicesDetailsRequestsValue = getFieldValue('invoicesDetailsRequests');
const first = fieldState.value && fieldState.value[0]; const first = fieldState.value && fieldState.value[0];
// 设置单据公用的数据相关 // 设置单据公用的数据相关
...@@ -353,7 +352,6 @@ export const useBusinessEffects = (context, actions) => { ...@@ -353,7 +352,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = res.data.map(item => ({ const goodOptions = res.data.map(item => ({
label: item.productName, label: item.productName,
value: item.id, value: item.id,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.id),
})); }));
setFieldState('invoicesDetailsRequests.*.product', state => { setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', res.data); FormPath.setIn(state, 'originAsyncData', res.data);
...@@ -383,7 +381,6 @@ export const useBusinessEffects = (context, actions) => { ...@@ -383,7 +381,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = details.map(item => ({ const goodOptions = details.map(item => ({
label: `${item.productName}${item.orderNo ? '---' + item.orderNo : ''}`, label: `${item.productName}${item.orderNo ? '---' + item.orderNo : ''}`,
value: item.id, value: item.id,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.id),
})); }));
setFieldState('invoicesDetailsRequests.*.product', state => { setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', details.map(item => ({ FormPath.setIn(state, 'originAsyncData', details.map(item => ({
...@@ -417,7 +414,6 @@ export const useBusinessEffects = (context, actions) => { ...@@ -417,7 +414,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = details.map(item => ({ const goodOptions = details.map(item => ({
label: `${item.productName}${item.orderNo ? '---订单号:' + item.orderNo : ''}`, label: `${item.productName}${item.orderNo ? '---订单号:' + item.orderNo : ''}`,
value: item.id, value: item.id,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.id),
})); }));
setFieldState('invoicesDetailsRequests.*.product', state => { setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', details); FormPath.setIn(state, 'originAsyncData', details);
...@@ -454,7 +450,6 @@ export const useBusinessEffects = (context, actions) => { ...@@ -454,7 +450,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = data.map(item => ({ const goodOptions = data.map(item => ({
label: `${item.productName}---订单号:${item.orderNo}`, label: `${item.productName}---订单号:${item.orderNo}`,
value: item.orderRecordId, value: item.orderRecordId,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.orderRecordId),
})); }));
setFieldState('invoicesDetailsRequests.*.product', state => { setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', data.map(item => ({ FormPath.setIn(state, 'originAsyncData', data.map(item => ({
...@@ -491,7 +486,6 @@ export const useBusinessEffects = (context, actions) => { ...@@ -491,7 +486,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = data.map(item => ({ const goodOptions = data.map(item => ({
label: `${item.productName}---订单号:${item.orderNo}`, label: `${item.productName}---订单号:${item.orderNo}`,
value: item.orderRecordId, value: item.orderRecordId,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.orderRecordId),
})); }));
setFieldState('invoicesDetailsRequests.*.product', state => { setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', data.map(item => ({ FormPath.setIn(state, 'originAsyncData', data.map(item => ({
...@@ -529,17 +523,38 @@ export const useBusinessEffects = (context, actions) => { ...@@ -529,17 +523,38 @@ export const useBusinessEffects = (context, actions) => {
setFieldValue('transport', ''); setFieldValue('transport', '');
setFieldValue('deliveryType', null); setFieldValue('deliveryType', null);
} }
// 已选的数据需要禁用掉,不可以重复选择
setFieldState('invoicesDetailsRequests.*.product', state => {
state.props.enum = state.props.enum.map((item) => ({...item, disabled: !!value.find(val => val.product === item.value)}));
});
}); });
// 关联明细 商品下拉框 联动商品ID、单价 // 关联明细 商品下拉框 联动商品ID、单价
onFieldInputChange$('invoicesDetailsRequests.*.product').subscribe(fieldState => { onFieldInputChange$('invoicesDetailsRequests.*.product').subscribe(fieldState => {
const { name, originAsyncData, value, props } = fieldState; const { name, originAsyncData, value } = fieldState;
const current = originAsyncData.find(item => item.id === value); const current = originAsyncData.find(item => item.id === value);
const invoicesTypeIdVal = getFieldValue('invoicesTypeId'); const invoicesTypeIdVal = getFieldValue('invoicesTypeId');
const invoicesDetailsRequestsValue = getFieldValue('invoicesDetailsRequests');
const itemNoValue = getFieldValue(FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.itemNo`
}));
// 这里判断是否货品 跟 商品 都已经选择过了,不可重复选择
const sameGood = invoicesDetailsRequestsValue.find(item => item.itemNo === itemNoValue);
if (
invoicesDetailsRequestsValue.length > 1 &&
sameGood &&
sameGood.product === value
) {
message.warning('存在相同货号+商品的组合,请重新选择');
setTimeout(() => {
setFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.product`
}),
state => {
state.value = undefined;
}
);
}, 0);
return;
}
// 取消选择 // 取消选择
if (!value) { if (!value) {
......
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