From 4c775de9de07291b345fd5c975a87230ddedd5ca Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 20 五月 2020 09:27:13 +0800
Subject: [PATCH] 2020-05-20

---
 src/templates/sharecomponent/cardcomponent/carddetailform/index.jsx |   92 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/src/templates/sharecomponent/cardcomponent/carddetailform/index.jsx b/src/templates/sharecomponent/cardcomponent/carddetailform/index.jsx
index d469a9a..8b42d52 100644
--- a/src/templates/sharecomponent/cardcomponent/carddetailform/index.jsx
+++ b/src/templates/sharecomponent/cardcomponent/carddetailform/index.jsx
@@ -15,6 +15,7 @@
 
   state = {
     formlist: null,
+    oriformlist: null,
     columns: null,
     actions: []
   }
@@ -22,37 +23,49 @@
   UNSAFE_componentWillMount () {
     const { card } = this.props
 
-    let columns = this.props.formlist.filter(item => item.key === 'field')[0].options
+    let columns = []
     let actions = []
-    if (card.actions) {
-      actions = this.props.formlist.filter(item => item.key === 'actions')[0].options
-    }
+
+    let formlist = this.props.formlist.filter(item => !item.forbid)
+    formlist.forEach(item => {
+      if (item.key === 'field') {
+        columns = JSON.parse(JSON.stringify(item.options))
+      } else if (item.key === 'actions') {
+        actions = JSON.parse(JSON.stringify(item.options))
+      }
+    })
 
     this.setState({
       columns: columns,
       actions: actions,
-      formlist: this.props.formlist.map(item => {
+      oriformlist: formlist,
+      formlist: formlist.map(item => {
         if (item.key === 'content' && card.datatype === 'dynamic') {
           item.hidden = true
         } else if (item.key === 'field' && card.datatype === 'static') {
           item.hidden = true
+        } else if (item.key === 'field' && card.elemType === 'avatar') {
+          item.options = columns.filter(option => option.type === card.type)
+        } else if (item.key === 'widthType' && card.elemType === 'avatar' && card.type === 'picture') {
+          item.hidden = false
+        } else if (item.key === 'size' && card.elemType === 'avatar' && card.type === 'icon') {
+          item.hidden = false
+        } else if (item.key === 'width' && card.elemType === 'avatar' && card.type === 'picture') {
+          item.hidden = false
         }
-
         return item
       })
     })
   }
 
-  componentDidMount () {
-
-  }
-
   typeChange = (key, value) => {
+    const { card } = this.props
+    const { columns, oriformlist } = this.state
+
     if (key === 'datatype') {
       this.setState({
-        formlist: this.props.formlist.map(item => {
+        formlist: oriformlist.map(item => {
           item.hidden = false
-
           if (item.key === 'content' && value === 'dynamic') {
             item.hidden = true
           } else if (item.key === 'field' && value === 'static') {
@@ -62,9 +75,41 @@
           return item
         })
       })
-      // if (this.props.form.getFieldValue('fieldlength') !== undefined) {
-      //   this.props.form.setFieldsValue({fieldlength: fieldlength})
-      // }
+    } else if (key === 'type') {
+      this.setState({
+        formlist: oriformlist.map(item => {
+          if (item.key === 'field') {
+            item.options = columns.filter(option => option.type === value)
+          } else if (item.key === 'widthType') {
+            item.hidden = value !== 'picture'
+          } else if (item.key === 'width') {
+            item.hidden = value !== 'picture'
+            item.max = card.widthType === 'ratio' ? 100 : 500
+          } else if (item.key === 'size') {
+            item.hidden = value !== 'icon'
+          }
+
+          return item
+        })
+      }, () => {
+        if (this.props.form.getFieldValue('field') !== undefined) {
+          this.props.form.setFieldsValue({field: ''})
+        }
+      })
+    } else if (key === 'widthType') {
+      this.setState({
+        formlist: oriformlist.map(item => {
+          if (item.key === 'width') {
+            item.max = value === 'ratio' ? 100 : 500
+          }
+
+          return item
+        })
+      }, () => {
+        if (this.props.form.getFieldValue('width') !== undefined) {
+          this.props.form.setFieldsValue({width: 32})
+        }
+      })
     }
   }
 
@@ -124,8 +169,7 @@
                     message: this.props.dict['form.required.input'] + item.label + '!'
                   }
                 ]
-              })(item.unlimit ? <InputNumber /> :
-                  <InputNumber min={item.min} max={item.max} precision={item.decimal} />)}
+              })(<InputNumber min={item.min} max={item.max} precision={0} />)}
             </Form.Item>
           </Col>
         )
@@ -219,13 +263,21 @@
           if (this.props.card.uuid) {
             values.uuid = this.props.card.uuid
           }
+          values.elemType = this.props.card.elemType
 
-          if (values.field && !values.content) {
-            values.content = columns.filter(col => col.value === values.field)[0].text
+          if (['detail', 'header'].includes(values.elemType)) {
+            if (values.field && !values.content) {
+              values.content = columns.filter(col => col.value === values.field)[0].text
+            }
           }
-          if (values.actions) {
+          if (['bottom', 'header'].includes(values.elemType) && values.actions) {
             values.actions = values.actions.map(item => actions.filter(action => action.value === item)[0])
           }
+          if (['avatar'].includes(values.elemType)) {
+            if (values.type === 'icon') {
+              values.icon = columns.filter(col => col.value === values.field)[0].icon
+            }
+          }
 
           resolve(values)
         } else {

--
Gitblit v1.8.0