Commit 57859ea4 authored by XieZhiXiong's avatar XieZhiXiong

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

parent eafd3910
......@@ -2,10 +2,10 @@
* @Author: XieZhiXiong
* @Date: 2020-09-16 15:16:47
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-02-19 17:42:55
* @LastEditTime: 2021-02-19 20:24:47
* @Description: 联动逻辑相关
*/
import { Modal } from 'antd';
import { Modal, message } from 'antd';
import { FormEffectHooks, FormPath } from '@formily/antd';
import { useLinkageUtils } from '@/utils/formEffectUtils';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
......@@ -317,7 +317,6 @@ export const useBusinessEffects = (context, actions) => {
// 关联单据改变
onFieldValueChange$('orderNo').subscribe(fieldState => {
const invoicesTypeIdVal = getFieldValue('invoicesTypeId');
const invoicesDetailsRequestsValue = getFieldValue('invoicesDetailsRequests');
const first = fieldState.value && fieldState.value[0];
// 设置单据公用的数据相关
......@@ -353,7 +352,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = res.data.map(item => ({
label: item.productName,
value: item.id,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.id),
}));
setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', res.data);
......@@ -383,7 +381,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = details.map(item => ({
label: `${item.productName}${item.orderNo ? '---' + item.orderNo : ''}`,
value: item.id,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.id),
}));
setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', details.map(item => ({
......@@ -417,7 +414,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = details.map(item => ({
label: `${item.productName}${item.orderNo ? '---订单号:' + item.orderNo : ''}`,
value: item.id,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.id),
}));
setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', details);
......@@ -454,7 +450,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = data.map(item => ({
label: `${item.productName}---订单号:${item.orderNo}`,
value: item.orderRecordId,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.orderRecordId),
}));
setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', data.map(item => ({
......@@ -491,7 +486,6 @@ export const useBusinessEffects = (context, actions) => {
const goodOptions = data.map(item => ({
label: `${item.productName}---订单号:${item.orderNo}`,
value: item.orderRecordId,
disabled: !!invoicesDetailsRequestsValue.find(val => val.product === item.orderRecordId),
}));
setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', data.map(item => ({
......@@ -529,17 +523,38 @@ export const useBusinessEffects = (context, actions) => {
setFieldValue('transport', '');
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、单价
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 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) {
......
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