| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Form, Row, Col, Input, InputNumber, Select } from 'antd' |
| | | import { Form, Row, Col, Input, InputNumber, Select, Tooltip, Icon } from 'antd' |
| | | import { formRule } from '@/utils/option.js' |
| | | import FileUpload from '@/tabviews/zshare/fileupload' |
| | | // import FileUpload from '@/tabviews/zshare/fileupload' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import './index.scss' |
| | | |
| | | const { TextArea } = Input |
| | | const FileUpload = asyncComponent(() => import('@/menu/components/share/sourcecomponent')) |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | |
| | | formlist: nextProps.formlist.map(item => { |
| | | if (item.key === 'cusfield' && isCusField) { |
| | | item.hidden = false |
| | | } else if (item.key === 'value' && item.type === 'fileupload') { |
| | | item.hidden = true |
| | | item.initval = fieldsvalue.value |
| | | } |
| | | |
| | | return item |
| | |
| | | if (!isCusField) { |
| | | delete fieldsvalue.cusfield |
| | | } |
| | | if (nextProps.editItem.type === 'image' && fieldsvalue.value) { |
| | | fieldsvalue.value = [{ |
| | | uid: '1', |
| | | name: fieldsvalue.value, |
| | | status: 'done', |
| | | url: fieldsvalue.value |
| | | }] |
| | | } else if (nextProps.editItem.type === 'image') { |
| | | fieldsvalue.value = [] |
| | | if (nextProps.editItem.type === 'image') { |
| | | this.setState({ |
| | | formlist: this.state.formlist.map(item => { |
| | | if (item.key === 'value' && item.type === 'fileupload') { |
| | | item.hidden = false |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | }) |
| | | delete fieldsvalue.value |
| | | } |
| | | |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | |
| | | this.handleSubmit() |
| | | } |
| | | |
| | | updateImg = (list) => { |
| | | if (list && list.length > 0) { |
| | | let url = list[0].url || list[0].response |
| | | if (url) { |
| | | this.props.form.setFieldsValue({ value: list }) |
| | | this.handleSubmit() |
| | | } |
| | | } else { |
| | | this.props.form.setFieldsValue({ value: [] }) |
| | | this.handleSubmit() |
| | | } |
| | | } |
| | | |
| | | resetForm = (param) => { |
| | | let _param = JSON.parse(JSON.stringify(param)) |
| | | delete _param.type |
| | |
| | | if (_param.field !== 'other_field') { |
| | | delete _param.cusfield |
| | | } |
| | | if (param.type === 'image' && param.value) { |
| | | _param.value = [{ |
| | | uid: '1', |
| | | name: param.value, |
| | | status: 'done', |
| | | url: param.value |
| | | }] |
| | | } else if (param.type === 'image') { |
| | | _param.value = [] |
| | | |
| | | if (param.type === 'image') { |
| | | delete _param.value |
| | | } |
| | | |
| | | this.props.form.setFieldsValue(_param) |
| | |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'fileupload') { |
| | | let filelist = [] |
| | | if (item.initval) { |
| | | filelist = [{ |
| | | uid: '1', |
| | | name: item.initval, |
| | | status: 'done', |
| | | url: item.initval |
| | | }] |
| | | } |
| | | |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={ |
| | | item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <Icon type="question-circle" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: filelist, |
| | | initialValue: item.initval || '', |
| | | rules: [ |
| | | { |
| | | required: item.required, |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <FileUpload maxFile={1} fileType={'text'} onChange={this.updateImg} /> |
| | | <FileUpload type="picture" placement="right" onChange={this.handleSubmit} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | |
| | | } else if (item.type === 'textarea') { |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.label} > |
| | | <Form.Item label={ |
| | | item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <Icon type="question-circle" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initval || '', |
| | | rules: [ |
| | |
| | | if (!err) { |
| | | values.uuid = this.props.editItem.uuid |
| | | values.type = this.props.editItem.type |
| | | |
| | | resolve(values) |
| | | } |
| | | }) |