king
2023-09-08 783ab4e467c95e26f7f031151507bd7ad8333a63
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
import React, {Component} from 'react'
import { Button, Modal, Form, Input, notification, Select, Divider } from 'antd'
import { PlusOutlined } from '@ant-design/icons'
 
import MKEmitter from '@/utils/events.js'
// import './index.scss'
 
const { Option } = Select
 
class SaveAsTemp extends Component {
  state = {
    visible: false,
    name: '',
    typeChar: '',
    typeName: '',
    menu: null
  }
 
  UNSAFE_componentWillMount() {
    let menuId = '16289973311406f3ko9nm8ehotdmu80o'
    let menu = window.GLOB.mkThdMenus.get(menuId)
 
    if (menu) {
      this.setState({menu: {
        ...menu,
        param: {}
      }})
    }
  }
 
  submit = () => {
    const { name, typeChar, typeName } = this.state
 
    if (!typeChar) {
      notification.warning({
        top: 92,
        message: '请选择模板类型!',
        duration: 5
      })
      return
    } else if (!name) {
      notification.warning({
        top: 92,
        message: '请填写模板名称!',
        duration: 5
      })
      return
    }
 
    this.setState({visible: false})
    this.props.onChange(name, typeChar, typeName)
  }
 
  triggerSave = () => {
    this.setState({visible: true, name: '', typeChar: '', typeName: ''})
  }
 
  changeType = (val, option) => {
    if (option && option.props) {
      this.setState({typeChar: option.props.value, typeName: option.props.children})
    }
  }
 
  addType = () => {
    const { menu } = this.state
 
    this.setState({visible: false})
 
    MKEmitter.emit('modifyTabs', menu, true)
  }
 
  render() {
    const { tempTypes } = this.props
    const { visible, menu } = this.state
 
    return (
      <>
        <Button onClick={() => this.triggerSave()}>保存为模板</Button>
        <Modal
          title="添加模板"
          wrapClassName="mk-temp-add-modal"
          visible={visible}
          width={600}
          maskClosable={false}
          onOk={this.submit}
          onCancel={() => { this.setState({ visible: false })}}
          destroyOnClose
        >
          {visible ? <Form>
            <Form.Item label="模板类型">
              {menu ? <Select placeholder="请选择模板类型" onChange={this.changeType} dropdownRender={menus => (
                <div>
                  {menus}
                  <Divider style={{ margin: '4px 0' }} />
                  <div className="mk-add-book" onMouseDown={this.addType}>
                    <PlusOutlined /> 添加
                  </div>
                </div>
              )}>
                {tempTypes.map(item => (
                  <Option key={item.data_code} value={item.data_code}>{item.data_name}</Option>
                ))}
              </Select> : <Select placeholder="请选择模板类型" onChange={this.changeType}>
                {tempTypes.map(item => (
                  <Option key={item.data_code} value={item.data_code}>{item.data_name}</Option>
                ))}
              </Select>}
            </Form.Item>
            <Form.Item label="模板名称">
              <Input onChange={(e) => this.setState({name: e.target.value})}/>
            </Form.Item>
            <div style={{clear: 'both'}}></div>
          </Form> : null}
        </Modal>
      </>
    )
  }
}
 
export default SaveAsTemp