From 5c8860f3cd8921e7eb0da7749628e9dc669b3203 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 17 三月 2020 10:19:16 +0800 Subject: [PATCH] 2020-03-17 --- src/views/printTemplate/mutilform/index.jsx | 93 ++++++++++++++++++++++++++++++++++++---------- 1 files changed, 73 insertions(+), 20 deletions(-) diff --git a/src/views/printTemplate/mutilform/index.jsx b/src/views/printTemplate/mutilform/index.jsx index 2d3dbf0..1d209f4 100644 --- a/src/views/printTemplate/mutilform/index.jsx +++ b/src/views/printTemplate/mutilform/index.jsx @@ -16,16 +16,53 @@ formlist: PropTypes.array // input鍥炶溅鎻愪氦 } + state = { + formlist: null, + type: 'box' + } + + UNSAFE_componentWillMount () { + this.setState({ + formlist: this.props.formlist + }) + } + UNSAFE_componentWillReceiveProps(nextProps) { if (!is(fromJS(this.props.editItem), fromJS(nextProps.editItem))) { this.setState({}, () => { let fieldsvalue = {} + let isCusField = false + let type = 'box' + nextProps.formlist.forEach(item => { + if (item.type === 'title') { + type = item.class + } + if (!item.key) return + if (item.key === 'field' && item.initval === 'other_field') { + isCusField = true + } fieldsvalue[item.key] = item.initval }) - this.props.form.setFieldsValue(fieldsvalue) + + this.setState({ + type: type, + formlist: nextProps.formlist.map(item => { + if (item.key === 'cusfield' && isCusField) { + item.hidden = false + } + + return item + }) + }, () => { + if (!isCusField) { + delete fieldsvalue.cusfield + } + this.props.form.setFieldsValue(fieldsvalue) + }) + }) } } @@ -38,6 +75,28 @@ width: option.width, height: option.height }) + } else if (item.key === 'field') { + if (value === 'other_field') { + this.setState({ + formlist: this.state.formlist.map(item => { + if (item.key === 'cusfield') { + item.hidden = false + } + + return item + }) + }) + } else { + this.setState({ + formlist: this.state.formlist.map(item => { + if (item.key === 'cusfield') { + item.hidden = true + } + + return item + }) + }) + } } this.handleSubmit() } @@ -48,14 +107,20 @@ delete _param.uuid delete _param.url + if (_param.field !== 'other_field') { + delete _param.cusfield + } + this.props.form.setFieldsValue(_param) } getFields() { const { getFieldDecorator } = this.props.form + const { type, formlist } = this.state const fields = [] - this.props.formlist.forEach((item, index) => { + formlist.forEach((item, index) => { + if (item.hidden) return if (item.type === 'title') { fields.push( @@ -67,23 +132,11 @@ ) } else if (item.type === 'text') { let _rules = [] - if (item.regular) { - if (item.regular === 'number') { - _rules = [{ - pattern: /^[0-9]*$/ig, - message: formRule.input.numbermsg - }] - } else if (item.regular === 'letter') { - _rules = [{ - pattern: /^[a-zA-Z]*$/ig, - message: formRule.input.lettermsg - }] - } else if (item.regular === 'letter&number') { - _rules = [{ - pattern: /^[a-zA-Z0-9]*$/ig, - message: formRule.input.letternummsg - }] - } + if (item.key === 'value' && type === 'barcode') { + _rules = [{ + pattern: /^[a-zA-Z0-9]*$/ig, + message: '鏉$爜鍊煎繀椤讳负鏁板瓧鎴栧瓧姣嶏紒' + }] } fields.push( <Col span={24} key={index}> @@ -93,7 +146,7 @@ rules: [ { required: !!item.required, - message: '璇疯緭鍏�' + item.label + '!' + message: '璇疯緭鍏�' + item.label + '瀛楁!' }, { max: 512, -- Gitblit v1.8.0