| | |
| | | |
| | | state = { |
| | | match: null, // 搜索条件匹配规则 |
| | | style: null, |
| | | searchlist: null, |
| | | formId: Utils.getuuid() |
| | | style: null, // 搜索条件类型 |
| | | label: null, // 提示文字 |
| | | required: null, // 是否必填 |
| | | searchlist: null, // 搜索项 |
| | | formId: Utils.getuuid() // 搜索表单Id |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | let searchlist = JSON.parse(JSON.stringify(this.props.searchlist)) |
| | | let match = {} |
| | | let label = {} |
| | | let style = {} |
| | | let required = {} |
| | | let _list = [] |
| | | let fieldMap = new Map() |
| | | |
| | |
| | | fieldMap.set(item.field, true) |
| | | |
| | | match[item.field] = item.match |
| | | label[item.field] = item.label |
| | | style[item.field] = item.type |
| | | required[item.field] = item.required === 'true' |
| | | |
| | | if (item.type === 'select' || item.type === 'link') { |
| | | item.oriOptions = JSON.parse(JSON.stringify(item.options)) |
| | |
| | | |
| | | this.setState({ |
| | | match: match, |
| | | label: label, |
| | | style: style, |
| | | required: required, |
| | | searchlist: _list |
| | | }) |
| | | } |
| | |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, {initialValue: item.initval })(<Input placeholder="" autoComplete="off" />)} |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, {initialValue: item.initval })( |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <Select |
| | | showSearch |
| | | onChange={(value) => {this.selectChange(item, value)}} |
| | |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, {initialValue: _initval })( |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: _initval, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <Select |
| | | showSearch |
| | | mode="multiple" |
| | | // onChange={(value) => {this.selectChange(item, value)}} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | getPopupContainer={() => document.getElementById(this.state.formId)} |
| | | > |
| | |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, {initialValue: item.initval ? moment().subtract(item.initval, 'days') : null })( |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval ? moment().subtract(item.initval, 'days') : null, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <DatePicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} /> |
| | | )} |
| | | </Form.Item> |
| | |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, {initialValue: item.initval ? moment().subtract(item.initval, 'month') : null })( |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval ? moment().subtract(item.initval, 'month') : null, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <MonthPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} /> |
| | | )} |
| | | </Form.Item> |
| | |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, {initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null })( |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <WeekPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} /> |
| | | )} |
| | | </Form.Item> |
| | |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, |
| | | { |
| | | initialValue: _defaultValue |
| | | initialValue: _defaultValue, |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <RangePicker |
| | | placeholder={['开始日期', '结束日期']} |
| | |
| | | |
| | | fields.push( |
| | | <Col span={6} style={{ whiteSpace: 'nowrap' }} key="actions"> |
| | | <Form.Item label={' '} colon={false}> |
| | | <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}> |
| | | <Button type="primary" htmlType="submit"> |
| | | {this.props.dict['main.search']} |
| | | </Button> |
| | |
| | | // 获取搜索条件值 |
| | | let search = [] |
| | | Object.keys(values).forEach(key => { |
| | | let _value = '' |
| | | if (this.state.style[key] === 'daterange') { |
| | | let _value = '' |
| | | if (values[key].length > 0) { |
| | | _value = [moment(values[key][0]).format('YYYY-MM-DD'), moment(values[key][1]).format('YYYY-MM-DD')] |
| | | } |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: _value, |
| | | match: this.state.match[key] |
| | | }) |
| | | } else if (this.state.style[key] === 'dateweek') { |
| | | let _value = '' |
| | | if (values[key]) { |
| | | _value = [moment(values[key]).startOf('week').format('YYYY-MM-DD'), moment(values[key]).endOf('week').format('YYYY-MM-DD')] |
| | | } |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: _value, |
| | | match: this.state.match[key] |
| | | }) |
| | | } else if (this.state.style[key] === 'date') { |
| | | let _value = '' |
| | | if (values[key]) { |
| | | _value = moment(values[key]).format('YYYY-MM-DD') |
| | | } |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: _value, |
| | | match: this.state.match[key] |
| | | }) |
| | | } else if (this.state.style[key] === 'datemonth') { |
| | | let _value = '' |
| | | if (values[key]) { |
| | | _value = moment(values[key]).format('YYYY-MM') |
| | | } |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: _value, |
| | | match: this.state.match[key] |
| | | }) |
| | | } else if (this.state.style[key] === 'multiselect') { |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: values[key], |
| | | match: this.state.match[key] |
| | | }) |
| | | _value = values[key] |
| | | |
| | | } else { |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: values[key].replace(/(^\s*|\s*$)/ig, ''), |
| | | match: this.state.match[key] |
| | | }) |
| | | _value = values[key].replace(/(^\s*|\s*$)/ig, '') |
| | | |
| | | } |
| | | |
| | | search.push({ |
| | | type: this.state.style[key], |
| | | key: key.replace(/@tail@$/, ''), |
| | | value: _value, |
| | | label: this.state.label[key], |
| | | match: this.state.match[key], |
| | | required: this.state.required[key] |
| | | }) |
| | | }) |
| | | return search |
| | | } |