提交 957cf7b8 authored 作者: chscls@163.com's avatar chscls@163.com

修改bug (reverted from commit 325d4dd5)

上级 325d4dd5
import React from 'react' import React from 'react'
import { Button, Row, Col, message,Input } from 'antd'; import { Button, Row, Col, message } from 'antd';
import ZdyTable from '../Table' import ZdyTable from '../Table'
import UUID from 'react-native-uuid'; import UUID from 'react-native-uuid';
...@@ -10,22 +10,29 @@ export default class ChildForm extends React.Component { ...@@ -10,22 +10,29 @@ export default class ChildForm extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
const objs = props.value || {}; const value = props.value || {};
this.state = { this.state = value
objs:objs
}
} }
triggerChange = (changedValue) => { triggerChange = (changedValue) => {
const bb = `${this.props.base52}` // Should provide an event to pass value to Form.
this.props.form.setFieldsValue({bb:changedValue}) const onChange = this.props.onChange;
if (onChange) {
onChange(Object.assign({}, this.state, changedValue));
}
}
componentWillReceiveProps(nextProps) {
// Should be a controlled component.
if ('value' in nextProps) {
const value = nextProps.value;
this.setState(value);
}
} }
componentDidMount = () => { componentDidMount = () => {
if (Object.keys(this.state).length == 0 && this.props.isEdit) { if (Object.keys(this.state).length == 0 && this.props.isEdit) {
if (this.props.num != null && this.props.num > 0) { if (this.props.num != null && this.props.num > 0) {
const {objs} = this.state const objs = this.state
if (this.props.min != null && this.props.min > this.props.num) { if (this.props.min != null && this.props.min > this.props.num) {
for (var i = 0; i < this.props.min; i++) { for (var i = 0; i < this.props.min; i++) {
objs["id_" + UUID.v4().replace(/-/g, "2")] = {} objs["id_" + UUID.v4().replace(/-/g, "2")] = {}
...@@ -36,35 +43,36 @@ export default class ChildForm extends React.Component { ...@@ -36,35 +43,36 @@ export default class ChildForm extends React.Component {
} }
} }
if (!('value' in this.props)) {
this.setState({objs}); this.setState({ ...objs });
}
this.triggerChange(objs); this.triggerChange({ ...objs });
} }
} }
} }
delete = (uuid) => { delete = (uuid) => {
const {objs} = this.state const objs = this.state
if (this.props.min != null && Object.keys(objs).length - 1 < this.props.min) { if (this.props.min != null && Object.keys(objs).length - 1 < this.props.min) {
message.error("不能小于最小限制") message.error("不能小于最小限制")
return return
} }
delete objs[uuid] delete objs[uuid]
this.triggerChange(objs); if (!('value' in this.props)) {
this.setState({objs}); this.setState({ ...objs });
}
this.triggerChange({ ...objs });
} }
add = () => { add = () => {
const {objs} = this.state const objs = this.state
console.log(objs)
if (this.props.max != null && Object.keys(objs).length + 1 > this.props.max) { if (this.props.max != null && Object.keys(objs).length + 1 > this.props.max) {
message.error("不能大于最大限制") message.error("不能大于最大限制")
...@@ -72,11 +80,12 @@ export default class ChildForm extends React.Component { ...@@ -72,11 +80,12 @@ export default class ChildForm extends React.Component {
} }
objs["id_" + UUID.v4().replace(/-/g, "2")] = {} objs["id_" + UUID.v4().replace(/-/g, "2")] = {}
this.triggerChange(objs); if (!('value' in this.props)) {
this.setState({objs}); this.setState({ ...objs });
}
this.triggerChange({ ...objs });
} }
...@@ -84,9 +93,9 @@ export default class ChildForm extends React.Component { ...@@ -84,9 +93,9 @@ export default class ChildForm extends React.Component {
render() { render() {
const {objs} = this.state; const objs = this.state;
const { form, mapData, sqlData, defaultValues, datas, base52, isEdit, addName, deleteName, obj, isMobile, json, modalInit } = this.props const { form, mapData, sqlData, defaultValues, datas, base52, isEdit, addName, deleteName, obj, isMobile, json,modalInit } = this.props
const span = json.span || 24 const span = json.span || 24
const gutter = json.gutter != null ? json.gutter : 0 const gutter = json.gutter != null ? json.gutter : 0
const rights = this.props.rights const rights = this.props.rights
...@@ -110,9 +119,9 @@ export default class ChildForm extends React.Component { ...@@ -110,9 +119,9 @@ export default class ChildForm extends React.Component {
return "" return ""
} }
return <Row key={r} gutter={gutter} ><Col style={{ textAlign: 'right' }} span={isEdit ? 23 : span} > return <Row key={r} gutter={gutter} ><Col style={{ textAlign: 'right' }} span={isEdit ? 23 : span} >
<ZdyTable key={r} modalInit={modalInit} formCode={this.props.formCode} <ZdyTable key={r} modalInit={modalInit} formCode={this.props.formCode}
formId={this.props.formId} formId={this.props.formId}
formConfig={datas} get='mobile' fatherCode={base52} isEdit={isEdit} index={r} obj={objs[r]} fatherObj={this.props.fatherObj} init={objs} isChild={true} form={form} mapData={mapData} sqlData={sqlData} {...datas} defaultValues={defaultValues} /> formConfig={datas} get='mobile' fatherCode={base52} isEdit={isEdit} index={r} obj={objs[r]} fatherObj={this.props.fatherObj} init={objs} isChild={true} form={form} mapData={mapData} sqlData={sqlData} {...datas} defaultValues={defaultValues} />
{rights.includes("delete") && isEdit ? <Button type='danger' onClick={this.delete.bind(this, r)}>{deleteName || "删除"} </Button> : ''} {rights.includes("delete") && isEdit ? <Button type='danger' onClick={this.delete.bind(this, r)}>{deleteName || "删除"} </Button> : ''}
</Col> </Col>
</Row> </Row>
...@@ -125,7 +134,6 @@ export default class ChildForm extends React.Component { ...@@ -125,7 +134,6 @@ export default class ChildForm extends React.Component {
return ( return (
<div style={{ width: "100%" }}> <div style={{ width: "100%" }}>
<Row gutter={gutter}> <Row gutter={gutter}>
{Object.keys(objs).map((r) => { {Object.keys(objs).map((r) => {
if (r == "") { if (r == "") {
......
...@@ -2962,14 +2962,15 @@ export default class tableCom extends Component { ...@@ -2962,14 +2962,15 @@ export default class tableCom extends Component {
} }
break; break;
case 'ChildForm': case 'ChildForm':
cm = cm = getFieldDecorator(dataColumn.base52, {
initialValue: initValue || {},
})(
<ChildForm <ChildForm
rights={json.rights || []} rights={json.rights || []}
isMobile={get === 'mobile'} isMobile={get === 'mobile'}
num={json.num} num={json.num}
min={json.min} min={json.min}
max={json.max} max={json.max}
value={initValue||{}}
json={json} json={json}
deleteName={json.deleteName} deleteName={json.deleteName}
addName={json.addName} addName={json.addName}
...@@ -2980,8 +2981,8 @@ export default class tableCom extends Component { ...@@ -2980,8 +2981,8 @@ export default class tableCom extends Component {
defaultValues={defaultValues} defaultValues={defaultValues}
sqlData={sqlData} sqlData={sqlData}
form={this.props.form} form={this.props.form}
/> />,
);
if (get === 'mobile' && json.isLabel && title) { if (get === 'mobile' && json.isLabel && title) {
cm = ( cm = (
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论