| | |
| | | import moment from 'moment' |
| | | import './index.scss' |
| | | |
| | | const {MonthPicker, WeekPicker} = DatePicker |
| | | const dateFormat = 'YYYY-MM-DD' |
| | | const weekFormat = 'YYYYMMDD' |
| | | const monthFormat = 'YYYY-MM' |
| | | // const {MonthPicker, WeekPicker} = DatePicker |
| | | // const dateFormat = 'YYYY-MM-DD' |
| | | // const weekFormat = 'YYYYMMDD' |
| | | // const monthFormat = 'YYYY-MM' |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | |
| | | let formats = {} |
| | | let match = {} |
| | | this.props.searchlist.forEach(item => { |
| | | if (item.Type === 'date') { |
| | | // formats[item.FieldName] = dateFormat |
| | | formats[item.FieldName] = weekFormat |
| | | } else if (item.ID === 'WHE1400200905') { |
| | | formats[item.FieldName] = monthFormat |
| | | } |
| | | match[item.FieldName] = item.Op |
| | | }) |
| | | this.setState({ |
| | |
| | | </Col> |
| | | ) |
| | | } else if (item.Type === 'date') { // 时间搜索 |
| | | if (item.ID === 'WHE14002009024') { |
| | | fields.push( |
| | | <Col span={6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.FieldName, {initialValue: moment('2019-09-14', dateFormat) })( |
| | | <DatePicker format={dateFormat} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.ID === 'WHE1400200905') { |
| | | fields.push( |
| | | <Col span={6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.FieldName, {initialValue: moment('2019-09', monthFormat) })( |
| | | <MonthPicker format={monthFormat} /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.ID === 'WHE1400200902') { |
| | | fields.push( |
| | | <Col span={6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.FieldName, {initialValue: moment('20190906', weekFormat) })( |
| | | <WeekPicker /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | let _initval = null |
| | | if (item.InitVal) { |
| | | _initval = moment().subtract(parseInt(item.InitVal), 'days') |
| | | } |
| | | fields.push( |
| | | <Col span={6} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.FieldName, {initialValue: _initval })( |
| | | <DatePicker /> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | // if (item.ID === 'WHE14002009024') { |
| | | // fields.push( |
| | | // <Col span={6} key={index}> |
| | | // <Form.Item label={item.label}> |
| | | // {getFieldDecorator(item.FieldName, {initialValue: moment('2019-09-14', dateFormat) })( |
| | | // <DatePicker format={dateFormat} /> |
| | | // )} |
| | | // </Form.Item> |
| | | // </Col> |
| | | // ) |
| | | // } else if (item.ID === 'WHE1400200905') { |
| | | // fields.push( |
| | | // <Col span={6} key={index}> |
| | | // <Form.Item label={item.label}> |
| | | // {getFieldDecorator(item.FieldName, {initialValue: moment('2019-09', monthFormat) })( |
| | | // <MonthPicker format={monthFormat} /> |
| | | // )} |
| | | // </Form.Item> |
| | | // </Col> |
| | | // ) |
| | | // } else if (item.ID === 'WHE1400200902') { |
| | | // fields.push( |
| | | // <Col span={6} key={index}> |
| | | // <Form.Item label={item.label}> |
| | | // {getFieldDecorator(item.FieldName, {initialValue: moment('20190906', weekFormat) })( |
| | | // <WeekPicker /> |
| | | // )} |
| | | // </Form.Item> |
| | | // </Col> |
| | | // ) |
| | | // } |
| | | } |
| | | }) |
| | | |
| | |
| | | Object.keys(searches).forEach(key => { |
| | | let val = searches[key] || '' |
| | | if (searches[key] && typeof(searches[key]) === 'object') { |
| | | if (this.state.formats[key] === weekFormat) { |
| | | val = moment(searches[key]).startOf('week').format(this.state.formats[key]) + ' ' + moment(searches[key]).endOf('week').format(this.state.formats[key]) |
| | | } else { |
| | | val = moment(searches[key]).format(this.state.formats[key]) |
| | | } |
| | | val = moment(searches[key]).format('YYYY-MM-DD') |
| | | } |
| | | search[key] = val |
| | | }) |
| | | |
| | | let valid = true // 校验必填项 |
| | | this.props.searchlist.forEach(item => { |
| | | let required = false |