addProject.vue
3.38 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<template>
<dialogBox title="配置常办项目" @submitForm="submitForm" saveButton="保存" :isFullscreen="false" width="50%"
@closeDialog="closeDialog" v-model="myValue">
<Tree :data="projectList" show-checkbox node-key="id" :default-checked-keys="defaultCheckeds" ref="tree"
default-expand-all :props="defaultProps" @check-change="handleClick" />
</dialogBox>
</template>
<script>
import { getMenuInfo } from "@/api/user.js";
import Tree from "@/components/Tree/src/tree.vue"
import { saveFrequentProjectsList, getHomeFrequentProjects } from "@/api/home.js";
export default {
components: {
Tree
},
props: {
value: { type: Boolean, default: false },
bindItem: { type: Array, default: [] }
},
data () {
return {
myValue: false,
defaultCheckeds: [],
projectList: [],
checkedItem: [],
defaultProps: {
children: "children",
label: "name",
disabled: function (data, node) {
if (data.children && data.children.length > 0) {
return true
} else {
return false
}
}
},
uniqueValue: ''//最后拿到的唯一选择的moduldCode值,相当于id
}
},
watch: {
value (val) {
this.myValue = val
if (val) {
this.queryClick()
}
}
},
mounted () {
this.dealCheckedItem();
},
methods: {
/**
* @description: submitForm
* @author: renchao
*/
submitForm () {
var checkedNodes = this.$refs.tree.getCheckedNodes();
if (checkedNodes.length > 6) {
this.$message.error("最多选择6个项目!");
return
}
saveFrequentProjectsList(checkedNodes).then(res => {
if (res.code == 200) {
this.$parent.queryProjectList();
this.$message.success("保存成功");
this.$emit("input", false);
} else {
this.$message.error(res.message);
}
})
},
/**
* @description: queryClick
* @author: renchao
*/
queryClick () {
let that = this
getMenuInfo().then(res => {
this.projectList = res.result.slice(0, -2)
})
function lookForAllId (arr = []) {
for (let item of that.bindItem) {
arr.push(item.id)
if (item.children && item.children.length) lookForAllId(item.children, arr)
}
return arr
}
this.defaultCheckeds = lookForAllId()
},
/**
* @description: dealCheckedItem
* @author: renchao
*/
dealCheckedItem () {
},
//关闭窗口
/**
* @description: 关闭窗口
* @author: renchao
*/
closeDialog () {
this.$emit("input", false);
},
//节点选择状态发生改变时
/**
* @description: 节点选择状态发生改变时
* @param {*} data
* @param {*} checked
* @param {*} node
* @author: renchao
*/
handleClick (data, checked, node) {
var checkedNodes = this.$refs.tree.getCheckedNodes();
if (checkedNodes.length > 6) {
this.$message({
message: '最后选择6条数据',
type: 'warning',
customClass: 'messageIndex'
})
this.$refs.tree.setChecked(data, false) // 取消当前节点的选中状态
}
}
}
}
</script>
<style scoped lang='scss'>
/deep/.el-tree-node.is-expanded>.el-tree-node__children {
display: flex;
flex-wrap: wrap;
}
</style>