最终效果图:
完整代码:
<template>
<div>
<div>
<div slot="header" class="clearfix">
<span class="dbzt">督办主题</span>
<span>
<el-button
style="float: right; padding: 3px 10px"
type="text"
icon="el-icon-plus"
@click="handleAdd"
v-hasRole="['jwgly']"
></el-button>
</span>
</div>
<el-menu default-active="0" class="el-menu-vertical-demo">
<template v-for="(item, index) in rcjd_jdztList">
<el-menu-item :index="index" :key="index" style="line-height: 20px;height: 60px;padding: 10px 20px;" @click="handleClick(index)">
<!-- <i class="el-icon-menu"></i> -->
<div class="themeTitle">
<div style="font-weight: 600;">{{item.themeName}}</div>
<div>{{item.createTime}}</div>
</div>
<div class="operation">
<div>
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(item)"
v-hasRole="['jwgly']"
>修改</el-button>
</div>
<div>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(item)"
v-hasRole="['jwgly']"
>删除</el-button>
</div>
</div>
</el-menu-item>
</template>
</el-menu>
</div>
<!-- 添加或修改责任监督设置-主题对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="主题名称" prop="themeName">
<el-input v-model="form.themeName" placeholder="请输入主题名称" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
listRcjd_jdzt,
getRcjd_jdzt,
delRcjd_jdzt,
addRcjd_jdzt,
updateRcjd_jdzt,
exportRcjd_jdzt
} from "@/api/zhjd/rcjd_jdzt";
export default {
name: "Rcjd_jdzt",
components: {},
data() {
return {
// 遮罩层
loading: true,
// 导出遮罩层
exportLoading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 责任监督设置-主题表格数据
rcjd_jdztList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {},
// 表单参数
form: {},
// 表单校验
rules: {
themeName: [
{
required: true,
message: "主题名称不能为空",
trigger: "blur"
}
]
}
};
},
created() {
this.getList();
},
methods: {
/** 查询责任监督设置-主题列表 */
getList() {
this.loading = true;
listRcjd_jdzt(this.queryParams).then(response => {
// 如果 rows 大于零 则将第一条数据返回给 父组件
if (response.rows.length > 0) {
var obj = response.rows[0];
this.$emit("firstLoad", obj);
this.rcjd_jdztList = response.rows;
this.total = response.total;
this.loading = false;
} else {
this.rcjd_jdztList = response.rows;
this.total = response.total;
this.loading = false;
}
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: null,
themeName: null,
createTime: null,
createBy: null,
updateTime: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加主题";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids;
getRcjd_jdzt(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改责任监督设置-主题";
});
},
handleClick(index) {
var obj = this.rcjd_jdztList[parseInt(index)];
this.$emit("callback", obj);
// 如果选项卡被点击则清除父组件的 firstThemeId
this.$emit("clear");
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateRcjd_jdzt(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addRcjd_jdzt(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm(
'是否确认删除责任监督设置-主题编号为"' + ids + '"的数据项?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}
)
.then(function() {
return delRcjd_jdzt(ids);
})
.then(() => {
this.getList();
this.msgSuccess("删除成功");
})
.catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有责任监督设置-主题数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
this.exportLoading = true;
return exportRcjd_jdzt(queryParams);
})
.then(response => {
this.download(response.msg);
this.exportLoading = false;
})
.catch(() => {});
}
}
};
</script>
<style scoped>
.themeTitle:hover + div {
display: block;
}
.operation:hover {
display: block;
}
.operation {
display: none;
z-index: 999;
position: fixed;
width: 100px;
text-align: center;
margin-top: -32px;
margin-left: 140px;
background-color: #ffffff;
box-shadow: 1px 0px 14px 1px #ccc9c9;
}
.dbzt {
margin-left: 18px;
font-weight: 600;
line-height: 34px;
}
</style>