import React from 'react' import i18n from 'i18next' import { is } from 'immutable' import newEventActions from 'actions/newEvent' import newEventStores from 'stores/newEvent' import { getActionBlockObjNode, getEventBlockByBid } from 'stores/funcs/newEvent' import { hasEsDbSeniorSearch, isApiMethod, paramIsHideKeep, isDbMallMethodShouldReload } from 'stores/funcs/event/methodUtils' import { shallowEqualImmutable } from 'utils/utils' import { EVENT_BLOCK_TYPE } from 'const/const' import propType from 'const/propType' // import { // getActionDbNodeType, // getDbCols, // getNode, // getActionDbId // } from './dbComs/actionDbFuncs' import BlockActionMethodParamItem from './BlockActionMethodParamItem' // import BlockActionMethodParamApiToggle from './BlockActionMethodParamApiToggle' // import BlockActionMethodParamEsSeniorSearch from './BlockActionMethodParamEsSeniorSearch' export default class BlockActionMethodParams extends React.Component { constructor(props) { super(props) this.state = { // paramsValue: this.getParamsValue(), // dbInfo: {} } this.onEventChange = this.onEventChange.bind(this) // this.updateDbInfo = this.updateDbInfo.bind(this) this.paramShouldShow = this.paramShouldShow.bind(this) // this.updateMethod = this.updateMethod.bind(this) this.getObject = this.getObject.bind(this) this.getName = this.getName.bind(this) // this.getParamsValue = this.getParamsValue.bind(this) // this.getInfo = this.getInfo.bind(this) this.getVisible = this.getVisible.bind(this) // this.replenishApiParams = this.replenishApiParams.bind(this) this.renderInfo = this.renderInfo.bind(this) } shouldComponentUpdate(nextProps, nextState) { return ( !shallowEqualImmutable(this.props, nextProps) || !shallowEqualImmutable(this.state, nextState) ) } componentDidMount() { this.unsubscribe = newEventStores.listen(this.onEventChange) // this.updateDbInfo() } componentWillUnmount() { this.unsubscribe() } componentDidUpdate(preProps) { // if (preProps.bid !== this.props.bid) { // this.setState({ // paramsValue: this.getParamsValue() // }) // this.updateDbInfo() // } else if ( // !preProps.actionName && // preProps.actionName !== this.props.actionName // ) { // // actionName由无到有 // process.nextTick(() => { // this.updateDbInfo() // }) // } else if ( // // DbMall比较特殊,切换不同方法时需要重新获取DbCols // preProps.actionName !== this.props.actionName && // isDbMallMethodShouldReload(this.props.actionName) // ) { // process.nextTick(() => { // this.updateDbInfo() // }) // } } onEventChange(status) { // let obj = {} // if (status) { // if ( // status.types.includes('updateBlockProp') && // this.props.bid === status.data.affectBlockId && // ['object', 'action'].indexOf(status.data.prop) >= 0 // ) { // let paramsValue = this.getParamsValue() // if (!is(this.state.params, params)) { // obj.params = params // } // // 切换对象时检查 // if (['object'].indexOf(status.data.prop) >= 0) { // this.updateDbInfo() // } // } else if ( // status.types.includes('reloadParamsItemMethod') && // this.props.bid === status.data.affectBlockId // ) { // this.updateMethod() // } // } // if (Object.keys(obj).length > 0) { // this.setState(obj) // } } // updateDbInfo() { // let { bid } = this.props // let node = getNode({ // bid: this.props.bid, // obj: this.getObject(), // useObj: true, // actionName: this.getName() // }) // let dbId = getActionDbId({ node: node, bid: bid }) // let dbNodeType = getActionDbNodeType({ // node: node, // bid: bid // }) // if (dbId) { // getDbCols({ // dbId: dbId, // nodeType: dbNodeType, // cb: dbCols => { // this.setState({ // dbInfo: { dbId, dbCols, dbNodeType } // }) // } // }) // } else { // if (Object.keys(this.state.dbInfo).length >= 0) { // this.setState({ // dbInfo: {} // }) // } // } // } paramShouldShow(param, index) { let result = true switch (this.getVisible()) { case 'part': if ( (!param.value && param.value !== 0 && param.value !== false) || ((param.type === propType.Formula || param.type === propType.FormulaColor || param.type === propType.FormulaJson) && param.value && !param.value.code) ) { result = false } break } if ( result && paramIsHideKeep({ param: param, bid: this.props.bid, actionName: this.getName(), index: index, nodeId: this.props.eventNodeId || newEventStores.curEventNodeId, isNewEvent: true }) ) { result = false } return result } // updateMethod() { // let objNode = getActionBlockObjNode({ // obj: this.getObject(), // blockId: this.props.bid // }) // if (objNode) { // newEventActions.updateActionMethod({ // nodeId: objNode.id, // targetBlockId: this.props.bid, // methods: [this.getName()] // }) // } // } getObject() { let _obj = null let block = getEventBlockByBid(this.props.bid) if (block) { _obj = block.object } return _obj } getName() { return this.props.actionName ? this.props.actionName || null : null } // getParamsValue() { // let result = [] // let block = getEventBlockByBid(this.props.bid) // if ( // block && // block.type === EVENT_BLOCK_TYPE.ACTION && // block.action && // block.action.params // ) { // result = block.action.params // } // return result // } getVisible() { return this.props.paramsVisible ? this.props.paramsVisible || 'all' : 'all' } // getInfo() { // let result = undefined // let block = getEventBlockByBid(this.props.bid) // if ( // block && // block.type === EVENT_BLOCK_TYPE.ACTION && // block.action && // block.action.info // ) { // result = block.action.info // } // return result // } // replenishApiParams(apiGroups, result) { // let groupHeader = (title, index) => { // let className = 'params-group' // if (index === 0) { // className += ' first' // } // return ( //