| | |
| | | class ExcelInColumn extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | columns: PropTypes.array, // 列名集合 |
| | | columnChange: PropTypes.func // 修改函数 |
| | | } |
| | | |
| | | state = { |
| | | editItem: null, // 编辑元素 |
| | | type: 'Nvarchar(50)', |
| | | locked: false |
| | | } |
| | | |
| | | edit = (record) => { |
| | | this.setState({ |
| | | editItem: record, |
| | | type: record.type || 'Nvarchar(50)' |
| | | }, () => { |
| | | if (!/^Nvarchar/.test(record.type)) { |
| | | this.props.form.setFieldsValue({ |
| | | min: record.min, |
| | | max: record.max |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | this.props.form.setFieldsValue({ |
| | | Column: record.Column, |
| | | Text: record.Text, |
| | | required: record.required || 'true', |
| | | import: record.import || 'true', |
| | | type: record.type |
| | | }) |
| | | if (record.type === 'Int' || /^Decimal/ig.test(record.type)) { |
| | | this.setState({ |
| | | locked: true |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | locked: false |
| | | }) |
| | | } |
| | | } |
| | | |
| | | typeChange = (val) => { |
| | |
| | | |
| | | |
| | | handleConfirm = () => { |
| | | // const { columns } = this.props |
| | | // 表单提交时检查输入值是否正确 |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | values.uuid = this.state.editItem ? this.state.editItem.uuid : '' |
| | | |
| | | if (/^Nvarchar/ig.test(values.type)) { |
| | | values.limit = values.type.match(/\d+/) ? values.type.match(/\d+/)[0] : '20000' |
| | | } else if (/^Decimal/ig.test(values.type)) { |
| | |
| | | |
| | | this.props.columnChange(values) |
| | | this.setState({ |
| | | editItem: null, |
| | | locked: false, |
| | | type: 'Nvarchar(50)' |
| | | }) |
| | |
| | | } |
| | | } |
| | | |
| | | let haslimit = !/^Nvarchar/.test(this.state.type) |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="verify-form"> |
| | | <Row gutter={24}> |
| | | <Col span={7}> |
| | | <Col span={6}> |
| | | <Form.Item label={dict['model.form.field']}> |
| | | {getFieldDecorator('Column', { |
| | | initialValue: '', |
| | |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Col span={6}> |
| | | <Form.Item label={dict['model.name']}> |
| | | {getFieldDecorator('Text', { |
| | | initialValue: '', |
| | |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Col span={6}> |
| | | <Form.Item label={dict['model.form.type']}> |
| | | {getFieldDecorator('type', { |
| | | initialValue: 'Nvarchar(50)' |
| | |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={3} className="add"> |
| | | <Button onClick={this.handleConfirm} type="primary" className="mk-green"> |
| | | {dict['model.save']} |
| | | </Button> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Col span={6}> |
| | | <Form.Item label={dict['model.required']}> |
| | | {getFieldDecorator('required', { |
| | | initialValue: 'true' |
| | |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Form.Item label={dict['model.import']}> |
| | | <Col span={6}> |
| | | <Form.Item style={{marginBottom: 0}} label={dict['model.import']}> |
| | | {getFieldDecorator('import', { |
| | | initialValue: 'true' |
| | | })( |
| | |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | {haslimit ? <Col span={7}> |
| | | <Form.Item label={'最小值'}> |
| | | <Col span={6}> |
| | | <Form.Item style={{marginBottom: 0}} label={'最小值'}> |
| | | {getFieldDecorator('min', { |
| | | initialValue: '' |
| | | })(<InputNumber />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {haslimit ? <Col span={7}> |
| | | <Form.Item label={'最大值'}> |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item style={{marginBottom: 0}} label={'最大值'}> |
| | | {getFieldDecorator('max', { |
| | | initialValue: '' |
| | | })(<InputNumber />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item style={{marginBottom: 0}} label={' '} colon={false}> |
| | | <Button onClick={this.handleConfirm} type="primary" className="mk-green"> |
| | | {dict['model.add']} |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Form> |
| | | ) |