pms/web/src/view/superAdmin/authority/components/datas.vue

96 lines
3.0 KiB
Vue
Raw Normal View History

2020-01-07 15:57:34 +08:00
<template>
<div>
2020-01-07 16:37:21 +08:00
<div class="clearflex" style="margin:18px">
2020-01-07 15:57:34 +08:00
<el-button @click="authDataEnter" class="fl-right" size="small" type="primary"> </el-button>
2020-01-07 16:37:21 +08:00
<el-button @click="all" class="fl-left" size="small" type="primary">全选</el-button>
<el-button @click="self" class="fl-left" size="small" type="primary">本部门</el-button>
<el-button @click="selfAndChildren" class="fl-left" size="small" type="primary">部门及以下</el-button>
2020-01-07 15:57:34 +08:00
</div>
<el-checkbox-group v-model="dataAuthorityId" @change="selectAuthority">
<el-checkbox v-for="(item,key) in authoritys" :label="item" :key="key">{{item.authorityName}}</el-checkbox>
</el-checkbox-group>
</div>
</template>
<script>
import {setDataAuthority} from '@/api/authority'
export default {
name: 'Datas',
data() {
return {
authoritys:[],
dataAuthorityId:[]
}
},
props: {
row: {
default: function() {
return {}
},
type: Object
},
authority: {
default: function() {
return {}
},
type: Array
}
},
methods:{
2020-01-07 16:37:21 +08:00
all(){
this.dataAuthorityId = [...this.authoritys]
2020-01-07 16:42:44 +08:00
this.row.dataAuthorityId = this.dataAuthorityId
2020-01-07 16:37:21 +08:00
},
self(){
2020-04-04 21:39:07 +08:00
this.dataAuthorityId = this.authoritys.filter(item=>item.authorityId===this.row.authorityId)
2020-01-07 16:42:44 +08:00
this.row.dataAuthorityId = this.dataAuthorityId
2020-01-07 16:37:21 +08:00
},
selfAndChildren(){
const arrBox = []
this.getChildrenId(this.row,arrBox)
2020-04-04 21:39:07 +08:00
this.dataAuthorityId = this.authoritys.filter(item=>arrBox.indexOf(item.authorityId)>-1)
2020-01-07 16:42:44 +08:00
this.row.dataAuthorityId = this.dataAuthorityId
2020-01-07 16:37:21 +08:00
},
getChildrenId(row,arrBox){
2020-04-04 21:39:07 +08:00
arrBox.push(row.authorityId)
2020-01-07 16:37:21 +08:00
row.children&&row.children.map(item=>{
this.getChildrenId(item,arrBox)
})
},
2020-01-07 15:57:34 +08:00
// 提交
async authDataEnter(){
const res = await setDataAuthority(this.row)
if(res.success){
this.$message({ type: 'success', message: res.msg })
}
},
// 平铺角色
roundAuthority(authoritys){
authoritys&&authoritys.map(item=>{
const obj = {}
2020-04-04 21:39:07 +08:00
obj.authorityId = item.authorityId
2020-01-07 15:57:34 +08:00
obj.authorityName = item.authorityName
this.authoritys.push(obj)
if(item.children.length){
this.roundAuthority(item.children)
}
})
},
// 选择
selectAuthority(){
this.row.dataAuthorityId = this.dataAuthorityId
}
},
created() {
this.authoritys = []
this.dataAuthorityId = []
this.roundAuthority(this.authority)
this.row.dataAuthorityId&&this.row.dataAuthorityId.map(item=>{
2020-04-04 21:39:07 +08:00
const obj = this.authoritys&&this.authoritys.filter(au=>au.authorityId === item.authorityId)&&this.authoritys.filter(au=>au.authorityId === item.authorityId)[0]
2020-01-07 15:57:34 +08:00
this.dataAuthorityId.push(obj)
})
}
}
</script>
<style lang="less">
</style>