From 137fb8ea6af2789b3238b22bac31d80bced41dfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 28 七月 2021 11:39:39 +0800
Subject: [PATCH] 2021-07-28

---
 src/views/printTemplate/mutilform/index.jsx |   83 +++++++++++++++++------------------------
 1 files changed, 35 insertions(+), 48 deletions(-)

diff --git a/src/views/printTemplate/mutilform/index.jsx b/src/views/printTemplate/mutilform/index.jsx
index f26ae33..120c3fd 100644
--- a/src/views/printTemplate/mutilform/index.jsx
+++ b/src/views/printTemplate/mutilform/index.jsx
@@ -1,12 +1,14 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Form, Row, Col, Input, InputNumber, Select } from 'antd'
+import { Form, Row, Col, Input, InputNumber, Select, Tooltip, Icon } from 'antd'
 import { formRule } from '@/utils/option.js'
-import FileUpload from '@/tabviews/zshare/fileupload'
+// import FileUpload from '@/tabviews/zshare/fileupload'
+import asyncComponent from '@/utils/asyncComponent'
 import './index.scss'
 
 const { TextArea } = Input
+const FileUpload = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
 
 class MainSearch extends Component {
   static propTpyes = {
@@ -52,6 +54,9 @@
           formlist: nextProps.formlist.map(item => {
             if (item.key === 'cusfield' && isCusField) {
               item.hidden = false
+            } else if (item.key === 'value' && item.type === 'fileupload') {
+              item.hidden = true
+              item.initval = fieldsvalue.value
             }
 
             return item
@@ -60,15 +65,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 = []
+          if (nextProps.editItem.type === 'image') {
+            this.setState({
+              formlist: this.state.formlist.map(item => {
+                if (item.key === 'value' && item.type === 'fileupload') {
+                  item.hidden = false
+                }
+    
+                return item
+              })
+            })
+            delete fieldsvalue.value
           }
 
           this.props.form.setFieldsValue(fieldsvalue)
@@ -112,19 +119,6 @@
     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
@@ -134,15 +128,9 @@
     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 = []
+
+    if (param.type === 'image') {
+      delete _param.value
     }
 
     this.props.form.setFieldsValue(_param)
@@ -238,21 +226,16 @@
           </Col>
         )
       } else if (item.type === 'fileupload') {
-        let filelist = []
-        if (item.initval) {
-          filelist = [{
-            uid: '1',
-            name: item.initval,
-            status: 'done',
-            url: item.initval
-          }]
-        }
-
         fields.push(
           <Col span={24} key={index}>
-            <Form.Item label={item.label}>
+            <Form.Item label={
+              item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}>
+                <Icon type="question-circle" />
+                {item.label}
+              </Tooltip> : item.label
+            }>
               {getFieldDecorator(item.key, {
-                initialValue: filelist,
+                initialValue: item.initval || '',
                 rules: [
                   {
                     required: item.required,
@@ -260,7 +243,7 @@
                   }
                 ]
               })(
-                <FileUpload maxFile={1} fileType={'text'} onChange={this.updateImg} />
+                <FileUpload type="picture" placement="right" onChange={this.handleSubmit} />
               )}
             </Form.Item>
           </Col>
@@ -268,7 +251,12 @@
       } else if (item.type === 'textarea') {
         fields.push(
           <Col span={24} key={index}>
-            <Form.Item label={item.label} >
+            <Form.Item label={
+              item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}>
+                <Icon type="question-circle" />
+                {item.label}
+              </Tooltip> : item.label
+            }>
               {getFieldDecorator(item.key, {
                 initialValue: item.initval || '',
                 rules: [
@@ -298,7 +286,6 @@
         if (!err) {
           values.uuid = this.props.editItem.uuid
           values.type = this.props.editItem.type
-
           resolve(values)
         }
       })

--
Gitblit v1.8.0