<template>
|
<GlobalWindow
|
:title="title"
|
:visible.sync="visible"
|
:confirm-working="isWorking"
|
@confirm="confirm"
|
>
|
<el-form :model="form" ref="form" style="margin-top:15px">
|
<el-form-item label="权限类型:" prop="type">
|
<el-select v-model="form.type" clearable filterable placeholder="请选择权限类型">
|
<el-option
|
v-for="(item, index) in options"
|
:key="index"
|
:label="item.name"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item v-if="form.type == 4" label="自定义部门:" prop="customData">
|
<el-cascader
|
:options="departments"
|
v-model="form.customData"
|
:props=defaultProps
|
clearable
|
></el-cascader>
|
</el-form-item>
|
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
// import Treeselect from 'vue-treeselect'
|
import { createRoleDataPermission } from '@/api/system/systemRole'
|
import { treeComList } from '@/api/ext/companyUserExt'
|
// import the styles
|
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
export default {
|
name: 'OperaSystemRoleWindow',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
options: [
|
{ name: '全部', id: 0 },
|
{ name: '所属部门及下属部门', id: 1 },
|
{ name: '所属部门及其子孙部门', id: 2 },
|
{ name: '仅所属部门', id: 3 },
|
{ name: '自定义部门', id: 4 }
|
],
|
// 表单数据
|
form: {
|
businessCode: null,
|
createTime: null,
|
createUser: null,
|
customData: [],
|
id: null,
|
roleId: null,
|
type: 0
|
},
|
defaultProps: {
|
multiple: true,
|
checkStrictly: true,
|
children: 'children',
|
label: 'name',
|
value: 'id',
|
emitPath: false
|
},
|
departments: []
|
}
|
},
|
created () {
|
this.config({
|
api: '/system/systemRole',
|
'field.id': 'id'
|
})
|
this.treeComList()
|
},
|
methods: {
|
// 部门树状结构数据
|
treeComList () {
|
treeComList({})
|
.then(res => {
|
// this.departments = this.tree([res])
|
this.departments = [res]
|
})
|
},
|
open (title, target) {
|
// console.log(title, target)
|
this.title = title
|
this.visible = true
|
// 新建
|
if (target == null) {
|
this.$nextTick(() => {
|
this.$refs.form.resetFields()
|
this.form[this.configData['field.id']] = null
|
})
|
return
|
}
|
// 编辑
|
this.$nextTick(() => {
|
for (const key in this.form) {
|
this.form[key] = target[key]
|
}
|
console.log(target);
|
if (target.customData === null || target.customData === '') {
|
this.form.customData = []
|
} else {
|
let customD = this.form.customData.split(',')
|
this.form.customData = customD.map((item) => { return parseInt(item) })
|
}
|
})
|
},
|
__confirmCreate () {
|
// console.log(JSON.stringify(this.form.customData));
|
// return
|
this.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
|
this.isWorking = true
|
let data = JSON.parse(JSON.stringify(this.form))
|
if (this.form.type === 4) {
|
data.customData = this.form.customData.join(',')
|
} else {
|
data.customData = ''
|
}
|
createRoleDataPermission(data)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('新建成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
})
|
},
|
__confirmEdit () {
|
// console.log(JSON.stringify(this.form.customData));
|
// return
|
this.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
// 调用更新接口
|
this.isWorking = true
|
let data = JSON.parse(JSON.stringify(this.form))
|
if (this.form.type === 4) {
|
data.customData = this.form.customData.join(',')
|
} else {
|
data.customData = ''
|
}
|
createRoleDataPermission(data)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('修改成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
})
|
}
|
}
|
}
|
</script>
|