提交 325d4dd5 authored 作者: chscls@163.com's avatar chscls@163.com

修改bug

上级 12a6fed3
import React from 'react' import React from 'react'
import { Button, Row, Col, message } from 'antd'; import { Button, Row, Col, message,Input } from 'antd';
import ZdyTable from '../Table' import ZdyTable from '../Table'
import UUID from 'react-native-uuid'; import UUID from 'react-native-uuid';
...@@ -10,29 +10,22 @@ export default class ChildForm extends React.Component { ...@@ -10,29 +10,22 @@ export default class ChildForm extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
const value = props.value || {}; const objs = props.value || {};
this.state = value this.state = {
objs:objs
}
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) { triggerChange = (changedValue) => {
// Should be a controlled component. const bb = `${this.props.base52}`
if ('value' in nextProps) { this.props.form.setFieldsValue({bb:changedValue})
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")] = {}
...@@ -43,36 +36,35 @@ export default class ChildForm extends React.Component { ...@@ -43,36 +36,35 @@ 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]
if (!('value' in this.props)) { this.triggerChange(objs);
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("不能大于最大限制")
...@@ -80,12 +72,11 @@ export default class ChildForm extends React.Component { ...@@ -80,12 +72,11 @@ export default class ChildForm extends React.Component {
} }
objs["id_" + UUID.v4().replace(/-/g, "2")] = {} objs["id_" + UUID.v4().replace(/-/g, "2")] = {}
if (!('value' in this.props)) { this.triggerChange(objs);
this.setState({ ...objs }); this.setState({objs});
}
this.triggerChange({ ...objs });
} }
...@@ -93,9 +84,9 @@ export default class ChildForm extends React.Component { ...@@ -93,9 +84,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
...@@ -119,9 +110,9 @@ export default class ChildForm extends React.Component { ...@@ -119,9 +110,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>
...@@ -134,6 +125,7 @@ export default class ChildForm extends React.Component { ...@@ -134,6 +125,7 @@ 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,15 +2962,14 @@ export default class tableCom extends Component { ...@@ -2962,15 +2962,14 @@ export default class tableCom extends Component {
} }
break; break;
case 'ChildForm': case 'ChildForm':
cm = getFieldDecorator(dataColumn.base52, { cm =
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}
...@@ -2981,8 +2980,8 @@ export default class tableCom extends Component { ...@@ -2981,8 +2980,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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论