code init
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
<template>
|
||||
<el-col :span="span">
|
||||
<el-form-item
|
||||
:label="config.attrName"
|
||||
:prop="config.attrField"
|
||||
label-width="150px"
|
||||
class="add-form-item"
|
||||
:class="{'form-item-disabled': disabled}"
|
||||
>
|
||||
<el-input
|
||||
:value="value"
|
||||
:placeholder="'请选择' + config.attrName"
|
||||
readonly
|
||||
:disabled="disabled"
|
||||
:id="config.attrField"
|
||||
@click.native="visible = true"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-drawer
|
||||
:title="config.attrName"
|
||||
:visible.sync="visible"
|
||||
:wrapper-closable="false"
|
||||
size="350px"
|
||||
append-to-body
|
||||
class="org-tree"
|
||||
@opened="drawerOpen"
|
||||
>
|
||||
<dept-tree
|
||||
:ref="config.attrField"
|
||||
:all-dept="allDept"
|
||||
:show-user="config.selVal === 'USERLIST'"
|
||||
:check-enable="true"
|
||||
:deptSelect="true"
|
||||
:treeDivId="config.attrField + 'Tree'"
|
||||
:editable="false"
|
||||
:onlyChecked="config.attrType === 'SEL_OPTS'"
|
||||
@treeOnCheck="handleTreeOnCheck"
|
||||
@treeDblClick="handleTreeDblClick">
|
||||
</dept-tree>
|
||||
|
||||
<div class="demo-drawer-footer">
|
||||
<el-button
|
||||
round
|
||||
class="common-button-primary"
|
||||
icon="el-icon-check"
|
||||
type="primary"
|
||||
@click="handleTreeDrawerConfirm">确定
|
||||
</el-button>
|
||||
<el-button
|
||||
round
|
||||
class="common-button-default"
|
||||
icon="el-icon-close"
|
||||
@click="handleTreeDrawerCancel">取消</el-button>
|
||||
</div>
|
||||
</el-drawer>
|
||||
</el-col>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'OrgTree',
|
||||
props: {
|
||||
config: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
value: {
|
||||
required: true
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 栅格比例
|
||||
span: {
|
||||
type: Number,
|
||||
default: 24
|
||||
},
|
||||
// 是否显示全部部门
|
||||
allDept: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
zNodes: {
|
||||
type: Array,
|
||||
default: () => {
|
||||
return []
|
||||
}
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
visible: false,
|
||||
treeCheckNode: [],
|
||||
checkedName: ''
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
placeholder () {
|
||||
return `请选择${this.config.attrName}`
|
||||
},
|
||||
showMessage () {
|
||||
return `${this.config.attrName}不能为空`
|
||||
},
|
||||
isRequired () {
|
||||
return !!this.config.isMust
|
||||
},
|
||||
isString (str) {
|
||||
return (typeof str === 'string') && str.constructor === String
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleTreeDblClick (treeId, treeNode) {
|
||||
console.log(treeNode.id)
|
||||
this.checkedName = treeNode.name
|
||||
this.$emit('input', treeNode.id)
|
||||
this.visible = false
|
||||
},
|
||||
handleTreeOnCheck (treeCheckNode) {
|
||||
this.treeCheckNode = treeCheckNode
|
||||
},
|
||||
getShowName (id) {
|
||||
let name = ''
|
||||
this.zNodes.map(item => {
|
||||
if (item.id === id) {
|
||||
name = item.oldname || item.name
|
||||
}
|
||||
})
|
||||
return name
|
||||
},
|
||||
handleTreeDrawerConfirm () {
|
||||
console.log(this.config.selVal)
|
||||
console.log(this.treeCheckNode)
|
||||
if (this.config.selVal === 'USERLIST') {
|
||||
const checkedList = []
|
||||
const checkedNameList = []
|
||||
this.treeCheckNode.map(item => {
|
||||
if (!item.isParent) {
|
||||
checkedList.push(item.id)
|
||||
checkedNameList.push(item.name)
|
||||
}
|
||||
})
|
||||
console.log(checkedNameList)
|
||||
this.checkedName = checkedNameList.join(',')
|
||||
console.log(this.checkedName)
|
||||
this.$emit('input', checkedList.join(','))
|
||||
} else {
|
||||
const checkedList = []
|
||||
const checkedNameList = []
|
||||
this.treeCheckNode.map(item => {
|
||||
checkedList.push(item.id)
|
||||
if (item.oldname) {
|
||||
checkedNameList.push(item.oldname)
|
||||
} else {
|
||||
checkedNameList.push(item.name)
|
||||
}
|
||||
})
|
||||
this.checkedName = checkedNameList.join(',')
|
||||
console.log(this.checkedName)
|
||||
this.$emit('input', checkedList.join(','))
|
||||
}
|
||||
this.visible = false
|
||||
},
|
||||
handleTreeDrawerCancel () {
|
||||
this.visible = false
|
||||
},
|
||||
// 赋值回显人员和部门
|
||||
drawerOpen () {
|
||||
let checkedArr = this.config.value ? this.config.value.split(',') : []
|
||||
if (checkedArr.length > 0) {
|
||||
setTimeout(() => {
|
||||
this.$nextTick(() => {
|
||||
this.$refs[this.config.attrField].checkedNode(checkedArr)
|
||||
})
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value (newVal) {
|
||||
console.log(newVal)
|
||||
this.checkedName = newVal || ''
|
||||
},
|
||||
checkedName (val) {
|
||||
console.log(val)
|
||||
this.$emit('update:value', val)
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.checkedName = this.config.valueName || ''
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user