king
2022-11-18 f05ce61d55d421926229e50136c3b18c0dd9c262
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Modal, Form, Tabs } from 'antd'
import { EditOutlined } from '@ant-design/icons'
 
import { getBaseForm, getOptionForm } from './formconfig'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
 
const { TabPane } = Tabs
const NormalForm = asyncComponent(() => import('@/components/normalform/modalform'))
 
class LineChartDrawerForm extends Component {
  static propTpyes = {
    plot: PropTypes.object,
    config: PropTypes.object,
    plotchange: PropTypes.func
  }
 
  state = {
    view: 'normal',
    visible: false,
    plot: null,
    formlist: null,
    baseFormlist: null
  }
 
  showDrawer = () => {
    const { config } = this.props
 
    this.setState({
      visible: true,
      view: 'normal',
      plot: fromJS(config.plot).toJS(),
      baseFormlist: getBaseForm(config.plot),
      formlist: getOptionForm(config.plot, config.columns)
    })
  }
 
  onSubmit = () => {
    const { config } = this.props
    const { plot, view } = this.state
 
    if (view === 'normal') {
      this.norRef.handleConfirm().then(res => {
        let _plot = {...plot, ...res}
 
        this.setState({
          plot: _plot,
          visible: false
        })
 
        this.props.plotchange({...config, plot: _plot})
      })
    } else if (view === 'base') {
      this.baseRef.handleConfirm().then(res => {
        let _plot = {...plot, ...res}
 
        this.setState({
          plot: _plot,
          visible: false
        })
 
        this.props.plotchange({...config, plot: _plot})
      })
    }
  }
 
  changeTab = (tab) => {
    const { plot, view } = this.state
 
    if (view === 'normal') {
      this.norRef.handleConfirm().then(res => {
        this.setState({
          plot: {...plot, ...res},
          view: tab
        })
      })
    } else if (view === 'base') {
      this.baseRef.handleConfirm().then(res => {
        this.setState({
          plot: {...plot, ...res},
          view: tab
        })
      })
    }
  }
 
  render() {
    const { config } = this.props
    const { view, visible, baseFormlist, formlist } = this.state
 
    return (
      <div className="line-chart-drawer-form">
        <EditOutlined title="编辑" onClick={this.showDrawer} />
        <Modal
          wrapClassName="mk-pop-modal"
          visible={visible}
          width={850}
          maskClosable={false}
          onOk={this.onSubmit}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          {config.name ? <div className="mk-com-name">{config.name} - 编辑</div> : null}
          <Tabs activeKey={view} onChange={this.changeTab}>
            <TabPane tab="组件设置" key="base">
              <NormalForm formlist={baseFormlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.baseRef = inst}/>
            </TabPane>
            <TabPane tab="图表设置" key="normal">
              <NormalForm formlist={formlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.norRef = inst}/>
            </TabPane>
          </Tabs>
        </Modal>
      </div>
    );
  }
}
 
export default Form.create()(LineChartDrawerForm)