浏览代码

feat: DIYTable控件 提交时value stringify 为字符串

ZhaoJun 1 年之前
父节点
当前提交
9cd759517d
共有 2 个文件被更改,包括 21 次插入33 次删除
  1. 7 1
      src/pages/Detail/AuditDetailed.js
  2. 14 32
      src/pages/Detail/CommitAuditModal.js

+ 7 - 1
src/pages/Detail/AuditDetailed.js

@@ -88,7 +88,13 @@ const AuditDetailed = props => {
     return (
       <>
         {item?.isTable === undefined ? (
-          <Form.Item key={id} name={id} label={formLabel} rules={[{ required }]}>
+          <Form.Item
+            key={id}
+            name={id}
+            label={formLabel}
+            rules={[{ required }]}
+            initialValue={item?.props?.defaultValue}
+          >
             {renderComponents()}
           </Form.Item>
         ) : (

+ 14 - 32
src/pages/Detail/CommitAuditModal.js

@@ -215,6 +215,11 @@ function CommitAuditModal(props) {
         ? data.find(item => item.template_node_id === approvalNode.Id).formComponentValues
         : [];
       let values = data[approvalNode.Id] || prevValues || [];
+      values.forEach(tempValue => {
+        if (tempValue.type === 'DIYTable') {
+          tempValue.value = [tempValue.value.map(item => JSON.stringify(item))];
+        }
+      });
       let audit_list = [],
         cc_list = [];
       approvalProcess[approvalNode.Id]?.forEach(item => {
@@ -318,37 +323,6 @@ function CommitAuditModal(props) {
       }
       // 回填之前的值结束后需要把formComponentValues清空 防止提交之前的值
       setFormComponentValues([]);
-      // 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();
@@ -575,6 +549,7 @@ function CommitAuditModal(props) {
   };
 
   const onFormValueChange = (changedFields, allValues) => {
+    console.log(allValues);
     const currentNodeID = auditList[currentTab].nodeId;
     const allFormItem = auditList[currentTab].items;
     const componentValue = formComponentValues[currentNodeID] || [];
@@ -590,6 +565,7 @@ function CommitAuditModal(props) {
       }
       // 没找到就给默认值
       if (!componentValue.find(item => item.id === tempFormItem.props.id)) {
+        // placeholder
         if (tempFormItem.componentName === 'TextNote') {
           componentValue.push({
             name: tempFormItem.props.label,
@@ -597,10 +573,13 @@ function CommitAuditModal(props) {
             value: [tempFormItem.props.placeholder],
           });
         } else {
+          const prevValue = allValues[tempFormItem.props.id];
+          console.log(prevValue);
+          // 从allValue中找到该值
           componentValue.push({
             name: tempFormItem.props.label,
             id: tempFormItem.props.id,
-            value: [],
+            value: Array.isArray(prevValue) ? [...prevValue] : [],
           });
         }
       }
@@ -721,6 +700,7 @@ function CommitAuditModal(props) {
     setLoading(true);
     try {
       const formList = getFromData(result);
+      console.log(formList);
       let params = {
         desc: fieldsValue.desc,
         // 审核流程id
@@ -771,6 +751,8 @@ function CommitAuditModal(props) {
         message.error('当前存在审批节点未绑定审批流程!请联系管理员。');
         return;
       }
+      debugger;
+      return;
       await querySaveBomForm({
         project_id: version.project_id,
         node_id: version.template_node_id,