From aed1ff699140de60131bf9cc1332c98063c66721 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 03 七月 2020 09:14:51 +0800
Subject: [PATCH] 2020-07-03

---
 src/views/printTemplate/mutilform/index.jsx |   63 ++++++++++++++++++++++---------
 1 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/src/views/printTemplate/mutilform/index.jsx b/src/views/printTemplate/mutilform/index.jsx
index 1d209f4..809500f 100644
--- a/src/views/printTemplate/mutilform/index.jsx
+++ b/src/views/printTemplate/mutilform/index.jsx
@@ -3,7 +3,7 @@
 import { is, fromJS } from 'immutable'
 import { Form, Row, Col, Input, InputNumber, Select } from 'antd'
 import { formRule } from '@/utils/option.js'
-import FileUpload from '../fileupload'
+import FileUpload from '@/tabviews/zshare/fileupload'
 import './index.scss'
 
 const { TextArea } = Input
@@ -60,6 +60,17 @@
           if (!isCusField) {
             delete fieldsvalue.cusfield
           }
+          if (nextProps.editItem.type === 'image' && fieldsvalue.value) {
+            fieldsvalue.value = [{
+              uid: '1',
+              name: fieldsvalue.value,
+              status: 'done',
+              url: fieldsvalue.value
+            }]
+          } else if (nextProps.editItem.type === 'image') {
+            fieldsvalue.value = []
+          }
+
           this.props.form.setFieldsValue(fieldsvalue)
         })
         
@@ -101,6 +112,19 @@
     this.handleSubmit()
   }
 
+  updateImg = (list) => {
+    if (list && list.length > 0) {
+      let url = list[0].url || list[0].response
+      if (url) {
+        this.props.form.setFieldsValue({ value: list })
+        this.handleSubmit()
+      }
+    } else {
+      this.props.form.setFieldsValue({ value: [] })
+      this.handleSubmit()
+    }
+  }
+
   resetForm = (param) => {
     let _param = JSON.parse(JSON.stringify(param))
     delete _param.type
@@ -109,6 +133,16 @@
 
     if (_param.field !== 'other_field') {
       delete _param.cusfield
+    }
+    if (param.type === 'image' && param.value) {
+      _param.value = [{
+        uid: '1',
+        name: param.value,
+        status: 'done',
+        url: param.value
+      }]
+    } else if (param.type === 'image') {
+      _param.value = []
     }
 
     this.props.form.setFieldsValue(_param)
@@ -204,23 +238,14 @@
           </Col>
         )
       } else if (item.type === 'fileupload') {
-        let filelist = this.props.data ? this.props.data[item.field] : item.initval
-        if (filelist && this.state.readin[item.field]) {
-          try {
-            filelist = filelist.split(',').map((url, index) => {
-              return {
-                uid: `${index}`,
-                name: url.slice(url.lastIndexOf('/') + 1),
-                status: 'done',
-                url: url,
-                origin: true
-              }
-            })
-          } catch {
-            filelist = []
-          }
-        } else {
-          filelist = []
+        let filelist = []
+        if (item.initval) {
+          filelist = [{
+            uid: '1',
+            name: item.initval,
+            status: 'done',
+            url: item.initval
+          }]
         }
 
         fields.push(
@@ -235,7 +260,7 @@
                   }
                 ]
               })(
-                <FileUpload />
+                <FileUpload maxFile={1} fileType={'text'} onChange={this.updateImg} />
               )}
             </Form.Item>
           </Col>

--
Gitblit v1.8.0