|
@@ -21,9 +21,7 @@ import {
|
|
|
} from 'antd';
|
|
|
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
|
|
import { connect } from 'dva';
|
|
|
-import { isArray, result, set } from 'lodash';
|
|
|
import { useForm } from 'rc-field-form';
|
|
|
-import { async } from '@antv/x6/lib/registry/marker/async';
|
|
|
import AuditDetailed from './AuditDetailed';
|
|
|
import AuditFlow from './AuditFlow';
|
|
|
import {
|
|
@@ -87,26 +85,154 @@ function CommitAuditModal(props) {
|
|
|
form: [],
|
|
|
});
|
|
|
|
|
|
+ function getDataValue(item) {
|
|
|
+ let arr = [];
|
|
|
+ arr.push(item.value);
|
|
|
+ if (item.children?.length > 0) {
|
|
|
+ const res = getDataValue(item.children[0]);
|
|
|
+ arr = arr.concat(res);
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ const initFormList = async () => {
|
|
|
+ const res = await queryGetBomForm({
|
|
|
+ project_id: version.project_id,
|
|
|
+ node_id: version.template_node_id,
|
|
|
+ });
|
|
|
+ if (res.data) {
|
|
|
+ const formList = JSON.parse(res.data.json);
|
|
|
+ setApprovalProcess(formList.approvalProcess || {});
|
|
|
+ return formList;
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param {*} currentId 当前节点
|
|
|
+ * @param {*} type 下一个节点的类型 custom-circle: 审批节点 custom-rect: 业务节点
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ const getNextNodes = (currentId, type) => {
|
|
|
+ const { edges, nodes } = flowDetail;
|
|
|
+ if (!currentId) return [];
|
|
|
+ // 删除虚线通向的节点
|
|
|
+ // let targetIds = edges
|
|
|
+ // .filter(edge => {
|
|
|
+ // let line = edge.attrs?.line?.strokeDasharray?.split(' ');
|
|
|
+ // return edge.source.cell == currentId && line && line[0] == '0';
|
|
|
+ // })
|
|
|
+ // .map(item => item.target.cell);
|
|
|
+ // console.log(
|
|
|
+ // '---------',
|
|
|
+ // edges.filter(edge => edge.source.cell == currentId)
|
|
|
+ // );
|
|
|
+ const targetIds = edges
|
|
|
+ .filter(edge => edge.source.cell === currentId)
|
|
|
+ .map(item => item.target.cell);
|
|
|
+
|
|
|
+ edges.filter(edge => edge.source.cell === currentId);
|
|
|
+ const auditNodes = nodes.filter(node => {
|
|
|
+ if (type && node.name !== type) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return targetIds.indexOf(node.id) !== -1;
|
|
|
+ });
|
|
|
+ const auditNode = auditNodes.map(item => {
|
|
|
+ return {
|
|
|
+ label: item.label,
|
|
|
+ value: item.Id,
|
|
|
+ Id: item.node_id,
|
|
|
+ parentId: currentId,
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+ });
|
|
|
+ return auditNode || [];
|
|
|
+ };
|
|
|
+
|
|
|
+ const treeData = currentId => {
|
|
|
+ const list = getNextNodes(currentId, 'custom-circle');
|
|
|
+ const fun = nodes => {
|
|
|
+ const re = nodes?.forEach((item, idx) => {
|
|
|
+ const data = getNextNodes(item.Id, 'custom-circle');
|
|
|
+ if (data || data.length > 0) list.push(...data);
|
|
|
+ fun(data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ fun(list);
|
|
|
+
|
|
|
+ const fun2 = list => {
|
|
|
+ const parents = list.filter(item => list.findIndex(node => node.Id == item.parentId) == -1);
|
|
|
+ let translator = (parents, children) => {
|
|
|
+ setLength(length + 1);
|
|
|
+ parents.forEach(parent => {
|
|
|
+ children.forEach((current, index) => {
|
|
|
+ if (current.parentId === parent.Id) {
|
|
|
+ let temp = JSON.parse(JSON.stringify(children));
|
|
|
+ temp.splice(index, 1);
|
|
|
+ translator([current], temp);
|
|
|
+ if (!parent.children.find(item => item.Id == current.Id))
|
|
|
+ parent.children.push(current);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+ translator(parents, list);
|
|
|
+ return parents;
|
|
|
+ };
|
|
|
+ return fun2(list);
|
|
|
+ };
|
|
|
+
|
|
|
+ const onChange = async (value, approvalProcess) => {
|
|
|
+ // 加载之前提交的form数据
|
|
|
+ const resFormData = await initFormList();
|
|
|
+ const resData = resFormData?.formList;
|
|
|
+ debugger;
|
|
|
+ const prevFormData =
|
|
|
+ resData && resData.length ? resData.map(resItem => JSON.parse(resItem)) : null;
|
|
|
+ if (prevFormData && prevFormData.length) {
|
|
|
+ const formValues = {};
|
|
|
+ prevFormData.forEach(pItem => {
|
|
|
+ formValues[pItem.template_node_id] = [...pItem.formComponentValues];
|
|
|
+ });
|
|
|
+ setFormComponentValues(formValues);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (value) {
|
|
|
+ changeAudit(value[value.length - 1]);
|
|
|
+ if (prevFormData !== null) {
|
|
|
+ setAuditListFun(approvalProcess, prevFormData);
|
|
|
+ } else {
|
|
|
+ setAuditListFun(approvalProcess);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ changeAudit('');
|
|
|
+ setAuditList([]);
|
|
|
+ setApprovalProcess({});
|
|
|
+ }
|
|
|
+ form.setFieldValue('next_template_node_id', '');
|
|
|
+ };
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (!visible) return;
|
|
|
|
|
|
const { edges, nodes } = flowDetail;
|
|
|
|
|
|
- let Id = version.template_node_id;
|
|
|
+ const Id = version.template_node_id;
|
|
|
const currentId = flowDetail.nodes.find?.(item => item.Id == Id)?.node_id;
|
|
|
const data = treeData(currentId);
|
|
|
- // console.log('===============审批节点======', data);
|
|
|
const nextNodes = getNextNodes(currentId, 'custom-rect');
|
|
|
if (data.length <= 0 || nextNodes.length > 0) {
|
|
|
setAuditId(currentId);
|
|
|
} else {
|
|
|
- let defaultValues = {};
|
|
|
- if (data.length == 1) {
|
|
|
- let value = getDataValue(data[0]);
|
|
|
- defaultValues[`circle`] = value;
|
|
|
+ const defaultValues = {};
|
|
|
+ if (data.length === 1) {
|
|
|
+ const value = getDataValue(data[0]);
|
|
|
+ defaultValues.circle = value;
|
|
|
} else {
|
|
|
data.forEach((item, index) => {
|
|
|
- let value = getDataValue(item);
|
|
|
+ const value = getDataValue(item);
|
|
|
defaultValues[`circle${index}`] = value;
|
|
|
});
|
|
|
}
|
|
@@ -114,8 +240,8 @@ function CommitAuditModal(props) {
|
|
|
setTimeout(async () => {
|
|
|
form.setFieldsValue(defaultValues);
|
|
|
const initForm = await initFormList();
|
|
|
- const approvalProcess = initForm?.approvalProcess ? initForm.approvalProcess : {};
|
|
|
- Object.values(defaultValues).forEach(value => onChange(value, approvalProcess));
|
|
|
+ const tempAP = initForm?.approvalProcess ? initForm.approvalProcess : {};
|
|
|
+ Object.values(defaultValues).forEach(value => onChange(value, tempAP));
|
|
|
}, 200);
|
|
|
}
|
|
|
setData(data);
|
|
@@ -164,100 +290,12 @@ function CommitAuditModal(props) {
|
|
|
// showUploadList: false,
|
|
|
};
|
|
|
|
|
|
- const initFormList = async () => {
|
|
|
- const res = await queryGetBomForm({
|
|
|
- project_id: version.project_id,
|
|
|
- node_id: version.template_node_id,
|
|
|
- });
|
|
|
- if (res.data) {
|
|
|
- const formList = JSON.parse(res.data.json);
|
|
|
- setApprovalProcess(formList.approvalProcess || {});
|
|
|
- return formList;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- const treeData = currentId => {
|
|
|
- const list = getNextNodes(currentId, 'custom-circle');
|
|
|
- const fun = nodes => {
|
|
|
- const re = nodes?.forEach((item, idx) => {
|
|
|
- const data = getNextNodes(item.Id, 'custom-circle');
|
|
|
- if (data || data.length > 0) list.push(...data);
|
|
|
- fun(data);
|
|
|
- });
|
|
|
- };
|
|
|
- fun(list);
|
|
|
-
|
|
|
- const fun2 = list => {
|
|
|
- const parents = list.filter(item => list.findIndex(node => node.Id == item.parentId) == -1);
|
|
|
- let translator = (parents, children) => {
|
|
|
- setLength(length + 1);
|
|
|
- parents.forEach(parent => {
|
|
|
- children.forEach((current, index) => {
|
|
|
- if (current.parentId === parent.Id) {
|
|
|
- let temp = JSON.parse(JSON.stringify(children));
|
|
|
- temp.splice(index, 1);
|
|
|
- translator([current], temp);
|
|
|
- if (!parent.children.find(item => item.Id == current.Id))
|
|
|
- parent.children.push(current);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- };
|
|
|
- translator(parents, list);
|
|
|
- return parents;
|
|
|
- };
|
|
|
- return fun2(list);
|
|
|
- };
|
|
|
-
|
|
|
const currentNodeId = useMemo(() => {
|
|
|
let Id = version.template_node_id;
|
|
|
setAuditId(currentNodeId);
|
|
|
return flowDetail.nodes.find?.(item => item.Id == Id)?.node_id;
|
|
|
}, [flowDetail, version]);
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param {*} currentId 当前节点
|
|
|
- * @param {*} type 下一个节点的类型 custom-circle: 审批节点 custom-rect: 业务节点
|
|
|
- * @returns
|
|
|
- */
|
|
|
- const getNextNodes = (currentId, type) => {
|
|
|
- const { edges, nodes } = flowDetail;
|
|
|
- if (!currentId) return [];
|
|
|
- // 删除虚线通向的节点
|
|
|
- // let targetIds = edges
|
|
|
- // .filter(edge => {
|
|
|
- // let line = edge.attrs?.line?.strokeDasharray?.split(' ');
|
|
|
- // return edge.source.cell == currentId && line && line[0] == '0';
|
|
|
- // })
|
|
|
- // .map(item => item.target.cell);
|
|
|
- // console.log(
|
|
|
- // '---------',
|
|
|
- // edges.filter(edge => edge.source.cell == currentId)
|
|
|
- // );
|
|
|
- let targetIds = edges
|
|
|
- .filter(edge => edge.source.cell == currentId)
|
|
|
- .map(item => item.target.cell);
|
|
|
-
|
|
|
- edges.filter(edge => edge.source.cell == currentId);
|
|
|
- let auditNodes = nodes.filter(node => {
|
|
|
- if (type && node.name != type) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- return targetIds.indexOf(node.id) != -1;
|
|
|
- });
|
|
|
- const result = auditNodes.map(item => {
|
|
|
- return {
|
|
|
- label: item.label,
|
|
|
- value: item.Id,
|
|
|
- Id: item.node_id,
|
|
|
- parentId: currentId,
|
|
|
- children: [],
|
|
|
- };
|
|
|
- });
|
|
|
- return result || [];
|
|
|
- };
|
|
|
-
|
|
|
const nextNodesList = useMemo(() => {
|
|
|
if (!auditId && !currentNodeId) return [];
|
|
|
return getNextNodes(auditId || currentNodeId, 'custom-rect');
|
|
@@ -268,35 +306,6 @@ function CommitAuditModal(props) {
|
|
|
setAuditId(node?.node_id);
|
|
|
};
|
|
|
|
|
|
- const onChange = async (value, approvalProcess) => {
|
|
|
- // 加载之前提交的form数据
|
|
|
- const resFormData = await initFormList();
|
|
|
- const resData = resFormData?.formList;
|
|
|
- const prevFormData =
|
|
|
- resData && resData.length ? resData.map(resItem => JSON.parse(resItem)) : null;
|
|
|
- if (prevFormData && prevFormData.length) {
|
|
|
- const formValues = {};
|
|
|
- prevFormData.forEach(pItem => {
|
|
|
- formValues[pItem.template_node_id] = [...pItem.formComponentValues];
|
|
|
- });
|
|
|
- setFormComponentValues(formValues);
|
|
|
- }
|
|
|
-
|
|
|
- if (value) {
|
|
|
- changeAudit(value[value.length - 1]);
|
|
|
- if (prevFormData !== null) {
|
|
|
- setAuditListFun(approvalProcess, prevFormData);
|
|
|
- } else {
|
|
|
- setAuditListFun(approvalProcess);
|
|
|
- }
|
|
|
- } else {
|
|
|
- changeAudit('');
|
|
|
- setAuditList([]);
|
|
|
- setApprovalProcess({});
|
|
|
- }
|
|
|
- form.setFieldValue('next_template_node_id', '');
|
|
|
- };
|
|
|
-
|
|
|
const getReComputeAudit = (items, changedValues) => {
|
|
|
const id = Object.keys(changedValues)[0];
|
|
|
const formItem = items?.find(item => item.props.id == id);
|
|
@@ -427,7 +436,14 @@ function CommitAuditModal(props) {
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
- const newData = [{ name: tableLabel, id: tableID, type: tableID.split('_')[0], value: rows }];
|
|
|
+ const newData = [
|
|
|
+ {
|
|
|
+ name: tableLabel,
|
|
|
+ id: tableID,
|
|
|
+ type: tableID.split('_')[0],
|
|
|
+ value: rows,
|
|
|
+ },
|
|
|
+ ];
|
|
|
setFormComponentValues(prevState => {
|
|
|
return { ...prevState, [currentNodeID]: newData };
|
|
|
});
|
|
@@ -435,11 +451,13 @@ function CommitAuditModal(props) {
|
|
|
};
|
|
|
|
|
|
const onFormValueChange = (changedFields, allValues) => {
|
|
|
+ console.log(allValues);
|
|
|
const currentNodeID = auditList[currentTab].nodeId;
|
|
|
const allFormItem = auditList[currentTab].items;
|
|
|
const componentValue = formComponentValues[currentNodeID] || [];
|
|
|
const currentFieldID = Object.keys(changedFields)[0];
|
|
|
const formItem = allFormItem.find(item => item.props.id === currentFieldID);
|
|
|
+ // 记录变更的formItem值
|
|
|
if (componentValue.length) {
|
|
|
for (let index = 0; index < componentValue.length; index++) {
|
|
|
const item = componentValue[index];
|
|
@@ -465,32 +483,35 @@ function CommitAuditModal(props) {
|
|
|
value: [changedFields[currentFieldID]],
|
|
|
});
|
|
|
}
|
|
|
- setFormComponentValues({ ...formComponentValues, [currentNodeID]: componentValue });
|
|
|
+ setFormComponentValues({
|
|
|
+ ...formComponentValues,
|
|
|
+ [currentNodeID]: componentValue,
|
|
|
+ });
|
|
|
formValueRef.current.form[currentNodeID] = [...componentValue];
|
|
|
advanceSubmit();
|
|
|
};
|
|
|
|
|
|
// 处理tabs页
|
|
|
const setAuditListFun = async (approvalProcess = {}, prevFormData = []) => {
|
|
|
- var fieldsValue = await form.validateFields();
|
|
|
+ const fieldsValue = await form.validateFields();
|
|
|
let addAuditList = [];
|
|
|
- let result = Object.values(fieldsValue)
|
|
|
+ const result = Object.values(fieldsValue)
|
|
|
.map(item => {
|
|
|
if (item && Array.isArray(item)) return item;
|
|
|
})
|
|
|
.filter(item => item)
|
|
|
.flat(Infinity);
|
|
|
- let nodeList = [...new Set(result)]
|
|
|
+ const nodeList = [...new Set(result)]
|
|
|
.map(Id => {
|
|
|
return flowDetail.nodes.find?.(item => item.Id == Id);
|
|
|
})
|
|
|
.filter(item => item);
|
|
|
- let flowIds = [...new Set(nodeList.map(item => item.flow_id))].join(',');
|
|
|
- let data = await queryProcessFlows({ ids: flowIds });
|
|
|
- if (data && data?.length > 0) {
|
|
|
- let newlist = nodeList.map(node => {
|
|
|
- let curData = data.find(item => item.id == node.flow_id);
|
|
|
- let newItem = {
|
|
|
+ const flowIds = [...new Set(nodeList.map(item => item.flow_id))].join(',');
|
|
|
+ const processFlows = await queryProcessFlows({ ids: flowIds });
|
|
|
+ if (processFlows && processFlows?.length > 0) {
|
|
|
+ const newlist = nodeList.map(node => {
|
|
|
+ const curData = processFlows.find(item => item.id === node.flow_id);
|
|
|
+ const newItem = {
|
|
|
name: curData?.name,
|
|
|
nodeId: node.Id,
|
|
|
items: JSON.parse(curData?.form_json || '[]'),
|
|
@@ -500,7 +521,7 @@ function CommitAuditModal(props) {
|
|
|
});
|
|
|
addAuditList = [...addAuditList, ...newlist];
|
|
|
}
|
|
|
- addAuditList.forEach((addAuditItem, index) => {
|
|
|
+ addAuditList.forEach(addAuditItem => {
|
|
|
// 回填部分组件的历史数据
|
|
|
if (prevFormData.length) {
|
|
|
const currentForm = prevFormData.find(
|
|
@@ -513,37 +534,37 @@ function CommitAuditModal(props) {
|
|
|
DDComponent.props.defaultValue = prevValue?.value || prevValue?.defaultValue;
|
|
|
});
|
|
|
}
|
|
|
- const tempFormComponentValues = JSON.parse(JSON.stringify(formComponentValues));
|
|
|
- const Components = Form3x.create({
|
|
|
- onValuesChange: (props, changedValues, allValues) => {
|
|
|
- const { items: allFormItem } = props;
|
|
|
- tempFormComponentValues[addAuditItem.nodeId] = allFormItem
|
|
|
- .map(formItem => {
|
|
|
- const itemProps = formItem.props;
|
|
|
- const val = allValues[itemProps.id];
|
|
|
- if (!itemProps.label || val === '') return;
|
|
|
- if (val instanceof Object) {
|
|
|
- return {
|
|
|
- name: itemProps.label,
|
|
|
- id: itemProps.id,
|
|
|
- value: [...val],
|
|
|
- };
|
|
|
- } else if (allValues[itemProps.id]) {
|
|
|
- return {
|
|
|
- name: itemProps.label,
|
|
|
- id: itemProps.id,
|
|
|
- value: [allValues[itemProps.id]] || undefined,
|
|
|
- };
|
|
|
- }
|
|
|
- })
|
|
|
- .filter(formItem => formItem);
|
|
|
- if (getReComputeAudit(allFormItem, changedValues)) advanceSubmit();
|
|
|
- console.log(tempFormComponentValues);
|
|
|
- setFormComponentValues({ ...tempFormComponentValues });
|
|
|
- },
|
|
|
- })(AuditDetailed);
|
|
|
-
|
|
|
- addAuditItem.FormComponents = <Components items={addAuditItem.items} />;
|
|
|
+ // const tempFormComponentValues = JSON.parse(JSON.stringify(formComponentValues));
|
|
|
+ // const Components = Form3x.create({
|
|
|
+ // onValuesChange: (props, changedValues, allValues) => {
|
|
|
+ // const { items: allFormItem } = props;
|
|
|
+ // tempFormComponentValues[addAuditItem.nodeId] = allFormItem
|
|
|
+ // .map(formItem => {
|
|
|
+ // const itemProps = formItem.props;
|
|
|
+ // const val = allValues[itemProps.id];
|
|
|
+ // if (!itemProps.label || val === '') return;
|
|
|
+ // if (val instanceof Object) {
|
|
|
+ // return {
|
|
|
+ // name: itemProps.label,
|
|
|
+ // id: itemProps.id,
|
|
|
+ // value: [...val],
|
|
|
+ // };
|
|
|
+ // } else if (allValues[itemProps.id]) {
|
|
|
+ // return {
|
|
|
+ // name: itemProps.label,
|
|
|
+ // id: itemProps.id,
|
|
|
+ // value: [allValues[itemProps.id]] || undefined,
|
|
|
+ // };
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // .filter(formItem => formItem);
|
|
|
+ // if (getReComputeAudit(allFormItem, changedValues)) advanceSubmit();
|
|
|
+ // console.log(tempFormComponentValues);
|
|
|
+ // setFormComponentValues({ ...tempFormComponentValues });
|
|
|
+ // },
|
|
|
+ // })(AuditDetailed);
|
|
|
+
|
|
|
+ // addAuditItem.FormComponents = <Components items={addAuditItem.items} />;
|
|
|
});
|
|
|
setAuditList(addAuditList);
|
|
|
advanceSubmit();
|
|
@@ -872,16 +893,6 @@ function CommitAuditModal(props) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-function getDataValue(item) {
|
|
|
- let arr = [];
|
|
|
- arr.push(item.value);
|
|
|
- if (item.children?.length > 0) {
|
|
|
- let res = getDataValue(item.children[0]);
|
|
|
- arr = arr.concat(res);
|
|
|
- }
|
|
|
- return arr;
|
|
|
-}
|
|
|
-
|
|
|
const uploadExcelByUrl = (nodeType, versionId) => {
|
|
|
const TEMPLATE_URL =
|
|
|
'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/doc/contract/2023-06-29/ed0d5dcd-6ce0-40df-9d17-a1f69245dbb9.xlsx';
|