Commit 8f0cfb93 authored by GuanHua's avatar GuanHua
parents 1209661b 532a1e41
......@@ -9,10 +9,9 @@ const RowStyleLayout = styled(props => <div {...props} />)`
width: 100%;
.relevance {
height: 100%;
background: #6b778c;
border: none;
border-radius: 0;
height: 100%;
&[disabled] {
background: #f5f5f5;
......@@ -21,6 +20,7 @@ const RowStyleLayout = styled(props => <div {...props} />)`
.ant-input-group-addon {
padding: 0;
border: none;
}
`;
......
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2020-09-16 15:16:47
* @LastEditors: XieZhiXiong
* @LastEditTime: 2020-09-25 11:31:15
* @LastEditTime: 2020-09-25 16:37:38
* @Description: 联动逻辑相关
*/
import { FormEffectHooks, FormPath } from '@formily/antd';
......@@ -303,6 +303,7 @@ export const useBusinessEffects = (context, actions) => {
linkage.componentProps('orderNo', params);
});
// 对应仓库改变
onFieldInputChange$('inventoryId').subscribe(fieldState => {
const current = fieldState.originAsyncData.find(item => item.id === fieldState.value);
if (current) {
......@@ -315,14 +316,19 @@ export const useBusinessEffects = (context, actions) => {
const relevanceInvoicesVal = getFieldValue('relevanceInvoices');
const first = fieldState.value && fieldState.value[0];
console.log('first', first)
setFieldValue('memberName', first ? first.supplyMembersName : '');
setFieldValue('supplyMembersName', first ? first.supplyMembersName : '');
setFieldValue('relevanceInvoicesId', first ? first.id : null);
setFieldValue('deliveryAddresId', first ? first.deliveryAddresId : 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) {
return;
}
......@@ -335,10 +341,10 @@ export const useBusinessEffects = (context, actions) => {
}).then(res => {
if (res.code === 1000) {
const goodOptions = res.data.map(item => ({
label: `${item.productId}/${item.productName}/¥${item.price}`,
value: item.id,
label: item.productName,
value: item.productId,
}));
setFieldState('invoicesDetailsRequests.*.productName', state => {
setFieldState('invoicesDetailsRequests.*.product', state => {
FormPath.setIn(state, 'originAsyncData', res.data);
FormPath.setIn(state, 'props.enum', goodOptions);
});
......@@ -374,14 +380,17 @@ export const useBusinessEffects = (context, actions) => {
default:
break;
}
});
// 关联单据改变
onFieldInputChange$('orderNo').subscribe(fieldState => {
setFieldValue('invoicesDetailsRequests', []);
});
// 关联明细 商品下拉框 联动商品ID、单价
onFieldInputChange$('invoicesDetailsRequests.*.productName').subscribe(fieldState => {
onFieldInputChange$('invoicesDetailsRequests.*.product').subscribe(fieldState => {
const { name, originAsyncData, value } = fieldState;
const current = originAsyncData.find(item => item.id === value);
const current = originAsyncData.find(item => item.productId === value);
if (!current) {
return;
......@@ -397,6 +406,14 @@ export const useBusinessEffects = (context, actions) => {
);
setFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.productName`
}),
state => {
state.value = current.productName;
}
);
setFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.price`
}),
state => {
......@@ -426,17 +443,17 @@ export const useBusinessEffects = (context, actions) => {
const { name, value } = fieldState;
const originAsyncData = getFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.productName`
return `invoicesDetailsRequests.${$1}.product`
}),
state => state.originAsyncData,
);
const goodId = getFieldState(
FormPath.transform(name, /\d/, $1 => {
return `invoicesDetailsRequests.${$1}.productName`
return `invoicesDetailsRequests.${$1}.product`
}),
state => state.value,
);;
const current = originAsyncData.find(item => item.id === goodId);
const current = originAsyncData.find(item => item.productId === goodId);
if (!current || isNaN(+value)) {
return;
......
import React, { useState, useEffect, useRef } from 'react';
import { Button, Card, Spin, message } from 'antd';
import { DeleteOutlined } from '@ant-design/icons';
import { Radio, ArrayTable } from '@formily/antd-components';
import { history, Prompt } from 'umi';
import moment from 'moment';
import { usePageStatus } from '@/hooks/usePageStatus';
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { SaveOutlined, PlusOutlined } from '@ant-design/icons';
import { createFormActions, FormEffectHooks } from '@formily/antd';
......@@ -123,14 +124,57 @@ const AddBills: React.FC<{}> = (props: any) => {
const {
transactionTime,
orderNo,
relevanceInvoicesId,
deliveryAddresId,
supplyMembersName,
fullAddress,
receiverName,
phone,
deliveryType,
isDefault,
invoicesDetailsList,
...rest
} = res.data;
const details = invoicesDetailsList ? invoicesDetailsList.map(item => ({
...item,
product: item.productId,
amount: `¥${(+item.productCount * item.price).toFixed(2)}`,
})) : [];
addSchemaAction.setFieldState(
'*(invoicesTypeId,orderNo)',
state => {
state.props['x-component-props'].disabled = true;
}
);
setBillInfo({
transactionTime: transactionTime ? moment(transactionTime) : moment(),
orderNo: orderNo ? [{ orderNo }] : [],
transactionTime: transactionTime ? moment(transactionTime).format('YYYY-MM-DD HH:mm:ss') : moment().format('YYYY-MM-DD HH:mm:ss'),
orderNo:
orderNo ?
[
{
orderNo,
id: +relevanceInvoicesId,
deliveryAddresId: +deliveryAddresId,
supplyMembersName,
fullAddress,
receiverName,
phone,
deliveryType,
isDefault,
}
] :
[]
,
invoicesDetailsRequests: details,
...rest,
invoicesTypeId: 'S001',
invoicesTypeId: 'S002',
});
productRowCtl.setSelectRow(details);
productRowCtl.setSelectedRowKeys(details.map(item => item.id));
}).finally(() => {
setInfoLoading(false);
});
......@@ -146,7 +190,56 @@ const AddBills: React.FC<{}> = (props: any) => {
switch (invoicesTypeId) {
// 采购入库单
case DOC_TYPE_PURCHASE_RECEIPT: {
setInfoLoading(true);
PublicApi.getOrderProcurementOrderDetails({
id: relevanceInvoicesId,
}).then(res => {
if (res.code !== 1000) {
return;
}
const {
supplyMembersName,
deliveryType,
deliveryAddresId,
orderNo,
province,
city,
area,
addres,
addresName,
tel,
isDefault,
} = res.data;
addSchemaAction.setFieldState(
'*(invoicesTypeId,orderNo)',
state => {
state.props['x-component-props'].disabled = true;
}
);
setBillInfo({
invoicesTypeId,
relevanceInvoices: +relevanceInvoices,
orderNo:
orderNo ?
[
{
orderNo,
id: +relevanceInvoicesId,
deliveryAddresId: +deliveryAddresId,
supplyMembersName,
fullAddress: `${province || ''}${city || ''}${area || ''}${addres || ''}`,
receiverName: addresName || '',
phone: tel || '',
deliveryType,
isDefault,
}
] :
[]
,
});
}).finally(() => {
setInfoLoading(false);
});
break;
}
......@@ -170,6 +263,7 @@ const AddBills: React.FC<{}> = (props: any) => {
addres,
addresName,
tel,
isDefault,
} = res.data;
addSchemaAction.setFieldState(
'*(invoicesTypeId,orderNo)',
......@@ -192,6 +286,7 @@ const AddBills: React.FC<{}> = (props: any) => {
receiverName: addresName || '',
phone: tel || '',
deliveryType,
isDefault,
}
] :
[]
......@@ -261,7 +356,7 @@ const AddBills: React.FC<{}> = (props: any) => {
setVisible(true);
};
const tableAddButton = (
const TableAddButton = pageStatus !== PageStatus.PREVIEW ? (
<Button
style={{ marginBottom: 16 }}
block
......@@ -271,7 +366,7 @@ const AddBills: React.FC<{}> = (props: any) => {
>
添加单据明细
</Button>
);
) : null;
const handleSubmit = value => {
const {
......@@ -284,14 +379,20 @@ const AddBills: React.FC<{}> = (props: any) => {
invoicesDetailsRequests = [],
...rest
} = value;
const newInvoicesDetailsRequests = invoicesDetailsRequests.map(item => ({
...item,
productCount: +item.productCount,
const newInvoicesDetailsRequests = invoicesDetailsRequests.map(({
product,
productCount,
...rest
}) => ({
productCount: +productCount,
...rest,
}));
const newTransactionTime = transactionTime ? moment(transactionTime).valueOf() : null;
const payload = {
orderNo: orderNo[0].orderNo,
relevanceInvoicesId: orderNo[0].id,
transactionTime: transactionTime ? transactionTime.valueOf() : null,
transactionTime: newTransactionTime,
invoicesDetailsRequests: newInvoicesDetailsRequests,
...rest,
};
......@@ -315,6 +416,25 @@ const AddBills: React.FC<{}> = (props: any) => {
});
} else {
// update action
PublicApi.postWarehouseInvoicesUpdata({
id: +id,
invoicesAbstract: payload.invoicesAbstract,
inventoryId: payload.inventoryId,
inventoryRole: payload.inventoryRole,
transactionTime: payload.transactionTime,
invoicesDetailsRequests: payload.invoicesDetailsRequests,
})
.then(res => {
if (res.code !== 1000) {
return;
}
setUnsaved(false);
setTimeout(() => {
history.goBack();
}, 800);
}).finally(() => {
setSubmitLoading(false);
});
}
break;
}
......@@ -336,6 +456,25 @@ const AddBills: React.FC<{}> = (props: any) => {
});
} else {
// update action
PublicApi.postWarehouseInvoicesUpdata({
id: +id,
invoicesAbstract: payload.invoicesAbstract,
inventoryId: payload.inventoryId,
inventoryRole: payload.inventoryRole,
transactionTime: payload.transactionTime,
invoicesDetailsRequests: payload.invoicesDetailsRequests,
})
.then(res => {
if (res.code !== 1000) {
return;
}
setUnsaved(false);
setTimeout(() => {
history.goBack();
}, 800);
}).finally(() => {
setSubmitLoading(false);
});
}
break;
}
......@@ -394,7 +533,8 @@ const AddBills: React.FC<{}> = (props: any) => {
brand: item.brand.name,
unit: item.unitName,
costPrice: item.costPrice,
productName: undefined,
product: undefined,
productName: item.productName,
productId: '',
price: 0,
productCount: 0,
......@@ -415,6 +555,29 @@ const AddBills: React.FC<{}> = (props: any) => {
return [];
}
const handleRemoveItem = (index: number) => {
const newSelectRow = [...productRowCtl.selectRow];
const newSelectedRowKeys = [...productRowCtl.selectedRowKeys];
const newValue = [...addSchemaAction.getFieldValue('invoicesDetailsRequests')];
newSelectRow.splice(index, 1);
newSelectedRowKeys.splice(index, 1);
productRowCtl.setSelectRow(newSelectRow);
productRowCtl.setSelectedRowKeys(newSelectedRowKeys);
newValue.splice(index, 1);
addSchemaAction.setFieldValue('invoicesDetailsRequests', newValue);
};
// ArrayTable自定义渲染
const renderListTableRemove = (index: number) => (
<Button
shape="circle"
icon={<DeleteOutlined />}
onClick={() => handleRemoveItem(index)}
/>
);
return (
<Spin spinning={infoLoading}>
<PageHeaderWrapper
......@@ -444,15 +607,20 @@ const AddBills: React.FC<{}> = (props: any) => {
}
>
<Card>
<NiceForm
<NiceForm
defaultValue={{
transactionTime: moment().format('YYYY-MM-DD HH:mm:ss'),
}}
initialValues={billInfo}
expressionScope={{
tableAddButton,
TableAddButton,
renderListTableRemove,
}}
components={{
RadioGroup: Radio.Group,
ArrayTable,
}}
editable={pageStatus !== PageStatus.PREVIEW}
effects={($, actions) => {
createEffects($, actions)
onFormInputChange$().subscribe(() => {
......
......@@ -253,7 +253,6 @@ export const addBillSchema: ISchema = {
transactionTime: {
type: 'date',
title: '单据时间',
default: moment(),
'x-component-props': {
format: 'YYYY-MM-DD HH:mm:ss',
showTime: true,
......@@ -325,17 +324,12 @@ export const addBillSchema: ISchema = {
},
},
},
memberName: {
supplyMembersName: {
type: 'string',
'x-component': 'Text',
title: '会员名称',
default: '',
},
// 不用于展示,只用于收集值
deliveryAddresId: {
type: 'string',
display: false,
},
address: {
type: 'string',
'x-component': 'Text',
......@@ -347,6 +341,36 @@ export const addBillSchema: ISchema = {
'x-component': 'Text',
title: '物流方式',
default: '',
},
// 不用于展示,只用于收集值
deliveryAddresId: {
type: 'string',
display: false,
},
// 不用于展示,只用于收集值
receiverName: {
type: 'string',
display: false,
},
// 不用于展示,只用于收集值
fullAddress: {
type: 'string',
display: false,
},
// 不用于展示,只用于收集值
phone: {
type: 'string',
display: false,
},
// 不用于展示,只用于收集值
deliveryType: {
type: 'number',
display: false,
},
// 不用于展示,只用于收集值
isDefault: {
type: 'boolean',
display: false,
},
},
},
......@@ -371,14 +395,15 @@ export const addBillSchema: ISchema = {
type: 'object',
'x-component': 'Children',
'x-component-props': {
children: '{{tableAddButton}}'
children: '{{TableAddButton}}'
},
},
invoicesDetailsRequests: {
type: 'array',
'x-component': 'ArrayTable',
'x-component-props': {
renderAddition: () => null,
renderAddition: () => null,
renderRemove: '{{renderListTableRemove}}',
},
items: {
type: 'object',
......@@ -418,7 +443,7 @@ export const addBillSchema: ISchema = {
title: '成本价',
'x-component': 'Text',
},
productName: {
product: {
type: 'string',
title: '商品名称',
enum: [],
......@@ -432,6 +457,11 @@ export const addBillSchema: ISchema = {
},
],
},
// 不用于展示,只收集值
productName: {
type: 'string',
display: false,
},
productId: {
type: 'string',
title: '商品ID',
......
......@@ -242,6 +242,7 @@ const Bills: React.FC<{}> = () => {
render: (_, record: any) => {
return (
<>
<Button type="link" onClick={() => history.push(`/memberCenter/tranactionAbility/stockSellStorage/addBills?id=${record.id}`)}>修改</Button>
{record.state === DOC_STATUS_UNREVIEWED && (
<>
<Button type="link" onClick={() => history.push(`/memberCenter/tranactionAbility/stockSellStorage/addBills?id=${record.id}`)}>修改</Button>
......
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