perf: optimize record summary
This commit is contained in:
parent
71c84a00de
commit
fbe0c14920
@ -1,45 +1,31 @@
|
|||||||
import { onFieldInit, onFieldValueChange } from '@formily/core';
|
import { observer, useForm } from '@formily/react';
|
||||||
import { useForm, useFormEffects } from '@formily/react';
|
|
||||||
import { ConversionLogics, RecordCategory } from '../../utils/constants';
|
import { ConversionLogics, RecordCategory } from '../../utils/constants';
|
||||||
import { Descriptions, Tabs, type DescriptionsProps } from 'antd';
|
import { Descriptions, Tabs } from 'antd';
|
||||||
import {
|
import {
|
||||||
CUSTOM_COMPONENT_TYPE_FORM_ITEM,
|
CUSTOM_COMPONENT_TYPE_FORM_ITEM,
|
||||||
KEY_CUSTOM_COMPONENT_LABEL,
|
KEY_CUSTOM_COMPONENT_LABEL,
|
||||||
KEY_CUSTOM_COMPONENT_TYPE,
|
KEY_CUSTOM_COMPONENT_TYPE,
|
||||||
} from '@hera/plugin-core/client';
|
} from '@hera/plugin-core/client';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React from 'react';
|
||||||
import { useRequest } from '@nocobase/client';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { formatCurrency, formatQuantity } from '../../utils/currencyUtils';
|
import { formatCurrency, formatQuantity } from '../../utils/currencyUtils';
|
||||||
export const RecordSummary = (props) => {
|
import { useCachedRequest, useLeaseItems } from '../hooks';
|
||||||
const [products, setProducts] = useState([]);
|
export const RecordSummary = observer((props) => {
|
||||||
const [leaseData, setLeaseData] = useState(null);
|
const form = useForm();
|
||||||
const [groupWeight, setGroupWeight] = useState([]);
|
const contractPlanId = form.values.contract_plan?.id;
|
||||||
const [recordWeight, setRecordWeight] = useState(0);
|
const inContractPlanId = form.values.in_contract_plan?.id;
|
||||||
|
const outContractPlanId = form.values.out_contract_plan?.id;
|
||||||
|
|
||||||
const [contractPlanId, setContractPlanId] = useState(-1);
|
const leaseData = form.values.price_items;
|
||||||
const [contractProducts, setContractProducts] = useState([]);
|
const recordWeight = form.values.weight;
|
||||||
const [inContractProducts, setInContractProducts] = useState([]);
|
const reqWeightRules = useCachedRequest<any>({
|
||||||
const [inContractPlanId, setInContractPlanId] = useState(-1);
|
|
||||||
const [outContractProducts, setOutContractProducts] = useState([]);
|
|
||||||
const [outContractPlanId, setOutContractPlanId] = useState(-1);
|
|
||||||
|
|
||||||
const contractPlans = useRequest<any>({
|
|
||||||
resource: 'contract_plans',
|
|
||||||
action: 'list',
|
|
||||||
params: {
|
|
||||||
appends: ['lease_items', 'lease_items.products'],
|
|
||||||
pageSize: 99999,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const reqWeightRules = useRequest<any>({
|
|
||||||
resource: 'weight_rules',
|
resource: 'weight_rules',
|
||||||
action: 'list',
|
action: 'list',
|
||||||
params: {
|
params: {
|
||||||
pageSize: 99999,
|
pageSize: 99999,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const reqProduct = useRequest<any>({
|
const reqProduct = useCachedRequest<any>({
|
||||||
resource: 'product',
|
resource: 'product',
|
||||||
action: 'list',
|
action: 'list',
|
||||||
params: {
|
params: {
|
||||||
@ -47,468 +33,300 @@ export const RecordSummary = (props) => {
|
|||||||
pageSize: 99999,
|
pageSize: 99999,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { loading: loadingLeaseItems } = useRequest<any>(
|
const { data: leaseItems } = useLeaseItems(contractPlanId);
|
||||||
{
|
const { data: inLeaseItems } = useLeaseItems(inContractPlanId);
|
||||||
resource: 'contract_plan_lease_items',
|
const { data: outLeaseItems } = useLeaseItems(outContractPlanId);
|
||||||
action: 'list',
|
|
||||||
params: {
|
const allPrice = {
|
||||||
appends: ['products'],
|
key: '1',
|
||||||
filter: {
|
name: '总金额',
|
||||||
contract_plan_id: contractPlanId,
|
total: 0,
|
||||||
},
|
unit: '',
|
||||||
pageSize: 9999,
|
};
|
||||||
},
|
const weight = {
|
||||||
},
|
key: '2',
|
||||||
{
|
name: '理论重量',
|
||||||
refreshDeps: [contractPlanId],
|
total: 0,
|
||||||
onSuccess(data) {
|
unit: '吨',
|
||||||
if (data?.data?.length > 0) {
|
};
|
||||||
const result = data.data;
|
const summaryProduct = {};
|
||||||
setContractProducts(result);
|
// 处理除实际重量的情况
|
||||||
} else {
|
form.values.items?.forEach((element) => {
|
||||||
setContractProducts([]);
|
// 1.获取产品的分类数据信息
|
||||||
}
|
const productCategory = reqProduct.data.data?.find(
|
||||||
},
|
(product) => product.category_id === element.product?.category_id,
|
||||||
},
|
)?.category;
|
||||||
);
|
if (productCategory) {
|
||||||
const { loading: loadingInLeaseItems } = useRequest<any>(
|
let summary, summaryUnit;
|
||||||
{
|
if (productCategory && productCategory.convertible) {
|
||||||
resource: 'contract_plan_lease_items',
|
summary = (element.count || 0) * element.product?.ratio;
|
||||||
action: 'list',
|
summaryUnit = productCategory.conversion_unit;
|
||||||
params: {
|
} else {
|
||||||
appends: ['products'],
|
summary = element.count || 0;
|
||||||
filter: {
|
summaryUnit = productCategory.unit;
|
||||||
contract_plan_id: inContractPlanId,
|
}
|
||||||
},
|
weight.total += ((element.count || 0) * element.product?.weight) / 1000;
|
||||||
pageSize: 9999,
|
if (!element.product) return;
|
||||||
},
|
if (summaryProduct[element.product.category_id]) {
|
||||||
},
|
summaryProduct[element.product.category_id].total += summary;
|
||||||
{
|
} else {
|
||||||
refreshDeps: [inContractPlanId],
|
summaryProduct[element.product.category_id] = {
|
||||||
onSuccess(data) {
|
name: productCategory.name,
|
||||||
if (data?.data?.length > 0) {
|
total: summary,
|
||||||
const result = data.data;
|
unit: summaryUnit,
|
||||||
setInContractProducts(result);
|
};
|
||||||
} else {
|
}
|
||||||
setInContractProducts([]);
|
}
|
||||||
}
|
});
|
||||||
},
|
// 入库合同方案小结
|
||||||
},
|
const contractSummary = {};
|
||||||
);
|
// 出库合同方案小结
|
||||||
const { loading: loadingOutLeaseItems } = useRequest<any>(
|
const outContractSummary = {};
|
||||||
{
|
// 报价方案小结
|
||||||
resource: 'contract_plan_lease_items',
|
const leaseSummary = {};
|
||||||
action: 'list',
|
// 计价数量的计算
|
||||||
params: {
|
const contractSummaryWeight = {
|
||||||
appends: ['products'],
|
key: '0',
|
||||||
filter: {
|
name: '理论重量',
|
||||||
contract_plan_id: outContractPlanId,
|
total: 0,
|
||||||
},
|
unit: '吨',
|
||||||
pageSize: 9999,
|
};
|
||||||
},
|
if (
|
||||||
},
|
(form.values.category === RecordCategory.lease || form.values.category === RecordCategory.lease2lease) &&
|
||||||
{
|
(leaseItems || inLeaseItems)
|
||||||
refreshDeps: [outContractPlanId],
|
) {
|
||||||
onSuccess(data) {
|
|
||||||
if (data?.data?.length > 0) {
|
|
||||||
const result = data.data;
|
|
||||||
setOutContractProducts(result);
|
|
||||||
} else {
|
|
||||||
setOutContractProducts([]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const [value, setValue] = useState<DescriptionsProps['items']>([]);
|
|
||||||
const [inContractvalue, setInContractvalue] = useState<DescriptionsProps['items']>([]);
|
|
||||||
const [outContractvalue, setOutContractvalue] = useState<DescriptionsProps['items']>([]);
|
|
||||||
const [leasevalue, setLeasevalue] = useState<DescriptionsProps['items']>([]);
|
|
||||||
const form = useForm();
|
|
||||||
const calcLeaseSum = () => {
|
|
||||||
const allPrice = {
|
|
||||||
key: '1',
|
|
||||||
name: '总金额',
|
|
||||||
total: 0,
|
|
||||||
unit: '',
|
|
||||||
};
|
|
||||||
const weight = {
|
|
||||||
key: '2',
|
|
||||||
name: '理论重量',
|
|
||||||
total: 0,
|
|
||||||
unit: '吨',
|
|
||||||
};
|
|
||||||
const summaryProduct = {};
|
|
||||||
// 处理除实际重量的情况
|
|
||||||
form.values.items?.forEach((element) => {
|
form.values.items?.forEach((element) => {
|
||||||
// 1.获取产品的分类数据信息
|
|
||||||
const productCategory = reqProduct.data.data?.find(
|
const productCategory = reqProduct.data.data?.find(
|
||||||
(product) => product.category_id === element.product?.category_id,
|
(product) => product.category_id === element.product?.category_id,
|
||||||
)?.category;
|
)?.category;
|
||||||
if (productCategory) {
|
// 合同方案
|
||||||
let summary, summaryUnit;
|
const in_contract = form.values.category === RecordCategory.lease ? leaseItems.data : inLeaseItems.data;
|
||||||
if (productCategory && productCategory.convertible) {
|
const contractPlain = in_contract.find((item) =>
|
||||||
summary = (element.count || 0) * element.product?.ratio;
|
item.products.find(
|
||||||
summaryUnit = productCategory.conversion_unit;
|
(product) => product.id - 99999 === element.product?.category_id || product.id === element.product?.id,
|
||||||
} else {
|
),
|
||||||
summary = element.count || 0;
|
);
|
||||||
summaryUnit = productCategory.unit;
|
// 计算合同方案的理论重量
|
||||||
}
|
const weightItem = calcTheoreticalWeight(element, reqWeightRules, contractPlain);
|
||||||
weight.total += ((element.count || 0) * element.product?.weight) / 1000;
|
contractSummaryWeight.total += weightItem;
|
||||||
if (!element.product) return;
|
const res = subtotal(contractPlain, element, productCategory, reqWeightRules);
|
||||||
if (summaryProduct[element.product.category_id]) {
|
if (res) {
|
||||||
summaryProduct[element.product.category_id].total += summary;
|
if (!contractSummary[element.product?.category_id]) {
|
||||||
} else {
|
|
||||||
summaryProduct[element.product.category_id] = {
|
|
||||||
name: productCategory.name,
|
|
||||||
total: summary,
|
|
||||||
unit: summaryUnit,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 入库合同方案小结
|
|
||||||
const contractSummary = {};
|
|
||||||
// 出库合同方案小结
|
|
||||||
const outContractSummary = {};
|
|
||||||
// 报价方案小结
|
|
||||||
const leaseSummary = {};
|
|
||||||
// 计价数量的计算
|
|
||||||
const contractSummaryWeight = {
|
|
||||||
key: '0',
|
|
||||||
name: '理论重量',
|
|
||||||
total: 0,
|
|
||||||
unit: '吨',
|
|
||||||
};
|
|
||||||
if (form.values.category === RecordCategory.lease || form.values.category === RecordCategory.lease2lease) {
|
|
||||||
form.values.items?.forEach((element) => {
|
|
||||||
const productCategory = reqProduct.data.data?.find(
|
|
||||||
(product) => product.category_id === element.product?.category_id,
|
|
||||||
)?.category;
|
|
||||||
// 合同方案
|
|
||||||
const in_contract = form.values.category === RecordCategory.lease ? contractProducts : inContractProducts;
|
|
||||||
const contractPlain = in_contract.find((item) =>
|
|
||||||
item.products.find(
|
|
||||||
(product) => product.id - 99999 === element.product?.category_id || product.id === element.product?.id,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// 计算合同方案的理论重量
|
|
||||||
const weightItem = calcTheoreticalWeight(element, reqWeightRules, contractPlain);
|
|
||||||
contractSummaryWeight.total += weightItem;
|
|
||||||
const res = subtotal(contractPlain, element, productCategory, reqWeightRules);
|
|
||||||
if (res) {
|
|
||||||
if (!contractSummary[element.product?.category_id]) {
|
|
||||||
contractSummary[element.product?.category_id] = {
|
|
||||||
name: productCategory?.name,
|
|
||||||
total: 0,
|
|
||||||
unit: res.unit,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
contractSummary[element.product?.category_id] = {
|
contractSummary[element.product?.category_id] = {
|
||||||
name: productCategory?.name,
|
name: productCategory?.name,
|
||||||
total: (contractSummary[element.product?.category_id].total += res.count),
|
total: 0,
|
||||||
unit: res.unit,
|
unit: res.unit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
contractSummary[element.product?.category_id] = {
|
||||||
}
|
name: productCategory?.name,
|
||||||
const leaseSummaryWeight = {
|
total: (contractSummary[element.product?.category_id].total += res.count),
|
||||||
key: '0',
|
unit: res.unit,
|
||||||
name: '理论重量',
|
};
|
||||||
total: 0,
|
}
|
||||||
unit: '吨',
|
});
|
||||||
};
|
}
|
||||||
const leaseSummaryPrice = {
|
const leaseSummaryWeight = {
|
||||||
key: '99',
|
key: '0',
|
||||||
name: '总金额',
|
name: '理论重量',
|
||||||
total: 0,
|
total: 0,
|
||||||
unit: '',
|
unit: '吨',
|
||||||
};
|
};
|
||||||
// 基本小结要带金额,报价小结也要带金额
|
const leaseSummaryPrice = {
|
||||||
if (form.values.category === RecordCategory.purchase || form.values.category === RecordCategory.purchase2lease) {
|
key: '99',
|
||||||
form.values.items?.forEach((element) => {
|
name: '总金额',
|
||||||
const productCategory = reqProduct.data.data?.find(
|
total: 0,
|
||||||
(product) => product.category_id === element.product?.category_id,
|
unit: '',
|
||||||
)?.category;
|
};
|
||||||
const rule = leaseData?.find(
|
// 基本小结要带金额,报价小结也要带金额
|
||||||
(rule) =>
|
if (form.values.category === RecordCategory.purchase || form.values.category === RecordCategory.purchase2lease) {
|
||||||
rule.product?.category_id === element.product?.category_id || rule.product?.id === element.product?.id,
|
form.values.items?.forEach((element) => {
|
||||||
);
|
const productCategory = reqProduct.data.data?.find(
|
||||||
if (rule) {
|
(product) => product.category_id === element.product?.category_id,
|
||||||
rule.conversion_logic_id = rule.conversion_logic.id;
|
)?.category;
|
||||||
const res = subtotal(rule, element, productCategory, reqWeightRules);
|
const rule = leaseData?.find(
|
||||||
const price = calcLeasePriceSum(element, rule, productCategory, recordWeight);
|
(rule) =>
|
||||||
leaseSummaryPrice.total += price;
|
rule.product?.category_id === element.product?.category_id || rule.product?.id === element.product?.id,
|
||||||
// 计算合同方案的理论重量
|
);
|
||||||
const weightItem = calcTheoreticalWeight(element, reqWeightRules, rule);
|
if (rule) {
|
||||||
leaseSummaryWeight.total += weightItem;
|
rule.conversion_logic_id = rule.conversion_logic.id;
|
||||||
if (res) {
|
const res = subtotal(rule, element, productCategory, reqWeightRules);
|
||||||
if (!leaseSummary[element.product?.category_id]) {
|
const price = calcLeasePriceSum(element, rule, productCategory, recordWeight);
|
||||||
leaseSummary[element.product?.category_id] = {
|
leaseSummaryPrice.total += price;
|
||||||
name: productCategory?.name,
|
// 计算合同方案的理论重量
|
||||||
total: 0,
|
const weightItem = calcTheoreticalWeight(element, reqWeightRules, rule);
|
||||||
unit: res.unit,
|
leaseSummaryWeight.total += weightItem;
|
||||||
};
|
if (res) {
|
||||||
}
|
if (!leaseSummary[element.product?.category_id]) {
|
||||||
leaseSummary[element.product?.category_id] = {
|
leaseSummary[element.product?.category_id] = {
|
||||||
name: productCategory?.name,
|
|
||||||
total: (leaseSummary[element.product?.category_id].total += res.count),
|
|
||||||
unit: res.unit,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (form.values.category === RecordCategory.purchase2lease) {
|
|
||||||
// 出现两次purchase2lease,上面处理报价小结,此处处理入库合同小结
|
|
||||||
form.values.items?.forEach((element) => {
|
|
||||||
const productCategory = reqProduct.data.data?.find(
|
|
||||||
(product) => product.category_id === element.product?.category_id,
|
|
||||||
)?.category;
|
|
||||||
const contractPlain = inContractProducts.find((item) =>
|
|
||||||
item.products.find(
|
|
||||||
(product) => product.id - 99999 === element.product?.category_id || product.id === element.product?.id,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const weightItem = calcTheoreticalWeight(element, reqWeightRules, contractPlain);
|
|
||||||
contractSummaryWeight.total += weightItem;
|
|
||||||
const res = subtotal(contractPlain, element, productCategory, reqWeightRules);
|
|
||||||
if (res) {
|
|
||||||
if (!contractSummary[element.product?.category_id]) {
|
|
||||||
contractSummary[element.product?.category_id] = {
|
|
||||||
name: productCategory?.name,
|
name: productCategory?.name,
|
||||||
total: 0,
|
total: 0,
|
||||||
unit: res.unit,
|
unit: res.unit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
leaseSummary[element.product?.category_id] = {
|
||||||
|
name: productCategory?.name,
|
||||||
|
total: (leaseSummary[element.product?.category_id].total += res.count),
|
||||||
|
unit: res.unit,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (form.values.category === RecordCategory.purchase2lease && inLeaseItems) {
|
||||||
|
// 出现两次purchase2lease,上面处理报价小结,此处处理入库合同小结
|
||||||
|
form.values.items?.forEach((element) => {
|
||||||
|
const productCategory = reqProduct.data.data?.find(
|
||||||
|
(product) => product.category_id === element.product?.category_id,
|
||||||
|
)?.category;
|
||||||
|
const contractPlain = inLeaseItems.data.find((item) =>
|
||||||
|
item.products.find(
|
||||||
|
(product) => product.id - 99999 === element.product?.category_id || product.id === element.product?.id,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const weightItem = calcTheoreticalWeight(element, reqWeightRules, contractPlain);
|
||||||
|
contractSummaryWeight.total += weightItem;
|
||||||
|
const res = subtotal(contractPlain, element, productCategory, reqWeightRules);
|
||||||
|
if (res) {
|
||||||
|
if (!contractSummary[element.product?.category_id]) {
|
||||||
contractSummary[element.product?.category_id] = {
|
contractSummary[element.product?.category_id] = {
|
||||||
name: productCategory?.name,
|
name: productCategory?.name,
|
||||||
total: (contractSummary[element.product?.category_id].total += res.count),
|
total: 0,
|
||||||
unit: res.unit,
|
unit: res.unit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
contractSummary[element.product?.category_id] = {
|
||||||
}
|
name: productCategory?.name,
|
||||||
const outContractSummaryWeight = {
|
total: (contractSummary[element.product?.category_id].total += res.count),
|
||||||
key: '0',
|
unit: res.unit,
|
||||||
name: '理论重量',
|
};
|
||||||
total: 0,
|
}
|
||||||
unit: '吨',
|
});
|
||||||
};
|
}
|
||||||
if (form.values.category === RecordCategory.lease2lease) {
|
const outContractSummaryWeight = {
|
||||||
// 此判断出现两次,上面处理入库小结,此处要处理出库小结
|
key: '0',
|
||||||
form.values.items?.forEach((element) => {
|
name: '理论重量',
|
||||||
const productCategory = reqProduct.data.data?.find(
|
total: 0,
|
||||||
(product) => product.category_id === element.product?.category_id,
|
unit: '吨',
|
||||||
)?.category;
|
};
|
||||||
const contractPlain = outContractProducts.find((item) =>
|
if (form.values.category === RecordCategory.lease2lease && outLeaseItems) {
|
||||||
item.products.find(
|
// 此判断出现两次,上面处理入库小结,此处要处理出库小结
|
||||||
(product) => product.id - 99999 === element.product?.category_id || product.id === element.product?.id,
|
form.values.items?.forEach((element) => {
|
||||||
),
|
const productCategory = reqProduct.data.data?.find(
|
||||||
);
|
(product) => product.category_id === element.product?.category_id,
|
||||||
const weightItem = calcTheoreticalWeight(element, reqWeightRules, contractPlain);
|
)?.category;
|
||||||
outContractSummaryWeight.total += weightItem;
|
const contractPlain = outLeaseItems.data.find((item) =>
|
||||||
const res = subtotal(contractPlain, element, productCategory, reqWeightRules);
|
item.products.find(
|
||||||
if (res) {
|
(product) => product.id - 99999 === element.product?.category_id || product.id === element.product?.id,
|
||||||
if (!outContractSummary[element.product?.category_id]) {
|
),
|
||||||
outContractSummary[element.product?.category_id] = {
|
);
|
||||||
name: productCategory?.name,
|
const weightItem = calcTheoreticalWeight(element, reqWeightRules, contractPlain);
|
||||||
total: 0,
|
outContractSummaryWeight.total += weightItem;
|
||||||
unit: res.unit,
|
const res = subtotal(contractPlain, element, productCategory, reqWeightRules);
|
||||||
};
|
if (res) {
|
||||||
}
|
if (!outContractSummary[element.product?.category_id]) {
|
||||||
outContractSummary[element.product?.category_id] = {
|
outContractSummary[element.product?.category_id] = {
|
||||||
name: productCategory?.name,
|
name: productCategory?.name,
|
||||||
total: (outContractSummary[element.product?.category_id].total += res.count),
|
total: 0,
|
||||||
unit: res.unit,
|
unit: res.unit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
outContractSummary[element.product?.category_id] = {
|
||||||
}
|
name: productCategory?.name,
|
||||||
// 常规小结
|
total: (outContractSummary[element.product?.category_id].total += res.count),
|
||||||
const items = [];
|
unit: res.unit,
|
||||||
for (const key in summaryProduct) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(summaryProduct, key)) {
|
|
||||||
const element = summaryProduct[key];
|
|
||||||
items.push({ ...element, key: key });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const result =
|
|
||||||
form.values.category === RecordCategory.purchase || form.values.category === RecordCategory.purchase2lease
|
|
||||||
? [weight, ...items, allPrice]
|
|
||||||
: [weight, ...items];
|
|
||||||
const showItems = result
|
|
||||||
.map((item) => {
|
|
||||||
if (!item.total) return;
|
|
||||||
return {
|
|
||||||
label: item.name,
|
|
||||||
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
|
||||||
};
|
};
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
setValue(showItems);
|
|
||||||
|
|
||||||
// 合同小结/入库合同小结(租赁单,使用合同 租赁直发单,使用入库合同)
|
|
||||||
const inContract = [];
|
|
||||||
for (const key in contractSummary) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(contractSummary, key)) {
|
|
||||||
const element = contractSummary[key];
|
|
||||||
inContract.push({ ...element, key: key });
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 常规小结
|
||||||
|
const items = [];
|
||||||
|
for (const key in summaryProduct) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(summaryProduct, key)) {
|
||||||
|
const element = summaryProduct[key];
|
||||||
|
items.push({ ...element, key: key });
|
||||||
}
|
}
|
||||||
inContract.unshift(contractSummaryWeight);
|
}
|
||||||
const inContractItems = inContract
|
const result =
|
||||||
.map((item) => {
|
form.values.category === RecordCategory.purchase || form.values.category === RecordCategory.purchase2lease
|
||||||
if (!item.total) return;
|
? [weight, ...items, allPrice]
|
||||||
return {
|
: [weight, ...items];
|
||||||
label: item.name,
|
const value = result
|
||||||
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
.map((item) => {
|
||||||
};
|
if (!item.total) return;
|
||||||
})
|
return {
|
||||||
.filter(Boolean);
|
label: item.name,
|
||||||
setInContractvalue(inContractItems);
|
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
// 出库合同小结
|
// 合同小结/入库合同小结(租赁单,使用合同 租赁直发单,使用入库合同)
|
||||||
const outContract = [];
|
const inContract = [];
|
||||||
for (const key in outContractSummary) {
|
for (const key in contractSummary) {
|
||||||
if (Object.prototype.hasOwnProperty.call(outContractSummary, key)) {
|
if (Object.prototype.hasOwnProperty.call(contractSummary, key)) {
|
||||||
const element = outContractSummary[key];
|
const element = contractSummary[key];
|
||||||
outContract.push({ ...element, key: key });
|
inContract.push({ ...element, key: key });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
outContract.unshift(outContractSummaryWeight);
|
}
|
||||||
const outContractItems = outContract
|
inContract.unshift(contractSummaryWeight);
|
||||||
.map((item) => {
|
const inContractvalue = inContract
|
||||||
if (!item.total) return;
|
.map((item) => {
|
||||||
return {
|
if (!item.total) return;
|
||||||
label: item.name,
|
return {
|
||||||
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
label: item.name,
|
||||||
};
|
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
||||||
})
|
};
|
||||||
.filter(Boolean);
|
})
|
||||||
setOutContractvalue(outContractItems);
|
.filter(Boolean);
|
||||||
|
|
||||||
// 报价小结
|
// 出库合同小结
|
||||||
const lease = [];
|
const outContract = [];
|
||||||
for (const key in leaseSummary) {
|
for (const key in outContractSummary) {
|
||||||
if (Object.prototype.hasOwnProperty.call(leaseSummary, key)) {
|
if (Object.prototype.hasOwnProperty.call(outContractSummary, key)) {
|
||||||
const element = leaseSummary[key];
|
const element = outContractSummary[key];
|
||||||
lease.push({ ...element, key: key });
|
outContract.push({ ...element, key: key });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lease.unshift(leaseSummaryWeight);
|
}
|
||||||
lease.push(leaseSummaryPrice);
|
outContract.unshift(outContractSummaryWeight);
|
||||||
const leaseItems = lease
|
const outContractvalue = outContract
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
if (!item.total) return;
|
if (!item.total) return;
|
||||||
return {
|
return {
|
||||||
label: item.name,
|
label: item.name,
|
||||||
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
setLeasevalue(leaseItems);
|
|
||||||
};
|
|
||||||
useFormEffects(() => {
|
|
||||||
onFieldInit('items.*', () => {
|
|
||||||
setProducts(_.cloneDeep(form.values.items));
|
|
||||||
});
|
|
||||||
onFieldValueChange('items.*', () => {
|
|
||||||
setProducts(_.cloneDeep(form.values.items));
|
|
||||||
});
|
|
||||||
onFieldInit('price_items.*', () => {
|
|
||||||
setLeaseData(_.cloneDeep(form.values.price_items));
|
|
||||||
});
|
|
||||||
onFieldValueChange('price_items.*', () => {
|
|
||||||
setLeaseData(_.cloneDeep(form.values.price_items));
|
|
||||||
});
|
|
||||||
onFieldInit('group_weight_items.*', () => {
|
|
||||||
setGroupWeight(_.cloneDeep(form.values.group_weight_items));
|
|
||||||
});
|
|
||||||
onFieldValueChange('group_weight_items.*', () => {
|
|
||||||
setGroupWeight(_.cloneDeep(form.values.group_weight_items));
|
|
||||||
});
|
|
||||||
onFieldInit('weight', () => {
|
|
||||||
setRecordWeight(_.cloneDeep(form.values.weight));
|
|
||||||
});
|
|
||||||
onFieldValueChange('weight', () => {
|
|
||||||
setRecordWeight(_.cloneDeep(form.values.weight));
|
|
||||||
});
|
|
||||||
|
|
||||||
onFieldInit('contract_plan', () => {
|
// 报价小结
|
||||||
if (form.values.contract_plan) {
|
const lease = [];
|
||||||
setContractPlanId(form.values.contract_plan.id);
|
for (const key in leaseSummary) {
|
||||||
} else {
|
if (Object.prototype.hasOwnProperty.call(leaseSummary, key)) {
|
||||||
setContractPlanId(-1);
|
const element = leaseSummary[key];
|
||||||
}
|
lease.push({ ...element, key: key });
|
||||||
});
|
|
||||||
onFieldValueChange('contract_plan', () => {
|
|
||||||
if (form.values.contract_plan) {
|
|
||||||
setContractPlanId(form.values.contract_plan.id);
|
|
||||||
} else {
|
|
||||||
setContractPlanId(-1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
onFieldInit('in_contract_plan', () => {
|
|
||||||
if (form.values.in_contract_plan) {
|
|
||||||
setInContractPlanId(form.values.in_contract_plan.id);
|
|
||||||
} else {
|
|
||||||
setInContractPlanId(-1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
onFieldValueChange('in_contract_plan', () => {
|
|
||||||
if (form.values.in_contract_plan) {
|
|
||||||
setInContractPlanId(form.values.in_contract_plan.id);
|
|
||||||
} else {
|
|
||||||
setInContractPlanId(-1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
onFieldInit('out_contract_plan', () => {
|
|
||||||
if (form.values.out_contract_plan) {
|
|
||||||
setOutContractPlanId(form.values.out_contract_plan.id);
|
|
||||||
} else {
|
|
||||||
setOutContractPlanId(-1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
onFieldValueChange('out_contract_plan', () => {
|
|
||||||
if (form.values.out_contract_plan) {
|
|
||||||
setOutContractPlanId(form.values.out_contract_plan.id);
|
|
||||||
} else {
|
|
||||||
setOutContractPlanId(-1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
!contractPlans.loading &&
|
|
||||||
!reqWeightRules.loading &&
|
|
||||||
!reqProduct.loading &&
|
|
||||||
!loadingLeaseItems &&
|
|
||||||
!loadingInLeaseItems &&
|
|
||||||
!loadingOutLeaseItems
|
|
||||||
) {
|
|
||||||
calcLeaseSum();
|
|
||||||
}
|
}
|
||||||
}, [
|
}
|
||||||
products,
|
lease.unshift(leaseSummaryWeight);
|
||||||
leaseData,
|
lease.push(leaseSummaryPrice);
|
||||||
groupWeight,
|
const leasevalue = lease
|
||||||
recordWeight,
|
.map((item) => {
|
||||||
contractPlans.loading,
|
if (!item.total) return;
|
||||||
reqWeightRules.loading,
|
return {
|
||||||
reqProduct.loading,
|
label: item.name,
|
||||||
loadingLeaseItems,
|
children: <p>{item.unit ? formatQuantity(item.total, 2) + item.unit : formatCurrency(item.total, 2)}</p>,
|
||||||
loadingInLeaseItems,
|
};
|
||||||
loadingOutLeaseItems,
|
})
|
||||||
]);
|
.filter(Boolean);
|
||||||
|
|
||||||
const items = [
|
const resultItems = [
|
||||||
{ label: '基础', value: value },
|
{ label: '基础', value: value },
|
||||||
{ label: '报价', value: leasevalue },
|
{ label: '报价', value: leasevalue },
|
||||||
{ label: '出库合同', value: outContractvalue },
|
{ label: '出库合同', value: outContractvalue },
|
||||||
{ label: form.values.category === RecordCategory.lease ? '合同' : '入库合同', value: inContractvalue },
|
{ label: form.values.category === RecordCategory.lease ? '合同' : '入库合同', value: inContractvalue },
|
||||||
];
|
];
|
||||||
|
|
||||||
const trans: any[] = items
|
const trans: any[] = resultItems
|
||||||
.map((item, index) => {
|
.map((item, index) => {
|
||||||
if (item.value.length) {
|
if (item.value.length) {
|
||||||
const data = {
|
const data = {
|
||||||
@ -534,7 +352,7 @@ export const RecordSummary = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
RecordSummary.displayName = 'RecordSummary';
|
RecordSummary.displayName = 'RecordSummary';
|
||||||
RecordSummary[KEY_CUSTOM_COMPONENT_TYPE] = CUSTOM_COMPONENT_TYPE_FORM_ITEM;
|
RecordSummary[KEY_CUSTOM_COMPONENT_TYPE] = CUSTOM_COMPONENT_TYPE_FORM_ITEM;
|
||||||
|
Loading…
Reference in New Issue
Block a user