提交 50c942ef authored 作者: 徐立's avatar 徐立

修复bug

上级 4adc8e52
import React from 'react' import React from 'react';
import { Button, Row, Col, message } 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';
import { Card, WingBlank } from 'antd-mobile'; import { Card, WingBlank } from 'antd-mobile';
export default class ChildForm extends React.Component { export default class ChildForm extends React.Component {
constructor(props) {
constructor(props) { super(props);
super(props) const value = props.value || {};
const value = props.value || {};
this.state = 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));
} }
triggerChange = (changedValue) => { };
// Should provide an event to pass value to Form. componentWillReceiveProps(nextProps) {
const onChange = this.props.onChange; // Should be a controlled component.
if (onChange) { if ('value' in nextProps) {
onChange(Object.assign({}, this.state, changedValue)); const value = nextProps.value;
} this.state = value;
}
componentWillReceiveProps(nextProps) {
// Should be a controlled component.
if ('value' in nextProps) {
const value = nextProps.value;
this.state = 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
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")] = {}
}
} else {
for (var i = 0; i < this.props.num; i++) {
objs["id_" + UUID.v4().replace(/-/g, "2")] = {}
}
}
if (!('value' in this.props)) {
this.setState({ ...objs });
}
this.triggerChange({ ...objs });
}
}
} }
delete = (uuid) => { }
const objs = this.state componentDidMount = () => {
const { json: { numCode }, form, base52 } = this.props if (Object.keys(this.state).length == 0 && this.props.isEdit) {
if (this.props.min != null && Object.keys(objs).length - 1 < this.props.min) { if (this.props.num != null && this.props.num > 0) {
message.error("不能小于最小限制") const objs = this.state;
if (this.props.min != null && this.props.min > this.props.num) {
return for (var i = 0; i < this.props.min; i++) {
objs['id_' + UUID.v4().replace(/-/g, '2')] = {};
}
} else {
for (var i = 0; i < this.props.num; i++) {
objs['id_' + UUID.v4().replace(/-/g, '2')] = {};
}
} }
delete objs[uuid]
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ ...objs }); this.setState({ ...objs });
} }
this.triggerChange({ ...objs }); this.triggerChange({ ...objs });
}
if (numCode != null) {
this.props.form.setFieldsValue({ [numCode]: Object.keys(objs).length })
}
} }
add = () => { };
const objs = this.state delete = uuid => {
const { json: { numCode }, form, base52 } = this.props const objs = this.state;
if (this.props.max != null && Object.keys(objs).length + 1 > this.props.max) { const {
message.error("不能大于最大限制") json: { numCode },
form,
return base52,
} } = this.props;
objs["id_" + UUID.v4().replace(/-/g, "2")] = {} if (this.props.min != null && Object.keys(objs).length - 1 < this.props.min) {
message.error('不能小于最小限制');
if (!('value' in this.props)) {
this.setState({ ...objs }); return;
}
this.triggerChange({ ...objs });
if (numCode != null) {
this.props.form.setFieldsValue({ [numCode]: Object.keys(objs).length })
}
} }
delete objs[uuid];
if (!('value' in this.props)) {
this.setState({ ...objs });
}
this.triggerChange({ ...objs });
if (numCode != null) {
this.props.form.setFieldsValue({ [numCode]: Object.keys(objs).length });
}
};
add = () => {
const objs = this.state;
const {
json: { numCode },
form,
base52,
} = this.props;
if (this.props.max != null && Object.keys(objs).length + 1 > this.props.max) {
message.error('不能大于最大限制');
return;
}
objs['id_' + UUID.v4().replace(/-/g, '2')] = {};
if (!('value' in this.props)) {
this.setState({ ...objs });
}
this.triggerChange({ ...objs });
if (numCode != null) {
this.props.form.setFieldsValue({ [numCode]: Object.keys(objs).length });
}
};
render() {
const objs = this.state;
const {
form,
mapData,
sqlData,
defaultValues,
datas,
base52,
isEdit,
addName,
deleteName,
obj,
isMobile,
json,
modalInit,
isPreview,
} = this.props;
const span = json.span || 24;
const gutter = json.gutter != null ? json.gutter : 0;
const rights = this.props.rights;
if (datas == null) {
return <div>还没有配置子表单key</div>;
}
render() { if (isMobile) {
const objs = this.state; return (
<WingBlank size="lg">
const { form, mapData, sqlData, defaultValues, datas, base52, isEdit, addName, deleteName, obj, isMobile, json, modalInit,isPreview } = this.props {Object.keys(objs).length > 1 || rights.includes('add') ? (
const span = json.span || 24 <Card>
const gutter = json.gutter != null ? json.gutter : 0 <Card.Body style={{ minHeight: 10 }}>
const rights = this.props.rights {Object.keys(objs).map(r => {
if (r == '') {
return '';
if (datas == null) { }
return (<div>还没有配置子表单key</div>) return (
} <Row key={r} gutter={gutter}>
<Col
if (isMobile) { style={{
zIndex: 55,
return ( }}
<WingBlank size="lg"> span={isEdit ? 24 : span}
{Object.keys(objs).length > 1 || rights.includes("add") ? <Card > >
<ZdyTable
<Card.Body style={{ minHeight: 10 }}> key={r}
{Object.keys(objs).map((r) => { modalInit={modalInit}
if (r == "") { formCode={this.props.formCode}
return "" formId={this.props.formId}
} isPreview={isPreview}
return <Row key={r} gutter={gutter} ><Col span={isEdit ? 24 : span} > formConfig={datas}
<ZdyTable key={r} modalInit={modalInit} formCode={this.props.formCode} get="mobile"
formId={this.props.formId} fatherCode={base52}
isPreview={isPreview} isEdit={isEdit}
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} /> index={r}
obj={objs[r]}
</Col> fatherObj={this.props.fatherObj}
{rights.includes("delete") && isEdit ? <Col style={{ textAlign: "right" }}><Button type='danger' size="small" onClick={this.delete.bind(this, r)}>{deleteName || "删除"} </Button> </Col>: ''} init={objs}
</Row> isChild={true}
})} form={form}
mapData={mapData}
{rights.includes("add") ? <Row> sqlData={sqlData}
<Col style={{ textAlign: "center" }}><Button type="primary" size="small" style={{ margin: "auto" }} onClick={this.add}>{addName || "新增"}</Button> </Col> {...datas}
</Row> : ""} defaultValues={defaultValues}
</Card.Body> />
</Card> : ""} </Col>
{rights.includes('delete') && isEdit ? (
</WingBlank> <Col style={{ textAlign: 'right' }}>
) <Button type="danger" size="small" onClick={this.delete.bind(this, r)}>
} {deleteName || '删除'}{' '}
</Button>{' '}
return (
<div style={{ width: "100%" }}>
<Row gutter={gutter}>
{Object.keys(objs).map((r) => {
if (r == "") {
return ""
}
return <Col
span={span}
>
<ZdyTable
modalInit={modalInit}
formConfig={datas}
key={r}
fatherCode={base52}
isEdit={isEdit}
index={r}
isPreview={isPreview}
obj={objs[r]}
formCode={this.props.formCode}
formId={this.props.formId}
fatherObj={this.props.fatherObj}
init={objs} isChild={true}
get="web"
form={form}
mapData={mapData}
sqlData={sqlData}
{...datas}
defaultValues={defaultValues} />
{rights.includes("delete") && isEdit ? <Button size="small"
style={{
position: "absolute",
left: ' 95%',
top: '10px',
transform: 'translateY(-50%)',
borderRadius: '50%',
height: '13px',
width: '13px',
padding: 0,
lineHeight: '10px'
}}
type='danger'
onClick={this.delete.bind(this, r)}>{deleteName || "-"}
</Button> : ""}
</Col> </Col>
) : (
''
)}
</Row>
);
})}
{rights.includes('add') ? (
<Row>
<Col style={{ textAlign: 'center' }}>
<Button
type="primary"
size="small"
style={{ margin: 'auto' }}
onClick={this.add}
>
{addName || '新增'}
</Button>{' '}
</Col>
</Row>
) : (
''
)}
</Card.Body>
</Card>
) : (
''
)}
</WingBlank>
);
}
})} return (
</Row> <div style={{ width: '100%' }}>
{rights.includes("add") && isEdit ? <Row><Col span={24} style={{ textAlign: "center" }}><Button style={{ margin: "auto" }} type='primary' onClick={this.add} size="small">{addName || "新增"}</Button></Col> </Row> : ""} <Row gutter={gutter}>
</div> {Object.keys(objs).map(r => {
if (r == '') {
return '';
}
); return (
} <Col span={span}>
<ZdyTable
modalInit={modalInit}
formConfig={datas}
key={r}
fatherCode={base52}
isEdit={isEdit}
index={r}
isPreview={isPreview}
obj={objs[r]}
formCode={this.props.formCode}
formId={this.props.formId}
fatherObj={this.props.fatherObj}
init={objs}
isChild={true}
get="web"
form={form}
mapData={mapData}
sqlData={sqlData}
{...datas}
defaultValues={defaultValues}
/>
{rights.includes('delete') && isEdit ? (
<Button
size="small"
style={{
position: 'absolute',
left: ' 95%',
top: '10px',
transform: 'translateY(-50%)',
borderRadius: '50%',
height: '13px',
width: '13px',
padding: 0,
lineHeight: '10px',
}}
type="danger"
onClick={this.delete.bind(this, r)}
>
{deleteName || '-'}
</Button>
) : (
''
)}
</Col>
);
})}
</Row>
{rights.includes('add') && isEdit ? (
<Row>
<Col span={24} style={{ textAlign: 'center' }}>
<Button style={{ margin: 'auto' }} type="primary" onClick={this.add} size="small">
{addName || '新增'}
</Button>
</Col>{' '}
</Row>
) : (
''
)}
</div>
);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论