import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, InputNumber, Select, Radio } from 'antd'
|
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 {
|
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 { getFieldDecorator } = this.props.form
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 18 }
|
}
|
}
|
return (
|
<Form {...formItemLayout} className="commontable-cospan-column-form" id="columncolspan">
|
<Row gutter={24}>
|
<Col span={12}>
|
<Form.Item label={this.props.dict['header.form.name']}>
|
{getFieldDecorator('label', {
|
initialValue: this.props.card.label,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + this.props.dict['header.form.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['header.form.type']}>
|
{getFieldDecorator('type', {
|
initialValue: this.props.dict['header.form.colspan'],
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + this.props.dict['header.form.type'] + '!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" disabled={true}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={this.props.dict['header.form.align']}>
|
{getFieldDecorator('Align', {
|
initialValue: this.props.card.Align,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + this.props.dict['header.form.align'] + '!'
|
}
|
]
|
})(
|
<Select
|
getPopupContainer={() => document.getElementById('columncolspan')}
|
>
|
<Select.Option value="left">{this.props.dict['header.form.alignLeft']}</Select.Option>
|
<Select.Option value="right">{this.props.dict['header.form.alignRight']}</Select.Option>
|
<Select.Option value="center">{this.props.dict['header.form.alignCenter']}</Select.Option>
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={this.props.dict['header.form.columnWidth']}>
|
{getFieldDecorator('Width', {
|
initialValue: this.props.card.Width,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + this.props.dict['header.form.columnWidth'] + '!'
|
}
|
]
|
})(<InputNumber min={1} max={1000} precision={0} />)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={this.props.dict['header.form.Hide']}>
|
{getFieldDecorator('Hide', {
|
initialValue: this.props.card.Hide,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + this.props.dict['header.form.Hide'] + '!'
|
}
|
]
|
})(
|
<Radio.Group>
|
<Radio value="true">{this.props.dict['header.form.true']}</Radio>
|
<Radio value="false">{this.props.dict['header.form.false']}</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={this.props.dict['header.form.order']}>
|
{getFieldDecorator('order', {
|
initialValue: this.props.card.order,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + this.props.dict['header.form.order'] + '!'
|
}
|
]
|
})(
|
<Select
|
getPopupContainer={() => document.getElementById('columncolspan')}
|
>
|
<Select.Option value="vertical">{this.props.dict['header.form.vertical']}</Select.Option>
|
<Select.Option value="horizontal">{this.props.dict['header.form.horizontal']}</Select.Option>
|
<Select.Option value="vertical2">{this.props.dict['header.form.vertical2']}</Select.Option>
|
<Select.Option value="topPicBottomText">{this.props.dict['header.form.topPicBottomText']}</Select.Option>
|
<Select.Option value="leftPicRightText">{this.props.dict['header.form.leftPicRightText']}</Select.Option>
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<TransferForm dict={this.props.dict} columns={this.props.columns} ref="column-transfer" selected={this.props.card.sublist}/>
|
</Col>
|
</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(MainSearch)
|