| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, InputNumber, Select, DatePicker, notification } from 'antd' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Form, Row, Col, Input, InputNumber, Select, DatePicker, notification, Collapse } from 'antd' |
| | | import moment from 'moment' |
| | | import { formRule } from '@/utils/option.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import FileUpload from '@/tabviews/tableshare/fileupload' |
| | | import FileUpload from '@/tabviews/zshare/fileupload' |
| | | import './index.scss' |
| | | |
| | | const {MonthPicker} = DatePicker |
| | | const { TextArea } = Input |
| | | const { Panel } = Collapse |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | action: PropTypes.object, // 按钮信息、表单列表 |
| | | setting: PropTypes.object, // 基本信息 |
| | | groups: PropTypes.array, // 表单组 |
| | | dict: PropTypes.object, // 字典项 |
| | | data: PropTypes.any, // 表格数据 |
| | | BData: PropTypes.any, // 主表数据 |
| | | configMap: PropTypes.object, // 按钮及下拉表单配置信息集 |
| | | inputSubmit: PropTypes.func // input回车提交 |
| | | } |
| | |
| | | state = { |
| | | datatype: null, |
| | | readtype: null, |
| | | formlist: [] |
| | | readin: null, |
| | | fieldlen: null, |
| | | groups: null, |
| | | formlist: [], |
| | | encrypts: [], // 加密字段 |
| | | intercepts: [], // 截取字段 |
| | | record: {} |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { data, BData } = this.props |
| | | let action = JSON.parse(JSON.stringify(this.props.action)) |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { datatype, encrypts } = this.state |
| | | if (nextProps.data && !is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | |
| | | let _fieldsvalue = {} |
| | | let _record = {} |
| | | Object.keys(nextProps.data).forEach(key => { |
| | | if (this.props.form.getFieldValue(key) !== undefined) { |
| | | if (datatype[key] === 'multiselect') { |
| | | let _val = nextProps.data[key] ? nextProps.data[key].split(',').filter(Boolean) : [] |
| | | _fieldsvalue[key] = _val |
| | | } else if (datatype[key] === 'date') { |
| | | let _val = nextProps.data[key] ? nextProps.data[key] : null |
| | | |
| | | if (_val) { |
| | | _val = moment(_val, 'YYYY-MM-DD') |
| | | } |
| | | |
| | | _fieldsvalue[key] = _val |
| | | } else if (datatype[key] === 'datemonth') { |
| | | let _val = nextProps.data[key] ? nextProps.data[key] : null |
| | | |
| | | if (_val) { |
| | | _val = moment(_val, 'YYYY-MM') |
| | | } |
| | | |
| | | _fieldsvalue[key] = _val |
| | | } else if (datatype[key] === 'datetime') { |
| | | let _val = nextProps.data[key] ? nextProps.data[key] : null |
| | | |
| | | if (_val) { |
| | | _val = moment(_val, 'YYYY-MM-DD HH:mm:ss') |
| | | } |
| | | |
| | | _fieldsvalue[key] = _val |
| | | } else if (datatype[key] === 'fileupload') { |
| | | let _val = nextProps.data[key] ? nextProps.data[key] : '' |
| | | |
| | | if (_val) { |
| | | try { |
| | | _val = _val.split(',').map((url, index) => { |
| | | return { |
| | | uid: `${index}`, |
| | | name: url.slice(url.lastIndexOf('/') + 1), |
| | | status: 'done', |
| | | url: url, |
| | | origin: true |
| | | } |
| | | }) |
| | | } catch { |
| | | _val = [] |
| | | } |
| | | } else { |
| | | _val = [] |
| | | } |
| | | |
| | | _fieldsvalue[key] = _val |
| | | } else if (datatype[key] === 'text' || datatype[key] === 'textarea') { |
| | | let _value = nextProps.data[key] |
| | | if (encrypts.includes(key)) { // 加密字段 |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | |
| | | _fieldsvalue[key] = _value |
| | | } else { |
| | | _fieldsvalue[key] = nextProps.data[key] |
| | | } |
| | | } else { |
| | | let _value = nextProps.data[key] |
| | | if (encrypts.includes(key)) { // 加密字段 |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | |
| | | _record[key] = _value |
| | | } |
| | | }) |
| | | |
| | | if (Object.keys(_fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(_fieldsvalue) |
| | | } |
| | | |
| | | this.setState({ |
| | | record: _record |
| | | }) |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { data, groups } = this.props |
| | | |
| | | let datatype = {} |
| | | let readtype = {} |
| | | let formlist = [] |
| | | if (action.groups.length > 0) { |
| | | action.groups.forEach(group => { |
| | | if (group.sublist.length === 0) return |
| | | let readin = {} |
| | | let fieldlen = {} |
| | | let _formlist = [] |
| | | let encrypts = [] |
| | | let intercepts = [] |
| | | |
| | | if (!group.default) { |
| | | formlist.push({ |
| | | type: 'title', |
| | | label: group.label, |
| | | uuid: group.uuid |
| | | }) |
| | | let _groups = groups.map(group => { |
| | | group.sublist = group.sublist.map(item => { |
| | | let _readin = item.readin !== 'false' |
| | | if (item.type === 'funcvar') { |
| | | _readin = false |
| | | item.initval = '' // 初始化为空 |
| | | } |
| | | |
| | | group.sublist.forEach(item => { |
| | | datatype[item.field] = item.type |
| | | readtype[item.field] = item.readonly === 'true' |
| | | formlist.push(item) |
| | | }) |
| | | }) |
| | | } else { |
| | | formlist = action.fields.map(item => { |
| | | if (item.type === 'textarea' && item.encryption === 'true') { |
| | | encrypts.push(item.field) |
| | | } |
| | | if (item.interception === 'true') { |
| | | intercepts.push(item.field) |
| | | } |
| | | |
| | | item.initVal = item.initval ? JSON.parse(JSON.stringify(item.initval)) : '' |
| | | |
| | | let _fieldlen = item.fieldlength || 50 |
| | | if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect') { |
| | | _fieldlen = item.fieldlength || 512 |
| | | } else if (item.type === 'number') { |
| | | _fieldlen = item.decimal ? item.decimal : 0 |
| | | } |
| | | |
| | | datatype[item.field] = item.type |
| | | readtype[item.field] = item.readonly === 'true' |
| | | readin[item.field] = _readin |
| | | fieldlen[item.field] = _fieldlen |
| | | |
| | | if (_readin && !/^date/.test(item.type) && data && data.hasOwnProperty(item.field)) { |
| | | let newval = data[item.field] |
| | | |
| | | if (encrypts.includes(item.field) && newval) { |
| | | try { |
| | | newval = window.decodeURIComponent(window.atob(newval)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | |
| | | item.initval = newval |
| | | } |
| | | |
| | | if (item.supvalue) { |
| | | item.supvalue = item.supvalue.split(',') |
| | | } |
| | | |
| | | _formlist.push(item) |
| | | |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | let _inputfields = formlist.filter(item => item.type === 'text' || item.type === 'number') // 用于过滤下拉菜单关联表单 |
| | | |
| | | formlist = formlist.map(item => { |
| | | if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') { |
| | | if (item.setAll === 'true') { |
| | | item.options.unshift({ |
| | | key: Utils.getuuid(), |
| | | Value: '', |
| | | Text: this.props.dict['main.all'] |
| | | }) |
| | | } |
| | | |
| | | if (item.resourceType === '1' && this.props.configMap.hasOwnProperty(item.uuid)) { |
| | | item.options = [...item.options, ...this.props.configMap[item.uuid]] |
| | | } |
| | | |
| | | item.oriOptions = JSON.parse(JSON.stringify(item.options)) |
| | | |
| | | if (item.linkSubField && item.linkSubField.length > 0) { |
| | | let _fields = _inputfields.map(_item => _item.field) |
| | | item.linkSubField = item.linkSubField.filter(_item => _fields.includes(_item)) |
| | | } |
| | | } |
| | | |
| | | if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) { |
| | | item.initval = BData[item.field] |
| | | } else if (!/^date/.test(item.type) && this.props.data && this.props.data.hasOwnProperty(item.field)) { |
| | | item.initval = this.props.data[item.field] |
| | | } |
| | | |
| | | return item |
| | | return group |
| | | }) |
| | | |
| | | let error = false |
| | | |
| | | formlist = formlist.map(item => { |
| | | if (item.type === 'link') { |
| | | let supItem = formlist.filter(form => form.field === item.linkField)[0] |
| | | |
| | | if (!supItem && data && data.hasOwnProperty(item.linkField)) { |
| | | supItem = {initval: data[item.linkField]} |
| | | _groups = _groups.map(group => { |
| | | group.sublist = group.sublist.map(item => { |
| | | if (item.type === 'link') { |
| | | let supItem = _formlist.filter(form => form.field === item.linkField)[0] |
| | | |
| | | // 关联显示列中的字段值,通过该值过滤下拉选项 |
| | | if (!supItem && data && data.hasOwnProperty(item.linkField)) { |
| | | supItem = {initval: data[item.linkField]} |
| | | } |
| | | |
| | | if (!supItem) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未查询到表单《' + item.label + '》关联字段!', |
| | | duration: 5 |
| | | }) |
| | | } else { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) |
| | | } |
| | | } |
| | | |
| | | if (!supItem) { |
| | | error = true |
| | | } else { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) |
| | | } |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '关联菜单设置错误!', |
| | | duration: 10 |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | return group |
| | | }) |
| | | |
| | | this.setState({ |
| | | readtype: readtype, |
| | | datatype: datatype, |
| | | formlist: formlist |
| | | }, () => { |
| | | if (action.setting && action.setting.focus) { |
| | | try { |
| | | let _form = document.getElementById('main-form-box') |
| | | let _item = _form.getElementsByTagName('input') |
| | | _item = [..._item] |
| | | _item.forEach(input => { |
| | | if (!input || input.id !== action.setting.focus) return |
| | | input.select() |
| | | }) |
| | | } catch { |
| | | console.warn('表单获取失败!') |
| | | } |
| | | } |
| | | readin: readin, |
| | | fieldlen: fieldlen, |
| | | formlist: _formlist, |
| | | groups: _groups |
| | | }) |
| | | } |
| | | |
| | | resetform = (formlist, supfields, index, fieldsvalue) => { |
| | | resetform = (groups, supfields, index, fieldsvalue) => { |
| | | index++ |
| | | let subfields = [] |
| | | |
| | | supfields.forEach(supfield => { |
| | | formlist = formlist.map(item => { |
| | | if (item.type === 'link' && item.linkField === supfield.field) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supfield.initval) |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | groups = groups.map(group => { |
| | | group.sublist = group.sublist.map(item => { |
| | | if (item.type === 'link' && item.linkField === supfield.field) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supfield.initval) |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | |
| | | fieldsvalue[item.field] = item.initval |
| | | |
| | | subfields.push(item) |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | return group |
| | | }) |
| | | }) |
| | | |
| | | if (subfields.length === 0 || index > 6) { |
| | | return {groups: groups, fieldsvalue: fieldsvalue} |
| | | } else { |
| | | return this.resetform(groups, subfields, index, fieldsvalue) |
| | | } |
| | | } |
| | | |
| | | selectChange = (_field, value, option) => { |
| | | const { record } = this.state |
| | | let groups = JSON.parse(JSON.stringify(this.state.groups)) |
| | | |
| | | let subfields = [] |
| | | let fieldsvalue = {} |
| | | let _record = {} |
| | | groups = groups.map(group => { |
| | | group.sublist = group.sublist.map(item => { |
| | | if (item.type === 'link' && item.linkField === _field.field) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === value) |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | |
| | | fieldsvalue[item.field] = item.initval |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | |
| | | if (subfields.length === 0 || index > 6) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | return formlist |
| | | } else { |
| | | return this.resetform(formlist, subfields, index, fieldsvalue) |
| | | } |
| | | } |
| | | |
| | | selectChange = (_field, value, option) => { |
| | | let formlist = JSON.parse(JSON.stringify(this.state.formlist)) |
| | | |
| | | let subfields = [] |
| | | let fieldsvalue = {} |
| | | formlist = formlist.map(item => { |
| | | if (item.type === 'link' && item.linkField === _field.field) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === value) |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | |
| | | fieldsvalue[item.field] = item.initval |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | return group |
| | | }) |
| | | |
| | | // 表单切换时,更新关联字段 |
| | | if (_field.type === 'select' && _field.linkSubField && _field.linkSubField.length > 0 && option.props.data) { |
| | | let _data = option.props.data |
| | | let fieldVal = {} |
| | | _field.linkSubField.forEach(subfield => { |
| | | fieldVal[subfield] = _data[subfield] |
| | | if (this.props.form.getFieldValue(subfield) !== undefined) { |
| | | fieldsvalue[subfield] = _data[subfield] |
| | | } else { |
| | | _record[subfield] = _data[subfield] |
| | | } |
| | | }) |
| | | this.props.form.setFieldsValue(fieldVal) |
| | | } |
| | | |
| | | if (subfields.length === 0) return |
| | | if (subfields.length === 0) { |
| | | if (Object.keys(fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | } |
| | | if (Object.keys(_record).length > 0) { |
| | | this.setState({ |
| | | record: {...record, ..._record} |
| | | }) |
| | | } |
| | | } else { |
| | | let result = this.resetform(groups, subfields, 0, fieldsvalue) |
| | | |
| | | formlist = this.resetform(formlist, subfields, 0, fieldsvalue) |
| | | if (Object.keys(result.fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | } |
| | | |
| | | this.setState({ |
| | | formlist: formlist |
| | | }) |
| | | let _param = { |
| | | groups: result.groups |
| | | } |
| | | |
| | | if (Object.keys(_record).length > 0) { |
| | | _param.record = {...record, ..._record} |
| | | } |
| | | |
| | | this.setState(_param) |
| | | } |
| | | } |
| | | |
| | | getFields() { |
| | | getFields(formlist) { |
| | | const { getFieldDecorator } = this.props.form |
| | | |
| | | const fields = [] |
| | | let cols = 2 |
| | | if (this.props.action.setting && this.props.action.setting.cols) { |
| | | cols = parseInt(this.props.action.setting.cols) |
| | | if (cols > 3 || cols < 1) { |
| | | if (this.props.setting && this.props.setting.cols) { |
| | | cols = parseInt(this.props.setting.cols) |
| | | if (cols > 4 || cols < 1) { |
| | | cols = 2 |
| | | } |
| | | } |
| | | |
| | | this.state.formlist.forEach((item, index) => { |
| | | if ((!item.field && item.type !== 'title') || item.hidden === 'true') return |
| | | formlist.forEach((item, index) => { |
| | | if (item.hidden === 'true') return |
| | | |
| | | if (item.supField && !item.supvalue.includes(this.props.form.getFieldValue(item.supField))) return |
| | | |
| | | if (item.type === 'title') { |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <p>{item.label}</p> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'text') { |
| | | if (item.type === 'text') { |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | initialValue: _initval, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | required: true, |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | |
| | | showSearch |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onChange={(value, option) => {this.selectChange(item, value, option)}} |
| | | disabled={item.readonly === 'true'} |
| | | > |
| | | {item.options.map(option => |
| | | <Select.Option id={option.key} data={hasSubField ? option : ''} title={option.Text} key={option.key} value={option.Value}>{option.Text}</Select.Option> |
| | |
| | | showSearch |
| | | mode="multiple" |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | disabled={item.readonly === 'true'} |
| | | > |
| | | {item.options.map(option => |
| | | <Select.Option id={option.key} title={option.Text} key={option.key} value={option.Value}>{option.Text}</Select.Option> |
| | |
| | | ) |
| | | } else if (item.type === 'date') { // 时间搜索 |
| | | let _initval = this.props.data ? this.props.data[item.field] : '' |
| | | if (_initval) { |
| | | if (_initval && this.state.readin[item.field]) { |
| | | _initval = moment(_initval, 'YYYY-MM-DD') |
| | | } else { |
| | | _initval = item.initval ? moment().subtract(item.initval, 'days') : null |
| | | } |
| | | |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <DatePicker /> |
| | | <DatePicker disabled={item.readonly === 'true'} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'datemonth') { |
| | | let _initval = this.props.data ? this.props.data[item.field] : '' |
| | | if (_initval) { |
| | | if (_initval && this.state.readin[item.field]) { |
| | | _initval = moment(_initval, 'YYYY-MM') |
| | | } else { |
| | | _initval = item.initval ? moment().subtract(item.initval, 'month') : null |
| | | } |
| | | |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <MonthPicker /> |
| | | <MonthPicker disabled={item.readonly === 'true'} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'datetime') { |
| | | let _initval = this.props.data ? this.props.data[item.field] : '' |
| | | if (_initval) { |
| | | |
| | | if (_initval && this.state.readin[item.field]) { |
| | | _initval = moment(_initval, 'YYYY-MM-DD HH:mm:ss') |
| | | } else { |
| | | _initval = item.initval ? moment().subtract(item.initval, 'days') : null |
| | | } |
| | | |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | } |
| | | ] |
| | | })( |
| | | // <DatePicker showTime getCalendarContainer={() => document.getElementById('form-box')} /> |
| | | <DatePicker showTime /> |
| | | <DatePicker showTime disabled={item.readonly === 'true'} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'fileupload') { |
| | | let filelist = this.props.data ? this.props.data[item.field] : item.initval |
| | | if (filelist) { |
| | | if (filelist && this.state.readin[item.field]) { |
| | | try { |
| | | filelist = filelist.split(',').map((url, index) => { |
| | | return { |
| | |
| | | } catch { |
| | | filelist = [] |
| | | } |
| | | } else { |
| | | filelist = [] |
| | | } |
| | | |
| | | fields.push( |
| | |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'linkMain') { |
| | | } else if (item.type === 'funcvar') { |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)} |
| | | initialValue: '系统自动生成', |
| | | })(<Input placeholder="" autoComplete="off" disabled={true} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'funcvar') { |
| | | // fields.push( |
| | | // <Col span={24 / cols} key={index}> |
| | | // <Form.Item label={item.label}> |
| | | // {getFieldDecorator(item.field, { |
| | | // initialValue: item.linkfield || '', |
| | | // })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)} |
| | | // </Form.Item> |
| | | // </Col> |
| | | // ) |
| | | } else if (item.type === 'textarea') { |
| | | let _labelcol = cols !== 3 ? 8 / cols : 3 |
| | | let _wrapcol = cols !== 3 ? 16 + (cols - 1) * 4 : 21 |
| | | let _style = {} |
| | | if (cols === 2) { |
| | | if (cols === 2 || cols === 4) { |
| | | _style.paddingLeft = '7px' |
| | | } |
| | | fields.push( |
| | |
| | | message: formRule.textarea.message |
| | | } |
| | | ] |
| | | })(<TextArea autosize={{ minRows: 2, maxRows: 6 }} disabled={item.readonly === 'true'} />)} |
| | | })(<TextArea autosize={{ minRows: 2, maxRows: item.maxRows || 6 }} disabled={item.readonly === 'true'} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | |
| | | } |
| | | |
| | | handleConfirm = () => { |
| | | const { record, encrypts, intercepts } = this.state |
| | | // 表单提交时检查输入值是否正确 |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | |
| | | if (!item.field) return |
| | | |
| | | if (item.type === 'funcvar') { |
| | | let _val = item.initval |
| | | if (values.hasOwnProperty(item.field)) { |
| | | _val = values[item.field] === '系统自动生成' ? '' : values[item.field] |
| | | } else if (record.hasOwnProperty(item.field)) { |
| | | _val = record[item.field] |
| | | } |
| | | search.push({ |
| | | type: 'funcvar', |
| | | readonly: 'true', |
| | | readin: false, |
| | | fieldlen: this.state.fieldlen[item.field], |
| | | key: item.field, |
| | | value: '' |
| | | value: _val |
| | | }) |
| | | } else if (item.hidden === 'true') { |
| | | } else if (item.hidden === 'true' && item.field !== this.props.setting.primaryKey) { |
| | | let _val = item.initval |
| | | if (record.hasOwnProperty(item.field)) { |
| | | _val = record[item.field] |
| | | } |
| | | |
| | | search.push({ |
| | | type: this.state.datatype[item.field], |
| | | readonly: this.state.readtype[item.field], |
| | | readin: this.state.readin[item.field], |
| | | fieldlen: this.state.fieldlen[item.field], |
| | | key: item.field, |
| | | value: item.initval |
| | | value: _val |
| | | }) |
| | | } else if (item.supField && !item.supvalue.includes(this.props.form.getFieldValue(item.supField))) { |
| | | search.push({ |
| | | type: this.state.datatype[item.field], |
| | | readonly: this.state.readtype[item.field], |
| | | readin: this.state.readin[item.field], |
| | | fieldlen: this.state.fieldlen[item.field], |
| | | key: item.field, |
| | | value: item.initVal |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | Object.keys(values).forEach(key => { |
| | | if (this.state.datatype[key] === 'funcvar') return |
| | | |
| | | let _value = '' |
| | | if (this.state.datatype[key] === 'datetime') { |
| | | let _value = '' |
| | | if (values[key]) { |
| | | _value = moment(values[key]).format('YYYY-MM-DD HH:mm:ss') |
| | | } |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: _value |
| | | }) |
| | | } else if (this.state.datatype[key] === 'datemonth') { |
| | | let _value = '' |
| | | if (values[key]) { |
| | | _value = moment(values[key]).format('YYYY-MM') |
| | | } |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: _value |
| | | }) |
| | | } else if (this.state.datatype[key] === 'date') { |
| | | let _value = '' |
| | | if (values[key]) { |
| | | _value = moment(values[key]).format('YYYY-MM-DD') |
| | | } |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: _value |
| | | }) |
| | | } else if (this.state.datatype[key] === 'number') { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key] |
| | | }) |
| | | _value = values[key] |
| | | |
| | | } else if (this.state.datatype[key] === 'multiselect') { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key] ? values[key].join(',') : '' |
| | | }) |
| | | _value = values[key] ? values[key].join(',') : '' |
| | | |
| | | } else if (this.state.datatype[key] === 'fileupload') { |
| | | let vals = [] |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: vals.join(',') |
| | | }) |
| | | } else if (this.state.datatype[key] === 'funcvar') { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key] |
| | | }) |
| | | _value = vals.join(',') |
| | | } else if (this.state.datatype[key] === 'text' || this.state.datatype[key] === 'textarea') { |
| | | _value = values[key].replace(/\t*|\v*/g, '') // 去除制表符 |
| | | |
| | | if (intercepts.includes(key)) { // 去除首尾空格 |
| | | _value = _value.replace(/(^\s*|\s*$)/g, '') |
| | | } |
| | | } else { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key].replace(/(^\s*|\s*$)/ig, '') |
| | | // value: values[key].replace(/[\x00-\xff]+/ig, '') |
| | | }) |
| | | _value = values[key] |
| | | |
| | | } |
| | | |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | readin: this.state.readin[key], |
| | | fieldlen: this.state.fieldlen[key], |
| | | key: key, |
| | | value: _value |
| | | }) |
| | | }) |
| | | |
| | | if (encrypts && encrypts.length > 0) { |
| | | search = search.map(item => { |
| | | let _value = item.value |
| | | if (encrypts.includes(item.key)) { |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | item.value = _value |
| | | |
| | | return item |
| | | }) |
| | | } |
| | | resolve(search) |
| | | } else { |
| | | reject(err) |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { setting } = this.props |
| | | const { groups } = this.state |
| | | const formItemLayout = { |
| | | labelCol: { |
| | | xs: { span: 24 }, |
| | |
| | | sm: { span: 16 } |
| | | } |
| | | } |
| | | |
| | | let _width = (setting && setting.width) || 100 |
| | | |
| | | let keys = groups.map(group => group.uuid) |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="ant-advanced-search-form main-form-field" id="main-form-box"> |
| | | <Row gutter={24}>{this.getFields()}</Row> |
| | | <Form {...formItemLayout} className="form-tab-form-field"> |
| | | <Collapse |
| | | defaultActiveKey={keys} |
| | | expandIconPosition='right' |
| | | > |
| | | {groups.map(group => |
| | | <Panel header={group.label} key={group.uuid}> |
| | | <Row style={{margin: '0 auto', width: _width + '%'}} gutter={24}>{this.getFields(group.sublist)}</Row> |
| | | </Panel> |
| | | )} |
| | | </Collapse> |
| | | </Form> |
| | | ) |
| | | } |