king
2024-12-05 4a356e81b1a456f0cb16f61f548c46171c26c1b6
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
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: files[0] ? files[0].data_code : '',
              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: 100,
                  message: '最大长度为100位!'
                }
              ]
            })(<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)