You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.0 KiB

2 years ago
<template>
<div>
<xy-dialog ref="dialog" :width="40" :is-show.sync="isShow" :type="'form'" :title="'目录授权'" :form="form"
:rules='rules' @submit="submit">
<template v-slot:name>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>组织类型
</div>
<div class="xy-table-item-content">
{{form.name}}
</div>
</div>
</template>
<template v-slot:catalog_ids>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>授权目录
</div>
<div class="xy-table-item-content">
<el-tree v-if="isShow" @check="getSelectedNodes" :data="catalogList" show-checkbox default-expand-all node-key="id"
ref="tree" highlight-current :props="defaultProps">
</el-tree>
</div>
</div>
</template>
</xy-dialog>
</div>
</template>
<script>
import {
save,
show,
index
} from "@/api/system/baseForm.js"
import {
deepCopy,
isNull
} from "@/utils";
export default {
components: {
},
data() {
return {
isShow: false,
id: '',
2 years ago
catalogList: [],
catalogListBefore:[],
2 years ago
defaultProps: {
children: 'children',
label: 'name'
},
table_name: 'organize_types',
form: {
name: '',
2 years ago
catalog_ids: [],
catalog_names:''
2 years ago
},
rules: {}
}
},
created() {
this.getCatalogList()
},
methods: {
async getCatalogList() {
const res = await index({
page_size: 999,
page: 1,
sort_type: 'ASC',
sort_name: 'sort',
table_name: 'catalogs',
})
2 years ago
if (res.data.length > 0) {
this.catalogListBefore = this.base.deepCopy(res.data)
2 years ago
this.catalogList = this.base.buildTree(res.data)
}
},
getSelectedNodes() {
const selectedItems = this.$refs.tree.getCheckedKeys()
2 years ago
this.form.catalog_ids = selectedItems
let names = []
this.catalogListBefore.map(item=>{
if(selectedItems.includes(item.id)){
names.push(item.name)
}
})
this.form.catalog_names = names.join(",")
console.log("selectedItems",this.catalogListBefore, selectedItems,this.form.catalog_names)
2 years ago
},
submit() {
console.log("this.form", this.form)
save({
table_name: this.table_name,
...this.form
}).then(res => {
this.$message({
type: 'success',
message: '授权成功'
})
this.isShow = false
this.$emit('refresh')
})
},
getDetail() {
show({
id: this.id,
table_name: this.table_name,
}).then(res => {
2 years ago
this.form = this.base.requestToForm(res,this.form)
2 years ago
// this.$refs.tree.setCurrentKey(this.res.catalog_ids);
if(res.catalog_ids){
this.$refs.tree.setCheckedKeys(res.catalog_ids,false)
}
// setCurrentKey
console.log("this.form", this.form)
})
}
},
watch: {
isShow(newVal) {
if (newVal) {
this.getDetail()
} else {
2 years ago
this.id = ''
this.form = {
name: '',
catalog_ids: [],
catalog_names:''
}
2 years ago
this.$refs['dialog'].reset()
}
},
}
}
</script>
<style scoped lang="scss">
::v-deep .description,
::v-deep .name,
::v-deep .catalog_ids {
flex-basis: 100%;
}
::v-deep .catalog_ids .xy-table-item {
align-items: flex-start;
}
</style>