From f36141f3075edf9d41928d64f759ad6bd1b1ac60 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 14 七月 2020 17:43:34 +0800 Subject: [PATCH] 2020-07-14 --- src/tabviews/zshare/topSearch/index.jsx | 253 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 204 insertions(+), 49 deletions(-) diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx index 60baa3b..478a1a4 100644 --- a/src/tabviews/zshare/topSearch/index.jsx +++ b/src/tabviews/zshare/topSearch/index.jsx @@ -1,8 +1,10 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' +import { fromJS } from 'immutable' import { Form, Row, Col, Input, Button, Select, DatePicker, notification } from 'antd' import moment from 'moment' +import Api from '@/api' import DateGroup from '@/tabviews/zshare/dategroup' import Utils from '@/utils/utils.js' import './index.scss' @@ -11,8 +13,11 @@ class MainSearch extends Component { static propTpyes = { + BID: PropTypes.any, // 鐖剁骇Id锛岀敤浜庢煡璇笅鎷夐�夋嫨椤� + dataManager: PropTypes.any, // 鏁版嵁鏉冮檺 + menuType: PropTypes.any, // 鑿滃崟鏉冮檺锛屾槸鍚︿负HS searchlist: PropTypes.array, // 鎼滅储鏉′欢鍒楄〃 - dict: PropTypes.object // 瀛楀吀椤� + dict: PropTypes.object // 瀛楀吀椤� } state = { @@ -26,7 +31,7 @@ } UNSAFE_componentWillMount () { - let searchlist = JSON.parse(JSON.stringify(this.props.searchlist)) + let searchlist = fromJS(this.props.searchlist).toJS() let match = {} let label = {} let style = {} @@ -46,7 +51,14 @@ required[item.field] = item.required === 'true' if (item.type === 'select' || item.type === 'link') { - item.oriOptions = JSON.parse(JSON.stringify(item.options)) + if (item.setAll === 'true') { + item.options.unshift({ + key: Utils.getuuid(), + Value: '', + Text: this.props.dict['main.all'] + }) + } + item.oriOptions = fromJS(item.options).toJS() } _list.push(item) @@ -66,8 +78,8 @@ } else { item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) } - } else if (item.type === 'group') { - _groups.push(JSON.parse(JSON.stringify(item))) + } else if (item.type === 'group' && item.Hide !== 'true') { + _groups.push(fromJS(item).toJS()) } return item @@ -80,45 +92,138 @@ required: required, searchlist: _list, groups: _groups + }, () => { + this.improveSearch() }) } - UNSAFE_componentWillReceiveProps(nextProps) { - let searchlist = JSON.parse(JSON.stringify(nextProps.searchlist)) - let _list = [] - let fieldMap = new Map() - + improveSearch = () => { + let searchlist = fromJS(this.props.searchlist).toJS() + let deffers = [] searchlist.forEach(item => { - if (fieldMap.has(item.field)) { - item.field = item.field + '@tail@' - } - fieldMap.set(item.field, true) + if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return - if (item.type === 'select' || item.type === 'link') { - item.oriOptions = JSON.parse(JSON.stringify(item.options)) + if (item.setAll === 'true') { + item.options.unshift({ + key: Utils.getuuid(), + Value: '', + Text: this.props.dict['main.all'] + }) } - _list.push(item) - }) + if (item.resourceType === '1' && item.dataSource) { + let _option = Utils.getSelectQueryOptions(item) + let _sql = Utils.formatOptions(_option.sql) + let isSSO = item.database === 'sso' - _list = _list.map(item => { - if (item.type === 'link') { - let supItem = _list.filter(form => form.field === item.linkField)[0] - - if (supItem) { - item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) + let param = { + func: 'sPC_Get_SelectedList', + LText: _sql, + obj_name: 'data', + arr_field: _option.field } - } - return item + if (this.props.BID) { + param.BID = this.props.BID + } + + if (this.props.dataManager) { // 鏁版嵁鏉冮檺 + param.LText = param.LText.replace(/\$@/ig, '/*') + param.LText = param.LText.replace(/@\$/ig, '*/') + } else { + param.LText = param.LText.replace(/@\$|\$@/ig, '') + } + + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + if (this.props.menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 + param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) + } + + let defer = new Promise(resolve => { + Api.getSystemCacheConfig(param, isSSO).then(res => { + res.search = item + resolve(res) + }) + }) + deffers.push(defer) + } else if (item.resourceType === '1' && !item.dataSource) { + notification.warning({ + top: 92, + message: item.label + ': ' + this.props.dict['main.datasource.settingerror'], + duration: 5 + }) + } }) - this.setState({ - searchlist: _list + if (deffers.length === 0) { + return + } + + Promise.all(deffers).then(result => { + result.forEach(res => { + if (res.status) { + searchlist = searchlist.map(item => { + if (item.uuid === res.search.uuid) { + res.data.forEach(cell => { + let _item = { + key: Utils.getuuid(), + Value: cell[res.search.valueField], + Text: cell[res.search.valueText] + } + + if (res.search.type === 'link') { + _item.parentId = cell[res.search.linkField] + } + + item.options.push(_item) + }) + } + return item + }) + } else { + notification.warning({ + top: 92, + message: res.search.label + ':' + res.message, + duration: 5 + }) + } + }) + + let _list = [] + let fieldMap = new Map() + + searchlist.forEach(item => { + if (fieldMap.has(item.field)) { + item.field = item.field + '@tail@' + } + fieldMap.set(item.field, true) + + if (item.type === 'select' || item.type === 'link') { + item.oriOptions = fromJS(item.options).toJS() + } + + _list.push(item) + }) + + _list = _list.map(item => { + if (item.type === 'link') { + let supItem = _list.filter(form => form.field === item.linkField)[0] + + if (supItem) { + item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) + } + } + + return item + }) + + this.setState({searchlist: _list}) }) } - resetform = (formlist, supfields, index) => { + resetform = (formlist, supfields, index, fieldsvalue) => { index++ let subfields = [] @@ -127,7 +232,10 @@ 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 : '' - item.hiden = true + + if (this.props.form.getFieldValue(item.field) !== undefined) { + fieldsvalue[item.field] = item.initval + } subfields.push(item) } @@ -138,19 +246,23 @@ if (subfields.length === 0 || index > 6) { return formlist } else { - return this.resetform(formlist, subfields, index) + return this.resetform(formlist, subfields, index, fieldsvalue) } } selectChange = (_field, value) => { - let formlist = JSON.parse(JSON.stringify(this.state.searchlist)) + let formlist = fromJS(this.state.searchlist).toJS() 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 : '' - item.hiden = true + + if (this.props.form.getFieldValue(item.field) !== undefined) { + fieldsvalue[item.field] = item.initval + } subfields.push(item) } @@ -162,19 +274,16 @@ return } - formlist = this.resetform(formlist, subfields, 0) + formlist = this.resetform(formlist, subfields, 0, fieldsvalue) + + if (Object.keys(fieldsvalue).length > 0) { + this.props.form.setFieldsValue(fieldsvalue) + } this.setState({ searchlist: formlist }, () => { - this.setState({ - searchlist: formlist.map(item => { - item.hiden = false - return item - }) - }, () => { - this.searchChange() - }) + this.searchChange() }) } @@ -183,7 +292,7 @@ const fields = [] this.state.searchlist.forEach((item, index) => { - if (item.hidden) return + if (item.Hide === 'true') return if (item.type === 'text') { // 鏂囨湰鎼滅储 fields.push( @@ -373,10 +482,46 @@ return fields } + addHideFieldValue = (values) => { + const { searchlist } = this.state + let hideValue = {} + searchlist.forEach(item => { + if (item.Hide === 'true') { + let value = '' + + if (item.type === 'multiselect') { // 涓嬫媺澶氶�� + value = item.initval ? item.initval.split(',').filter(Boolean) : [] + } else if (item.type === 'date') { // 鏃堕棿鎼滅储 + value = item.initval ? moment().subtract(item.initval, 'days') : '' + } else if (item.type === 'datemonth') { + value = item.initval ? moment().subtract(item.initval, 'month') : '' + } else if (item.type === 'dateweek') { + value = item.initval ? moment().subtract(item.initval * 7, 'days') : '' + } else if (item.type === 'daterange') { + if (item.initval) { + try { + let _initval = JSON.parse(item.initval) + value = [moment().subtract(_initval[0], 'days'), moment().subtract(_initval[1], 'days')] + } catch { + value = '' + } + } + } else { + value = item.initval + } + + hideValue[item.field] = value + } + }) + + return {...hideValue, ...values} + } + handleSearch = (e) => { // 鍥炶溅鎴栫偣鍑绘悳绱� e.preventDefault() this.props.form.validateFields((err, values) => { + values = this.addHideFieldValue(values) let searches = this.getFieldsValues(values) this.props.refreshdata(searches) }) @@ -385,6 +530,7 @@ searchChange = () => { this.setState({}, () => { this.props.form.validateFields((err, values) => { + values = this.addHideFieldValue(values) let searches = this.getFieldsValues(values) this.props.refreshdata(searches) }) @@ -402,12 +548,21 @@ this.refs[item.uuid].reset() }) } - this.props.form.resetFields() - this.props.form.validateFields((err, values) => { - // 寮傛鑾峰彇鏇存柊鍚庣殑鏃堕棿缁� - this.setState({}, () => { - let searches = this.getFieldsValues(values) - this.props.refreshdata(searches) + + let searchlist = this.state.searchlist.map(item => { + item.initval = item.oriInitval + return item + }) + + this.setState({searchlist}, () => { + this.props.form.resetFields() + this.props.form.validateFields((err, values) => { + // 寮傛鑾峰彇鏇存柊鍚庣殑鏃堕棿缁� + this.setState({}, () => { + values = this.addHideFieldValue(values) + let searches = this.getFieldsValues(values) + this.props.refreshdata(searches) + }) }) }) } -- Gitblit v1.8.0