You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.0 KiB
Vue
130 lines
3.0 KiB
Vue
<template>
|
|
<el-dialog
|
|
class="addUserDialog"
|
|
:title="title"
|
|
:visible.sync="isShow"
|
|
:close-on-click-modal="false"
|
|
width="470px"
|
|
@close="handleclose"
|
|
>
|
|
<el-form
|
|
label-position="left"
|
|
ref="formInfo"
|
|
label-width="100px"
|
|
:rules="title == '新增' ? rules : xgrules"
|
|
:model="formdata"
|
|
>
|
|
<el-form-item label="角色名称:" prop="roleName">
|
|
<el-input
|
|
placeholder="请输入角色名称"
|
|
v-model="formdata.roleName"
|
|
autocomplete="off"
|
|
></el-input>
|
|
</el-form-item>
|
|
</el-form>
|
|
<div slot="footer" class="dialog-footer">
|
|
<el-button @click="isShow = false">取 消</el-button>
|
|
<el-button type="primary" @click="submitForm()">确 定</el-button>
|
|
</div>
|
|
</el-dialog>
|
|
</template>
|
|
<script>
|
|
import { addUserApi, updateUserApi } from "@/utils/api/index";
|
|
export default {
|
|
props: {
|
|
title: String,
|
|
},
|
|
data() {
|
|
return {
|
|
roleUser: "",
|
|
isShow: false,
|
|
|
|
formdata: {},
|
|
rules: {
|
|
roleName: [
|
|
{ required: true, message: "请输入用户名", trigger: "blur" },
|
|
],
|
|
},
|
|
xgrules: {
|
|
roleName: [
|
|
{ required: true, message: "请输入用户名", trigger: "blur" },
|
|
],
|
|
},
|
|
};
|
|
},
|
|
methods: {
|
|
//判断
|
|
getdataform(val) {
|
|
console.log(val);
|
|
if (val == null) {
|
|
return (this.formdata = {
|
|
role: 2,
|
|
});
|
|
}
|
|
//this.formdata = val;
|
|
this.formdata = JSON.parse(JSON.stringify(val));
|
|
},
|
|
// 保存确定操作
|
|
submitForm() {
|
|
this.$refs.formInfo.validate((valid) => {
|
|
if (valid) {
|
|
if (this.title == "新增") {
|
|
addUserApi(this.formdata)
|
|
.then((res) => {
|
|
if (res.code == 200) {
|
|
this.$message({
|
|
duration: 1500,
|
|
showClose: true,
|
|
message: "添加成功",
|
|
type: "success",
|
|
});
|
|
this.isShow = false;
|
|
} else {
|
|
this.$message.error(res.msg);
|
|
}
|
|
})
|
|
.catch((err) => {});
|
|
} else {
|
|
updateUserApi(this.formdata)
|
|
.then((res) => {
|
|
if (res.code == 200) {
|
|
this.$message.success("修改成功");
|
|
this.isShow = false;
|
|
} else {
|
|
this.$message.error(res.msg);
|
|
}
|
|
})
|
|
.catch((err) => {});
|
|
}
|
|
} else {
|
|
console.log("error submit!!");
|
|
return false;
|
|
}
|
|
});
|
|
},
|
|
display() {
|
|
this.isShow = true;
|
|
this.roleUser = localStorage.getItem("role");
|
|
},
|
|
hide() {
|
|
this.isShow = false;
|
|
},
|
|
handleclose() {
|
|
this.$parent.roleListAll();
|
|
},
|
|
},
|
|
mounted() {},
|
|
};
|
|
</script>
|
|
<style lang="less">
|
|
.addUserDialog {
|
|
.el-form-item {
|
|
.el-input,
|
|
.el-select,
|
|
.el-input-number {
|
|
width: 100%;
|
|
}
|
|
}
|
|
}
|
|
</style>
|