| | |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 父级Id,用于查询下拉选择项 |
| | | config: PropTypes.object, // 组件配置信息 |
| | | BID: PropTypes.any, |
| | | config: PropTypes.object |
| | | } |
| | | |
| | | state = { |
| | |
| | | item.advanced = false |
| | | } |
| | | |
| | | if (item.checkShift && !item.initval) { |
| | | let d = '' |
| | | if (window.GLOB.CacheData.has(item.$supId)) { |
| | | d = window.GLOB.CacheData.get(item.$supId) |
| | | d = d[item.dateShift] || '' |
| | | if (d) { |
| | | d = moment(d).format('YYYY-MM-DD') |
| | | d = d === 'Invalid date' ? '' : d |
| | | } |
| | | } |
| | | |
| | | if (d) { |
| | | if (item.type === 'daterange') { |
| | | if (item.$initval === 'week') { |
| | | item.initval = [moment(d).startOf('week').format(item.format), moment(d).endOf('week').format(item.format)].join(',') |
| | | } else if (item.$initval === 'month') { |
| | | item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',') |
| | | } else if (item.$initval === 'lastMonth') { |
| | | item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',') |
| | | } else { |
| | | try { |
| | | let _initval = JSON.parse(item.$initval) |
| | | let _vals = [moment(d).subtract(_initval[0], 'days').format(item.format), moment(d).subtract(_initval[1], 'days').format(item.format)] |
| | | item.initval = _vals.join(',') |
| | | } catch (e) { |
| | | item.initval = '' |
| | | } |
| | | } |
| | | } else { |
| | | item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM') |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (item.type === 'group') { |
| | | record[item.field] = item.initType |
| | | record[item.datefield] = item.initval |
| | |
| | | if (item.resourceType === '1' && item.dataSource) { |
| | | let _option = Utils.getSelectQueryOptions(item) |
| | | |
| | | let exec = true |
| | | if (item.checkBid) { |
| | | item.sql = _option.sql |
| | | item.arr_field = _option.field |
| | | |
| | | exec = !!BID |
| | | } |
| | | |
| | | if (exec) { |
| | | _option.sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`) |
| | | |
| | | if (window.GLOB.debugger === true) { |
| | |
| | | mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`) |
| | | } else { |
| | | localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | searchlist: _list |
| | | }, () => { |
| | | if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') { |
| | | this.improveSimpleSearch(deForms) |
| | | this.improveSimpleSearch(deForms, false) |
| | | } else if (mainItems.length > 0 || localItems.length > 0) { |
| | | this.improveSearch(mainItems, localItems) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | const { config, BID } = this.props |
| | | |
| | | if (config.checkBid && nextProps.BID !== BID) { |
| | | this.resetOptions(nextProps.BID) |
| | | } |
| | | } |
| | | |
| | | resetOptions = (BID) => { |
| | | let deForms = [] |
| | | let searchlist = fromJS(this.state.searchlist).toJS().map(item => { |
| | | if (item.checkBid) { |
| | | let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`) |
| | | |
| | | if (window.GLOB.debugger === true) { |
| | | console.info(sql) |
| | | } |
| | | |
| | | deForms.push({ |
| | | ...item, |
| | | arr_field: item.arr_field, |
| | | data_sql: Utils.formatOptions(sql) |
| | | }) |
| | | } else if (item.checkShift) { |
| | | let d = '' |
| | | if (window.GLOB.CacheData.has(item.$supId)) { |
| | | d = window.GLOB.CacheData.get(item.$supId) |
| | | d = d[item.dateShift] || '' |
| | | if (d) { |
| | | d = moment(d).format('YYYY-MM-DD') |
| | | d = d === 'Invalid date' ? '' : d |
| | | } |
| | | } |
| | | |
| | | if (d) { |
| | | if (item.type === 'daterange') { |
| | | if (item.$initval === 'week') { |
| | | item.initval = [moment(d).startOf('week').format(item.format), moment(d).endOf('week').format(item.format)].join(',') |
| | | } else if (item.$initval === 'month') { |
| | | item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',') |
| | | } else if (item.$initval === 'lastMonth') { |
| | | item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',') |
| | | } else { |
| | | try { |
| | | let _initval = JSON.parse(item.$initval) |
| | | let _vals = [moment(d).subtract(_initval[0], 'days').format(item.format), moment(d).subtract(_initval[1], 'days').format(item.format)] |
| | | item.initval = _vals.join(',') |
| | | } catch (e) { |
| | | item.initval = '' |
| | | } |
| | | } |
| | | } else { |
| | | item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM') |
| | | } |
| | | } |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | if (deForms.length > 0) { |
| | | this.improveSimpleSearch(deForms, true, searchlist) |
| | | } else { |
| | | this.setState({ |
| | | searchlist: searchlist |
| | | }) |
| | | |
| | | setTimeout(() => { |
| | | this.handleSubmit() |
| | | }, 20) |
| | | } |
| | | } |
| | | |
| | | resetCheckcard = (item) => { |
| | |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetSearch(result) |
| | | this.resetSearch(result, false) |
| | | }) |
| | | } |
| | | |
| | | // 测试系统单个请求下拉选项 |
| | | improveSimpleSearch = (deForms) => { |
| | | improveSimpleSearch = (deForms, trigger, searchlist) => { |
| | | if (deForms.length === 0) return |
| | | |
| | | let deffers = deForms.map((item, index) => { |
| | |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetSearch(result) |
| | | this.resetSearch(result, trigger, searchlist) |
| | | }) |
| | | } |
| | | |
| | | resetSearch = (result) => { |
| | | let trigger = false |
| | | let _searchlist = fromJS(this.state.searchlist).toJS().map(item => { |
| | | resetSearch = (result, submit, searchlist) => { |
| | | let trigger = submit |
| | | let _searchlist = fromJS(searchlist || this.state.searchlist).toJS().map(item => { |
| | | if (['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(item.type) && result[item.field] && result[item.field].length > 0) { |
| | | let options = [] |
| | | let map = new Map() |
| | |
| | | item.options = item.oriOptions |
| | | } |
| | | |
| | | if (item.$first && item.options.length > 0) { |
| | | if (item.$first) { |
| | | if (item.options.length > 0) { |
| | | item.initval = item.options[0].Value |
| | | trigger = true |
| | | } else { |
| | | item.initval = '' |
| | | } |
| | | } |
| | | |
| | | return item |
| | |
| | | if (trigger) { |
| | | setTimeout(() => { |
| | | this.handleSubmit() |
| | | }, 10) |
| | | }, 20) |
| | | } |
| | | } |
| | | |
| | |
| | | } else if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') { |
| | | content = (<MKSelect config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />) |
| | | } else if (item.type === 'date' || item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') { |
| | | content = (<MKDatePicker config={item} onChange={(val) => this.recordChange(val, false, item)} />) |
| | | content = (<MKDatePicker config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />) |
| | | } else if (item.type === 'group') { |
| | | field = item.datefield |
| | | content = <DateGroup position={index} config={item} onChange={(val, type) => this.dateGroupChange(val, type, item)} /> |