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

修改bug (reverted from commit 325d4dd5)

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