Commit 8b53279a authored by zhangwenshuai's avatar zhangwenshuai

增加表单即时编辑的校验

parent 76b93f18
...@@ -15,25 +15,26 @@ ...@@ -15,25 +15,26 @@
* */ * */
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Form, Button } from 'antd'; import { Form, Button } from 'antd';
import { emptyModel } from '@/submodule/components/apolloTable/component/base/_utils/setFormatter';
import { defaultLocale } from '@/submodule/components/apolloTable/locale';
import _ from 'lodash';
import styles from './index.less'; import styles from './index.less';
import { config } from '../component/base/config'; import { config } from '../component/base/config';
import { transferAttr } from '../component/base/_utils/transferAttr'; import { transferAttr } from '../component/base/_utils/transferAttr';
import { getFormat, setFormat } from '../component/base'; import { getFormat, setFormat } from '../component/base';
import { Provider } from '../component/context'; import { Provider } from '../component/context';
import { emptyModel } from '@/submodule/components/apolloTable/component/base/_utils/setFormatter';
import { defaultLocale } from '@/submodule/components/apolloTable/locale';
import _ from 'lodash';
const FormItem = Form.Item; const FormItem = Form.Item;
class FormWrap extends Component { class FormWrap extends Component {
wrapDom:any; wrapDom: any;
handleSubmit = (e) => { handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const { rowId, form, handleSubmit, data, rowData, detailType } = this.props; const {
rowId, form, handleSubmit, data, rowData, detailType,
} = this.props;
form.validateFieldsAndScroll((err, values) => { form.validateFieldsAndScroll((err, values) => {
console.log(data, 8888)
if (!err) { if (!err) {
const newValues: any[] = []; const newValues: any[] = [];
_.keys(values).map((key) => { _.keys(values).map((key) => {
...@@ -90,7 +91,7 @@ class FormWrap extends Component { ...@@ -90,7 +91,7 @@ class FormWrap extends Component {
}; };
renderEditForm = (item) => { renderEditForm = (item) => {
const { getFieldDecorator } = this.props.form; const { getFieldDecorator, validateFieldsAndScroll } = this.props.form;
const { rowData, rowId, getInstanceDetail, onBlurFn } = this.props; const { rowData, rowId, getInstanceDetail, onBlurFn } = this.props;
const { const {
columnType, columnType,
...@@ -119,24 +120,28 @@ class FormWrap extends Component { ...@@ -119,24 +120,28 @@ class FormWrap extends Component {
const transferColumn = transferAttr(columnType, newProps); const transferColumn = transferAttr(columnType, newProps);
const disabled = readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag); const disabled = readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag);
const onBlurFn1 = (changedValue: any, newVal: any) => { const onBlurFn1 = (changedValue: any, newVal: any) => {
validateFieldsAndScroll((err:any) => {
let temp: any[] = []; // 即时编辑时需要对表单必填等规则校验
value.map((item: any) => { if (!err) {
temp.push({ text: item.text, value: item.value }); let temp: any[] = [];
value.map((item: any) => {
temp.push({ text: item.text, value: item.value });
});
if (temp.length === 0) {
temp = emptyModel;
}
if (!!item.requiredFlag && Array.isArray(newVal) && !newVal[0].value) {
return;
}
if (_.isEqual(temp, newVal)) {
return;
}
if (typeof onBlurFn === 'function') {
onBlurFn(changedValue);
}
}
}); });
if (temp.length === 0) { };
temp = emptyModel;
}
if (!!item.requiredFlag && Array.isArray(newVal) && !newVal[0].value) {
return
}
if (_.isEqual(temp, newVal)) {
return;
}
if (typeof onBlurFn === 'function') {
onBlurFn(changedValue)
}
}
return ( return (
<FormItem key={columnName} label={this.renderLabel(item)}> <FormItem key={columnName} label={this.renderLabel(item)}>
{getFieldDecorator(columnName, { {getFieldDecorator(columnName, {
...@@ -182,12 +187,14 @@ class FormWrap extends Component { ...@@ -182,12 +187,14 @@ class FormWrap extends Component {
}; };
render() { render() {
const { loading, isShowDelBtn, data, btnWrapStyle, name, colsNum, delLabel, hideOperateBtn } = this.props; const {
loading, isShowDelBtn, data, btnWrapStyle, name, colsNum, delLabel, hideOperateBtn,
} = this.props;
return ( return (
<Provider value={{ locale: this.getContext() }}> <Provider value={{ locale: this.getContext() }}>
<div className={styles.wrap}> <div className={styles.wrap}>
<p className={styles.titleCls}>{name || '客户跟进'}</p> <p className={styles.titleCls}>{name}</p>
<div <div
id="gotop" id="gotop"
className={styles.formItemCls} className={styles.formItemCls}
...@@ -224,7 +231,7 @@ class FormWrap extends Component { ...@@ -224,7 +231,7 @@ class FormWrap extends Component {
) : null} ) : null}
<Button onClick={this.handleCancel} className={styles.btnCls}> <Button onClick={this.handleCancel} className={styles.btnCls}>
取消 取消
</Button> </Button>
<Button <Button
onClick={this.handleSubmit} onClick={this.handleSubmit}
type="primary" type="primary"
...@@ -233,7 +240,7 @@ class FormWrap extends Component { ...@@ -233,7 +240,7 @@ class FormWrap extends Component {
id="submitBtn" // 用于业务监听此dom节点 id="submitBtn" // 用于业务监听此dom节点
> >
确定 确定
</Button> </Button>
</div> </div>
</div> </div>
) )
...@@ -245,26 +252,4 @@ class FormWrap extends Component { ...@@ -245,26 +252,4 @@ class FormWrap extends Component {
} }
} }
function mapPropsToFields(props) { export default Form.create({ name: 'editFormV3' })(FormWrap);
const returnObj = {};
const { data, renderEditForm, rowData } = props;
data.forEach((el) => {
// let detailConfig: any;
// if (typeof renderEditForm === 'function') {
// detailConfig = renderEditForm({ cellData: el.value, rowData, columnConfig: el });
// } else {
// detailConfig = config[String(el.columnType)] || config['1'];
// }
// const formatValue = getFormat(detailConfig, el, el.value);
// console.log('formatValue',formatValue)
returnObj[el.columnType] = Form.createFormField({
value: el.value,
});
});
return returnObj;
}
function onValuesChange(props: any, changedValues: any, allValues: any) {
if (props.changeValue) { }
}
export default Form.create({ name: 'form_view' })(FormWrap);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment