|
@@ -90,6 +90,7 @@ export default {
|
|
|
authAllPrice: [],
|
|
|
leafNode:[],
|
|
|
checkLeafNode:[],
|
|
|
+ priceCheckNode:[],
|
|
|
form: {},
|
|
|
rules: {},
|
|
|
authType: '1',
|
|
@@ -165,9 +166,18 @@ export default {
|
|
|
const _this = this
|
|
|
this.$refs.ruleForm.validate(valid => {
|
|
|
if (valid) {
|
|
|
- const arr = [...this.checkedKeys, ...this.halfCheckedKeys, ...this.checkedData].filter((x, index,self)=>self.indexOf(x)===index)
|
|
|
- console.log(this.checkedData)
|
|
|
-
|
|
|
+ // 功能权限时的已选价格菜单或价格权限时的已选功能菜单
|
|
|
+ const checkData = this.authType == 1 ? this.priceCheckNode : this.checkedData.filter(item => !this.priceCheckNode.includes(item))
|
|
|
+ // 功能权限时,首次半选节点拿不到值(this.halfCheckedKeys为空时),
|
|
|
+ // 此时通过从所有已选checkedData数据中过滤当前选择的功能菜单和已选的价格菜单,剩下的就是半选节点
|
|
|
+ let halfCheckedKeys = this.halfCheckedKeys.length ? this.halfCheckedKeys : this.checkedData.filter(item => ![...this.checkedKeys,...checkData].includes(item))
|
|
|
+ // 功能权限没有选择任何菜单或价格权限时,halfCheckedKeys 半选节点为空
|
|
|
+ if(this.checkedKeys.length==0 || this.authType == 0){
|
|
|
+ halfCheckedKeys = []
|
|
|
+ }
|
|
|
+ // 最终保存的节点,包括当前已选的和半选的节点
|
|
|
+ const arr = [...this.checkedKeys, ...halfCheckedKeys, ...checkData].filter((x, index,self)=>self.indexOf(x)===index)
|
|
|
+ console.log(arr, '--444--')
|
|
|
_this.spinning = true
|
|
|
addMenuPower({ id: this.id, menuIds: arr.join(',') }).then(res => {
|
|
|
if (res.status == 200) {
|
|
@@ -257,6 +267,25 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ // 根据id查找是否价格菜单
|
|
|
+ getPriceTreeNode(data, arr){
|
|
|
+ const _this = this
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ const node = data[i]
|
|
|
+ if(_this.isPriceNode(node)){
|
|
|
+ // 默认回显已选节点
|
|
|
+ const hasCheck = _this.priceCheckNode.find(item => item == node.id)
|
|
|
+ // 已选节点勾选
|
|
|
+ const hasNode = arr.find(item => item == node.id)
|
|
|
+ if (hasNode && !hasCheck) {
|
|
|
+ _this.priceCheckNode.push(node.id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (node.children && node.children.length) {
|
|
|
+ _this.getPriceTreeNode(node.children, arr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
pageInit(){
|
|
|
this.id = this.nowData.role.id
|
|
|
this.titleText = (this.nowData.type == 1 ? '功能权限分配': '价格权限分配') + '(' + this.nowData.role.name + ')'
|
|
@@ -265,20 +294,26 @@ export default {
|
|
|
// 权限类型, 1功能权限设置,0 价格权限设置
|
|
|
this.authType = this.nowData.type
|
|
|
this.checkedData = arr ? arr.split(',') : []
|
|
|
+
|
|
|
// 找出叶子节点
|
|
|
const treeData = this.nowData.allMenuList
|
|
|
-
|
|
|
this.expandedKeys.push(treeData.id)
|
|
|
+
|
|
|
+ // 获取已选的价格菜单
|
|
|
+ this.getPriceTreeNode(treeData, this.checkedData)
|
|
|
+
|
|
|
+ // 功能权限设置
|
|
|
if(this.authType == 1){
|
|
|
this.findLeaf(treeData, this.checkedData)
|
|
|
}
|
|
|
+ // 价格权限设置
|
|
|
if(this.authType == 0){
|
|
|
this.findPrice(treeData, this.checkedData)
|
|
|
this.hasAllSelect()
|
|
|
}
|
|
|
- this.checkedData = this.checkedData.filter(item => !this.checkedKeys.includes(item))
|
|
|
- // console.log(this.checkedData)
|
|
|
// console.log(this.checkedKeys)
|
|
|
+ // console.log(this.checkedData)
|
|
|
+
|
|
|
this.treeData = treeData
|
|
|
|
|
|
if(this.authType == 0){
|
|
@@ -308,6 +343,7 @@ export default {
|
|
|
this.id = ''
|
|
|
this.authAllPrice = []
|
|
|
this.checkLeafNode = []
|
|
|
+ this.priceCheckNode = []
|
|
|
this.leafNode = []
|
|
|
this.checkedKeys = []
|
|
|
this.expandedKeys = []
|