|
|
|
@ -1,12 +1,15 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<el-dialog ref="nf-dialog" |
|
|
|
<el-dialog |
|
|
|
|
|
|
|
ref="nf-dialog" |
|
|
|
class="nf-dialog" |
|
|
|
class="nf-dialog" |
|
|
|
v-model="visible" |
|
|
|
v-model="visible" |
|
|
|
title="部门选择" |
|
|
|
title="部门选择" |
|
|
|
width="60%" |
|
|
|
width="60%" |
|
|
|
:before-close="handleClose" |
|
|
|
:before-close="handleClose" |
|
|
|
append-to-body> |
|
|
|
append-to-body |
|
|
|
<avue-crud v-if="isInit" |
|
|
|
> |
|
|
|
|
|
|
|
<avue-crud |
|
|
|
|
|
|
|
v-if="isInit && visible" |
|
|
|
:option="option" |
|
|
|
:option="option" |
|
|
|
:table-loading="loading" |
|
|
|
:table-loading="loading" |
|
|
|
:data="data" |
|
|
|
:data="data" |
|
|
|
@ -14,21 +17,18 @@ |
|
|
|
ref="crud" |
|
|
|
ref="crud" |
|
|
|
@search-change="searchChange" |
|
|
|
@search-change="searchChange" |
|
|
|
@search-reset="searchReset" |
|
|
|
@search-reset="searchReset" |
|
|
|
@selection-change="selectionList=$event" |
|
|
|
@selection-change="selectionList = $event" |
|
|
|
@row-click="rowClick" |
|
|
|
@row-click="rowClick" |
|
|
|
@on-load="onLoad" |
|
|
|
@on-load="onLoad" |
|
|
|
@tree-load="treeLoad"> |
|
|
|
@tree-load="treeLoad" |
|
|
|
|
|
|
|
> |
|
|
|
</avue-crud> |
|
|
|
</avue-crud> |
|
|
|
<template #footer> |
|
|
|
<template #footer> |
|
|
|
<span class="dialog-footer"> |
|
|
|
<span class="dialog-footer"> |
|
|
|
<el-button @click="handleClose" |
|
|
|
<el-button @click="handleClose" size="default">取消</el-button> |
|
|
|
size="default">取消</el-button> |
|
|
|
<el-button type="primary" @click="handleConfirm" size="default">确定</el-button> |
|
|
|
<el-button type="primary" |
|
|
|
|
|
|
|
@click="handleConfirm" |
|
|
|
|
|
|
|
size="default">确定</el-button> |
|
|
|
|
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
</el-dialog> |
|
|
|
</el-dialog> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<script> |
|
|
|
<script> |
|
|
|
@ -40,20 +40,20 @@ export default { |
|
|
|
}, |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
watch: { |
|
|
|
visible: { |
|
|
|
visible: { |
|
|
|
handler (val) { |
|
|
|
handler(val) { |
|
|
|
if (val) this.changeDefaultChecked() |
|
|
|
if (val) this.changeDefaultChecked() |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
computed: { |
|
|
|
ids () { |
|
|
|
ids() { |
|
|
|
let ids = []; |
|
|
|
let ids = []; |
|
|
|
this.selectionList.forEach(ele => { |
|
|
|
this.selectionList.forEach(ele => { |
|
|
|
ids.push(ele[this.props.id]); |
|
|
|
ids.push(ele[this.props.id]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return ids.join(","); |
|
|
|
return ids.join(","); |
|
|
|
}, |
|
|
|
}, |
|
|
|
names () { |
|
|
|
names() { |
|
|
|
let names = []; |
|
|
|
let names = []; |
|
|
|
this.selectionList.forEach(ele => { |
|
|
|
this.selectionList.forEach(ele => { |
|
|
|
names.push(ele[this.props.name]); |
|
|
|
names.push(ele[this.props.name]); |
|
|
|
@ -61,7 +61,7 @@ export default { |
|
|
|
return names.join(","); |
|
|
|
return names.join(","); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
data () { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
isInit: false, |
|
|
|
isInit: false, |
|
|
|
visible: false, |
|
|
|
visible: false, |
|
|
|
@ -113,11 +113,11 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted () { |
|
|
|
mounted() { |
|
|
|
this.init() |
|
|
|
this.init() |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
init () { |
|
|
|
init() { |
|
|
|
if (!this.isInit) { |
|
|
|
if (!this.isInit) { |
|
|
|
if (this.customOption) { |
|
|
|
if (this.customOption) { |
|
|
|
const { deptColumn, deptProps } = this.customOption |
|
|
|
const { deptColumn, deptProps } = this.customOption |
|
|
|
@ -127,7 +127,7 @@ export default { |
|
|
|
this.isInit = true |
|
|
|
this.isInit = true |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
handleConfirm () { |
|
|
|
handleConfirm() { |
|
|
|
if (this.selectionList.length === 0) { |
|
|
|
if (this.selectionList.length === 0) { |
|
|
|
this.$message.warning("请至少选择一项") |
|
|
|
this.$message.warning("请至少选择一项") |
|
|
|
return |
|
|
|
return |
|
|
|
@ -135,16 +135,16 @@ export default { |
|
|
|
this.$emit('confirm', this.ids, this.names) |
|
|
|
this.$emit('confirm', this.ids, this.names) |
|
|
|
this.handleClose() |
|
|
|
this.handleClose() |
|
|
|
}, |
|
|
|
}, |
|
|
|
handleClose (done) { |
|
|
|
handleClose(done) { |
|
|
|
// this.selectionClear() |
|
|
|
// this.selectionClear() |
|
|
|
this.visible = false |
|
|
|
this.visible = false |
|
|
|
if (done && typeof done == 'function') done() |
|
|
|
if (done && typeof done == 'function') done() |
|
|
|
}, |
|
|
|
}, |
|
|
|
searchReset () { |
|
|
|
searchReset() { |
|
|
|
this.query = {} |
|
|
|
this.query = {} |
|
|
|
this.onLoad(this.page) |
|
|
|
this.onLoad(this.page) |
|
|
|
}, |
|
|
|
}, |
|
|
|
searchChange (params, done) { |
|
|
|
searchChange(params, done) { |
|
|
|
this.query = { |
|
|
|
this.query = { |
|
|
|
...params, |
|
|
|
...params, |
|
|
|
parentId: '' |
|
|
|
parentId: '' |
|
|
|
@ -153,26 +153,31 @@ export default { |
|
|
|
this.onLoad(this.page, params) |
|
|
|
this.onLoad(this.page, params) |
|
|
|
done() |
|
|
|
done() |
|
|
|
}, |
|
|
|
}, |
|
|
|
selectionClear () { |
|
|
|
selectionClear() { |
|
|
|
this.selectionList = [] |
|
|
|
this.selectionList = [] |
|
|
|
if (this.$refs.crud) this.$refs.crud.toggleSelection() |
|
|
|
if (this.$refs.crud) this.$refs.crud.toggleSelection() |
|
|
|
}, |
|
|
|
}, |
|
|
|
rowClick (row) { |
|
|
|
rowClick(row) { |
|
|
|
this.$refs.crud.toggleSelection([row]) |
|
|
|
this.$refs.crud.toggleSelection([row]) |
|
|
|
}, |
|
|
|
}, |
|
|
|
changeDefaultChecked () { |
|
|
|
changeDefaultChecked() { |
|
|
|
this.selectionClear() |
|
|
|
// this.selectionClear() |
|
|
|
if (this.defaultChecked) { |
|
|
|
if (this.defaultChecked) { |
|
|
|
const checks = this.defaultChecked.split(",") |
|
|
|
const checks = this.defaultChecked.split(",") |
|
|
|
if (checks.length > 0) { |
|
|
|
if (checks.length > 0) { |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
checks.forEach(c => { |
|
|
|
checks.forEach(c => { |
|
|
|
const row = this.findRow(this.data, c) |
|
|
|
let row = this.findRow(this.data, c) |
|
|
|
if (row) this.$refs.crud.toggleRowSelection(row, true) |
|
|
|
if (!row) { |
|
|
|
|
|
|
|
row = this.selectionList.find(d => d.id == c) // 勾选列表查找 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (row && this.$refs.crud) this.$refs.crud.toggleRowSelection(row, true) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}, 500) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
findRow (list, id) { |
|
|
|
findRow(list, id) { |
|
|
|
if (!list) return |
|
|
|
if (!list) return |
|
|
|
for (let i = 0; i < list.length; i++) { |
|
|
|
for (let i = 0; i < list.length; i++) { |
|
|
|
const data = list[i] |
|
|
|
const data = list[i] |
|
|
|
@ -180,7 +185,7 @@ export default { |
|
|
|
else if (data.children) return this.findRow(data.children, id) |
|
|
|
else if (data.children) return this.findRow(data.children, id) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
onLoad (page, params = {}) { |
|
|
|
onLoad(page, params = {}) { |
|
|
|
this.loading = true; |
|
|
|
this.loading = true; |
|
|
|
const param = { |
|
|
|
const param = { |
|
|
|
parentId: 0, |
|
|
|
parentId: 0, |
|
|
|
@ -189,15 +194,21 @@ export default { |
|
|
|
this.$axios.get(this.url, { params: param }).then(res => { |
|
|
|
this.$axios.get(this.url, { params: param }).then(res => { |
|
|
|
this.data = this.getAsVal(res, this.props.data) || [] |
|
|
|
this.data = this.getAsVal(res, this.props.data) || [] |
|
|
|
this.loading = false |
|
|
|
this.loading = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDefaultChecked() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
treeLoad (tree, treeNode, resolve) { |
|
|
|
treeLoad(tree, treeNode, resolve) { |
|
|
|
const parentId = tree.id; |
|
|
|
const parentId = tree.id; |
|
|
|
this.$axios.get(this.url, { params: { parentId } }).then(res => { |
|
|
|
this.$axios.get(this.url, { params: { parentId } }).then(res => { |
|
|
|
resolve(this.getAsVal(res, this.props.data) || []); |
|
|
|
const list = this.getAsVal(res, this.props.data) || [] |
|
|
|
|
|
|
|
resolve(list) |
|
|
|
|
|
|
|
const parent = this.findRow(this.data, parentId) |
|
|
|
|
|
|
|
parent.children = list |
|
|
|
|
|
|
|
this.changeDefaultChecked() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
getAsVal (obj, bind = '') { |
|
|
|
getAsVal(obj, bind = '') { |
|
|
|
let result = this.deepClone(obj) |
|
|
|
let result = this.deepClone(obj) |
|
|
|
if (this.validatenull(bind)) return result |
|
|
|
if (this.validatenull(bind)) return result |
|
|
|
bind.split('.').forEach(ele => { |
|
|
|
bind.split('.').forEach(ele => { |
|
|
|
|