From 8b53279a2bee6a55d9eb5e33b49048cae5b93221 Mon Sep 17 00:00:00 2001 From: zhangwenshuai Date: Tue, 21 Jul 2020 15:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A1=A8=E5=8D=95=E5=8D=B3?= =?UTF-8?q?=E6=97=B6=E7=BC=96=E8=BE=91=E7=9A=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/apolloTable/editFormV3/index.tsx | 87 +++++++++------------ 1 file changed, 36 insertions(+), 51 deletions(-) diff --git a/components/apolloTable/editFormV3/index.tsx b/components/apolloTable/editFormV3/index.tsx index fb939f0..1855df4 100644 --- a/components/apolloTable/editFormV3/index.tsx +++ b/components/apolloTable/editFormV3/index.tsx @@ -15,25 +15,26 @@ * */ import React, { Component } from 'react'; 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 { config } from '../component/base/config'; import { transferAttr } from '../component/base/_utils/transferAttr'; import { getFormat, setFormat } from '../component/base'; 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; class FormWrap extends Component { - wrapDom:any; + wrapDom: any; handleSubmit = (e) => { e.preventDefault(); e.stopPropagation(); - const { rowId, form, handleSubmit, data, rowData, detailType } = this.props; + const { + rowId, form, handleSubmit, data, rowData, detailType, + } = this.props; form.validateFieldsAndScroll((err, values) => { - console.log(data, 8888) if (!err) { const newValues: any[] = []; _.keys(values).map((key) => { @@ -90,7 +91,7 @@ class FormWrap extends Component { }; renderEditForm = (item) => { - const { getFieldDecorator } = this.props.form; + const { getFieldDecorator, validateFieldsAndScroll } = this.props.form; const { rowData, rowId, getInstanceDetail, onBlurFn } = this.props; const { columnType, @@ -119,24 +120,28 @@ class FormWrap extends Component { const transferColumn = transferAttr(columnType, newProps); const disabled = readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag); const onBlurFn1 = (changedValue: any, newVal: any) => { - - let temp: any[] = []; - value.map((item: any) => { - temp.push({ text: item.text, value: item.value }); + validateFieldsAndScroll((err:any) => { + // 即时编辑时需要对表单必填等规则校验 + if (!err) { + 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 ( {getFieldDecorator(columnName, { @@ -182,12 +187,14 @@ class FormWrap extends Component { }; render() { - const { loading, isShowDelBtn, data, btnWrapStyle, name, colsNum, delLabel, hideOperateBtn } = this.props; + const { + loading, isShowDelBtn, data, btnWrapStyle, name, colsNum, delLabel, hideOperateBtn, + } = this.props; return (
-

{name || '客户跟进'}

+

{name}

取消 - + +
) @@ -245,26 +252,4 @@ class FormWrap extends Component { } } -function mapPropsToFields(props) { - 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); +export default Form.create({ name: 'editFormV3' })(FormWrap); -- 2.21.0