index.jsx 1.65 KB
Newer Older
DarkForst's avatar
DarkForst committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
import React, { useState,useEffect } from 'react';
import { connect } from 'umi';
import { Tree, Input, Button,TreeSelect } from 'antd';
import style from './index.less';
import { dicFindUtils, DictBizType, ApproveType, convertFieldToNum,parseAreaTreeData } from '@/utils/utils';
const { Search } = Input;

const DeviceTree = (props) => {
    const {
        treeCheckable,
        isNameValue,
        value,
        oStyle,
        dict:{
            dicTotalsList
        }
       } = props;
    const [treeData,setTreeData] = useState([]);
    useEffect(async () => {
        let treeData = dicFindUtils(dicTotalsList,DictBizType.deviceType);
        console.log(`device treeData is:`, treeData);
        let DeviceTreeArr = parseAreaTreeData(treeData, isNameValue);
        setTreeData(DeviceTreeArr);
    }, [dicTotalsList]);
    console.log(`treeData is:`, treeData,`value is:`,value);
    const changeParent = (val) => {
        props.onChange(val);
    };
    return (
        <div className={style.popover_tree}>
            <TreeSelect
                defaultValue = { value } 
                treeCheckable = { treeCheckable ? true : false}
                treeData={treeData && treeData.length > 0 && treeData || []}
                showSearch={true}
                placeholder='请选择'
                onChange={changeParent}
                allowClear
                readOnly={props.readOnly}
                disabled={props.disabled}
                treeNodeFilterProp= "title"
                style = {oStyle}
            />
        </div>
    );
};
export default connect(({ dict, universal,user, loading}) => ({
    universal,
    dict,
    user,
}))(DeviceTree);