/* * Author: 黎永顺 * name: 公式列表 * Description: * Date: 2023/4/25 */ import React, { Component } from "react"; import { WeaInputSearch, WeaLocaleProvider } from "ecCom"; import { Tree } from "antd"; import cs from "classnames"; import { formualSearchField, formualSearchGroup, getFormulaDes } from "../../../apis/item"; import "../index.less"; const TreeNode = Tree.TreeNode; const getLabel = WeaLocaleProvider.getLabel; class CodeAction extends Component { constructor(props) { super(props); this.state = { disabled: false, variableText: "", funcText: "", variItemText: "", variableList: [], //变量列表 variableExpandedKeys: [], //变量展开的节点 funcList: [], //函数列表 funcExpandedKeys: [], //函数展开的节点 funcHoverItem: {} //选中的函数节点 }; } componentDidMount() { const { groupParams = {} } = this.props; this.getFormulaDes(); this.formualSearchGroup(groupParams); } componentWillReceiveProps(nextProps, nextContext) { const { isCustomFunction, isCustomFunctionClick, onChangeCustomFunction } = nextProps; if (isCustomFunction === "1" && !isCustomFunctionClick) { this.setState({ disabled: true }); } else { this.setState({ disabled: false }, () => { isCustomFunction === "1" && onChangeCustomFunction("0"); }); } } getFormulaDes = () => { getFormulaDes().then(({ data }) => { if (!_.isEmpty(data)) this.setState({ funcList: data }); }); }; formualSearchGroup = (payload) => { formualSearchGroup(payload).then(({ status, data }) => { if (status) this.setState({ variableList: _.map(data, item => ({ ...item, children: [{ name: "", fieldId: "searchInput" }] })) }); }); }; formualSearchField = (sourceId) => { const { groupParams } = this.props; const { variableList } = this.state; formualSearchField({ sourceId, extendParam: { ...groupParams } }).then(({ status, data }) => { if (status) { this.setState({ variableList: _.map(variableList, it => ({ ...it, children: sourceId === it.key ? [...it.children, ...data] : [...it.children] })) }); } }); }; handleExpandVari = (variableExpandedKeys, { expanded, node }) => { const { props: { eventKey } } = node; const { variableList } = this.state; this.setState({ variableExpandedKeys }); if (expanded) { this.formualSearchField(eventKey); } else { this.setState({ variableList: _.map(variableList, it => ({ ...it, children: eventKey === it.key ? [{ name: "", fieldId: "searchInput" }] : [...it.children] })) }); } }; handleVariNode = (selectedKeys) => { const { onVariSelect } = this.props; const { variableList } = this.state; const parentNode = _.map(variableList, it => it.key); if (selectedKeys.join() && selectedKeys.join().indexOf("searchInput") === -1 && !parentNode.includes(selectedKeys.join())) { const selectParentNodeKey = selectedKeys.join().split("_")[0]; const convertStr = _.reduce(variableList, (pre, cur) => { if (cur.key === selectParentNodeKey) { return pre + cur.value + "." + _.find(cur.children, child => child.fieldId === selectedKeys.join()).name; } return pre; }, ""); onVariSelect(convertStr); } }; render() { const { variableList, variableExpandedKeys, variableText, variItemText, funcList, funcText, funcExpandedKeys, funcHoverItem, disabled } = this.state; const { groupParams = {} } = this.props; const { referenceType } = groupParams; const variableDatalist = _.filter(variableList, it => it.value.indexOf(variableText) !== -1); const funcDatalist = _.map(funcList, it => ({ ...it, children: _.filter(it.children, child => _.lowerCase(child.name).indexOf(_.lowerCase(funcText)) !== -1) })); return (