import React, {Component} from 'react'
|
import { Form, Input, Select, Radio, Col } from 'antd'
|
|
import MKFileUpload from './fileupload'
|
|
const { TextArea } = Input
|
|
class AddAttach extends Component {
|
state = {
|
f_method: 'upload',
|
}
|
|
handleConfirm = () => {
|
const { files } = this.props
|
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (err) return
|
|
files.forEach(item => {
|
if (item.data_code === values.data_code) {
|
values.data_name = item.data_name
|
values.BID = item.id
|
}
|
})
|
|
if (values.f_method === 'input') {
|
values.url = values.fileurl
|
}
|
|
resolve(values)
|
})
|
})
|
}
|
|
fileChange = (val, name) => {
|
if (name) {
|
this.props.form.setFieldsValue({attachments_title: name})
|
}
|
}
|
|
render() {
|
const { files } = this.props
|
const { getFieldDecorator } = this.props.form
|
const { f_method } = this.state
|
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
}
|
}
|
|
return (
|
<Form {...formItemLayout} onKeyDown={this.onEnterSubmit}>
|
<Col span={12}>
|
<Form.Item label="文件夹">
|
{getFieldDecorator('data_code', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: '请选择文件夹!'
|
}
|
]
|
})(<Select>
|
{files.map(option =>
|
<Select.Option key={option.id} value={option.data_code}>{option.data_name}</Select.Option>
|
)}
|
</Select>)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label="添加方式">
|
{getFieldDecorator('f_method', {
|
initialValue: 'upload',
|
rules: [
|
{
|
required: true,
|
message: '请选择添加方式!'
|
}
|
]
|
})(<Radio.Group onChange={(e) => this.setState({f_method: e.target.value})}>
|
<Radio value="upload">上传</Radio>
|
<Radio value="input">输入</Radio>
|
</Radio.Group>)}
|
</Form.Item>
|
</Col>
|
{f_method === 'upload' ? <Col span={12}>
|
<Form.Item label="文件">
|
{getFieldDecorator('url', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: '请添加文件!'
|
}
|
]
|
})(<MKFileUpload config={{
|
initval: '',
|
compress: 'false',
|
suffix: '',
|
maxfile: 1,
|
fileType: 'text'
|
}} onChange={(val, name) => this.fileChange(val, name)} />)}
|
</Form.Item>
|
</Col> : <Col span={24}>
|
<Form.Item label="文件地址">
|
{getFieldDecorator('fileurl', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: '请输入文件地址!'
|
}
|
]
|
})(<TextArea autoSize={{ minRows: 2 }}/>)}
|
</Form.Item>
|
</Col>}
|
<Col span={12}>
|
<Form.Item label="文件名">
|
{getFieldDecorator('attachments_title', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: '请输入文件名!'
|
},
|
{
|
max: 50,
|
message: '最大长度为50位!'
|
}
|
]
|
})(<Input />)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label="备注">
|
{getFieldDecorator('remark', {
|
initialValue: '',
|
rules: [
|
{
|
max: 512,
|
message: '最大长度为512位!'
|
}
|
]
|
})(<TextArea autoSize={{ minRows: 2 }}/>)}
|
</Form.Item>
|
</Col>
|
<div style={{clear: 'both'}}></div>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(AddAttach)
|