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

修改bug

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