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
|
},
|
|
};
|