<template>
<el-dialog
title="列表字段设置"
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose"
>
<el-checkbox
class="pl-20 w100"
style="height: 50px; background-color: #f5f5f7"
:indeterminate="isIndeterminate"
v-model="checkAll"
@change="handleCheckAllChange"
>
<span class="ml-20 fw-800">字段</span>
<span class="fw-800" style="margin-left: 280px">拖拽排序</span>
</el-checkbox>
<el-checkbox class="pl-20 w100" checked style="height: 50px">
<span class="ml-20 fw-600">姓名</span>
</el-checkbox>
<el-tree
:data="data"
show-checkbox
node-key="id"
icon-class="el"
default-expand-all
@node-drag-start="handleDragStart"
@node-drag-enter="handleDragEnter"
@node-drag-leave="handleDragLeave"
@node-drag-over="handleDragOver"
@node-drag-end="handleDragEnd"
@node-drop="handleDrop"
draggable
:allow-drop="allowDrop"
:allow-drag="allowDrag"
>
</el-tree>
<span slot="footer" class="dialog-footer">
<el-button size="mini" @click="dialogVisible = false">取 消</el-button>
<el-button size="mini" type="primary" @click="dialogVisible = false"
>确 定</el-button
>
</span>
</el-dialog>
</template>
<script>
export default {
data() {
return {
dialogVisible: false,
checkAll: false,
isIndeterminate: true,
defaultProps: {
children: 'children',
label: 'label'
},
data: [
{
id: 1,
label: '一级 1'
},
{
id: 2,
label: '一级 2'
},
{
id: 3,
label: '一级 3'
}
]
}
},
methods: {
// handleClose(done) {
// this.$confirm('确认关闭?')
// .then((_) => {
// done()
// })
// .catch((_) => {})
// },
onShow() {
this.dialogVisible = true
// console.log(this.cities, 'cities')
console.log(123, 'cities')
},
//
handleDragStart(node, ev) {
console.log('drag start', node)
},
handleDragEnter(draggingNode, dropNode, ev) {
console.log('tree drag enter: ', dropNode.label)
},
handleDragLeave(draggingNode, dropNode, ev) {
console.log('tree drag leave: ', dropNode.label)
},
handleDragOver(draggingNode, dropNode, ev) {
console.log('tree drag over: ', dropNode.label)
},
handleDragEnd(draggingNode, dropNode, dropType, ev) {
console.log('tree drag end: ', dropNode && dropNode.label, dropType)
},
handleDrop(draggingNode, dropNode, dropType, ev) {
console.log('tree drop: ', dropNode.label, dropType)
},
allowDrop(draggingNode, dropNode, type) {
if (dropNode.data.label) {
return type !== 'inner'
} else {
return true
}
},
allowDrag(draggingNode) {
return draggingNode.data.label.indexOf('三级 3-2-2') === -1
},
//
handleCheckAllChange(val) {
this.checkedCities = val ? cityOptions : []
this.isIndeterminate = false
},
handleCheckedCitiesChange(value) {
let checkedCount = value.length
this.checkAll = checkedCount === this.cities.length
this.isIndeterminate =
checkedCount > 0 && checkedCount < this.cities.length
}
}
}
</script>
<style scoped>
::v-deep .el-checkbox {
display: flex;
align-items: center;
padding: 0 20px;
}
::v-deep .el-checkbox__label {
color: #343435 !important;
}
::v-deep .el-tree-node__expand-icon {
display: none;
}
::v-deep .el-tree-node__label {
font-weight: 600;
}
::v-deep .el-tree-node__label {
/* 保证:after为元素的显示 */
background-image: url('');
}
::v-deep .el-tree-node__label:after {
display: inline-block;
background-image: url('../../assets/icon/caidan.png');
background-position: center center;
background-size: 40px 20px;
content: '';
width: 40px;
height: 20px;
/* visibility: hidden; 隐藏content中的内容*/
margin-left: 280px;
}
::v-deep .el-tree-node {
height: 50px;
display: flex;
align-items: center;
}
</style>