zhiyong.zhou
2024-03-04 dfd7249fad876dee96480d70ff6f5ebd60207617
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
export default {
    decode(obj) {
        if (!obj) {
            return null;
        }
        if (Array.isArray(obj)) {
            return this.decodeArray(obj);
        } else if (typeof obj == "object") {
            return this.decodeObject(obj);
        } else if (typeof obj == "string") {
            try {
                return decodeURIComponent(obj);
            } catch (e) {
                return obj;
            }
        } else {
            return obj;
        }
    },
    decodeArray(data) {
        for (let i = 0; i < data.length; i++) {
            if (typeof data[i] == 'string') {
                data[i] = this.decode(data[i]);
            } else {
                data[i] = this.decodeObject(data[i]);
            }
        }
 
        return data;
    },
    decodeObject(data) {
        for (const prop in data) {
            if (data[prop]) {
                data[prop] = this.decode(data[prop]);
            }
        }
 
        return data;
    },
    convertToTreeData(data, parent,index,parentId) {
        const tempJson = data.find(f =>
            f.index_no === index
        )
        parent.children = {
            "id": tempJson.id,
            "parentId": parentId,
            "name": "审批人",
            "type": "APPROVAL",
            "children":{},//必须要 不然选中的值无法传递
            "props":
                {
                    "assignedType": "ASSIGN_USER",
                    "nobody": {
                        "handler": "TO_PASS",
                        "assignedUser": []
                    },
                    "refuse": {
                        "type": "TO_END",
                        "target": ""
                    },
                    "assignedUser": [{"id": tempJson.board_id||tempJson.rule_code, "name": tempJson.name,"type":tempJson.board_id!=null?"group":"staff"}],
                    "approvalGroup":tempJson.board_id!=null?{"id":tempJson.board_id,"name":tempJson.name}:"",
                    "staffGroup":tempJson.board_id!=null?"":{"id":tempJson.rule_code,"name":tempJson.name},
                }
        }
        //节点数组的大小 大于当前循环的 说明还有子项 继续循环
        if (data.length >index) {
            let getChildren = this.convertToTreeData(data, parent.children, index+1,parent.children.id)
            parent.children=getChildren
        }
        return parent;
    },
    //审批流树形结构转换为json
    dataTree(data, index, parentId) {
        let result = [];//存放结果
        let names = [];//存放审批人
        let ruleCode = [];//架构组
        data.props.assignedUser.forEach(org => names.push(org.name));
        let ids = []
        data.props.assignedUser.forEach(org => ids.push(org.id));
        // 修改的时候 根据选中类型是架构还是审批组 渲染数据
        if(data.props.assignedUser[0].type==='staff'){
            ids = [];
            data.props.assignedUser.forEach(org => ruleCode.push(org.id));
        }else{
            //判断选中的数据类型是架构还是审批组 如果是架构 将审批组清空 board_id置为空
            if (data.props.staffGroup!=undefined&& Object.keys(data.props.staffGroup).length!==0) {
                ids = [];
                data.props.assignedUser.forEach(org => ruleCode.push(org.id));
            }
        }
 
        //插入流程数组项
        result.push(
            {
                name: String(names).replaceAll(',', '、'),
                id: data.id||'',
                parent_id: parentId||'',
                index_no: index,
                board_id: ids.length > 0 ? String(ids).replaceAll(',', '、') : null,
                rule_code: ruleCode.length > 0 ? String(ruleCode).replaceAll(',', '、') : null
            }
        ) // 只取当前节点的信息,不包括 children
        //如果下面还有子项 继续往下读数据
        if (data.children!==undefined&&Object.keys(data.children).length !== 0) {
            let getChildren = this.dataTree(data.children, index + 1, parentId)
            result = result.concat(getChildren)
        }
 
        return result
    },
 
};