king
2021-12-10 2cb09105d702ccae0644126ca6ea7f85e1f218bc
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, InputNumber, Select, Radio, Tooltip } from 'antd'
import { QuestionCircleOutlined } from '@ant-design/icons'
 
import { formRule } from '@/utils/option.js'
import TransferForm from '@/templates/zshare/transferform'
// import './index.scss'
 
class MainSearch extends Component {
  static propTpyes = {
    dict: PropTypes.object, // 字典项
    columns: PropTypes.array,
    card: PropTypes.any,
    inputSubmit: PropTypes.any   // 回车提交事件
  }
 
  componentDidMount () {
    try {
      let _form = document.getElementById('label')
      if (_form && _form.select) {
        _form.select()
      }
    } catch (e) {
      console.warn('表单focus失败!')
    }
  }
 
  handleConfirm = () => {
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          let targetKeys = this.refs['column-transfer'].state.targetKeys
 
          delete values.type // 删除type,此处值为'合并列'文字
 
          let subfield = []  // 用于查看合并列字段
          this.props.columns.forEach(col => {
            if (col.field && targetKeys.includes(col.uuid)) {
              subfield.push(col.field)
            }
          })
          subfield = subfield.join(', ')
 
          let _card = {...this.props.card, ...values, sublist: targetKeys, subfield: subfield}
 
          delete _card.focus
 
          resolve(_card)
        } else {
          reject(err)
        }
      })
    })
  }
 
  handleSubmit = (e) => {
    e.preventDefault()
 
    if (this.props.inputSubmit) {
      this.props.inputSubmit()
    }
  }
 
  render() {
    const { card } = this.props
    const { getFieldDecorator } = this.props.form
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      }
    }
    return (
      <Form {...formItemLayout} style={{minHeight: '190px'}} id="columncolspan">
        <Row gutter={24}>
          <Col span={12}>
            <Form.Item label={this.props.dict['model.name']}>
              {getFieldDecorator('label', {
                initialValue: card.label,
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.input'] + this.props.dict['model.name'] + '!'
                  },
                  {
                    max: formRule.input.max,
                    message: formRule.input.message
                  }
                ]
              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={this.props.dict['model.form.type']}>
              {getFieldDecorator('type', {
                initialValue: this.props.dict['model.form.colspan'],
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.input'] + this.props.dict['model.form.type'] + '!'
                  }
                ]
              })(<Input placeholder="" autoComplete="off" disabled={true}/>)}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={this.props.dict['model.form.align']}>
              {getFieldDecorator('Align', {
                initialValue: card.Align,
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + this.props.dict['model.form.align'] + '!'
                  }
                ]
              })(
                <Select
                  getPopupContainer={() => document.getElementById('columncolspan')}
                >
                  <Select.Option value="left">{this.props.dict['model.form.alignLeft']}</Select.Option>
                  <Select.Option value="right">{this.props.dict['model.form.alignRight']}</Select.Option>
                  <Select.Option value="center">{this.props.dict['model.form.alignCenter']}</Select.Option>
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={this.props.dict['model.form.columnWidth']}>
              {getFieldDecorator('Width', {
                initialValue: card.Width,
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.input'] + this.props.dict['model.form.columnWidth'] + '!'
                  }
                ]
              })(<InputNumber min={1} max={1000} precision={0} onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={
              <Tooltip placement="topLeft" title="选择显示分组,表格会展开添加分组的子列,此时排列方式会失效。">
                <QuestionCircleOutlined className="mk-form-tip" />
                显示分组
              </Tooltip>
            }>
              {getFieldDecorator('unfold', {
                initialValue: card.unfold || 'false'
              })(
                <Radio.Group>
                  <Radio value="true">{this.props.dict['model.true']}</Radio>
                  <Radio value="false">{this.props.dict['model.false']}</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={this.props.dict['model.hidden']}>
              {getFieldDecorator('Hide', {
                initialValue: card.Hide || 'false',
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + this.props.dict['model.hidden'] + '!'
                  }
                ]
              })(
                <Radio.Group>
                  <Radio value="true">{this.props.dict['model.true']}</Radio>
                  <Radio value="false">{this.props.dict['model.false']}</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label="排列">
              {getFieldDecorator('order', {
                initialValue: card.order,
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + '排列!'
                  }
                ]
              })(
                <Select getPopupContainer={() => document.getElementById('columncolspan')} >
                  <Select.Option value="vertical">纵向</Select.Option>
                  <Select.Option value="horizontal">横向</Select.Option>
                  <Select.Option value="vertical2">纵向(2列)</Select.Option>
                  <Select.Option value="topPicBottomText">上图下文</Select.Option>
                  <Select.Option value="leftPicRightText">左图右文</Select.Option>
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={24}>
            <TransferForm columns={this.props.columns} ref="column-transfer" selected={card.sublist}/>
          </Col>
        </Row>
      </Form>
    )
  }
}
 
export default Form.create()(MainSearch)