<template>
|
<div class="edit-dropdown-box">
|
<el-dialog
|
:title="'编辑下拉框>' + editDropdownConfig.title"
|
:visible.sync="editConfig.editVisible"
|
:width="dialogWidth"
|
:before-close="handleClose"
|
:append-to-body="true"
|
>
|
<el-table :data="tableData" style="width: 100%" :header-cell-style="{ background: '#f4f8fe' }">
|
<el-table-column label="名称" prop="name">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.name" size="mini"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column label="显示颜色" prop="color">
|
<template slot-scope="scope">
|
<el-color-picker v-model="scope.row.color" size="small" @change="colorClick(scope.row)"></el-color-picker>
|
</template>
|
</el-table-column>
|
<el-table-column label="设为默认" prop="setDefault">
|
<template slot-scope="scope">
|
<el-switch
|
v-model="scope.row.setDefault"
|
active-color="#2E68DB"
|
inactive-color="#AEB9CA"
|
size="mini"
|
@change="setDefaultClick(scope.row)"
|
>
|
</el-switch>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" width="110px">
|
<template slot-scope="scope">
|
<i
|
v-if="scope.$index !== tableData.length - 1"
|
class="el-icon-bottom common-style"
|
title="下移"
|
@click="moveDownClick(scope.$index, scope.row)"
|
></i>
|
<i
|
v-if="scope.$index !== 0"
|
class="el-icon-top common-style"
|
title="上移"
|
@click="moveUpClick(scope.$index, scope.row)"
|
></i>
|
<i class="el-icon-delete common-style" title="删除" @click="deleteClick(scope.$index, scope.row)"></i>
|
</template>
|
</el-table-column>
|
</el-table>
|
<div style="padding: 10px">
|
<el-button type="text" size="mini" @click="addDropdown">新增下拉框</el-button>
|
<el-button type="text" size="mini">恢复默认颜色</el-button>
|
</div>
|
<div slot="footer">
|
<el-button type="primary" size="small" @click="editConfig.editVisible = false">保存</el-button>
|
<el-button size="small" @click="editConfig.editVisible = false">取消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
export default {
|
name: "EditDropdownDialog",
|
props: {
|
editDropdownConfig: {
|
type: Object,
|
default: () => {
|
return {
|
editVisible: false,
|
title: "",
|
infomation: {
|
name: "",
|
color: "",
|
setDefault: ""
|
}
|
}
|
}
|
}
|
},
|
components: {},
|
computed: {},
|
data() {
|
return {
|
dialogWidth: "20%",
|
editConfig: this.editDropdownConfig,
|
tableData: [
|
{
|
name: "1",
|
color: "red",
|
setDefault: true
|
},
|
{
|
name: "2",
|
color: "blue",
|
setDefault: false
|
},
|
{
|
name: "3",
|
color: null,
|
setDefault: false
|
},
|
{
|
name: "4",
|
color: null,
|
setDefault: false
|
}
|
]
|
}
|
},
|
created() {},
|
methods: {
|
handleClose() {
|
this.editConfig.editVisible = false
|
},
|
// 颜色选择
|
colorClick(row) {
|
console.log(row)
|
},
|
// 设为默认
|
setDefaultClick(row) {
|
if (row.setDefault) {
|
if (this.tableData !== null) {
|
this.tableData = this.tableData.map((item) => {
|
if (item.name !== row.name) {
|
item.setDefault = false
|
}
|
return item
|
})
|
}
|
}
|
},
|
// 上移
|
moveUpClick(index) {
|
var that = this
|
const upData = that.tableData[index - 1]
|
that.tableData.splice(index - 1, 1)
|
that.tableData.splice(index, 0, upData)
|
},
|
// 下移
|
moveDownClick(index) {
|
var that = this
|
const downData = that.tableData[index + 1]
|
that.tableData.splice(index + 1, 1)
|
that.tableData.splice(index, 0, downData)
|
},
|
// 删除
|
deleteClick(row) {
|
let id = this.tableData.findIndex((item) => {
|
if (item.name === row.name) {
|
return true
|
}
|
})
|
this.tableData.splice(id, 1)
|
},
|
// 新增下拉框
|
addDropdown() {
|
this.tableData.push({
|
name: "5",
|
color: null,
|
setDefault: false
|
})
|
}
|
}
|
}
|
</script>
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
<style lang="scss" scoped>
|
// .edit-dropdown-box {
|
// }
|
.common-style {
|
font-size: 16px;
|
margin-left: 10px;
|
cursor: pointer;
|
}
|
.first {
|
margin-left: 0px;
|
}
|
</style>
|