| | |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import './index.scss' |
| | | |
| | | const {MonthPicker, WeekPicker, RangePicker} = DatePicker |
| | | const { MonthPicker, WeekPicker, RangePicker } = DatePicker |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 父级Id,用于查询下拉选择项 |
| | | menuType: PropTypes.any, // 菜单权限,是否为HS |
| | | searchlist: PropTypes.array, // 搜索条件列表 |
| | | config: PropTypes.object, // 组件配置信息(自定义页面) |
| | | refreshdata: PropTypes.func // 刷新数据 |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | match: null, // 搜索条件匹配规则 |
| | | style: null, // 搜索条件类型 |
| | | label: null, // 提示文字 |
| | | required: null, // 是否必填 |
| | | searchlist: null, // 搜索项 |
| | | groups: null, // 组合搜索项 |
| | | formId: Utils.getuuid() // 搜索表单Id |
| | | formId: '', // 搜索表单Id |
| | | match: null, // 搜索条件匹配规则 |
| | | style: null, // 搜索条件类型 |
| | | label: null, // 提示文字 |
| | | required: null, // 是否必填 |
| | | searchlist: null, // 搜索项 |
| | | groups: null, // 组合搜索项 |
| | | float: '', // 浮动 |
| | | showButton: true, // 是否显示搜索按钮 |
| | | searchStyle: null // 搜索条件样式 |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | let searchlist = fromJS(this.props.searchlist).toJS() |
| | | const { config, menuType, searchlist } = this.props |
| | | |
| | | let _searchlist = [] |
| | | let match = {} |
| | | let label = {} |
| | | let style = {} |
| | |
| | | let mainItems = [] // 云端或单点数据 |
| | | let localItems = [] // 本地数据 |
| | | let deForms = [] // 测试系统,单个请求 |
| | | let float = '' |
| | | let showButton = true |
| | | let searchStyle = null |
| | | let formId = Utils.getuuid() |
| | | |
| | | searchlist.forEach(item => { |
| | | if (searchlist) { |
| | | _searchlist = fromJS(searchlist).toJS() |
| | | } else if (config) { |
| | | _searchlist = fromJS(config.search).toJS() |
| | | if (config.type === 'search' && config.subtype === 'mainsearch') { |
| | | float = config.wrap.float |
| | | showButton = config.wrap.float === 'left' && config.wrap.show === 'true' |
| | | searchStyle = config.style |
| | | } else { |
| | | formId = '' |
| | | showButton = false |
| | | float = 'right' |
| | | } |
| | | } |
| | | |
| | | _searchlist.forEach(item => { |
| | | if (fieldMap.has(item.field)) { |
| | | item.field = item.field + '@tail@' |
| | | } |
| | |
| | | } |
| | | |
| | | // 测试系统单个请求 |
| | | if (this.props.menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) { |
| | | if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) { |
| | | deForms.push({ |
| | | ...item, |
| | | arr_field: _option.field, |
| | |
| | | }) |
| | | |
| | | this.setState({ |
| | | match: match, |
| | | label: label, |
| | | style: style, |
| | | required: required, |
| | | match, |
| | | label, |
| | | style, |
| | | float, |
| | | formId, |
| | | required, |
| | | showButton, |
| | | searchStyle, |
| | | searchlist: _list, |
| | | groups: _groups |
| | | }, () => { |
| | | if (this.props.menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) { |
| | | if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) { |
| | | this.improveSimpleSearch(deForms) |
| | | } else { |
| | | this.improveSearch(mainItems, localItems) |
| | |
| | | |
| | | getFields() { |
| | | const { getFieldDecorator } = this.props.form |
| | | const { dict } = this.state |
| | | const { dict, showButton, formId } = this.state |
| | | const fields = [] |
| | | |
| | | this.state.searchlist.forEach((item, index) => { |
| | |
| | | if (item.type === 'text') { // 文本搜索 |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval, |
| | | rules: [ |
| | |
| | | message: dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | })(<Input placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onPressEnter={this.handleSearch} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'select') { // 下拉搜索 |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval, |
| | | rules: [ |
| | |
| | | showSearch |
| | | onChange={(value) => {this.selectChange(item, value)}} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | getPopupContainer={() => document.getElementById(this.state.formId)} |
| | | getPopupContainer={() => formId ? document.getElementById(formId) : document.body} |
| | | > |
| | | {item.options.map((option, i) => |
| | | <Select.Option id={`${i}`} title={option.Text} key={`${i}`} value={option.Value}>{option.Text}</Select.Option> |
| | |
| | | let _initval = item.initval ? item.initval.split(',').filter(Boolean) : [] |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: _initval, |
| | | rules: [ |
| | |
| | | mode="multiple" |
| | | onChange={this.searchChange} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | getPopupContainer={() => document.getElementById(this.state.formId)} |
| | | getPopupContainer={() => formId ? document.getElementById(formId) : document.body} |
| | | > |
| | | {item.options.map((option, i) => |
| | | <Select.Option id={`${i}`} title={option.Text} key={`${i}`} value={option.Value}>{option.Text}</Select.Option> |
| | |
| | | } else if (item.type === 'date') { // 时间搜索 |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval ? moment().subtract(item.initval, 'days') : null, |
| | | rules: [ |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <DatePicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} /> |
| | | <DatePicker onChange={this.searchChange} getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | |
| | | } else if (item.type === 'datemonth') { |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval ? moment().subtract(item.initval, 'month') : null, |
| | | rules: [ |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <MonthPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} /> |
| | | <MonthPicker onChange={this.searchChange} getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | |
| | | } else if (item.type === 'dateweek') { |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null, |
| | | rules: [ |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <WeekPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} /> |
| | | <WeekPicker onChange={this.searchChange} getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | |
| | | |
| | | fields.push( |
| | | <Col className="daterange" span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''}> |
| | | {getFieldDecorator(item.field, |
| | | { |
| | | initialValue: _defaultValue, |
| | |
| | | placeholder={['开始日期', '结束日期']} |
| | | renderExtraFooter={() => 'extra footer'} |
| | | onChange={this.searchChange} |
| | | getCalendarContainer={() => document.getElementById(this.state.formId)} |
| | | getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} |
| | | /> |
| | | )} |
| | | </Form.Item> |
| | |
| | | } else if (item.type === 'group') { |
| | | fields.push( |
| | | <Col span={item.ratio || 6} key={index}> |
| | | <Form.Item label={item.label} className={item.required === 'true' ? 'group-required' : ''}> |
| | | <Form.Item label={item.labelShow !== 'false' ? item.label : ''} className={item.required === 'true' ? 'group-required' : ''}> |
| | | <DateGroup ref={item.uuid} position={index} card={item} onGroupChange={this.searchChange} /> |
| | | </Form.Item> |
| | | </Col> |
| | |
| | | } |
| | | }) |
| | | |
| | | fields.push( |
| | | <Col span={6} style={{ whiteSpace: 'nowrap' }} key="actions"> |
| | | <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}> |
| | | <Button type="primary" htmlType="submit"> |
| | | {dict['main.search']} |
| | | </Button> |
| | | <Button style={{ marginLeft: 8 }} onClick={this.handleReset}> |
| | | {dict['main.reset']} |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | if (showButton) { |
| | | fields.push( |
| | | <Col span={6} style={{ whiteSpace: 'nowrap' }} key="actions"> |
| | | <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}> |
| | | <Button type="primary" onClick={this.handleSearch}> |
| | | {dict['main.search']} |
| | | </Button> |
| | | <Button style={{ marginLeft: 8 }} onClick={this.handleReset}> |
| | | {dict['main.reset']} |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } |
| | | |
| | | return fields |
| | | } |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { float, searchStyle } = this.state |
| | | const formItemLayout = { |
| | | labelCol: { |
| | | xs: { span: 24 }, |
| | |
| | | } |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="top-search" id={this.state.formId} onSubmit={this.handleSearch}> |
| | | <Form {...formItemLayout} className={`top-search ${float}`} style={searchStyle} id={this.state.formId}> |
| | | <Row gutter={24}>{this.getFields()}</Row> |
| | | </Form> |
| | | ) |