From 6257816acce548a113081578140058cd99e83160 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 05 十月 2020 10:01:16 +0800
Subject: [PATCH] 2020-10-05

---
 src/menu/components/card/data-card/index.jsx |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/src/menu/components/card/data-card/index.jsx b/src/menu/components/card/data-card/index.jsx
index 2e9670f..6c239b5 100644
--- a/src/menu/components/card/data-card/index.jsx
+++ b/src/menu/components/card/data-card/index.jsx
@@ -2,7 +2,7 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Icon, Popover } from 'antd'
+import { Icon, Popover, Modal } from 'antd'
 
 import asyncComponent from '@/utils/asyncComponent'
 import asyncIconComponent from '@/utils/asyncIconComponent'
@@ -16,6 +16,8 @@
 const SettingComponent = asyncIconComponent(() => import('@/menu/datasource'))
 const WrapComponent = asyncIconComponent(() => import('./wrapsetting'))
 const CardComponent = asyncComponent(() => import('../cardcomponent'))
+
+const { confirm } = Modal
 
 class antvBarLineChart extends Component {
   static propTpyes = {
@@ -63,10 +65,11 @@
         style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
         columns: [],
         scripts: [],
-        // action: [],
         subcards: [{
           uuid: Utils.getuuid(),
-          setting: { width: 6 },
+          setting: { width: 6, type: 'simple'},
+          style: {borderWidth: '1px', borderColor: '#e8e8e8'},
+          backStyle: {},
           elements: [],
           backElements: []
         }]
@@ -100,6 +103,9 @@
     MKEmitter.removeListener('submitStyle', this.getStyle)
   }
 
+  /**
+   * @description 鍗$墖琛屽灞備俊鎭洿鏂帮紙鏁版嵁婧愶紝鏍峰紡绛夛級
+   */
   updateComponent = (component) => {
     this.setState({
       card: component
@@ -111,6 +117,42 @@
     this.props.updateConfig(component)
   }
 
+  /**
+   * @description 鍗曚釜鍗$墖淇℃伅鏇存柊
+   */
+  updateCard = (cell) => {
+    let card = fromJS(this.state.card).toJS()
+
+    card.subcards = card.subcards.map(item => {
+      if (item.uuid === cell.uuid) return cell
+      return item
+    })
+
+    this.setState({card})
+
+    this.props.updateConfig(card)
+  }
+
+  /**
+   * @description 鍗曚釜鍗$墖淇℃伅鏇存柊
+   */
+  deleteCard = (cell) => {
+    let card = fromJS(this.state.card).toJS()
+    let _this = this
+
+    confirm({
+      content: '纭畾鍒犻櫎鍗$墖鍚楋紵',
+      onOk() {
+        card.subcards = card.subcards.filter(item => item.uuid !== cell.uuid)
+    
+        _this.setState({card})
+    
+        _this.props.updateConfig(card)
+      },
+      onCancel() {}
+    })
+  }
+
   changeStyle = () => {
     const { card } = this.state
 
@@ -120,12 +162,15 @@
   getStyle = (comIds, style) => {
     const { card } = this.state
 
-    if (comIds.length > 1 || comIds[0] !== card.uuid) return
+    if (comIds.length !== 1 || comIds[0] !== card.uuid) return
+
+    let _card = {...card, style}
 
     this.setState({
-      card: {...card, style}
+      card: _card
     })
-    console.log(style)
+    
+    this.props.updateConfig(_card)
   }
 
   render() {
@@ -143,7 +188,7 @@
         } trigger="hover">
           <Icon type="tool" />
         </Popover>
-        {card.subcards.map(subcard => (<CardComponent key={subcard.uuid} config={card} card={subcard} updateElement={this.updateComponent}/>))}
+        {card.subcards.map(subcard => (<CardComponent key={subcard.uuid} config={card} card={subcard} updateElement={this.updateCard} deleteElement={this.deleteCard}/>))}
         {card.wrap.addable === 'true' ? <div className="card-add-button"><Icon type="plus" /></div> : null}
       </div>
     )

--
Gitblit v1.8.0