// 核心库 import React, { Component } from 'react' import { connect } from 'dva' // 组件库 import { Row, Col, Select, TreeSelect, Button, Collapse, Icon } from 'antd' import IFComponent from '../common/IFComponent' // 工具库 import { getDataFieldValue, setDataFieldValue, initFilter, guid } from '../utils/common' import getControl from '../utils/getControl' import { getFieldConfigs, getGroupByGroupConfigs } from '../utils/getFieldConfigs' import { isEqual } from 'lodash' const Option = Select.Option const Panel = Collapse.Panel const TreeSelectNode = TreeSelect.TreeNode // dateType 对应 controlType const dataMapControl = { 2: 7, 3: 3, 4: 4, 5: 10, 6: 12, 8: 17, 9: 18, 10: 19, 11: 9, 12: 20, 13: 21, 14: 11, 15: 22, 16: 23, 17: 2 } const digGroupData = (arr, target) => { for (let i = 0, j = arr.length; i < j; i++) { if (arr[i].id === target) return arr[i] if (Array.isArray(arr[i].childGroups) && arr[i].childGroups.length) { const result = digGroupData(arr[i].childGroups, target) if (result) return result } } } const operator1 = [ { value: 1, label: '等于' }, { value: 2, label: '不等于' }, { value: 7, label: '开始于' }, { value: 8, label: '结束于' }, { value: 9, label: '包含' } ] const operator3 = [ { value: 1, label: '等于' }, { value: 2, label: '不等于' } ] const operator7 = [ { value: 1, label: '等于' }, { value: 2, label: '不等于' }, { value: 3, label: '小于' }, { value: 4, label: '小于或等于' }, { value: 5, label: '大于' }, { value: 6, label: '大于或等于' } ] function PanelContent (props) { // 新增一组字段 const addFieldConfig = () => { const { code, config, customConfigId, onChange, onPressEnter } = props !config.fieldConfigs && (config.fieldConfigs = []) config.fieldConfigs.push({ id: guid(), searchGroupId: config.id, isSysQueryField: false, userCCQueryId: customConfigId || null, code, onChange, data: { onPressEnter } }) props.onPanelContentChange instanceof Function && props.onPanelContentChange() } // 删除一组字段 const deleteFieldConfig = (id) => { const { config } = props const findIndex = config.fieldConfigs.findIndex(item => item.id === id) if (findIndex !== -1) { config.fieldConfigs.splice(findIndex, 1) props.onPanelContentChange instanceof Function && props.onPanelContentChange() } } // 字段选择 const onSelectChange = (id, nodeData) => { const dataType = getDataFieldValue(nodeData, 'DataType') const controlType = dataMapControl[dataType] ? dataMapControl[dataType] : 1 // 配置出选中的配置 const fieldConfig = { field: getDataFieldValue(nodeData, 'FieldName'), label: getDataFieldValue(nodeData, 'ShowLabel'), controlType, dataType, operator: controlType === 1 ? '9' : '1', isCustom: getDataFieldValue(nodeData, 'IsCustom'), isSysParam: getDataFieldValue(nodeData, 'IsSysParam'), defaultValue: null, isSysQueryField: getDataFieldValue(nodeData, 'IsSysField', false), caseType: getDataFieldValue(nodeData, 'CaseType'), isRequire: getDataFieldValue(nodeData, 'IsRequire') } // 获取到当前选中项 const { config } = props const find = config.fieldConfigs.find(item => item.id === id) if (find) { Object.keys(fieldConfig).forEach(key => { // 重写当前选中项各项值为选中的配置 setDataFieldValue(find, key, getDataFieldValue(fieldConfig, key)) !find.data && (find.data = {}) find.data.enumName = getDataFieldValue(nodeData, 'EnumName') }) props.onPanelContentChange instanceof Function && props.onPanelContentChange() } } // 操作关系选择 const onOperatorChange = (id, value) => { const { config } = props const find = config.fieldConfigs.find(item => item.id === id) if (find) { find.operator = value ? value.toString() : '' props.onPanelContentChange instanceof Function && props.onPanelContentChange() } } // 构造树节点 const getFieldTreeNode = (data) => { return data.filter(item => !item.IsCustom).map(item => { if (item.Children) { return ( {getFieldTreeNode(item.Children)} ) } return ( {item.IsRequire ? * : null}{item.Label}} key={item.FieldName} value={item.FieldName} data={item} isLeaf={item.IsLeaf} /> ) }) } // TreeSelect 远程数据加载 const handleLoadChildTreeNode = (treeNode) => { const { login, formId, dispatch } = props const { data } = treeNode.props if (data.Children) return Promise.resolve() const json = initFilter(login.OrgId, formId, 'CREATE_TIME', 0, 1, data.FieldName, data.TypeName, data.Label) return dispatch({ type: 'search/getQueryFields', payload: json }).then(ret => { treeNode.props.data.Children = ret }) } const { data, config, queryFields } = props const { fieldConfigs = [], childGroups = [] } = config return ( <> } > { fieldConfigs.map((item, index) => { item.value = getDataFieldValue(data, item.id) const options = item.controlType === 1 ? operator1 : item.controlType === 3 ? operator3 : item.controlType === 7 ? operator7 : [] return ( onSelectChange(item.id, node.props.data)} onChange={value => !value && onSelectChange(item.id, null)} dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} style={{ width: '100%' }} > {getFieldTreeNode(queryFields)} {getControl(item)}