/* * 数据推送 * 自定义薪资项目选择树 * @Author: 黎永顺 * @Date: 2024/11/20 * @Wechat: * @Email: 971387674@qq.com * @description: */ import React, { Component } from "react"; import { WeaLocaleProvider } from "ecCom"; import { TreeSelect } from "antd"; import { formualSearchField, formualSearchGroup } from "../../../../apis/item"; import cs from "classnames"; const getLabel = WeaLocaleProvider.getLabel; const TreeNode = TreeSelect.TreeNode; class CustomTreeSelect extends Component { constructor(props) { super(props); this.state = { sourceList: [] }; } componentDidMount() { formualSearchGroup({ referenceType: "sql" }).then(({ status, data }) => { if (status) this.setState({ sourceList: _.map(data, o => ({ ...o, isLeaf: true })) }); }); } getSourceItem = (sourceId) => { formualSearchField({ sourceId, extendParam: { referenceType: "sql" } }).then(({ status, data }) => { if (status) { this.setState({ sourceList: _.map(this.state.sourceList, o => { if (o.key === sourceId) return { ...o, children: _.map(data, k => ({ key: k.fieldId, value: k.name, fieldType: k.fieldType, isLeaf: false })) }; return { ...o }; }) }); } }); }; generateTreeNodes = (data) => { const treeNodes = [], showData = [...data]; showData.map((item) => { let title = (
{item.value} { item.fieldType ? {item.fieldType === "number" ? getLabel(111, "数字") : getLabel(111, "文本")} : }
); treeNodes.push(); }); return treeNodes; }; handleSelect = (nodeValue) => { const { form } = this.props, { sourceList } = this.state; const [source, __] = nodeValue.split("_"); const itemName = _.find(_.find(sourceList, o => o.key === source).children, k => k.key === nodeValue).value; form.updateFields({ item: nodeValue, itemName, source }); }; render() { const { sourceList } = this.state, { detail } = this.props; const { itemName } = detail; return ( this.getSourceItem(node.props.value)} onSelect={this.handleSelect} treeNodeFilterProp="title" filterTreeNode={(inputValue, treeNode) => { const title = treeNode.props.title.props ? treeNode.props.title.props.children[0].props.children : treeNode.props.title; return title.toLowerCase().indexOf(inputValue.toLowerCase()) >= 0; }}> { _.map(sourceList, o => ( {this.generateTreeNodes(o.children || [])} )) } ); } } export default CustomTreeSelect;