| | |
| | | class SettingForm extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | data: PropTypes.object |
| | | group: PropTypes.object, // 字典项 |
| | | config: PropTypes.object |
| | | } |
| | | |
| | | state = { |
| | | source: null, |
| | | selectds: null, |
| | | default: null |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { config, group } = this.props |
| | | |
| | | let _source = null |
| | | let _default = config.groups[config.groups.length - 1] |
| | | let _selectds = [] |
| | | |
| | | if (config.groups.length === 1) { |
| | | _source = config.fields.filter(item => !item.origin) |
| | | } else { |
| | | _source = [..._default.sublist, ...group.sublist] |
| | | _selectds = group.sublist.map(item => { return item.uuid }) |
| | | } |
| | | |
| | | this.setState({ |
| | | source: _source, |
| | | selectds: _selectds, |
| | | default: _default |
| | | }) |
| | | } |
| | | |
| | | handleConfirm = () => { |
| | |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | resolve(values) |
| | | let targetKeys = this.refs['fields-transfer'].state.targetKeys |
| | | let defaultlist = this.state.source.filter(item => !targetKeys.includes(item.uuid)) |
| | | |
| | | values.sublist = targetKeys.map(item => { |
| | | return this.state.source.filter(cell => cell.uuid === item)[0] |
| | | }) |
| | | |
| | | resolve({ |
| | | default: {...this.state.default, sublist: defaultlist}, |
| | | target: values |
| | | }) |
| | | } else { |
| | | reject(err) |
| | | } |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { data } = this.props |
| | | const { group, config } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | |
| | | const formItemLayout = { |
| | |
| | | <Row gutter={24}> |
| | | <Col span={12}> |
| | | <Form.Item label="分组名称"> |
| | | {getFieldDecorator('title', { |
| | | initialValue: data.title |
| | | {getFieldDecorator('label', { |
| | | initialValue: group.label, |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.input'] + '分组名称!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off"/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={12}> |
| | | <Form.Item label="排序"> |
| | | {getFieldDecorator('sort', { |
| | | initialValue: data.sort |
| | | initialValue: group.hasOwnProperty('sort') ? group.sort : config.groups.length |
| | | })(<InputNumber min={0} max={100} precision={0} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <TransferForm dict={this.props.dict} columns={this.props.columns} ref="column-transfer" selected={this.props.card.sublist}/> |
| | | <TransferForm dict={this.props.dict} fields={this.state.source} ref="fields-transfer" selected={this.state.selectds}/> |
| | | </Col> |
| | | </Row> |
| | | </Form> |