king
2021-08-26 966ff7fb84181f0fa86a56569a8492453c3ae80a
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal } from 'antd'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import ModalForm from './modalform'
import './index.scss'
 
class NormalFormComponent extends Component {
  static propTpyes = {
    width: PropTypes.any,
    check: PropTypes.any,
    title: PropTypes.string,
    getForms: PropTypes.func,
    update: PropTypes.func
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    formlist: []
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(this.props.children), fromJS(nextProps.children))
  }
 
  trigger = () => {
    this.setState({
      visible: true,
      formlist: this.props.getForms()
    })
  }
 
  submit = () => {
    const { check } = this.props
 
    this.Ref.handleConfirm().then(res => {
      if (check) {
        this.props.update(res, () => {
          this.setState({
            visible: false,
            formlist: []
          })
        })
      } else {
        this.setState({
          visible: false,
          formlist: []
        })
        this.props.update(res)
      }
    })
  }
 
  cancel = () => {
    this.setState({ visible: false })
 
    this.props.cancel && this.props.cancel()
  }
 
  render () {
    const { title, width, children, double } = this.props
    const { visible, dict, formlist } = this.state
 
    return (
      <>
        {!double ? <span onClick={this.trigger}>{children}</span> : <span onDoubleClick={this.trigger}>{children}</span>}
        <Modal
          wrapClassName="popview-modal"
          title={title}
          visible={visible}
          width={width}
          maskClosable={false}
          okText={dict['model.confirm']}
          onOk={this.submit}
          onCancel={this.cancel}
          destroyOnClose
        >
          <ModalForm
            formlist={formlist}
            inputSubmit={this.submit}
            wrappedComponentRef={(inst) => this.Ref = inst}
          />
        </Modal>
      </>
    )
  }
}
 
export default NormalFormComponent