瀏覽代碼

Merge branch 'develop'

ZhaoJun 1 年之前
父節點
當前提交
f8156f0959

+ 72 - 5
src/components/DDComponents/DIYTable/index.tsx

@@ -32,7 +32,7 @@ function DIYTable(props: IProps) {
   const [tableData, setTableData] = useState<TableDataType[]>([{ index: 1 }]);
 
   // table列配置
-  const tableColumnDef = [
+  const tableColumnDef: ColumnsType<any> = [
     {
       title: '序号',
       dataIndex: 'index',
@@ -40,6 +40,67 @@ function DIYTable(props: IProps) {
     },
   ];
 
+  const [commitValue, setCommitValue] = useState<any[]>([]);
+
+  const handleValueChange = (value: any, id: string, label: string) => {
+    let ids = id.split(';');
+    let [rowIndex, colIndex] = ids[0].split(',').map(item => Number(item));
+    let [columnID, _tableID] = ids[1].split('>');
+    let [columnLabel, _tableLabel] = label.split('>');
+
+    const cell = {
+      name: columnLabel,
+      id: columnID,
+      type: columnID.split('_')[0],
+      value: [value],
+    };
+    // 组装可能用到的数据
+    const cols = [];
+    cols[colIndex] = cell;
+    const rows = [];
+    rows[rowIndex] = cols;
+
+    const newValues = JSON.parse(JSON.stringify(commitValue)) || [];
+
+    if (newValues.length !== 0 && newValues[rowIndex] !== undefined) {
+      newValues.forEach((row: any, rindex: number) => {
+        if (rindex === rowIndex) {
+          if (row[colIndex] !== undefined) {
+            row.forEach((_col: any, cindex: number) => {
+              if (cindex === colIndex) {
+                row[colIndex] = cell;
+              }
+            });
+          } else {
+            row[colIndex] = cell;
+          }
+        }
+      });
+    } else {
+      newValues[rowIndex] = cols;
+    }
+
+    const textNode = columns?.find(item => item.componentName === 'TextNote');
+    if (textNode) {
+      const textNodeIndex = columns?.findIndex(item => item.componentName === 'TextNote');
+      const textCell = {
+        name: textNode.props.label,
+        id: textNode.props.id,
+        type: textNode.componentName,
+        value: [textNode.props.placeholder],
+      };
+      newValues.forEach(item => {
+        if (textNodeIndex !== -1) {
+          item[textNodeIndex] = textCell;
+        }
+      });
+    }
+    console.log(newValues);
+
+    setCommitValue(newValues);
+    onChange(newValues);
+  };
+
   // 表单填写时的表格生成
   const handleGenerateTable = () => {
     if (columns !== undefined && columns.length) {
@@ -64,7 +125,9 @@ function DIYTable(props: IProps) {
                   style={{ padding: '0', margin: '0' }}
                   options={column.props.options}
                   disabled={column.props.disabled}
-                  onChange={onChange}
+                  onChange={value => {
+                    handleValueChange(value, id, `${columnLabel}>${table.props.label}`);
+                  }}
                 />
               );
             };
@@ -81,7 +144,9 @@ function DIYTable(props: IProps) {
                   placeholder={column.props.placeholder}
                   format={column.props.format}
                   disabled={column.props.disabled}
-                  onChange={onChange}
+                  onChange={value => {
+                    handleValueChange(value, id, `${columnLabel}>${table.props.label}`);
+                  }}
                 />
               );
             };
@@ -98,7 +163,9 @@ function DIYTable(props: IProps) {
                   style={{ padding: '4px 11px' }}
                   disabled={column.props.disabled}
                   unit={column.props.unit}
-                  onChange={onChange}
+                  onChange={value => {
+                    handleValueChange(value, id, `${columnLabel}>${table.props.label}`);
+                  }}
                 />
               );
             };
@@ -111,7 +178,7 @@ function DIYTable(props: IProps) {
                   disabled={column.props.disabled}
                   placeholder={column.props.placeholder}
                   onChange={e =>
-                    onChange?.(e.target.value, id, `${columnLabel}>${table.props.label}`)
+                    handleValueChange?.(e.target.value, id, `${columnLabel}>${table.props.label}`)
                   }
                 />
               );

+ 3 - 4
src/components/DDComponents/ProjectField/index.js

@@ -31,8 +31,7 @@ function DDProjectField(props) {
       disabled={disabled}
       defaultValue={value ? Number(value) : undefined}
       onChange={val => {
-        console.log(val);
-        const project = projectList.find(item => item.id === val);
+        const project = projectList.find(item => item.ID === val);
         onChange(`${val}`);
       }}
       filterOption={(input, option) =>
@@ -40,8 +39,8 @@ function DDProjectField(props) {
       }
       options={projectList.map(item => {
         return {
-          label: `${item.project_name}(${item.project_full_code})`,
-          value: item.id,
+          label: `${item.Name}(${item.Code})`,
+          value: item.ID,
         };
       })}
     />

+ 10 - 14
src/pages/Detail/AuditDetailed.js

@@ -4,7 +4,7 @@ import { Button, Form } from 'antd';
 import { FormulaType } from '@/components/AuditForm/FormulaModal';
 
 const AuditDetailed = props => {
-  const { allValues = [], items, form, onValuesChange, onTableValChange } = props;
+  const { allValues = [], items, form, onValuesChange } = props;
 
   const depId = useMemo(() => {
     const id = items.find(item => item.componentName === 'DepartmentField')?.props.id;
@@ -90,19 +90,15 @@ const AuditDetailed = props => {
     // if (!component) return null;
     return (
       <>
-        {item?.isTable === undefined ? (
-          <Form.Item
-            key={id}
-            name={id}
-            label={formLabel}
-            rules={[{ required }]}
-            initialValue={item?.props?.defaultValue}
-          >
-            {renderComponents()}
-          </Form.Item>
-        ) : (
-          <DDComponents item={item} onChange={onTableValChange} />
-        )}
+        <Form.Item
+          key={id}
+          name={id}
+          label={formLabel}
+          rules={[{ required }]}
+          initialValue={item?.props?.defaultValue}
+        >
+          {renderComponents()}
+        </Form.Item>
       </>
     );
   };

+ 0 - 94
src/pages/Detail/CommitAuditModal.js

@@ -470,99 +470,6 @@ function CommitAuditModal(props) {
     setCurrentTab(index);
   };
 
-  const onDIYTableChange = (value, id, label) => {
-    const currentNodeID = auditList[currentTab]?.nodeId;
-    if (!currentNodeID) return;
-    const oldData = formComponentValues[currentNodeID] || [];
-
-    const ids = id.split(';');
-    const [rowIndex, colIndex] = ids[0].split(',').map(item => Number(item));
-    const [columnID, tableID] = ids[1].split('>');
-    const [columnLabel, tableLabel] = label.split('>');
-
-    const cell = {
-      name: columnLabel,
-      id: columnID,
-      type: columnID.split('_')[0],
-      value: [value],
-    };
-    // 组装可能用到的数据
-    const cols = [];
-    cols[colIndex] = cell;
-    const rows = [];
-    rows[rowIndex] = cols;
-
-    if (oldData && oldData.length) {
-      const table = oldData.find(item => item.id === tableID);
-      if (table) {
-        const oldRows = table.value;
-        if (oldRows) {
-          const oldCols = oldRows[rowIndex];
-          if (oldCols) {
-            // 记录可编辑控件
-            table.value[rowIndex][colIndex] = cell;
-            const newData = oldData.map(item => {
-              if (item.id === table.id) {
-                return table;
-              }
-              return item;
-            });
-            setFormComponentValues(prevState => {
-              return { ...prevState, [currentNodeID]: newData };
-            });
-          } else {
-            table.value[rowIndex] = cols;
-            const newData = oldData.map(item => {
-              if (item.id === table.id) {
-                return table;
-              }
-              return item;
-            });
-            setFormComponentValues(prevState => {
-              return { ...prevState, [currentNodeID]: newData };
-            });
-          }
-        } else {
-          table.value = rows;
-          const newData = oldData.map(item => {
-            if (item.id === table.id) {
-              return table;
-            }
-            return item;
-          });
-          setFormComponentValues(prevState => {
-            return { ...prevState, [currentNodeID]: newData };
-          });
-        }
-      } else {
-        const newData = [
-          ...oldData,
-          {
-            name: tableLabel,
-            id: tableID,
-            type: tableID.split('_')[0],
-            value: rows,
-          },
-        ];
-        setFormComponentValues(prevState => {
-          return { ...prevState, [currentNodeID]: newData };
-        });
-      }
-    } else {
-      const newData = [
-        {
-          name: tableLabel,
-          id: tableID,
-          type: tableID.split('_')[0],
-          value: rows,
-        },
-      ];
-      setFormComponentValues(prevState => {
-        return { ...prevState, [currentNodeID]: newData };
-      });
-    }
-  };
-
   const onFormValueChange = (changedFields, allValues) => {
     const currentNodeID = auditList[currentTab]?.nodeId;
     if (!currentNodeID) return;
@@ -922,7 +829,6 @@ function CommitAuditModal(props) {
                   items={item.items}
                   form={aduitDetailForm}
                   onValuesChange={onFormValueChange}
-                  onTableValChange={onDIYTableChange}
                 />
               </Col>
               <Col offset={1} span={6}>

+ 6 - 8
src/pages/Detail/FormAndFilesNode.js

@@ -62,16 +62,12 @@ const renderFrom = (data, projects) => {
   try {
     const ding_schema = JSON.parse(data)[0];
     const formData = JSON.parse(ding_schema)?.formComponentValues;
-    formData.forEach(item => {
-      if (item.type === 'DIYTable') {
-        item.value = item.value.map(row => JSON.parse(row));
-      }
-    });
+
     if (formData.length == 0) return <Empty description="没有表单信息" />;
     return (
       <>
         {formData.map((item, idx) => {
-          if (item.type === 'DIYTable') {
+          if (item.id.includes('DIYTable')) {
             return (
               <Form.Item
                 key={`FormAndFilesNode_${item.id}`}
@@ -88,8 +84,10 @@ const renderFrom = (data, projects) => {
           if (item.id.includes('ProjectField')) {
             if (value) {
               value = Number(value);
-              const project = projects.find(item => item.id === value);
-              value = `${project.project_name}(${project.project_full_code})`;
+              const project = projects.find(pitem => pitem.ID === value);
+              if (project) {
+                value = `${project.Name}(${project.Code})`;
+              }
             }
           }
           return (