addGroupCom copy.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. v-model="dialogVisible"
  5. width="400px"
  6. @close="closeDialog(0)"
  7. @open="open"
  8. >
  9. <el-form
  10. ref="formInfo"
  11. :model="form"
  12. class="demo-form-inline"
  13. label-width="100px"
  14. :rules="rules"
  15. >
  16. <el-form-item label="分组名称:" prop="watchName">
  17. <el-input v-model="form.watchName" ></el-input>
  18. </el-form-item>
  19. <div style="text-align: right">
  20. <el-button type="primary" @click="submitForm('formInfo')"
  21. >保存</el-button
  22. >
  23. </div>
  24. </el-form>
  25. </el-dialog>
  26. </template>
  27. <script>
  28. export default {
  29. name: "AddGroupCom",
  30. props: {
  31. dialogTitle: {
  32. type: String,
  33. default: "新建分组",
  34. },
  35. itemInfo: {
  36. type: Object,
  37. default: function () {
  38. return {};
  39. },
  40. },
  41. },
  42. data() {
  43. return {
  44. checked: true,
  45. showDialog: false,
  46. formInfo: JSON.parse(JSON.stringify(this.itemInfo)),
  47. rules: {
  48. watchName: [
  49. // required 是否为必填项, trigger:表单验证的触发时机,失去焦点进行验证
  50. { required: true, message: "请输入分组名称", trigger: "blur" },
  51. {
  52. min: 3,
  53. max: 6,
  54. message: "用户名长度在 3 到 6 个字符",
  55. trigger: "blur",
  56. },
  57. ],
  58. },
  59. };
  60. },
  61. methods: {
  62. roleValid(rule, value, callback) {
  63. if (value.length === 0) {
  64. callback(new Error("不能为空"));
  65. } else {
  66. callback();
  67. }
  68. },
  69. // 保存操作
  70. submitForm(formName) {
  71. const params = Object.assign(this.formInfo, {});
  72. params
  73. this.$refs[formName].validate((valid) => {
  74. if (valid) {
  75. // 走保存请求
  76. this.$message({
  77. message: "操作成功!",
  78. type: "success",
  79. });
  80. this.closeDialog(1);
  81. } else {
  82. return false;
  83. }
  84. });
  85. },
  86. // 关闭弹框
  87. closeDialog(flag) {
  88. this.$refs["formInfo"].resetFields();
  89. this.showDialog = false;
  90. this.$emit("closeDialog", flag);
  91. },
  92. },
  93. };
  94. </script>
  95. <style scoped lang="scss">
  96. </style>